這個問題有點難。 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiMultimedia/html/delphi_20061104112712179.html
我想得到其它應用程式的視窗大小和地區,不知道怎麼辦?請高手指點。
最好能有原始碼。
var aRect: TRect;
begin
GetWindowRect(Handle,aRect);
ShowMessage(Format('(%d,%d,%d,%d) Height:%d Width:%d',[aRect.Left,aRect.Top,aRect.Right,aRect.Bottom,aRect.Bottom-aRect.Top,aRect.Right-aRect.Left]));
end;
樓上的是用視窗控制代碼取得視窗大小
別的應用程式的視窗控制代碼用 FindWindow 取得
Handle := FindWindow(nil, '視窗的標題');
如果視窗標題相同就沒辦法了, 會找到第一個相同的視窗
恩,高手。謝謝你們。
不過我還有一個問題,我想滑鼠移動到一個視窗上的時候,把它的邊框加粗(用顏色顯示出來),這個通過你們的提示已經可以實現了,可是,我想在滑鼠離開的時候就還原,怎麼對別的應用程式的視窗實現這個功能,感覺一畫上去就不知道怎麼還原了,給點提示。謝謝了。。。
我還想問一個問題。用什麼方法可以通過控制代碼得到其它視窗邊框的顏色。謝謝各位的參與。
越問越多了哈
COLORREF GetPixel(
HDC hdc,// handle of device context
int XPos,// x-coordinate of pixel
int nYPos // y-coordinate of pixel
);
得到定點處的 Color
要的參數是 DC
HDC GetDC(
HWND hWnd // handle of window
);
用你的視窗控制代碼取得
忘了說 上面 getdc 是取得客戶區的, 想取得整個視窗可以用
HDC GetDCEx(
HWND hWnd,// handle of window
HRGN hrgnClip,// handle of clip region
DWORD flags // device-context creation flags
);
怕你還問, 再說, 那兩個 pos 是相對於視窗的, 相對於螢幕的 pos 要作一次轉換
BOOL ClientToScreen(
HWND hWnd,// window handle for source coordinates
LPPOINT lpPoint // pointer to structure containing screen coordinates
);
用的是(delphi)TPoint 結構
取得 mouse 當前位置的是
BOOL GetCursorPos(
LPPOINT lpPoint // address of structure for cursor position
);
相對 delphi 參數應該是 var Point: TPoint, 這個取得的是相對螢幕的 mouse cursor 位置
上面 ClientToScreen 說倒了, 你要用 ScreenToClient