 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
guest3456 Guest
|
Posted: Tue Mar 16, 2010 3:42 am Post subject: creating a POINTS struct, NumPut problems, etc |
|
|
i'm trying to create a POINTS structure to pass to PostMessage
| Code: |
;POINTS STRUCTURE
;http://msdn.microsoft.com/en-us/library/dd162808%28VS.85%29.aspx
VarSetCapacity(POINTS, 4, 0)
NumPut(1905, POINTS, 0, "Short") ; x-coord
NumPut(258, POINTS, 2, "Short") ; y-coord
PostMessage, 0xA1,11, &POINTS, , ahk_id%win%
;http://msdn.microsoft.com/en-us/library/ms645620%28VS.85%29.aspx
;WM_NCLBUTTONDOWN = 0xA1
;HTRIGHT = 11 (right border)
|
when i use Winspector Spy for the NCLBUTTONDOWN message, it tells me the wParam = 0x0000000b which in decimal is (11) so thats correct.
then it says the lParam is 0x00d18b4c. now, unless i'm misunderstanding, then the two coords in hex are 00d1 and 8b4c. but when i use hex2dec converter, it says 00d1 = 209, and 8b4c = 35660 which doesn't match the 1905x258 that i'm trying to send. what gives? |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Tue Mar 16, 2010 3:48 am Post subject: |
|
|
btw, i've tried
| Code: |
VarSetCapacity(POINTS, 8, 0)
NumPut(1905, POINTS, 0)
NumPut(258, POINTS, 4)
|
and i still get the same lParam as 0x00d18b4c
is that strange? |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Tue Mar 16, 2010 3:56 am Post subject: |
|
|
just to show how it should work (i think), if i do
| Code: |
CoordMode, Mouse, Screen
Click, 1905,258
|
Winspector reports lParam as 0x01020771
which, broken down hex to dec
0102 = 258
0771 = 1905 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Mar 16, 2010 4:17 am Post subject: |
|
|
| Code: | | PostMessage, 0xA1, 11, 1905|258<<16, , ahk_id%win% |
|
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Tue Mar 16, 2010 4:29 am Post subject: |
|
|
wow thats easy. thanks.
was there some fundamental error in my struct creation/passing? |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Mar 16, 2010 6:38 am Post subject: Re: creating a POINTS struct, NumPut problems, etc |
|
|
| guest3456 wrote: | | now, unless i'm misunderstanding, then the two coords in hex are 00d1 and 8b4c... |
...POINTS is a struct, you can't read the raw hex without converting it...
StructParser returns...
| Code: | VarSetCapacity(points, 4, 0)
; typedef struct tagPOINTS {
points_x:=NumGet(points, 0, "Short")
points_y:=NumGet(points, 2, "Short")
; }
; typedef struct tagPOINTS {
NumPut(points_x, points, 0, "Short")
NumPut(points_y, points, 2, "Short")
; } |
...so you are NumPut'ing correctly, but you need to NumGet to decode any value from the struct...(or do obscure math on Winspector Spy's lParam value {but sometimes a wParam/lParam will be a memory address & not a "value" to do math on})...
| guest3456 wrote: | | was there some fundamental error in my struct creation/passing? |
...no, a POINTS structure is a really simple struct & Sean likes to thoroughly obfuscate code by using magic numbers everywhere, throwing in obscure math & not explaining anything...
| Code: | | PostMessage, 0xA1, 11, 1905|258<<16, , ahk_id%win% |
...I'm getting REAL SICK of magic number code all over this forum (impossible to read, understand, debug)...plz people stop using magic numbers...
Here's an example of better code, but it still has Sean's cryptic "1905|258<<16" crap...
| Code: | ;// ASSIGN magic numbers!!!...
WM_NCLBUTTONDOWN:=0xA1
HTRIGHT:=11
;// THEN use them...
PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, 1905|258<<16, , ahk_id %win% |
...remember, that's still not perfect, since it doesn't properly create the struct & it's cryptic as hell...
Here's potentially correct code (not tested)...
| Code: | ;// ASSIGN magic numbers!!!...
WM_NCLBUTTONDOWN:=0xA1
HTRIGHT:=11
points_x:=1905
points_y:=258
VarSetCapacity(points, 4, 0)
NumPut(points_x, points, 0, "Short")
NumPut(points_y, points, 2, "Short")
;// THEN use them...
PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, POINTS, , ahk_id %win%
;// ...also try...
;//PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, &POINTS, , ahk_id %win%
;//...later...
points_x:=NumGet(points, 0, "Short")
points_y:=NumGet(points, 2, "Short") |
...that's nearly the same as your original code, you just have to ignore Winspector Spy & NumGet in AutoHotkey if you need the value in a POINTS struct...
What was the original problem that led you to post?...your orig code seems to be (obscure, but basically) correct! Does the PostMessage not succeed?...try my above code where I removed the & on &POINTS... |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Tue Mar 16, 2010 1:46 pm Post subject: Re: creating a POINTS struct, NumPut problems, etc |
|
|
thank you for your post.
| Anonymous wrote: | | guest3456 wrote: | | now, unless i'm misunderstanding, then the two coords in hex are 00d1 and 8b4c... |
...POINTS is a struct, you can't read the raw hex without converting it...
|
i was converting it from hex to decimal. if you look at my 3rd post in the thread, when i manually click the point with AHK code (or if i manually click it myself), the correct lParam is passed.
| Anonymous wrote: |
StructParser returns...
| Code: | VarSetCapacity(points, 4, 0)
; typedef struct tagPOINTS {
points_x:=NumGet(points, 0, "Short")
points_y:=NumGet(points, 2, "Short")
; }
; typedef struct tagPOINTS {
NumPut(points_x, points, 0, "Short")
NumPut(points_y, points, 2, "Short")
; } |
...so you are NumPut'ing correctly, but you need to NumGet to decode any value from the struct...(or do obscure math on Winspector Spy's lParam value {but sometimes a wParam/lParam will be a memory address & not a "value" to do math on})...
|
was not aware of that script, but wtf then, if i'm creating the struct properly, then the problem must be with passing it through PostMessage (see below)
| Anonymous wrote: |
;// THEN use them...
PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, POINTS, , ahk_id %win%
;// ...also try...
;//PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, &POINTS, , ahk_id %win%
Does the PostMessage not succeed?...try my above code where I removed the & on &POINTS... |
the PostMessage succeeds, i see the WM_NCLBUTTONDOWN, but i've tried both these ways and the lParam is incorrect both times
good reminder though to just define my constants.. i've just been keeping the comments as reference |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Mar 16, 2010 1:57 pm Post subject: |
|
|
| Quote: | | Here's potentially correct code (not tested)... | Your code is obviously wrong, my code was the correct one. Don't post about you're feeling cryptic. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Mar 16, 2010 2:53 pm Post subject: |
|
|
| guest3456 wrote: | | was there some fundamental error in my struct creation/passing? | In this case, you have to pass the struct as By-Val, not as By-Ref, i.e., &POINTS will not work.
And, keep in mind that there is no way to pass binary data/integer to built-in AHK Commands, so, POINTS will not work. |
|
| Back to top |
|
 |
