Date: 02-16-2022
Return to Index
created by gbSnippets
'A Callback function has to handle any of the thousands of messages Windows may
'send. Fortunately, most programs actually see only a limited number of messages.
'Here's a listing of the more-often used messages, conveniently placed in a Callback function
'Primary Code:
'Example #1: just the messages listed
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Activate 'setn to the window being activated and window being deactivated
Case %WM_ActivateApp 'focus returns to app from another app
Case %WM_Char 'when keyboard is pressed
Case %WM_Close 'sent to window that is about to close
Case %WM_Command 'control notifications
Case %WM_ContextMenu 'user clicked the right mouse button (right-clicked) in a window.
Case %WM_Create 'when the dialog is first created, before it becomes visible
Case %WM_Destroy 'window is being destroyed. after window is removed from screen (children still exist)
Case %WM_DropFiles 'when a file is dropped on a drop-activated control/dialog
Case %WM_EraseBkgnd 'indicates that a window needs to be erased
Case %WM_GetDlgCode 'give all keyboard events
Case %WM_GetMinMaxInfo 'whenever dialog dimension is about to change
Case %WM_Help 'when F1 is pressed
Case %WM_HotKey 'when user presses a registered hotkey
Case %WM_InitDialog 'immediately before a dialog box is displayed
Case %WM_InitMenuPopup 'sent before a popup menu is displayed
Case %WM_MenuSelect 'when a user selects a menu item
Case %WM_MouseMove 'when cursor moves
Case %WM_Notify 'control notifications
Case %WM_Paint 'client area need redrawn
Case %WM_SetCursor 'sent if mouse causes cursor to move
Case %WM_Size 'size has changed
Case %WM_SysCommand 'command chosen from Window menu or upper right buttons
Case %WM_Timer 'timer event
End Select
End Function
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Activate 'sent to window being activated and window being deactivated
Case %WM_ActivateApp 'focus returns to app from another app
Case %WM_Char 'when keyboard is pressed
Case %WM_Close 'sent to window that is about to close
Case %WM_Command 'control notifications
If CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then MsgBox "I was clicked!"
Case %WM_ContextMenu 'user clicked the right mouse button (right-clicked) in a window.
Case %WM_Create 'when the dialog is first created, before it becomes visible
Case %WM_Destroy 'window is being destroyed. after window is removed from screen (children still exist)
Case %WM_DropFiles 'when a file is dropped on a drop-activated control/dialog
Case %WM_EraseBkgnd 'indicates that a window needs to be erased
Case %WM_GetDlgCode 'give all keyboard events
Case %WM_GetMinMaxInfo 'whenever dialog dimension is about to change
Case %WM_Help 'when F1 is pressed
Case %WM_HotKey 'when user presses a registered hotkey
Case %WM_InitDialog 'immediately before a dialog box is displayed
Case %WM_InitMenuPopup 'sent before a popup menu is displayed
Case %WM_MenuSelect 'when a user selects a menu item
Case %WM_MouseMove 'when cursor moves
Case %WM_Notify 'control notifications
Case %WM_Paint 'client area need redrawn
Case %WM_SetCursor 'sent if mouse causes cursor to move
Case %WM_Size 'size has changed
Case %WM_SysCommand 'command chosen from Window menu or upper right buttons
Case %WM_Timer 'timer event
End Select
End Function
'gbs_00076
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm