|
-
Feb 3rd, 2000, 03:56 AM
#1
Thread Starter
New Member
I have a problem for the more advanced users out there... perhaps someone knows the answer.
I am trying to find the co-ordinates for a window other than my application. The article from MSDN at http://msdn.microsoft.com/library/ps...ndows_4f73.htm tells me I can use 'GetWindowInfo' to find this, but it returns a pointer to a structure, and I need to read data from the sub-structure of that structure... is it possible? Can anyone provide me with a snippet of code that, given a hWnd (Window Handle) will tell me the x,y co-ordinates of the window... also, can anyone find a way of telling me if the window has focus.
-----
Even harder: can I sub-class another window? I want to know whenever the window I have the hWnd for loses focus, or changes its size without having to deal with any event. Is this possible?
Anyone succeeding in solving either of these two problems will have my respect forever :-)
JamesW
-
Feb 3rd, 2000, 04:06 AM
#2
You don't have to use GetWindowInfo API to get the information you want. Instead, you can use GetWindowRect to find out the coordinates and GetForgroundWindow to find ou the window that has a focus.
Code:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Command1_Click()
Dim rec As RECT
Dim lHwnd As Long
Dim strMsg As String
Call GetWindowRect(Me.hwnd, rec)
lHwnd = GetForegroundWindow
strMsg = "X: " & rec.Left & vbCrLf
strMsg = strMsg & "Y: " & rec.Top & vbCrLf
If lHwnd = Me.hwnd Then
strMsg = strMsg & "Window is the windows that has focus."
Else
strMsg = strMsg & "Window is the windows that doesn't have focus."
End If
MsgBox strMsg
End Sub
For this example I've used a form in my project, but you can substitute that with the valid Window Handle (hWnd) of your choice.
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 02-03-2000).]
-
Feb 3rd, 2000, 04:28 AM
#3
Thread Starter
New Member
You have my eternal gratitude :-) in case you ever need it
If you ever need any help with TCP/IP development, networking, etc. please call me!
James.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|