|
-
Aug 1st, 2008, 09:34 AM
#1
[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
Anyone got any better methods or point out what I'm doing wrong?
Cheers
Chris
Last edited by chris128; Aug 1st, 2008 at 09:38 AM.
-
Aug 1st, 2008, 11:11 AM
#2
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
-
Aug 1st, 2008, 11:33 AM
#3
Re: Maximise active window
hai chris,
actually you try to maximize the window or close it or what
-
Aug 1st, 2008, 12:13 PM
#4
Re: Maximise active window
 Originally Posted by Fazi
hai chris,
actually you try to maximize the window or close it or what 
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.
Last edited by chris128; Aug 1st, 2008 at 01:20 PM.
-
Aug 1st, 2008, 01:01 PM
#5
Re: Maximise active window
sorry chris,
i am vb6 and in vb6 that code look like ok
-
Aug 1st, 2008, 01:16 PM
#6
Re: Maximise active window
 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
-
Aug 6th, 2008, 12:13 PM
#7
Re: Maximise active window
no one else got any ideas?
-
Aug 7th, 2008, 01:00 AM
#8
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.
-
Aug 7th, 2008, 04:12 AM
#9
Re: Maximise active window
Thanks I'll give that a go Oh and I'm using VB.NET btw, not VB6.
-
Aug 7th, 2008, 04:29 AM
#10
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.
_
-
Aug 7th, 2008, 04:43 AM
#11
Re: Maximise active window
 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.
_
Works perfectly thanks!
-
Aug 7th, 2008, 04:53 AM
#12
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.
-
Aug 7th, 2008, 04:54 AM
#13
Re: [RESOLVED] Maximise active window
Will do
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
|