Sign in to follow this  
Followers 0
ijourneaux

$WM_COMMAND Handler problems

4 posts in this topic

Based on other forum posts, I created a WM_Command handler that monitors if $SampleTypeCombi has been modified.

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _WinAPI_HiWord($wParam)
    Local $nID = _WinAPI_LoWord($wParam)
    Local $hCtrl = $lParam
    Switch $nID
        Case $SampleTypeCombo
            Switch $nNotifyCode
    Case $CBN_EDITUPDATE, $CBN_EDITCHANGE; when user types in new data
     $iStatusFlag = True
    Case $CBN_SELCHANGE; item from drop down selected
     $iStatusFlag = True
   EndSwitch
  EndSwitch
; Proceed the default Autoit3 internal message commands.
; You also can complete let the line out.
; !!! But only 'Return' (without any value) will not proceed
; the default Autoit3-message in the future !!!
   Return $GUI_RUNDEFMSG
EndFunc  ;==>MY_WM_COMMAND

The while loop looks like

While 1
Sleep(500)  ; Idle around
if($IStatusFlag) Then
  $IStatusFlag = False
  consoleWrite("Test"& @CRLF)
  consoleWrite("Test2 - " & GUICtrlRead($SampleTypeCombo)&@crlf)
  ReadOriginSize(@scriptdir & "\PickoutDetection.ini", GUICtrlRead($SampleTypeCombo))
  UpdateOriginSize()
  if(SetScanner (GUICtrlRead($SampleTypeCombo))) Then
   msgbox(0, "Status", "Scanner profile successfully changed to " & GUICtrlRead($SampleTypeCombo))
  else
   msgbox(0, "Error", "Possible problem changing scanner profile to " & GUICtrlRead($SampleTypeCombo))
  endif
Endif
WEnd

Unfortuantely when I edit $sampletypecombo, the event associated with one of my buttons "Start Scanning" is also fired before the code in the while loop is processed.

; BUTTON
$startscanningbutton = GuiCtrlCreateButton("Start Scanning Process", 70, 140, 150, 30)
GUICtrlSetOnEvent($startscanningbutton, "StartScanning")

Where is the mistake I am making.

Take Care.

Share this post


Link to post
Share on other sites



ijourneaux,

When I add enough code to let me run your snippets (TOP TIP: post running code - it greatly increases the chances of getting a useful answer ;)) I get no problems at all:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>

Opt("GUIOnEventMode", 1)

Global $IStatusFlag = False

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_On_Exit")

$SampleTypeCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "Fred|Tom|Dick|Harry")

$startscanningbutton = GuiCtrlCreateButton("Start Scanning Process", 70, 140, 150, 30)
GUICtrlSetOnEvent($startscanningbutton, "StartScanning")

GUISetState()

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")


While 1
    Sleep(500) ; Idle around
    If ($IStatusFlag) Then
        $IStatusFlag = False
        ConsoleWrite("Test" & @CRLF)
        ConsoleWrite("Test2 - " & GUICtrlRead($SampleTypeCombo) & @CRLF)
        #cs
        ReadOriginSize(@ScriptDir & "PickoutDetection.ini", GUICtrlRead($SampleTypeCombo))
        UpdateOriginSize()
        If (SetScanner(GUICtrlRead($SampleTypeCombo))) Then
            MsgBox(0, "Status", "Scanner profile successfully changed to " & GUICtrlRead($SampleTypeCombo))
        Else
            MsgBox(0, "Error", "Possible problem changing scanner profile to " & GUICtrlRead($SampleTypeCombo))
        EndIf
        #ce
    EndIf
WEnd

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode = _WinAPI_HiWord($wParam)
    Local $nID = _WinAPI_LoWord($wParam)
    Local $hCtrl = $lParam
    Switch $nID
        Case $SampleTypeCombo
            Switch $nNotifyCode
                Case $CBN_EDITUPDATE, $CBN_EDITCHANGE; when user types in new data
                    $IStatusFlag = True
                Case $CBN_SELCHANGE; item from drop down selected
                    $IStatusFlag = True
            EndSwitch
    EndSwitch
    ; Proceed the default Autoit3 internal message commands.
    ; You also can complete let the line out.
    ; !!! But only 'Return' (without any value) will not proceed
    ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func StartScanning()
    ConsoleWrite("Scanning" & @CRLF)
EndFunc

Func _On_Exit()
    Exit
EndFunc

I cannot look inside your ReadOriginSize, UpdateOriginSize and SetScanner functions - are you sure nothing in there is firing the scanning process? :)

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

#3 ·  Posted (edited)

Thanks for pointing me in the correct direction. I should have done what you did as a first step. SImplify the code and determine if the problem existed. In my case, the code in SetScanner was accidentally triggering StartScanning. SetScanner brings up the scanners control page, where I select the scaner parameters using ControlCommand and I exit the scanner control page by pressing the Ok button. Unfortunately the scanners control page window doesn't have a name so I am using

ControlCommand("", "", "[CLASS:ComboBox; INSTANCE:1]", "SelectString", $ScannerProfile)

and

ControlClick("", "", "[CLASS:Button; INSTANCE:1]")

On my development computer I don't have the scanner application install so the ControlClick command merrily clicks on the StartScanning Button. <KICK pants in self>

Trying to come up with a way to trap the condition where the scanner app is not installed.

Thanks for the help.

Edited by ijourneaux

Share this post


Link to post
Share on other sites

ijourneaux,

Do not kick too hard! :)

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