Sign in to follow this  
Followers 0
Morthawt

Alternate method of getting GUI messages

21 posts in this topic

I am trying to make a way to interrupt an ongoing process to still have access to GUI aspects etc.

Here I am trying to grab GUI messages ASAP with an adlib. The issue is the CPU does spike even though it is doing the same thing as being inside a while 1 loop. Every 1 milisecond it grabs the info and thats it.

Now, the only thing I have come up with is the adlib its self is doing more work than a while 1 loop that just grabs the messages. However that is a guess. The fact it only fires off ever 1 millisecond should offer some CPU protection though because a while loop without any sleeps fires off hundreds of times in 1 millisecond...

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("GUI Window", 205, 73, -1, -1)
$Button1 = GUICtrlCreateButton("Button1", 8, 8, 187, 57)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $nMsg
AdlibRegister('GUIGetMessages', 1)

While 1
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func GUIGetMessages()
$nMsg = GUIGetMsg()
EndFunc

Can you tell me what you think a good way to make something like this work without wasting CPU is? Preferably a simple elegant method rather than complicated and convoluted.

The idea behind this kind of code was that at a later time in the script I could just check the $nMsg for something and perform an action at any point in my script without breaking anything.

Share this post


Link to post
Share on other sites



Instead of using an Adlib function, you could use a Windows message function to read the buttons (GUIRegisterMsg), see the link in my signature for a demo script I posted that will show how it could work.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Morthawt,

You are asking for trouble with that approach. Your Adlib function is very unlikely to return within the 1ms delay you have set - GUIGetMsg has a built-in delay of about 12ms to rest the CPU, although this is reduced if the CPU is not doing much. Firing the Adlib function again and again before it returns is very likely to end up with "stack overflow" errors. :(

I would suggest using one of the techniques demonstrated in the Interrupting a running function tutorial in the Wiki. ;)

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

u could even try Subclassing the GUI and receive the Messages through the WndProc


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

How would you do that?

From how I understand it, that's similar to using OnEventMode. Or is it?

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Well so far from the examples I have seen, the only method that does what I would want in any sort of way requires something I steer clear of, which is the whole GUI Register thing. Unless there is some other method not covered in the Wiki that does not need "magic numbers" or prior technical Microsoft api/coding knowledge.

Share this post


Link to post
Share on other sites

Morthawt,

The tutorial to which I linked uses the "GUI Register thing" because in most cases there is no other way of doing what you want. Give it a try - it is not as bad as you think. There is basic tutorial in the Wiki, lots of examples on the forum amd a whole bunch of people to answer your questions. ;)

M23

1 person likes this

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

#10 ·  Posted (edited)

lol.. I guess it will be one of those days where I feel up to the task of breaking through the "Too hard" barrier. I typically hate things where I have to go learning microsoft crap. I love how the manual has 95% of everything I need, but it does not come with that microsoft knowledge as part of it which makes me want to instantly say no when I see those microsoft pages. So, maybe if a day comes where I feel untouchable I will give it a go and try to understand the intricacies of it all but for now it's going to have to wait until then lol.

Either way I appreciate finding out what it takes so I can either acomplish something differently or work around not being able to do it instead of wasting a whole load of time trying to come up with rubbish methods of doing something that is intrinsicly not possible without extraordinary means.

The first time I saw Autoit, well I can't quote what I said without my post being censored lol. Suffice to say it had the same sentiment of "screw that..." Until months later upon encountering Autoit again I gave it a go and put time and bloody-mindedness into learning, or at least "attempting" to understand it due to my mind set being different than before when I was 100% against learning a new computer language. Then it was easier than eating (almost).

Edited by Morthawt

Share this post


Link to post
Share on other sites

Morthawt,

