 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
albedoa
Joined: 18 May 2008 Posts: 18
|
Posted: Wed Aug 06, 2008 3:37 pm Post subject: Can't grasp basic understanding of SetWindowPos() |
|
|
I have just discovered DLLCall, and I read the Microsoft documentation for SetWindowPos() ( http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx ), but still don't understand what any of it means. I can see that one of the variables is for the window handle, but I don't know how to get a handle or exactly what it means to be a handle. I'm pretty lost.
Can someone write a simple example of a DLLCall to SetWindowPos() and explain what each particular part is and what it does? I feel as though I could get a grasp on this if it were just explained once.
Thank you! |
|
| Back to top |
|
 |
BoBo² Guest
|
Posted: Wed Aug 06, 2008 3:58 pm Post subject: |
|
|
ControlGet, hwnd
WinGet, id |
|
| Back to top |
|
 |
albedoa
Joined: 18 May 2008 Posts: 18
|
Posted: Wed Aug 06, 2008 4:14 pm Post subject: |
|
|
I appreciate the attempt at helping me, but my confusion must run a bit deeper than you presume. With what you gave me, I did this:
| Code: | WinGet id,, Untitled - Notepad
DllCall("SetWindowPos", "uint", id, "uint", HWND_TOP) |
Nothing happened. Shouldn't that send Notepad to the top? I got it to be always on top by doing this:
| Code: | WinGet id,, Untitled - Notepad
DllCall("SetWindowPos", "uint", id, "uint", -1) |
And then I sent it behind some other windows by doing this:
| Code: | WinGet id,, Untitled - Notepad
DllCall("SetWindowPos", "uint", id, "uint", 2) |
I am reading the parameter list, but I must be missing something simple. A more thorough walkthrough of any of my examples would make it click. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Aug 06, 2008 6:00 pm Post subject: |
|
|
| Code: | DllCall("SetWindowPos", "uint", hwnd, "uint", HWND_TOP)
MsgBox %Errorlevel% |
above code returns A-20 which is
| manual wrote: | | An (the letter A followed by an integer n): The function was called but was passed too many or too few arguments. "n" is the number of bytes by which the argument list was incorrect. If n is positive, too many arguments (or arguments that were too large) were passed, or the call requires CDecl. If n is negative, too few arguments were passed. This situation should be corrected to ensure reliable operation of the function. The presence of this error may also indicate that an exception occurred, in which case the function returns a blank value. |
refer to msdn SetWindowPos() The syntax is
| Code: | BOOL SetWindowPos(
HWND hWnd,
HWND hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
UINT uFlags
); |
you've missed red colored arguments. correct usage of it is
| Code: | hwnd := WinExist("ahk_class Notepad") ;get handle
DllCall("SetWindowPos"
, "UInt", hWnd ;handle
, "UInt", 0 ;HWND_TOP
, "Int", 0 ;x
, "Int", 0 ;y
, "Int", 300 ;width
, "Int", 300 ;height
, "UInt", 0x4000) ;SWP_ASYNCWINDOWPOS |
when msdn describes arguments such as HWND_TOP and SWP_ASYNCWINDOWPOS you should put the constants behind it.
for example google "#define HWND_TOP" to get the constant of HWND_TOP. in this case the constant for HWND_TOP is 0
however there are handy tools to do this easily such as Easy WinAPI and Win32 Constants |
|
| Back to top |
|
 |
albedoa
Joined: 18 May 2008 Posts: 18
|
Posted: Wed Aug 06, 2008 7:42 pm Post subject: |
|
|
| Now I am thinking I am completely lost. Is the code you posted supposed to do something? Because it doesn't on my system. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Aug 06, 2008 7:52 pm Post subject: |
|
|
| open notepad first then run the code |
|
| Back to top |
|
 |
albedoa
Joined: 18 May 2008 Posts: 18
|
Posted: Wed Aug 06, 2008 7:57 pm Post subject: |
|
|
Heh, I did. It must be something simple. This is my code:
| Code: | f1::
hWnd := WinExist("ahk_class Notepad") ;get handle
DllCall("SetWindowPos"
, "UInt", hWnd ;handle
, "UInt", 0 ;HWND_TOP
, "Int", 0 ;x
, "Int", 0 ;y
, "Int", 300 ;width
, "Int", 300 ;height
, "UInt", 0x4000) ;SWP_ASYNCWINDOWPOS
return |
It does nothing. I can confirm that a handle is stored in hWnd, but the DllCall doesn't do anything.
Edit: Oh hey, that's a lie. It does resize and move the window, but isn't it supposed to reorder it on the Z axis? |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Aug 06, 2008 8:04 pm Post subject: |
|
|
| albedoa wrote: | | isn't it supposed to reorder it on the Z axis? | No but you can put -1 at hWndInsertAfter to set AlwaysOnTop which brings it to top anyway. otherwise you should call SetWindowLong. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Aug 06, 2008 8:06 pm Post subject: |
|
|
| Anonymous wrote: | | you should call SetWindowLong. | i mean SetForegroundWindow |
|
| Back to top |
|
 |
albedoa
Joined: 18 May 2008 Posts: 18
|
Posted: Wed Aug 06, 2008 8:17 pm Post subject: |
|
|
Ah, that's where my confusion lies. Thanks so much for the help. If you read this, can you tell me why the SetWindowPos() pages says:
| Quote: |
HWND_TOP
Places the window at the top of the Z order.
|
That's why I thought it was supposed to bring Notepad to the front. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Aug 06, 2008 8:36 pm Post subject: |
|
|
| that means puts the window at the top of Z order except current foreground window. so it'll be the foreground window when current foreground is minimized or gone |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Wed Aug 06, 2008 10:17 pm Post subject: |
|
|
why are you doing this all inside DllCall? The whole point of AHK is to wrap these dllcalls to make it easier to use. Do the AHK commands not do what you want in this case? _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
albedoa
Joined: 18 May 2008 Posts: 18
|
Posted: Thu Aug 14, 2008 1:29 am Post subject: |
|
|
Is there an AHK command to place a window second from the top? I thought my search was extensive.
The DllCall command is specifically for those calls which AHK lacks a command for, no? |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Thu Aug 14, 2008 5:30 am Post subject: |
|
|
i'm not sure about second from top. we can do top and bottom easily enough. You are correct that if there are no AHK commands, DllCall can usually do it. _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|