Jump to content

Recommended Posts

Posted (edited)

Here is demo example for catching/processing doubleclick NOTIFY message on StatusBar control

also with distinguishing on which part of statusbar was clicked

; http://msdn.microsoft.com/en-us/library/windows/desktop/bb760734%28v=VS.85%29.aspx
 
#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
 
Global $hGUI = GUICreate("Statusbar doubleclick demo", 400, 300)
$sb_dblclk_id = GUICtrlCreateDummy() ; statusbar doubleclick ID
$label = GUICtrlCreateLabel('abc', 10,10,100)
 
Global $hStatus = _GUICtrlStatusBar_Create($hGUI)
Global $aParts[3] = [125, 250]
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
_GUICtrlStatusBar_SetText($hStatus, "Text1", 0)
_GUICtrlStatusBar_SetText($hStatus, "Text2", 1)
_GUICtrlStatusBar_SetText($hStatus, "Text3", 2)
 
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
 
While 1
    Switch GuiGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sb_dblclk_id
            OnStatusBarDoubleClick(GUICtrlRead($sb_dblclk_id))
    EndSwitch
WEnd
 
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
 
    If $hWndGUI = $hGUI Then
 
        $NMHDR = DllStructCreate($tagNMHDR , $lParam)
        $hWndFrom = DllStructGetData($NMHDR, 'hWndFrom')
        $event = DllStructGetData($NMHDR, 'Code')
 
        If $event = $NM_DBLCLK And $hWndFrom = $hStatus Then
            $NMMOUSE = DllStructCreate($tagNMMOUSE , $lParam)
            $part = DllStructGetData($NMMOUSE, 'ItemSpec')
;~           OnStatusBarDoubleClick($part)
         GUICtrlSendToDummy($sb_dblclk_id, $part)
        EndIf
    EndIf
 
    Return $GUI_RUNDEFMSG
EndFunc
 
Func OnStatusBarDoubleClick($sb_part)
    ConsoleWrite('statusbar doubleclick, part=' & $sb_part & ' text=' & _GUICtrlStatusBar_GetText($hStatus, $sb_part) & @CRLF)
EndFunc

Note that GUICtrlSendToDummy() is used only for non-blocking processing of WM_NOTIFY message, so in this way you can have in OnStatusBarDoubleClick() also long lasting or blocking code like messagebox without any harm on system.

EDIT: The same way as $NM_DBLCLK can be used also $NM_CLICK

Edited by Zedna
  • 1 year later...
Posted

Just for the reference, here is modification of my example

using _SendMessage() with custom message instead of GUICtrlSendToDummy().

With GUICtrlSendToDummy() you can send only 1 parameter and it must be numeric.

With _SendMessage() you can send 2 parameters (wParam+lParam) and it can be diferent types.

This is ideal when catching messages in ListView where you can trap/send item/subitem or item/state parameters for example.

; <a href='http://msdn.microsoft.com/en-us/library/windows/desktop/bb760734%28v=VS.85%29.aspx' class='bbc_url' title='External link' rel='nofollow external'>http://msdn.microsoft.com/en-us/library/windows/desktop/bb760734%28v=VS.85%29.aspx</a>

#include <GUIConstantsEX.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>

Global Const $WM_SB_DBLCLK = $WM_USER + 1

Global $hGUI = GUICreate("Statusbar doubleclick demo", 400, 300)
$label = GUICtrlCreateLabel('abc', 10,10,100)

Global $hStatus = _GUICtrlStatusBar_Create($hGUI)
Global $aParts[3] = [125, 250]
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
_GUICtrlStatusBar_SetText($hStatus, "Text1", 0)
_GUICtrlStatusBar_SetText($hStatus, "Text2", 1)
_GUICtrlStatusBar_SetText($hStatus, "Text3", 2)

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
GUIRegisterMsg($WM_SB_DBLCLK, "WM_SB_DBLCLK")

While 1
    Switch GuiGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam

    If $hWndGUI = $hGUI Then

        $NMHDR = DllStructCreate($tagNMHDR , $lParam)
        $hWndFrom = DllStructGetData($NMHDR, 'hWndFrom')
        $event = DllStructGetData($NMHDR, 'Code')

        If $event = $NM_DBLCLK And $hWndFrom = $hStatus Then
            $NMMOUSE = DllStructCreate($tagNMMOUSE , $lParam)
            $part = DllStructGetData($NMMOUSE, 'ItemSpec')
            _SendMessage($hGUI, $WM_SB_DBLCLK, $part, 0)
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

Func WM_SB_DBLCLK($hWnd, $MsgID, $wParam, $lParam)
    ConsoleWrite('statusbar doubleclick, part=' & $wParam & ' text=' & _GUICtrlStatusBar_GetText($hStatus, $wParam) & @CRLF)
EndFunc
Posted

Nice example of using WM_USER. Thanks.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Because it will cause the application to "lock up". Try it and see AZJIO.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 7/1/2013 at 8:13 PM, AZJIO said:

guinness

I tried many times and I didn't see a difference. Maybe it is necessary to open a new thread?

Yeah do that please.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...