Sign in to follow this  
Followers 0
Andreik

Use WM_COMMAND to handle specific messages

8 posts in this topic

#1 ·  Posted (edited)

Can I use WM_COMMAND to handle EN_CHANGE message but not BN_CLICKED? As long WM_COMMAND process the message BN_CLICKED I am not able to catch the button click in loop using GUIGetMsg().

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

$hMain = GUICreate("Test",400,400)
$hButton = GUICtrlCreateButton("Click Me",100,100,100,30)
$hInput = GUICtrlCreateInput("",100,200,100,30)
GUIRegisterMsg($WM_COMMAND,'WM_COMMAND')
GUISetState(@SW_SHOW,$hMain)

While True
    Switch GUIGetMsg()
        Case $hButton
            MsgBox(0,"Message","You just clicked me.")
        Case -3 ; GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch _WinAPI_HiWord($wParam)
        Case $EN_CHANGE
            TrayTip("Read",GUICtrlRead(_WinAPI_LoWord($wParam)),1)
            Return 0
    EndSwitch
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

EDIT: I got this working in this way but I'm looking for something more elegant

#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

$hMain = GUICreate("Test",400,400)
$hButton = GUICtrlCreateButton("Click Me",100,100,100,30)
$hInput = GUICtrlCreateInput("",100,200,100,30)
$hDummy = GUICtrlCreateDummy()
GUIRegisterMsg($WM_COMMAND,'WM_COMMAND')
GUISetState(@SW_SHOW,$hMain)

While True
    Switch GUIGetMsg()
        Case $hDummy
            Switch GUICtrlRead($hDummy)
                Case $hButton
                    MsgBox(0,"Message","You just clicked me.")
            EndSwitch
        Case -3 ; GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch _WinAPI_HiWord($wParam)
        Case $EN_CHANGE
            TrayTip("Read",GUICtrlRead(_WinAPI_LoWord($wParam)),1)
            Return 0
        Case $BN_CLICKED
            GUICtrlSendToDummy($hDummy,_WinAPI_LoWord($wParam))
    EndSwitch
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites



That's how I would do it, as stated in the reply PM I sent to you.


_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

#3 ·  Posted (edited)

Could you not do this.

#include <GUIConstantsEx.au3>

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch _WinAPI_HiWord($wParam)
        Case $EN_CHANGE
            TrayTip("Read",GUICtrlRead(_WinAPI_LoWord($wParam)),1)
            Return 0
        Case $BN_CLICKED
            Return $GUI_RUNDEFMSG ;If you want AutoIt to run its internal handler for a message, return the variable $GUI_RUNDEFMSG
    EndSwitch
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Hmm...does that work? If it does then I have learnt something new today.


_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

#5 ·  Posted (edited)

Nope, it doesn't work. I already tried that.  ;)

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Do a switch on the control id first?

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>

$hMain = GUICreate("Test", 400, 400)
$cButton = GUICtrlCreateButton("Click Me", 100, 100, 100, 30)
$cInput = GUICtrlCreateInput("", 100, 200, 100, 30)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState(@SW_SHOW, $hMain)

While True
Switch GUIGetMsg()
Case $cButton
MsgBox(0, "Message", "You just clicked me.")
Case -3 ; GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
Switch _WinAPI_LoWord($wParam) ; iIDFrom
Case $cInput
Switch _WinAPI_HiWord($wParam) ; iCode
Case $EN_CHANGE
TrayTip("Read", GUICtrlRead(_WinAPI_LoWord($wParam)), 1)
;Return 0
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND

Edit:

Also you used

$hButton = GUICtrlCreateButton("Click Me", 100, 100, 100, 30)

from the "h" I would think the variable contains a handle. I recommend to use something more like this:

$cButton = GUICtrlCreateButton("Click Me", 100, 100, 100, 30)

$hButton = GUICtrlGetHandle($cButton)

Edited by KaFu

Share this post


Link to post
Share on other sites

I was wondering why all this short examples work so good and when I work on my project nothing works as I expect. The answer is simple and I have to apologize JohnOne and I should listen guiness >long time ago. I don't know why but I knew that $GUI_RUNDEFMSG='' and of course I used magic numbers and magic texts so it's obviously that script not behaved as I expected. Thanks guys!

PS: Now I like the old comment of guinness.  :graduated:


When the words fail... music speaks

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