Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "RichEdit.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 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 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
'wParam - virtual code of key pressed by user that prompted Windows to issue this notificaton
'lParam - NULL if system is performing a query
' - otherwise, pointer to a MSG structure
If lParam = %Null Then ' system is performing a query
iReturn = CallWindowProc (oldProc, hWnd, Msg, wParam, lParam) 'do here, not at end of NewProc
If (iReturn And %DlgC_HasSetSel) = %DlgC_HasSetSel Then 'does flag contain %DLGC_HasSetSel
iReturn = iReturn Xor %DlgC_HasSetSel 'remove %DLGC_HasSetSel
Function = iReturn : Exit Function 'return flag to system
End If
End If
If lParam = %Null Then
iReturn = CallWindowProc (OldProc, hWnd, Msg, wParam, lParam)
If (iReturn And %DlgC_WantTab) = %DlgC_WantTab Then
iReturn = iReturn Xor %DlgC_WantTab
End If
End If
End Select
Function = CallWindowProc(OldProc&, hWnd, Msg, wParam, lParam) 'returns un-modified flag to system
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_00716
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm