AutoHotkey Community

It is currently May 27th, 2012, 5:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 42 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: March 16th, 2010, 4:42 am 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 4:48 am 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 4:56 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 5:17 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Code:
PostMessage, 0xA1, 11, 1905|258<<16, , ahk_id%win%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 5:29 am 
wow thats easy. thanks.

was there some fundamental error in my struct creation/passing?


Report this post
Top
  
Reply with quote  
PostPosted: March 16th, 2010, 7:38 am 
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...

Sean wrote:
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...


Report this post
Top
  
Reply with quote  
PostPosted: March 16th, 2010, 2:46 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 2:57 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 3:53 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 4:16 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 1:19 am 
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...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 1:42 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 3:10 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 3:38 am 
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...

Sean wrote:
Don't lie.

...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!...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 4:27 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], HotkeyStick, mrhobbeys, rbrtryn and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group