Date: 02-16-2022
Return to Index
created by gbSnippets
'User-defined and subclassed controls receive the WM_GetDlgCode message.
'The WM_GetDlgCode message can be used to modify how an application responds to
'keyboard activity. However, it is received only by user-defined and subclassed
'controls.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.inc"
#Include "commctrl.inc"
%IDC_Control = 500 : %IDC_Button = 501 : %IDC_Label = 502
Global hDlg As Dword, OldProc&
Function PBMain() As Long
Dialog New Pixels, 0, "WM_GetDlgCode Test",300,300,600,210, %WS_OverlappedWindow To hDlg
' Local REstyle&, buf$
' buf$ = "This is sample" + $CrLf + "text for the" + $CrLf + "edit control."
' REstyle& = %WS_Child Or %WS_Visible Or %ES_MultiLine Or %WS_VScroll Or %ES_AutoHScroll _
' Or %WS_HScroll Or %ES_AutoVScroll Or %ES_WantReturn Or %ES_NoHideSel Or %WS_TabStop
' LoadLibrary("riched32.dll") : InitCommonControls
' Control Add "RichEdit", hDlg, %IDC_Control, buf$,10,10,180,120, REstyle&
Local TBstyle&
TBstyle& = %WS_TabStop Or %WS_Border Or %ES_Left Or %ES_AutoHScroll _
Or %ES_MultiLine Or %ES_NoHideSel Or %ES_WantReturn
Control Add TextBox, hDlg, %IDC_Control, "TextBox", 10,10,580,120, TBStyle&
' Control Add Option, hDlg, %IDC_Control, "Push", 10,10,580,120
' Control Add ComboBox, hDlg, %IDC_Control, , 10,10,580,120
' Control Add ListBox, hDlg, %IDC_Control, , 10,10,580,120
' Control Add Label, hDlg, %IDC_Control, "Test", 10,10,580,120
' Control Add ListView, hDlg, %IDC_Control, "Test", 10,10,580,120
Control Add Label, hDlg, %IDC_Label,"<message>", 10,140,580,20
Control Add Button, hDlg, %IDC_Button,"Push", 10,170,160,20 'just here to give a different control to receive focus
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
OldProc& = SetWindowLong(GetDlgItem(hDlg,%IDC_Control), %GWL_WndProc, CodePtr(NewProc)) 'subclass
Case %WM_Destroy
SetWindowLong GetDlgItem(hDlg,%IDC_Control), %GWL_WNDPROC, OldProc& 'un-subclass
End Select
End Function
Function NewProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Local iReturn As Long, temp$
Select Case Msg
Case %WM_GetDlgCode
iReturn = CallWindowProc (OldProc, hWnd, Msg, wParam, lParam)
If (iReturn And %DlgC_Button) = %DlgC_Button Then temp$ = temp$ + " Button "
If (iReturn And %DlgC_DefPushButton) = %DlgC_DefPushButton Then temp$ = temp$ + " DefPushButton "
If (iReturn And %DlgC_RadioButton) = %DlgC_RadioButton Then temp$ = temp$ + " RadioButton "
If (iReturn And %DlgC_Static) = %DlgC_Static Then temp$ = temp$ + " Static "
If (iReturn And %DlgC_UnDefPushButton) = %DlgC_UnDefPushButton Then temp$ = temp$ + " UndefPushButton "
If (iReturn And %DlgC_HasSetSel) = %DlgC_HasSetSel Then temp$ = temp$ + " HasSetSel"
If (iReturn And %DlgC_WantAllKeys) = %DlgC_WantAllKeys Then temp$ = temp$ + " WantAllKeys"
If (iReturn And %DlgC_WantArrows) = %DlgC_WantArrows Then temp$ = temp$ + " WantArrows"
If (iReturn And %DlgC_WantChars) = %DlgC_WantChars Then temp$ = temp$ + " WantChars"
If (iReturn And %DlgC_WantTab) = %DlgC_WantTab Then temp$ = temp$ + " WantTAB"
If (iReturn And %DlgC_WantMessage) = %DlgC_WantMessage Then temp$ = temp$ + " WantMessage"
Control Set Text hDlg, %IDC_Label, temp$
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam)
End Function
' Function = iReturn : Exit Function
' If (iReturn And %DlgC_WantArrows) = %DlgC_WantArrows Then iReturn = iReturn Xor %DlgC_WantArrows
'The DLGC_WANTCHARS, DLGC_WANTTAB and DLGC_WANTARROWS flags are just conveniences
'that save you the trouble of checking certain categories of messages.
'The return codes above can be used by user-defined controls or, in a subclass procedure,
'to modify the behavior of predefined controls. To subclass a control, call the predefined
'control's window procedure first, then modify the necessary bits in the return code.
'wParam 'not used
'lParam 'if not %Null, is pointer to MSG structure
'DLGC_BUTTON 'control is a Button
'DLGC_DEFPUSHBUTTON 'control is a default Push Button
'DLGC_RADIOBUTTON 'control is an Option Button
'DLGC_STATIC 'control is a Static control (PB line, label, image controls)
'DLGC_UNDEFPUSHBUTTON 'control is a Push Buttion, but not the default Push Button
'DLGC_HASSETSEL 'control processes EM_SETSEL messages.
'DLGC_WANTALLKEYS 'control processes all keyboard input
'DLGC_WANTARROWS 'control processes arrow keys
'DLGC_WANTCHARS 'control processes WM_Char messages
'DLGC_WANTTAB 'control processes the TAB key
'DLGC_WANTMESSAGE 'control processes the message in the MSG structure that lParam points to
' Case WM_KEYDOWN:
' If wParam == %VK_TAB Then
' SetFocus(GetNextDlgTabItem(GetParent(hwnd), hwnd, FALSE))
' Function = 0 'message handled
' End If
'There are many things wrong with this approach. You can spend quite a lot of time
'nitpicking the little details, how this code fails to set focus in a dialog box properly,
'how it fails to take nested dialogs into account, how it fails to handle the Shift+Tab
'navigation key, how it blatantly assumes that the control is part of a dialog box in the
'first place! But all of these little details are missing the big picture: Instead of fighting
'against the dialog manager and reimplementing all the parts we want to keep and ignoring the
'parts we want to skip, we should be working with the dialog manager and expressing our
'intentions in the manner the dialog manager expects.
'Animation Image List Rich Edit Trackbar
'Button IP Address Control Scroll Bar Tree View
'ComboBox List Box Static Control Up-Down COntrol
'ComboBoxEx List View Status Bar
'Date and Time Picker Month Calendar SysLink
'Edit Control Pager TAB
'Flat Scroll Bar Progress Bar Task Dialog
'Header Control Property Sheet Toolbar
'Hot Key Rebar Tooltip
'gbs_00714
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm