[RESOLVED] Maximise active window
Hi Guys,
Anyone got any idea how to use an API to maximise whatever program currently has focus?
This is what I have so far:
vb.net Code:
Private Declare Function GetForeGroundWindow Lib "user32" Alias "GetForegroundWindow" () As IntPtr
Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_MAXIMIZE = 3
Then I'm using it like this:
vb.net Code:
ShowWindow(GetForeGroundWindow, SW_MAXIMIZE)
However, that just makes the active window dissapear for some reason... it doesnt close it, the process still remains running but it just hides the window :sick:
Anyone got any better methods or point out what I'm doing wrong?
Cheers
Chris
Re: Maximise active window
That should work but your GetForegroundWindow API ends with " As IntPtr", the VB6 API viewer show it "As Long"
Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Re: Maximise active window
hai chris,
actually you try to maximize the window or close it or what :confused: :D
Re: Maximise active window
Quote:
Originally Posted by Fazi
hai chris,
actually you try to maximize the window or close it or what :confused: :D
I am trying to maximize it... but when I use the code I posted, the window gets closed and that is not what I want.
Re: Maximise active window
sorry chris,
i am vb6 :sick: and in vb6 that code look like ok :(
Re: Maximise active window
Quote:
Originally Posted by Edgemeal
That should work but your GetForegroundWindow API ends with " As IntPtr", the VB6 API viewer show it "As Long"
Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Actually that bit works fine as I've been using GetForegroundWindow in other projects and havent had a problem. Its just the ShowWindow function that isnt working as I want it to :(
Re: Maximise active window
no one else got any ideas? :(
Re: Maximise active window
I'm pretty sure IntPtr is the problem.
I don't even think it exists in Vb6. Try it with a Long, if this is vb6.
It's probably assuming a variant type.
In .net it exists but it's not really the correct data type to match the ShowWindow function parameter.
Try all Longs as Integers, or Int32 instead.
There are a couple of other API's that will do what you want.
For example SetWindowPlacement, is the next one that comes to mind.
Re: Maximise active window
Thanks I'll give that a go :) Oh and I'm using VB.NET btw, not VB6.
Re: Maximise active window
Code:
Const SW_MAXIMIZE As Int32 = 3
Private Declare Function apiGetForeGroundWindow Lib "user32" Alias "GetForegroundWindow" () As Int32
Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Int32, ByVal nCmdShow As Int32) As Int32
Code:
apiShowWindow(apiGetForeGroundWindow, SW_MAXIMIZE)
Works fine here.:wave:
_
Re: Maximise active window
Quote:
Originally Posted by TTn
Code:
Const SW_MAXIMIZE As Int32 = 3
Private Declare Function apiGetForeGroundWindow Lib "user32" Alias "GetForegroundWindow" () As Int32
Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Int32, ByVal nCmdShow As Int32) As Int32
Code:
apiShowWindow(apiGetForeGroundWindow, SW_MAXIMIZE)
Works fine here.:wave:
_
Works perfectly :) thanks!
Re: [RESOLVED] Maximise active window
Good.
As you notice, I've put a prefix on the function call, so it is an actual Alias with a different name than the original function.
I've also declared the data type for the constant.
The data types match those, where they are being passed.
Stick to those rules consistently, and you'll be fine most of the time.:D
Re: [RESOLVED] Maximise active window