Jump to content

Recommended Posts

  • 1 year later...
  • 2 years later...
On 29-1-2014 at 1:09 AM, HAMID said:

 

$listview = GUICtrlCreateListView("", 0, 0, 100, 80)
$hlistview = GUICtrlGetHandle($listview)
$hlistviewHeader = _GUICtrlListView_GetHeader($hlistview)
$chk = _GUICtrlButton_Create($hlistviewHeader, "", 0, 0, 20, 20, $BS_AUTOCHECKBOX)

 

@ajit you can try this

This works, but how can I listen for events on this checkbox? GUIGetMsg() doesn't work in this case.

Link to post
Share on other sites

Nobody?

I can't get it working with WM_COMMAND either. If I use the GUI handle as parent it works, but when I use the listviewheader handle as parent it doesn't work.

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Local $hGUI = GUICreate("Test", 200, 200)

Local $idChk_1 = _GUICtrlButton_Create($hGUI, "Check1", 5, 5, 90, 20, $BS_AUTO3STATE)

Local $listview = GUICtrlCreateListView("|Column1|Column2", 5, 40, 190, 150)
Local $hlistview = GUICtrlGetHandle($listview)
Local $hlistviewHeader = _GUICtrlListView_GetHeader($hlistview)
$idChk_2 = _GUICtrlButton_Create($hlistviewHeader, "", 4, 1.5, 15, 20, $BS_AUTO3STATE)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Exit

; React on a button click
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam

    Switch $hCtrl
    Case $idChk_1, $idChk_2
        Switch $nNotifyCode
            Case $BN_CLICKED
                MsgBox($MB_SYSTEMMODAL, "WM_command", "click")

        EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Edited by Bolluhhhhh
Link to post
Share on other sites

The checkbox in the header is too far away from the GUI for the WM_COMMAND message handler to be able to catch the events.

To catch the events you have to use subclassing. WM_COMMAND messages are always sent to the parent window. The parent window of $idChk_2 is the header control. You have to subclass the header control:

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPIShellEx.au3>

Local $hGUI = GUICreate("Test", 200, 200)

Local $idChk_1 = _GUICtrlButton_Create($hGUI, "Check1", 5, 5, 90, 20, $BS_AUTO3STATE)

Local $listview = GUICtrlCreateListView("|Column1|Column2", 5, 40, 190, 150)
Local $hlistview = GUICtrlGetHandle($listview)
Local $hlistviewHeader = _GUICtrlListView_GetHeader($hlistview)
$idChk_2 = _GUICtrlButton_Create($hlistviewHeader, "", 4, 1.5, 15, 20, $BS_AUTO3STATE)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

Local $pHeaderCallback = DllCallbackGetPtr( DllCallbackRegister( "HeaderCallback", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) )
_WinAPI_SetWindowSubclass( $hlistviewHeader, $pHeaderCallback, 9999, 0 )

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Exit

; React on a button click
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Local $hCtrl = $lParam

    Switch $hCtrl
    Case $idChk_1, $idChk_2
        Switch $nNotifyCode
            Case $BN_CLICKED
                MsgBox($MB_SYSTEMMODAL, "WM_command", "click")

        EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func HeaderCallback( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $pData )
  Local $nNotifyCode = BitShift($wParam, 16)
  Local $hCtrl = $lParam

  Switch $hCtrl
    Case $idChk_2
      Switch $nNotifyCode
          Case $BN_CLICKED
              MsgBox($MB_SYSTEMMODAL, "Header", "click")
      EndSwitch
  EndSwitch

  Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0]
EndFunc

 

Link to post
Share on other sites
  • 2 weeks later...

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...