1 | #include <GuiConstantsEx.au3> |
---|
2 | #include <WindowsConstants.au3> |
---|
3 | #include <GuiListView.au3> |
---|
4 | #include <HeaderConstants.au3> |
---|
5 | #include <WinAPI.au3> |
---|
6 | |
---|
7 | ; The 0-based column to be disabled |
---|
8 | Global $iFix_Col |
---|
9 | Global $hOld_WndProc |
---|
10 | ; Get new WndProc hamdle and pointer |
---|
11 | Global $hNew_WndProc = DllCallbackRegister("_New_LVHdr_Proc", "lresult", "hwnd;uint;wparam;lparam") |
---|
12 | Global $pNew_WndProc = DllCallbackGetPtr($hNew_WndProc) |
---|
13 | ; To save old WndProc handle |
---|
14 | Global $hOld_WndProc |
---|
15 | |
---|
16 | _Main() |
---|
17 | |
---|
18 | Func _Main() |
---|
19 | Local Const $hGUI = GUICreate("ListView Fix Column Width", 400, 300) |
---|
20 | |
---|
21 | Local Const $cListView = GUICtrlCreateListView("Column 0|Column 1|Column 2|Column 3", 10, 10, 380, 220) |
---|
22 | GUICtrlCreateListViewItem("0|1|2|3", $cListView) |
---|
23 | |
---|
24 | Global $hLVHdr = _GUICtrlListView_GetHeader($cListView) |
---|
25 | |
---|
26 | $cButton = GUICtrlCreateButton("Test", 10, 250, 80, 30) |
---|
27 | |
---|
28 | GUISetState() |
---|
29 | |
---|
30 | ; Prevent resizing of column 1 |
---|
31 | $iFix_Col = 1 |
---|
32 | |
---|
33 | ; Prevent drag resize |
---|
34 | GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") |
---|
35 | |
---|
36 | ; SubClass LV Header |
---|
37 | $hOld_WndProc = _WinAPI_SetWindowLong($hLVHdr, $GWL_WNDPROC, $pNew_WndProc) |
---|
38 | ConsoleWrite("Old proc: 0x" & Hex($hOld_WndProc, 8) & @CRLF) |
---|
39 | |
---|
40 | ; Loop until user exits |
---|
41 | While 1 |
---|
42 | Switch GUIGetMsg() |
---|
43 | Case $GUI_EVENT_CLOSE |
---|
44 | Exit |
---|
45 | Case $cButton |
---|
46 | ConsoleWrite("Pressed" & @CRLF) |
---|
47 | EndSwitch |
---|
48 | WEnd |
---|
49 | |
---|
50 | GUIDelete($hGUI) |
---|
51 | EndFunc ;==>_Main |
---|
52 | |
---|
53 | Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) |
---|
54 | |
---|
55 | ; Get details of message |
---|
56 | Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam) |
---|
57 | ; Look for header resize code |
---|
58 | $iCode = DllStructGetData($tNMHEADER, "Code") |
---|
59 | Switch $iCode |
---|
60 | Case $HDN_BEGINTRACKW |
---|
61 | ; Now get column being resized |
---|
62 | Local $iCol = DllStructGetData($tNMHEADER, "Item") |
---|
63 | If $iCol = $iFix_Col Then |
---|
64 | ; Prevent resizing |
---|
65 | Return True |
---|
66 | Else |
---|
67 | ; Allow resizing |
---|
68 | Return False |
---|
69 | EndIf |
---|
70 | EndSwitch |
---|
71 | |
---|
72 | EndFunc ;==>_WM_NOTIFY |
---|
73 | |
---|
74 | Func _New_LVHdr_Proc($hWnd, $iMsg, $wParam, $lParam) |
---|
75 | |
---|
76 | Switch $iMsg |
---|
77 | Case $WM_SETCURSOR |
---|
78 | Return True |
---|
79 | EndSwitch |
---|
80 | |
---|
81 | ; Now call previous WndProc and complete the chain |
---|
82 | Return _WinAPI_CallWindowProc($hOld_WndProc, $hWnd, $iMsg, $wParam, $lParam) |
---|
83 | ;Return CallWindowProc($hOld_WndProc, $hWnd, $iMsg, $wParam, $lParam) |
---|
84 | EndFunc ;==>_New_LVHdr_Proc |
---|
85 | |
---|
86 | Func CallWindowProc($lpPrevWndFunc, $hWnd, $Msg, $wParam, $lParam) |
---|
87 | Return DllCall("user32.dll", "lresult", "CallWindowProc", "ptr", $lpPrevWndFunc, "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)[0] |
---|
88 | EndFunc ;==>CallWindowProc |
---|