請問如何得知滑鼠移入、移出工作列? |
答題得分者是:Cyril
|
小野豬
一般會員 ![]() ![]() 發表:2 回覆:5 積分:1 註冊:2003-05-04 發送簡訊給我 |
|
Cyril
一般會員 ![]() ![]() 發表:1 回覆:2 積分:10 註冊:2008-12-03 發送簡訊給我 |
這是一個笨方法,使用SHAppBarMessage() API去取得TaskBar的Rect,接著再用GetCursorPos()取得滑鼠在整個Screen的位置,最後
就判斷滑鼠的位置是否在取到的Rect中,整個Catch滑鼠位置改變是用簡單的Timer元件,你也使用其它方式讓系統通知你滑鼠的位置改變 的CALLBACK函數,再由該函數實做。 procedure TForm1.Timer1Timer(Sender: TObject); var AppBarData: TAppBarData; CursorPos: TPoint; begin ZeroMemory(@AppBarData, sizeof(TAppBarData)); AppBarData.cbSize := sizeof(TAppBarData); AppBarData.hWnd := Handle; SHAppBarMessage(ABM_GETTASKBARPOS, AppBarData); ZeroMemory(@CursorPos, sizeof(CursorPos)); GetCursorPos(CursorPos); if ((CursorPos.x >= AppBarData.rc.Left) and (CursorPos.x <= AppBarData.rc.Right) and (CursorPos.y >= AppBarData.rc.Top) and (CursorPos.y <= AppBarData.rc.Bottom)) then begin //滑鼠移入工作列 OutputDebugString(PChar('滑鼠移入工作列')); end else begin //滑鼠移出工作列 OutputDebugString(PChar('滑鼠移出工作列')); end; end; |
小野豬
一般會員 ![]() ![]() 發表:2 回覆:5 積分:1 註冊:2003-05-04 發送簡訊給我 |
感謝 Cyril 的答案
我後來在web查了好多資料, 參照不同的作法 :=(,); :=(,,,); :=(,,,); :=(,,,); :=(,,,); 轉貼至http://www.52delphi.com/list.asp?id=87 這樣的方法可以取得系統工作列上的按鈕, 後來我改用以下的方式再加上MouseHook 就行了 function TForm1.TaskmanWindow: HWND; var hShellTrayWnd:HWND; begin hShellTrayWnd := FindWindow('Shell_TrayWnd', nil); Result := hShellTrayWnd; end; function TForm1.fn_MouseInToolBar(var hdWindow:HWND):Boolean; var hdParentWin:HWND; begin if hdWindow=0 then //桌面 begin Result := False; Exit; end; // Result := (hdWindow=TaskmanWindow); if not Result then begin hdParentWin := GetParent(hdWindow); Result := fn_MouseInToolBar(hdParentWin); end; end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |