-
Mar 18th, 2015, 10:17 AM
#1
Thread Starter
New Member
[RESOLVED] Get the active window size
I need to get the active window size [ Width,Height ]
I was searching for a hours on Google but...
I'm a beginner so I didn't really understand so much
what ever, after playing with api and searching
here what I got
(put a timer1 and 2 text(text1,2)
Code:
Private Declare Function M_GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
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 Function GetActiveWindow() As Long
Dim xHwnd As Long
xHwnd = M_GetActiveWindow()
GetActiveWindow = xHwnd
End Function
Sub GetWindowSize(ByVal hWnd As Long, Width As Long, Height As Long)
Dim rc As RECT
GetWindowRect hWnd, rc
Width = rc.Right - rc.Left
Height = rc.Bottom - rc.Top
End Sub
Private Sub Timer1_Timer()
Dim rc As RECT
Call GetWindowRect(GetActiveWindow, rc)
Text1.Text = rc.Right - rc.Left
Text2.Text = rc.Bottom - rc.Top
End Sub
the code above working with my form,but not working for other program windows
it should get the size of any active window
please edit the code above or if there is a better way to do what I'm looking for
any help would be appreciate
thanks in advance.
-
Mar 18th, 2015, 11:05 AM
#2
Re: Get the active window size
What are you trying to do here? Are you just trying to move the text box on your form based on the size of whatever window is active? If so that doesn't make a lot of sense to do if not then I can't guess what you are trying to do so you would need to be more descriptive of what you are trying to do and what problems you are facing.
-
Mar 18th, 2015, 11:09 AM
#3
Thread Starter
New Member
Re: Get the active window size
Originally Posted by DataMiser
What are you trying to do here? Are you just trying to move the text box on your form based on the size of whatever window is active? If so that doesn't make a lot of sense to do if not then I can't guess what you are trying to do so you would need to be more descriptive of what you are trying to do and what problems you are facing.
I trying to get window width and height
not my program window, any other program window.
-
Mar 18th, 2015, 11:21 AM
#4
Re: Get the active window size
Use the GetForeGroundWindow API function instead of GetActiveWindow:
Code:
Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long
-
Mar 18th, 2015, 11:34 AM
#5
Thread Starter
New Member
Re: Get the active window size
Originally Posted by Peter Swinkels
Use the GetForeGroundWindow API function instead of GetActiveWindow:
Code:
Private Declare Function GetForegroundWindow Lib "User32.dll" () As Long
Million of thanks for you ♥
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
|