在compact framwork中add horizontal scroll to listbox

我在XdaII(多普達696英文版)中作應用程序開發,其中涉及到爲listbox添加水平滾動條。核心代碼如下:

 

         const int GWL_STYLE = (-16);

         const int LB_SETHORIZONTALEXTENT  = 0x0194;

         const long WS_HSCROLL    =      0x00100000L;

         const int SWP_FRAMECHANGED  = 0x0020;

         const int SWP_NOMOVE        =    0x0002; 

         const int SWP_NOSIZE        =    0x0001; 

         const int SWP_NOZORDER      =    0x0004;

         const int WM_VSCROLL        =    0x0115;

         const int SB_BOTTOM         =    7;

 

         [DllImport("coredll.dll")]      

         static extern IntPtr GetCapture();  

         [DllImport("coredll.dll")]      

         static extern uint SendMessage(IntPtr hwnd, int msg, int wParam, int lParam);      

         [DllImport("coredll.dll")]      

         static extern uint GetWindowLong(IntPtr hwnd, int index);

         [DllImport("coredll.dll")]      

         static extern uint SetWindowLong(IntPtr hwnd, int index,uint dwNewLong);

         [DllImport("coredll.dll")]      

         static extern uint SetWindowPos(IntPtr hwnd, IntPtr hWndInsertAfter,int x,int y,int cx,int cy,uint uFlags);

private void ModifyStyle(uint addStyle, uint removeStyle)

         { // Get current window style

              uint windowStyle = GetWindowLong(GetCapture(), GWL_STYLE);

              if (addStyle != 0)

              { // Modify style

                   SetWindowLong(GetCapture(), GWL_STYLE, windowStyle | addStyle);

              }

              else

              {

                   // Remove style

                   SetWindowLong(GetCapture(), GWL_STYLE, windowStyle & ~removeStyle);

              }

              // Let the window know

              SetWindowPos(GetCapture(), IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_FRAMECHANGED);

             

     }

private void FrmDispatchJob_Load(object sender, System.EventArgs e)

         {

              this.listBox_Job.Capture=true;

              IntPtr handle=GetCapture();

              SendMessage(handle, LB_SETHORIZONTALEXTENT, 250,0);

              SendMessage(handle, WM_VSCROLL, SB_BOTTOM,0);

              ModifyStyle((uint)WS_HSCROLL, 0);

              this.listBox_Job.Capture=false;

     }

但是莫名的遇見下列行爲異常:

Ok, on this screen, it is normal. Without touching anything.

On this screen, I tapped the white part of the scroll bar in GREEN.  The text will shift to the right, but the indicator (IN RED) does not move to the right.  It stays on the left side.

並且我在.net framework 中也做了相應的測試,行爲還是如上異常。

我搜羅,對比了一下,並且發現在vb6.0中用如下所述http://www.freevbcode.com/ShowCode.asp?ID=5362&NoBox=True

實現add horizontal scroll to listbox 結果一切正常。二者之間沒有本質的區別呀?爲什麼我用c#實現出來的add horizontal scroll to listbox 行爲會有問題呢?很是不解,所以拿來跟大家一起探討,還請各位不吝賜教! 
發佈了18 篇原創文章 · 獲贊 16 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章