Что нового

Новые стили и форматы заголовка в Vista+

Yashied

Модератор
Команда форума
Глобальный модератор
Сообщения
5 379
Репутация
2 711
Простой пример работы с новыми стилями и форматами заголовка в Windows Vista+.

Код:
#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIHeader.au3>
#Include <GUIListView.au3>
#Include <GUIMenu.au3>
#Include <StructureConstants.au3>
#Include <WindowsConstants.au3>

; Vista+ format constants
Global Const $HDF_CHECKBOX = 0x00000040
Global Const $HDF_CHECKED = 0x00000080
Global Const $HDF_FIXEDWIDTH = 0x00000100
Global Const $HDF_SPLITBUTTON = 0x01000000

; Vista+ notification constants
Global Const $HDN_DROPDOWN = $HDN_FIRST - 18

$hForm = GUICreate('MyGUI', 400, 200)
$LV = GUICtrlCreateListView('Column1|Column2|Column3', 10, 10, 380, 180)

DllCall('uxtheme.dll', 'uint', 'SetWindowTheme', 'hwnd', GUICtrlGetHandle($LV), 'wstr', 'Explorer', 'ptr', 0)

$hHdr = _GUICtrlListView_GetHeader(-1)
$Format = _GUICtrlHeader_GetItemFormat($hHdr, 0)
_WinAPI_SetWindowLong($hHdr, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hHdr, $GWL_STYLE), $HDS_CHECKBOXES))
_GUICtrlHeader_SetItemFormat($hHdr, 0, BitOR($Format, $HDF_SPLITBUTTON))
_GUICtrlHeader_SetItemWidth($hHdr, 0, 120)
_GUICtrlHeader_SetItemFormat($hHdr, 1, BitOR($Format, $HDF_SPLITBUTTON))
_GUICtrlHeader_SetItemWidth($hHdr, 1, 120)
_GUICtrlHeader_SetItemFormat($hHdr, 2, BitOR($Format, BitOR($HDF_CHECKBOX, $HDF_FIXEDWIDTH, $HDF_SPLITBUTTON)))
_GUICtrlHeader_SetItemWidth($hHdr, 2, 120)

$Dummy = GUICtrlCreateDummy()
$Menu = GUICtrlCreateContextMenu($Dummy)
GUICtrlCreateMenuItem('Item1', $Menu)
GUICtrlCreateMenuItem('Item2', $Menu)
GUICtrlCreateMenuItem('Item3', $Menu)
$Menu = GUICtrlGetHandle($Menu)

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()

While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			ExitLoop
		Case $Dummy
			_GUICtrlMenu_TrackPopupMenu($Menu, $hForm)
	EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
	Switch $hWnd
		Case $hForm

			Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
			Local $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
			Local $Code = DllStructGetData($tNMHDR, 'Code')

			Switch $hWndFrom
				Case $hHdr
					If @AutoItX64 Then
						Local $tNMHEADER = DllStructCreate('hwnd hWndFrom;uint_ptr IDFrom;int Code;uint Aligment;int Item;int Button;ptr pItem', $lParam)
					Else
						Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
					EndIf
					Local $tHDITEM = DllStructCreate($tagHDITEM, DllStructGetData($tNMHEADER, 'pItem'))
					Local $Item = DllStructGetData($tNMHEADER, 'Item')

					Switch $Code
						Case $HDN_DROPDOWN
							GUICtrlSendToDummy($Dummy, $Item)
						Case $HDN_ITEMCHANGINGW
							If BitAND(DllStructGetData($tHDITEM, 'Mask'), $HDI_FORMAT) Then
								$Format = BitAND($Format, $HDF_CHECKED)
								If BitXOR(BitAND(DllStructGetData($tHDITEM, 'Fmt'), $HDF_CHECKED), $Format) Then
									If $Format Then
										ConsoleWrite('Column' & ($Item + 1) & ': ' & 'Unchecked' & @CR)
									Else
										ConsoleWrite('Column' & ($Item + 1) & ': ' & 'Checked' & @CR)
									EndIf
								EndIf
							EndIf
						Case $HDN_ITEMCHANGEDW
							If BitAND(DllStructGetData($tHDITEM, 'Mask'), $HDI_FORMAT) Then
								$Format = _GUICtrlHeader_GetItemFormat($hHdr, $Item)
							EndIf
					EndSwitch
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


 
Верх