2 回答

TA貢獻(xiàn)1942條經(jīng)驗 獲得超3個贊
先看SendMessage
SendMessage(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam);
第一個參數(shù)HWND hWnd
故名思議是窗體句柄,你這兒作為參數(shù)傳遞進(jìn)來了
第二個參數(shù)UINT Msg
是windows消息常量,這里使用到兩個0x201,0x202,還是百科就可以找到,如下:
WM_LBUTTONDOWN = $0201;//按下鼠標(biāo)左鍵
WM_LBUTTONUP = $0202;//釋放鼠標(biāo)左鍵
第三個參數(shù)WPARAM wParam
MSDN里頭有這么一段
WM_LBUTTONDOWN
WPARAM wParam
LPARAM lParam;
Parameters
wParam
Indicates whether various virtual keys are down. This parameter can be one or more of the following values.
MK_CONTROL
The CTRL key is down.
MK_LBUTTON
The left mouse button is down.//這句是重點(diǎn)了,而后我查找MK_LBUTTON的值,就是定義為 0x01.也就是為什么是(IntPtr)1。
第四個參數(shù)LPARAM IParam
MSDN里說到
lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
這里說到低位代表X坐標(biāo),指向左上角,高位則代表Y坐標(biāo)。從代碼中的(IntPtr)(y * 65536 + x)參數(shù)不難分析到,y * 65536相當(dāng)于<<16。65536代表16位數(shù)據(jù)的數(shù)據(jù)量,這個是屬于位的運(yùn)算。比如0-65535是個16位unsigned int類型的數(shù)據(jù)范圍,一共能取到的數(shù)就是65536.這個數(shù)據(jù)是個32位的數(shù)據(jù),前16位代表了X坐標(biāo)值,后16位為Y值,所以按照這個寫法應(yīng)該是正確的。

TA貢獻(xiàn)1830條經(jīng)驗 獲得超3個贊
SendMessage 第二個參數(shù),指定發(fā)送的消息類型, 如鼠標(biāo)消息WM_LBUTTONDOWN,WM_MOUSEMOVE等。鍵盤消息:WM_KEYDOWN,WM_KEYUP
沒問題,最后2個參數(shù)也不必轉(zhuǎn)成句柄。
- 2 回答
- 0 關(guān)注
- 512 瀏覽
添加回答
舉報