|
-
Jun 20th, 2005, 09:36 PM
#1
Thread Starter
Admodistrator
Help with Hwnds...
Sorry if the title is misleading, but i couldnt think of a name for it. I have a client called Trillian (like aim+msn+yahoo all in one buddylist)..
Well, i have this code ATM to find the thing and shrink it
VB Code:
Option Explicit
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim tWnd As Long
Dim frmname As String
Private Sub Form_Load()
frmname = "ConsoleWindowClass"
tWnd = FindWindow(frmname, vbNullString) ' Change stuff in quotes so it will shrink it!! i.e. for paint it would be "paint"
MsgBox tWnd
If tWnd <> 0 Then
SetWindowPos tWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
Else: MsgBox frmname & " not found!"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowPos tWnd, 0, 200, 0, 100, 100, SWP_SHOWWINDOW
MsgBox tWnd
End Sub
well, this is for shrinking Dos windows and resizing. Im wondering, is it possible to find the windows coordinates before resizing it, so i place it exactly as it was?
-
Jun 20th, 2005, 09:42 PM
#2
Re: Help with Hwnds...
Look for GetWindowRect in MSDN. you can use that.
-
Jun 20th, 2005, 09:50 PM
#3
Thread Starter
Admodistrator
Re: Help with Hwnds...
thanks bud. Almost there i think (at least for now)
my setwindowpos has 5 variables that go with it:
hwnd As Long, hWndInsertAfter As Long, x As Long, y As Long, cx As Long, cy As Long, wFlags As Long
but getwindowrect only uses 4..not sure what to do..
VB Code:
Option Explicit
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim tWnd As Long
Dim frmname As String
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim Sizeofwin As RECT
Private Sub Form_Load()
frmname = "ConsoleWindowClass"
tWnd = FindWindow(frmname, vbNullString) ' Change stuff in quotes so it will shrink it!! i.e. for paint it would be "paint"
MsgBox tWnd
GetWindowRect tWnd, Sizeofwin
If tWnd <> 0 Then
SetWindowPos tWnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
Else: MsgBox frmname & " not found!"
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowPos tWnd, Left, Top, Right, Bottom, , SWP_SHOWWINDOW
MsgBox tWnd
End Sub
-
Jun 20th, 2005, 10:07 PM
#4
Re: Help with Hwnds...
Your Sizeofwin contains the four coordinates you need:
(Sizeofwin.Left, Sizeofwin.Top) are the coordinates of the top left corner of the window.
(Sizeofwin.Bottom, Sizeofwin.Right) are coordinates of the bottom right corner.
So you use them in pairs. I am not sure what the x, cx, y and cy represent in the SetWindowPos.
-
Jun 20th, 2005, 10:15 PM
#5
Re: Help with Hwnds...
Ahh, here are the explanations:
Code:
· X
Specifies the new position of the left side of the window.
· Y
Specifies the new position of the top of the window.
· cx
Specifies the new width of the window, in pixels.
· cy
Specifies the new height of the window, in pixels.
So you would have:
X = Sizeofwin.Left
Y = Sizeofwin.Top
CX = Sizeofwin.Right - Sizeofwin.Left
CY = Sizeofwin.Top - Sizeofwin.Bottom
-
Jun 20th, 2005, 10:29 PM
#6
Thread Starter
Admodistrator
Re: Help with Hwnds...
so what am i doing wrong then?
VB Code:
Option Explicit
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Sub SetWindowPos Lib "User32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim tWnd As Long
Dim frmname As String
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Command1_Click(Index As Integer)
frmname = "ConsoleWindowClass"
tWnd = FindWindow(frmname, vbNullString) ' Change stuff in quotes so it will shrink it!! i.e. for paint it would be "paint"
MsgBox tWnd
GetWindowRect tWnd, Sizeofwin 'oLeft = Sizeofwin.Left: oTop = Sizeofwin.Top: oRight = Sizeofwin.Right: oBottom = Sizeofwin.Bottom
If tWnd <> 0 Then
SetWindowPos tWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
Else: MsgBox frmname & " not found!"
End If
End Sub
Private Sub Command2_Click()
SetWindowPos tWnd, Sizeofwin.Left, Sizeofwin.Top, Sizeofwin.Right - Sizeofwin.Left, Sizeofwin.Top - Sizeofwin.Bottom, Sizeofwin.Top - Sizeofwin.Bottom, SWP_SHOWWINDOW
End Sub
-
Jun 20th, 2005, 10:33 PM
#7
Re: Help with Hwnds...
try this instead (for command2)
SetWindowPos tWnd, -2, Sizeofwin.Left, Sizeofwin.Top, Sizeofwin.Right - Sizeofwin.Left, Sizeofwin.Top - Sizeofwin.Bottom, SWP_SHOWWINDOW
-
Jun 20th, 2005, 10:40 PM
#8
Re: Help with Hwnds...
or this if the above doesn't work:
SetWindowPos tWnd, HWND_TOP, Sizeofwin.Left, Sizeofwin.Top, Sizeofwin.Right - Sizeofwin.Left, Sizeofwin.Top - Sizeofwin.Bottom, SWP_SHOWWINDOW
-
Jun 20th, 2005, 10:50 PM
#9
Thread Starter
Admodistrator
Re: Help with Hwnds...
whats hwnd_top const value?
also, i think this is happening because the values arent being saved. I.E. it keeps the values until i call them again when its minimized. so i tried this:
VB Code:
Option Explicit
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Sub SetWindowPos Lib "User32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim tWnd As Long
Dim frmname As String
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim sizeofwin As RECT
Dim Oleft As Long, oTop As Long, oRight As Long, oBottom As Long
Private Sub Command1_Click(Index As Integer)
frmname = "ConsoleWindowClass"
tWnd = FindWindow(frmname, vbNullString) ' Change stuff in quotes so it will shrink it!! i.e. for paint it would be "paint"
MsgBox tWnd
GetWindowRect tWnd, sizeofwin 'oLeft = Sizeofwin.Left: oTop = Sizeofwin.Top: oRight = Sizeofwin.Right: oBottom = Sizeofwin.Bottom
Oleft = sizeofwin.Left: oTop = sizeofwin.Top: oRight = sizeofwin.Right: oBottom = sizeofwin.Bottom
If tWnd <> 0 Then
SetWindowPos tWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
Else: MsgBox frmname & " not found!"
End If
End Sub
Private Sub Command2_Click()
SetWindowPos tWnd, -2, Oleft, oTop, oRight - Oleft, oTop - oBottom, SWP_SHOWWINDOW
End Sub
but it still not working..what should i do next?
-
Jun 20th, 2005, 11:02 PM
#10
Re: Help with Hwnds...
Try plugging some real numbers. I don't think this is right, but I'm not sure.
I think you'd just specify coordinates instead of subtracting them.
VB Code:
oTop, oLeft, oBottom, oRight ' May be close
(Sizeofwin.Left, Sizeofwin.Top) are the coordinates of the top left corner of the window.
(Sizeofwin.Bottom, Sizeofwin.Right) are coordinates of the bottom right corner.
-
Jun 20th, 2005, 11:13 PM
#11
Thread Starter
Admodistrator
Re: Help with Hwnds...
almost...
VB Code:
Option Explicit
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Sub SetWindowPos Lib "User32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim tWnd As Long
Dim frmname As String
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim sizeofwin As RECT
Dim Oleft As Long, oTop As Long, oRight As Long, oBottom As Long
Private Sub Command1_Click(Index As Integer)
frmname = "ConsoleWindowClass"
tWnd = FindWindow(frmname, vbNullString) ' Change stuff in quotes so it will shrink it!! i.e. for paint it would be "paint"
MsgBox tWnd
GetWindowRect tWnd, sizeofwin 'oLeft = Sizeofwin.Left: oTop = Sizeofwin.Top: oRight = Sizeofwin.Right: oBottom = Sizeofwin.Bottom
Oleft = sizeofwin.Left: oTop = sizeofwin.Top: oRight = sizeofwin.Right: oBottom = sizeofwin.Bottom
If tWnd <> 0 Then
SetWindowPos tWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
Else: MsgBox frmname & " not found!"
End If
End Sub
Private Sub Command2_Click()
SetWindowPos tWnd, -2, Oleft, oTop, oRight, oBottom, SWP_SHOWWINDOW
End Sub
its on the screen now, but still not how i left it
-
Jun 20th, 2005, 11:14 PM
#12
Re: Help with Hwnds...
If your window is fixed size, you can hardoce the CX and CY as they are width and height. X and Y represent the position.
Regarding dglienas post, this is the explanation of the API:
Code:
Parameter Information
· hWnd
Identifies the window.
· lpRect
Points to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window.
as they are coordinates, they have to be subtracted.
-
Jun 20th, 2005, 11:17 PM
#13
Thread Starter
Admodistrator
Re: Help with Hwnds...
VB Code:
Private Sub Command2_Click()
SetWindowPos tWnd, -2, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_SHOWWINDOW
End Sub
still not right, but what is the -2? its what got it on the screen
-
Jun 20th, 2005, 11:18 PM
#14
Re: Help with Hwnds...
Try comparing real position values of the window with the values that the GetWindowRect returns.
-
Jun 20th, 2005, 11:20 PM
#15
Re: Help with Hwnds...
Also, try this (in command2):
SetWindowPos tWnd, -2, 0, 0, 0, 0, SWP_SHOWWINDOW
-
Jun 20th, 2005, 11:20 PM
#16
Thread Starter
Admodistrator
Re: Help with Hwnds...
how should i compare them? how do i see its 'real' coordinates?
-
Jun 20th, 2005, 11:21 PM
#17
Re: Help with Hwnds...
-2 is the value of the HWND_TOP constant. It brings it to the top.
-
Jun 20th, 2005, 11:23 PM
#18
Re: Help with Hwnds...
Post the values for each of these, and we should be able to see what's going on.
OLeft=
oTop=
oRight=
OBottom=
-
Jun 20th, 2005, 11:35 PM
#19
Thread Starter
Admodistrator
Re: Help with Hwnds...
okay
Before minimizing:
44:58:713:396
After opening:
44:58:713:732
so its this last one thats messing up.
-
Jun 20th, 2005, 11:40 PM
#20
Re: Help with Hwnds...
Did you try this: SetWindowPos tWnd, -2, 0, 0, 0, 0, SWP_SHOWWINDOW
I think that should leave it unchanged, and automatically open it in the original location.
-
Jun 20th, 2005, 11:45 PM
#21
Thread Starter
Admodistrator
Re: Help with Hwnds...
yes, that places the form with properties of 0,0,0,0
making it invisible..
-
Jun 20th, 2005, 11:49 PM
#22
Re: Help with Hwnds...
Try using these two lines:
Call SetWindowPos(tWnd, -1, 0, 0, 0, 0, 3)
Call SetWindowPos(tWnd, -2, 0, 0, 0, 0, 3)
They should bring the window to the top, without resizing it.
-
Jun 20th, 2005, 11:52 PM
#23
Thread Starter
Admodistrator
Re: Help with Hwnds...
well, in command1 when i hide it..
SetWindowPos tWnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
doesnt that make it 0000, so bringing it to the front without resizing will leave nothing.
let me try it though
-
Jun 20th, 2005, 11:55 PM
#24
Re: Help with Hwnds...
Actually, you are doing it wrong when minimizing. You are setting its size to Zero, instead of minimizing it.
-
Jun 21st, 2005, 12:00 AM
#25
Re: Help with Hwnds...
Tada! Done:
VB Code:
Option Explicit
Const SWP_HIDEWINDOW = &H80
Const SWP_SHOWWINDOW = &H40
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Sub SetWindowPos Lib "User32" _
(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, _
ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim tWnd As Long
Dim frmname As String
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim sizeofwin As RECT
Dim Oleft As Long, oTop As Long, oRight As Long, oBottom As Long
Private Sub Command1_Click()
frmname = "Notepad"
tWnd = FindWindow(frmname, vbNullString) ' Change stuff in quotes so it will shrink it!! i.e. for paint it would be "paint"
MsgBox tWnd
GetWindowRect tWnd, sizeofwin 'oLeft = Sizeofwin.Left: oTop = Sizeofwin.Top: oRight = Sizeofwin.Right: oBottom = Sizeofwin.Bottom
Oleft = sizeofwin.Left: oTop = sizeofwin.Top: oRight = sizeofwin.Right: oBottom = sizeofwin.Bottom
If tWnd <> 0 Then
SetWindowPos tWnd, -2, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_HIDEWINDOW
Else
MsgBox frmname & " not found!"
End If
End Sub
Private Sub Command2_Click()
SetWindowPos tWnd, -1, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_SHOWWINDOW
SetWindowPos tWnd, -2, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_SHOWWINDOW
DoEvents
End Sub
-
Jun 21st, 2005, 12:12 AM
#26
Thread Starter
Admodistrator
Re: Help with Hwnds...
Great!!Thanks alot there..
SetWindowPos tWnd, -1, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_SHOWWINDOW
SetWindowPos tWnd, -2, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_SHOWWINDOW
why do you have both there? just a mistake?
-
Jun 21st, 2005, 12:18 AM
#27
Re: Help with Hwnds...
Because I'm stupid. That's a dumb way of setting a window on top. The line with -1 turns on the Always on top, and the -2 turns it off, so it just brings it to the top.
A simple way is to use only one line which just brings the window on top of the ZOrder
SetWindowPos tWnd, 0, Oleft, oTop, oRight - Oleft, oBottom - oTop, SWP_SHOWWINDOW
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
|