guest3456 Guest
|
Posted: Tue Mar 16, 2010 3:16 pm Post subject: |
|
|
| Sean wrote: | | guest3456 wrote: | | was there some fundamental error in my struct creation/passing? | In this case, you have to pass the struct as By-Val, not as By-Ref, i.e., &POINTS will not work.
And, keep in mind that there is no way to pass binary data/integer to built-in AHK Commands, so, POINTS will not work. |
thank you sir, that explains it. much appreciated |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Mar 17, 2010 12:19 am Post subject: |
|
|
| Sean wrote: | | Your code is obviously wrong... |
...it's not obviously wrong, if I didn't test it...& again you don't EXPLAIN how it's wrong!
| Sean wrote: | | ...my code was the correct one. |
...no, your code is not "correct", it's unreadable & only works cuz obscure math is able to create this struct, try that trick with any, more complicated, struct...
| Sean wrote: | | Don't post about you're feeling cryptic. |
...what?...that don't make sense. But what's cryptic is your code...& apparant refusal to explain anything...
| Sean wrote: | | ...i.e., &POINTS will not work. |
...WHY?...you say things & NEVER explain them...why will it fscking not work???...&POINTS is attempting to pass ByRef...POINTS is trying to pass ByVal...it should work!
| Sean wrote: | | ...there is no way to pass binary data/integer to built-in AHK Commands, so, POINTS will not work. |
...why not?...my code is near-perfect (but untested), if the PostMessage AHK Command is incapable of passing the value properly (WHY???), then I'll create a DllCall PostMessage wrapper that CAN handle it...THIS IS NOW TESTED!!!...
| Code: | WM_NCLBUTTONDOWN:=0xA1
HTRIGHT:=11
F9::
;//hwnd:=win
hwnd:=WinExist("a")
points_x:=1905
points_y:=258
points_cryptic:=points_x|points_y<<16
VarSetCapacity(points, 4, 0)
NumPut(points_x, points, 0, "Short")
NumPut(points_y, points, 2, "Short")
;//PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, points_cryptic, , ahk_id %hwnd%
;//DllCall("PostMessage", "UInt", hwnd, "UInt", WM_NCLBUTTONDOWN, "UInt", HTRIGHT, "UInt", points_cryptic)
;//PostMessage(hwnd, WM_NCLBUTTONDOWN, HTRIGHT, points_cryptic)
;// These WORK!
PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, points, , ahk_id %hwnd%
;//PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, &points, , ahk_id %hwnd%
;//PostMessage(hwnd, WM_NCLBUTTONDOWN, HTRIGHT, points)
;//DllCall("PostMessage", "UInt", hwnd, "UInt", WM_NCLBUTTONDOWN, "UInt", HTRIGHT, "UInt", points)
;//...later...
points_x:=NumGet(points, 0, "Short")
points_y:=NumGet(points, 2, "Short")
return
/*
BOOL PostMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
*/
PostMessage(p_hwnd, p_msg, p_wParam, p_lParam) {
return DllCall("PostMessage", "UInt", p_hwnd, "UInt", p_msg, "UInt", p_wParam, "UInt", p_lParam)
} |
...all of these WORK!...
| Code: | PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, points, , ahk_id %hwnd%
;//PostMessage, WM_NCLBUTTONDOWN, HTRIGHT, &points, , ahk_id %hwnd%
;//PostMessage(hwnd, WM_NCLBUTTONDOWN, HTRIGHT, points)
;//DllCall("PostMessage", "UInt", hwnd, "UInt", WM_NCLBUTTONDOWN, "UInt", HTRIGHT, "UInt", points) |
...WTF r u taking about Sean?...
The point is: your cryptic math is ONLY capable of creating REALLY simple structs & to top it off it's unreadable...& to top that off, you don't explain it... |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Mar 17, 2010 12:42 am Post subject: |
|
|
| Quote: | | But what's cryptic is your code...& apparant refusal to explain anything... | It's only you who's feeling cryptic about it, solely rooted in your ignorance. And keep in mind, I'm not your teacher.
| Quote: | | ...all of these WORK!... | Don't lie. You still don't understand what this PostMessage is supposed to do, even after the explanation in the top post, and even with the link to the MSDN documentation. |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 3254 Location: Simi Valley, CA
|
Posted: Wed Mar 17, 2010 2:10 am Post subject: |
|
|
In my experience, the NC?BUTTONXXX class of messages only pass the mouse pointer's position as a rarely-used reference.
Also, the trick with NCLBUTTONDOWN is that the left mouse button should also be down when the message is passed (e.g: Click Left Down) and then releasing the left button typically ends the moving/sizing action.
And here's a crude illustration of NCLBUTTONDOWN with several of the wparam values | Code: | HTCAPTION = 2
HTBOTTOM = 15
HTBOTTOMLEFT = 16
HTBOTTOMRIGHT = 17
HTLEFT = 10
HTRIGHT = 11
HTTOP = 12
HTTOPLEFT = 13
HTTOPRIGHT = 14
Gui, Color, 44FF88
Gui, Margin, 3, 3
Gui, +LastFound +Owner -Caption +AlwaysOnTop
Gui, Font, S12 CDD2211, Arial
Gui, Add, Text, w150 voutput center +BackGroundTrans, 150 x 150
Gui, Show, x250 y0, Ruler OSD
1Gui_HWND := WinExist()
Loop 8
{
g := A_Index + 9
Gui, %g%:Default
Gui, Color, 886644
Gui, +LastFound +Toolwindow -Caption +AlwaysOnTop
Gui, Show, y-99999 w10 h10, Ruler Handle
Winset, Transparent, 96
%g%Gui_HWND := WinExist()
}
Gui, 2:Default
Gui, Color, FF0044
Gui, +LastFound +Owner -Caption +AlwaysOnTop +Resize
Gui, Show, w146 h146, Resizable Ruler
Winset, Transparent, 96
2Gui_HWND := WinExist()
OnMessage( 0x201, "WM_LBUTTONDOWN" )
OnMessage( 0x232, "WM_EXITSIZEMOVE" )
WM_EXITSIZEMOVE( 0, 0, 0, 2Gui_HWND )
Return
WM_LBUTTONDOWN( wparam, lparam, msg, hwnd ) {
Global
If ( A_Gui != 1 )
PostMessage, 0xA1, %A_Gui%, 0,, Ahk_ID %2Gui_HWND%
Else
PostMessage, 0xA1, 2, 0,, Ahk_ID %1Gui_HWND%
}
WM_EXITSIZEMOVE( wparam, lparam, msg, hwnd ) {
Global
WinGetPos, x, y, w, h, Ahk_ID %2Gui_HWND%
GuiControl, 1:, output, %w% / %h%
SetWinDelay, 50
Gui, 10:Show, % "x" x - 25 " y" y + h // 2 - 5
Gui, 11:Show, % "x" x + w + 15 " y" y + h // 2 - 5
Gui, 12:Show, % "x" x + w // 2 - 5 " y" y - 25
Gui, 15:Show, % "x" x + w // 2 - 5 " y" y + h + 15
Gui, 13:Show, % "x" x - 25 " y" y - 25
Gui, 14:Show, % "x" x + w + 15 " y" y - 25
Gui, 16:Show, % "x" x - 25 " y" y + h + 15
Gui, 17:Show, % "x" x + w + 15 " y" y + h + 15
}
GuiContextMenu:
i = 2,10,11,12,13,14,15,16,17
Loop, Parse, i, `,
Gui, %A_LoopField%:Show, y-99999
Gui, 1:Minimize
Return
GuiSize:
If ( A_EventInfo != 1 )
{
Gui, 1:Show
Gui, 2:Show
}
Return
2GuiSize:
GuiControl, 1:, output, %A_GuiWidth% / %A_GuiHeight%
Return
GuiClose:
Exitapp |
_________________ Ternary (a ? b : c) guide TSV Table Manipulation Library
Post code inside [code][/code] tags! |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Mar 17, 2010 2:38 am Post subject: |
|
|
| Sean wrote: | | ...solely rooted in your ignorance. |
...I am NOT ignorant, I understand how your bit shifting works, but IT'S STILL CRYPTIC!
| Sean wrote: | | And keep in mind, I'm not your teacher. |
...fine, if you don't wanna explain YOUR code, then don't post it...
...I'm not lying...THOSE DO WORK, TEST THEM...
| Sean wrote: | | You still don't understand what this PostMessage is supposed to do... |
...don't try to tell me what I don't know!...it's supposed to simulate the msg a window receives when you click the Left mouse button down on the non-client area of a window (in this case the right side)...
My code DOES work, I don't have Winspector Spy or care what it reports for it's lParam, the code works...run it, press F9, move the mouse & the right side of the active window will be moving as if you are resizing the window...cuz the PostMessage was received AND IT IS WORKING!... |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Mar 17, 2010 3:27 am Post subject: |
|
|
| Quote: | | ...I am NOT ignorant, I understand how your bit shifting crap works, but IT'S STILL CRYPTIC! | Go complain to C/C++ creators or Chris about your thought that bit shift is crap.
| Quote: | | ...fine, if you don't wanna explain YOUR code, then don't post it... | You don't tell me what to do or not. Definitely it's not for you, so, don't use it.
| Quote: | | THOSE DO WORK, TEST THEM... | It's not because your code was correct, but, to your surprise, Windows Developers put a lot of efforts to support lame codes too. The POINTS struct in many Windows Messages tends to be ignored if not make a sense at all. Go show your appreciation to Windows Developers. Period. |
|
| 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
|