As you wish - but as with your reluctance to use other than the installed UDFs you are just reducing your ability to get the most out of AutoIt. :(

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

I know, there are pro's and cons either way. But while I am a resource guy, I like the self sufficient resources. If I am using a UDF to do something I cannot do myself and something changes with Autoit and that UDF breaks, I cannot guarantee that I can fix it myself or that the original person or anyone else would fix it. So I like to know that all my work is made with what Autoit comes with.

I don't mind using UDF that it comes with by default but I just choose to not use externally obtained UDF. Yes it can limit me, but I know Autoit its self is limiting compared to a fully blown programming language, so I choose to not let it bother me. I am just glad to finally learn a language that allows me to actually do things useful. I can automate things, make basic programs, even make little games here and there. I am happy with that, even though I do improve my knowledge over time, gradually.

Share this post


Link to post
Share on other sites

If you run the demo that I linked you to, you won't have to "go through the Microsoft" thing, it shows you what the numbers are and you can figure out from reading the code how it gets them.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Morthawt,

I know Autoit its self is limiting compared to a fully blown programming language

I am not at all sure I share your point of view there - certainly AutoIt (like any other language) has limits, but the very idea of some of the UDFs and the more exotic commands like DllCall and GUIRegisterMsg is to expand them as far as possible! ;)

But you have made your decision - now you have to live with the implications for your coding. All I ask is that you do not reflect this attitude in your tutorial videos. :)

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

K, I am bookmarking it and I will check it out. I glanced at it before and saw a bunch of magic numbers and assumed it was too much work, as usual lol. I really have to be in the mood to get stuck into something new and seemingly complex.

Share this post


Link to post
Share on other sites

Morthawt,

I am not at all sure I share your point of view there - certainly AutoIt (like any other language) has limits, but the very idea of some of the UDFs and the more exotic commands like DllCall and GUIRegisterMsg is to expand them as far as possible! ;)

But you have made your decision - now you have to live with the implications for your coding. All I ask is that you do not reflect this attitude in your tutorial videos. :)

M23

lol, of course I would not suggest people limit themselves.That is just what I do to prevent myself from saying "screw it all" and generalizing that "everything Autoit" is just too difficult. I focus on what I can do and how I can use it then gradually expand my abilities. Works best for me.

I agree they do open things up, those things, however as far as DLL's go so far my start and end is opening a dll for _ispressed to work correctly and then closing it upon exit.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Ok BrewManNH, I did just now have a look at the source code and ran it etc. I have absolutely no idea how or where those magic numbers come from or what they even mean. However these things I will quote are what have kept me away 100% from using that ability:

Func MY_SYS_COMMAND($hWnd, $msg, $wParam, $lParam)

BitShift($wParam, 16)

BitAND($wParam, 0x0000FFFF)

Case 0xf060
ConsoleWrite("!Exit pressed" & @LF)
Exit

The last one I have only seen in your demo, I have only ever seen variables used before if I recall. But since I have no understanding of those things I keep clear like the plague. If I had a concrete understanding of those things listed and it did not need to do Microsoft research to do everything then I would jump on it like crazy.

Edited by Morthawt

Share this post


Link to post
Share on other sites

Here's the same demo re-written to eliminate the magic numbers.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
GUIRegisterMsg($WM_COMMAND, "_WM_EXTRACTOR")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_EXTRACTOR")
GUIRegisterMsg($WM_HSCROLL, "_WM_EXTRACTOR")
$GUI = GUICreate("Test GUI", 200, 200, -1, -1, BitOR($WS_THICKFRAME, $gui_ss_default_gui))
$Button = GUICtrlCreateButton("Test", 20, 20)
$Button2 = GUICtrlCreateButton(" Another Test ", 20, 100)
$Slider = GUICtrlCreateSlider(20, 60, 150)
$hSlider = GUICtrlGetHandle($Slider)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button
            MsgBox(0, "", "You pressed the button marked TEST")
        Case $Button2
            MsgBox(0, "", "You pressed the button marked 'Another Test'")
    EndSwitch
