Jump to content
Sign in to follow this  
JakeJohnson74

Help understanding help file example code

Recommended Posts

JakeJohnson74

Hello, I am an old programmer, but brand new to Autoit and relatively new to Graphics programming. 

I am trying to learn a bit about GDIPlus and was looking at the _GDIPlus_GraphicsTransformPoints UDF and  they capturing events from the mouse for example: 

Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    $g_iMouseX = BitAND($lParam, 0x0000FFFF)
    $g_iMouseY = BitShift($lParam, 16)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_LBUTTONDOWN

What I am looking for is to go through this example and fully understand what is happening. 

So... First question has to do with overall naming conventions: 

$g_iMouseX

While I realize I can name a var just about anything I want to name it - in this example does the "g" represent graphics? and the "i" represent type Int? 

If this is the accepted and recognized naming convention for vars I would like to follow suit and actually "know" what I am naming it for. 

Second question, What exactly are the BitAND and BitShift functions doing here? 

Regardless of the value of $lParam why are they "anding" it with FFFF? It's basically saying I have a value of X and I'm BitANDing with all 1's. In other words whatever my value is, let it all through unchanged. I don't understand this.

TIA to anyone who will to take the time to explain this function to me or point me to a resource that will explain this to me as I seem to be having trouble finding it on my own. 

Edit* I would also like to point out that I see the $wParam $lParam used all over the place and have no Idea what their values are or what they are used for. 

If this is beyond the scope of AutoIT and a general windows programming "thing" please feel free to point me in that direction as I have no issues researching this on my own. It just all seems foreign to me at this point, so sometimes it is hard to know where to start.

Edited by JakeKenmode

Share this post


Link to post
Share on other sites
Melba23

JakeKenmode

Here we go:

- 1. The "g_" is for Global as those variables are declared in that scope at the top of the script. This is not necessary, but it helps to remind you of the scope later. The "i" is for "integer" as that is what is stored within the variable - again not necessary, but good coding practice. There is a UDF standards page in the Wiki which sets out what we consider to be good variable naming practice.

- 2. The BitAND & BitShift function break the content of $lParam into 2 separate parts - the X & Y values are stored in there as the high and low order bytes and this allows you to separate them. $wParam & $lParam are values returned by Windows which vary according to the particular message received - they can be values, pointers to structures holding more data, or basically anything at all. MSDN explains it in a lot more details (and good luck with that!).

I hope that helps. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
JakeJohnson74

Awesome! Stupid brain farts! I haven't even looked at the wiki! Thanks! 

As for the logical Bitwise stuff - I'll go root around MSDN. 

I hate looking at code and not knowing "why" things are being done lol. I get that it is using $lParam to get the mouse X and Y

   0000 0010 0000 0001 = 0x0201 (the win message value for the left mouse click)

x 1111 1111 1111 1111 = 0x0000FFFF

-------------------------------

  0000 0010 0000 0001

So the result of the BitAND is letting everything through :( so I don't get it. Why "And" something with all 1's? Its like saying 1 x 1 = 1 

Then to obtain the Y they are shifting $lParam 16 bits to the right? Wouldn't that shift the entire value out? 

0000 0010 0000 0001 = 0x0201 (the win message value for the left mouse click)

-> 16 bits 

0000 0000 0000 0000 ?

Maybe I am thinking too far into it hah! Im off to MSDN! (which by the way reads like a Medical document! lol)

Share this post


Link to post
Share on other sites
Melba23

JakeKenmode,

Read what I said - $lParam does NOT contain the message value - it contains the mouse X and Y coordinates in the high and low words. So what happens is this:

Data inside 32 bit $lParam - each integer is 16 bits:
YYYYXXXX

To get the X coord we BitAND:
YYYYXXXX
0000FFFF
--------
0000XXXX

And then for the Y coord we shift to the right by 16 bits:
YYYYXXXX
0YYYYXXX - by 4
00YYYYXX - by 8
000YYYYX - by 12
0000YYYY - by 16
Clearer now? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
JakeJohnson74

Hahah very :) I just worked it out on my own as well and was coming back here to correct my other post! 

You beat me too it! I used Msgboxes to show me the light lol. 

$lParam for my example click was :

91010B so in Binary 

0000 0000 1001 0001 0000 0001 0000 1011 (32 bits! I was thinking 16! which is why I thought a 16 bit shift cleared the value and didn't make sense. It's also why I thought filtering on the first 16 bits was useless on the X value) 

0000 0000 1001 0001 0000 0001 0000 1011 <- X value Anding 1111 1111 1111 1111

X = 267 

Then Shifting 16 bits right gives you:

0000 0000 1001 0001 0000 0001 0000 1011

0000 0000 0000 0000 0000 0000 1001 0001 <- Y Value 

Y = 145

All very clear now :) Awesome! Thanks

Edited by JakeKenmode

Share this post


Link to post
Share on other sites
Melba23

JakeKenmode,

 

All very clear now

Great. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×