WEnd
Func _WM_EXTRACTOR($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $iMsg
        Case $WM_HSCROLL
            Switch $lParam
                Case $hSlider
                    ConsoleWrite("+Slider moved to: " & GUICtrlRead($Slider) & @LF)
            EndSwitch
        Case $WM_VSCROLL
        Case $WM_COMMAND
            Switch $nID
                Case $Button
                    ConsoleWrite(">Button Test pressed" & @LF)
                Case $Button2
                    ConsoleWrite(">Button Another Test pressed" & @LF)
                Case Else
                    MsgBox(0, "MY_WM_COMMAND", "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                            "MsgID" & @TAB & ":" & $msg & @LF & _
                            "wParam" & @TAB & ":" & $wParam & @LF & _
                            "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                            "WM_COMMAND - Infos:" & @LF & _
                            "-----------------------------" & @LF & _
                            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                            "CtrlID" & @TAB & ":" & $nID & @LF & _
                            "CtrlHWnd" & @TAB & ":" & $hCtrl)
            EndSwitch
        Case $WM_SYSCOMMAND
            Switch $wParam
                Case $SC_CLOSE
                    ConsoleWrite("!Exit pressed" & @LF)
                    Exit
                Case $SC_RESTORE
                    ConsoleWrite("!Restore window" & @LF)
                Case $SC_MINIMIZE
                    ConsoleWrite("!Minimize Window" & @LF)
                Case $SC_MOUSEMENU + 3
                    ConsoleWrite("!System menu pressed" & @LF)
                Case $SC_MOVE
                    ConsoleWrite("!System menu Move Option pressed" & @LF)
                    Return 0
                Case $SC_SIZE
                    ConsoleWrite("!System menu Size Option pressed" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 2 ; This and the following case statements are only valid when the GUI is resizable
                    ConsoleWrite("!Right side of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 1
                    ConsoleWrite("!Left side of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 8
                    ConsoleWrite("!Lower Right corner of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 7
                    ConsoleWrite("!Lower Left corner of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 6
                    ConsoleWrite("!Bottom side of GUI clicked" & @LF)
                    Return 0
                Case Else
                    MsgBox(0, "MY_WM_COMMAND", "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                            "MsgID" & @TAB & ":" & $msg & @LF & _
                            "wParam" & @TAB & ":" & $wParam & @LF & _
                            "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                            "WM_COMMAND - Infos:" & @LF & _
                            "-----------------------------" & @LF & _
                            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                            "CtrlID" & @TAB & ":" & $nID & @LF & _
                            "CtrlHWnd" & @TAB & ":" & $hCtrl)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_EXTRACTOR

The numbers I used are stored in the MenuConstants.au3 file except for the ones that use "$SC_MOUSEMENU +", those values don't have named variables, and I can't even find a reference to a variable name that Microsoft uses.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Here's the same demo re-written to eliminate the magic numbers.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>
GUIRegisterMsg($WM_COMMAND, "_WM_EXTRACTOR")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_EXTRACTOR")
GUIRegisterMsg($WM_HSCROLL, "_WM_EXTRACTOR")
$GUI = GUICreate("Test GUI", 200, 200, -1, -1, BitOR($WS_THICKFRAME, $gui_ss_default_gui))
$Button = GUICtrlCreateButton("Test", 20, 20)
$Button2 = GUICtrlCreateButton(" Another Test ", 20, 100)
$Slider = GUICtrlCreateSlider(20, 60, 150)
$hSlider = GUICtrlGetHandle($Slider)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button
            MsgBox(0, "", "You pressed the button marked TEST")
        Case $Button2
            MsgBox(0, "", "You pressed the button marked 'Another Test'")
    EndSwitch
WEnd
Func _WM_EXTRACTOR($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Switch $iMsg
        Case $WM_HSCROLL
            Switch $lParam
                Case $hSlider
                    ConsoleWrite("+Slider moved to: " & GUICtrlRead($Slider) & @LF)
            EndSwitch
        Case $WM_VSCROLL
        Case $WM_COMMAND
            Switch $nID
                Case $Button
                    ConsoleWrite(">Button Test pressed" & @LF)
                Case $Button2
                    ConsoleWrite(">Button Another Test pressed" & @LF)
                Case Else
                    MsgBox(0, "MY_WM_COMMAND", "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                            "MsgID" & @TAB & ":" & $msg & @LF & _
                            "wParam" & @TAB & ":" & $wParam & @LF & _
                            "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                            "WM_COMMAND - Infos:" & @LF & _
                            "-----------------------------" & @LF & _
                            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                            "CtrlID" & @TAB & ":" & $nID & @LF & _
                            "CtrlHWnd" & @TAB & ":" & $hCtrl)
            EndSwitch
        Case $WM_SYSCOMMAND
            Switch $wParam
                Case $SC_CLOSE
                    ConsoleWrite("!Exit pressed" & @LF)
                    Exit
                Case $SC_RESTORE
                    ConsoleWrite("!Restore window" & @LF)
                Case $SC_MINIMIZE
                    ConsoleWrite("!Minimize Window" & @LF)
                Case $SC_MOUSEMENU + 3
                    ConsoleWrite("!System menu pressed" & @LF)
                Case $SC_MOVE
                    ConsoleWrite("!System menu Move Option pressed" & @LF)
                    Return 0
                Case $SC_SIZE
                    ConsoleWrite("!System menu Size Option pressed" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 2 ; This and the following case statements are only valid when the GUI is resizable
                    ConsoleWrite("!Right side of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 1
                    ConsoleWrite("!Left side of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 8
                    ConsoleWrite("!Lower Right corner of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 7
                    ConsoleWrite("!Lower Left corner of GUI clicked" & @LF)
                    Return 0
                Case $SC_MOUSEMENU + 6
                    ConsoleWrite("!Bottom side of GUI clicked" & @LF)
                    Return 0
                Case Else
                    MsgBox(0, "MY_WM_COMMAND", "GUIHWnd" & @TAB & ":" & $hWnd & @LF & _
                            "MsgID" & @TAB & ":" & $msg & @LF & _
                            "wParam" & @TAB & ":" & $wParam & @LF & _
                            "lParam" & @TAB & ":" & $lParam & @LF & @LF & _
                            "WM_COMMAND - Infos:" & @LF & _
                            "-----------------------------" & @LF & _
                            "Code" & @TAB & ":" & $nNotifyCode & @LF & _
                            "CtrlID" & @TAB & ":" & $nID & @LF & _
                            "CtrlHWnd" & @TAB & ":" & $hCtrl)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_EXTRACTOR

The numbers I used are stored in the MenuConstants.au3 file except for the ones that use "$SC_MOUSEMENU +", those values don't have named variables, and I can't even find a reference to a variable name that Microsoft uses.

Ok the variables make a lot of sense, mostly. However could you briefely explain to me the idea and the workings of this part?

Func _WM_EXTRACTOR($hWnd, $iMsg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0x0000FFFF)

I have no idea, even after reading the manual, what BitShift or BitAND are actually doing. Also even if I did I would need to understand what they are needed for and what they are doing in this example you have given so that I can start to work with it on my own, knowing that I can get the ball rolling and understand the process and reasoning.

Share this post


Link to post
Share on other sites

Realistically, you don't need to know what they're doing to work with the results given. Although I understand the need to know more than just blind faith.

BitShift will "rotate" the bits of the number the number of times you put in the function to the right. If you understand binary numbers you can visualize that everytime you move a bit right, you're cutting the original number in half. It's probably not needed in this function, but it was in the script I used for the demo. When you BitAnd a number, you're using AND on the original number with a mask. In this case, it's stripping off all of the MSBits of the number and leaving you with just the LSB (big endian) or vice versa (little endian). When you AND a number with another number, any bit that's not a 1 will end up being a 0, you need a 1 in each place in the bits to get a 1 returned.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  
Followers 0