Monitor Messages - Callback (GetMsgText)

Category: Debug

Date: 03-28-2012

Return to Index


 
'Programmers often need to check to see which messages are received by their
'application, where the message text is provided, not just the message number.
 
'Primary Code:
'Credit: Chris Boss
'This approach simply calls a Function each time the Callback function is called,
'sending Cb.Msg to a function which returns the text description of messages of interest.
'Note that some messages happen a LOT, so note how the extra Case statement is
'used to exclude unwanted messages from the generated list
Function GetMsgText(Msg&)
   Select Case Msg&
      Case %WM_CtlColorListBox       'include as desired - use to skip any message(s)
      Case %WM_Activate:C$="WM_ACTIVATE"
      Case %WM_ActivateApp: c$ = "%WM_ActivateApp"
         ' statements are added for each possible message
         'see compilable example below for more detailed listing
         'of messages. pulled from win32api.inc
   End Select
End Function
 
'Compilable Example:
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
#Include "Win32API.inc"
Global hDlg As Dword
 
Function PBMain() As Long
   Dim a(0) as String
   a(0) = "Message List"
   Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
   Control Add ListBox, hDlg, 100,a(), 10,10,170,170
   Dialog Show Modal hDlg Call DlgProc
End Function
 
CallBack Function DlgProc() As Long
   Static i As Long
   Incr i
   Select Case CB.Msg
      Case %WM_CtlColorListBox       'include as desired - use to skip any message(s)
      Case Else
         ListBox Insert hDlg, 100, 1, Format$(i,"00000   ") + GetMsgText(CB.Msg)
         GetMsgText CB.Msg
   End Select
End Function
 
Function GetMsgText(Msg&) As String
   Local c$
   Select Case Msg&
      Case %WM_Activate: c$ = "%WM_Activate"
      Case %WM_ActivateApp: c$ = "%WM_ActivateApp"
      Case %WM_AFXFirst: c$ = "%WM_AFXFirst"
      Case %WM_AFXLast: c$ = "%WM_AFXLast"
      Case %WM_App: c$ = "%WM_App"
      Case %WM_AppCommand: c$ = "%WM_AppCommand"
      Case %WM_AskCBFormatName: c$ = "%WM_AskCBFormatName"
      Case %WM_CancelJournal: c$ = "%WM_CancelJournal"
      Case %WM_CancelMode: c$ = "%WM_CancelMode"
      Case %WM_CaptureChanged: c$ = "%WM_CaptureChanged"
      Case %WM_ChangeCBChain: c$ = "%WM_ChangeCBChain"
      Case %WM_ChangeUIState: c$ = "%WM_ChangeUIState"
      Case %WM_Char: c$ = "%WM_Char"
      Case %WM_CharToItem: c$ = "%WM_CharToItem"
      Case %WM_ChildActivate: c$ = "%WM_ChildActivate"
      Case %WM_Clear: c$ = "%WM_Clear"
      Case %WM_Close: c$ = "%WM_Close"
      Case %WM_Command: c$ = "%WM_Command"
      Case %WM_CommNotify: c$ = "%WM_CommNotify"
      Case %WM_Compacting: c$ = "%WM_Compacting"
      Case %WM_CompareItem: c$ = "%WM_CompareItem"
      Case %WM_ContextMenu: c$ = "%WM_ContextMenu"
      Case %WM_Copy: c$ = "%WM_Copy"
      Case %WM_CopyData: c$ = "%WM_CopyData"
      Case %WM_Create: c$ = "%WM_Create"
      Case %WM_CtlColorBTN: c$ = "%WM_CtlColorBTN"
      Case %WM_CtlColorDLG: c$ = "%WM_CtlColorDLG"
      Case %WM_CtlColorEdit: c$ = "%WM_CtlColorEdit"
      Case %WM_CtlColorListBox: c$ = "%WM_CtlColorListBox"
      Case %WM_CtlColorMsgBox: c$ = "%WM_CtlColorMsgBox"
      Case %WM_CtlColorScrollBar: c$ = "%WM_CtlColorScrollBar"
      Case %WM_CtlColorStatic: c$ = "%WM_CtlColorStatic"
      Case %WM_Cut: c$ = "%WM_Cut"
      Case %WM_DeadChar: c$ = "%WM_DeadChar"
      Case %WM_DeleteItem: c$ = "%WM_DeleteItem"
      Case %WM_Destroy: c$ = "%WM_Destroy"
      Case %WM_DestroyClipboard: c$ = "%WM_DestroyClipboard"
      Case %WM_DeviceChange: c$ = "%WM_DeviceChange"
      Case %WM_DevmodeChange: c$ = "%WM_DevmodeChange"
      Case %WM_DisplayChange: c$ = "%WM_DisplayChange"
      Case %WM_DrawClipboard: c$ = "%WM_DrawClipboard"
      Case %WM_DrawItem: c$ = "%WM_DrawItem"
      Case %WM_DropFiles: c$ = "%WM_DropFiles"
      Case %WM_Enable: c$ = "%WM_Enable"
      Case %WM_Endsession: c$ = "%WM_Endsession"
      Case %WM_EnterIdle: c$ = "%WM_EnterIdle"
      Case %WM_EnterMenuLoop: c$ = "%WM_EnterMenuLoop"
      Case %WM_EraseBkgnd: c$ = "%WM_EraseBkgnd"
      Case %WM_ExitMenuLoop: c$ = "%WM_ExitMenuLoop"
      Case %WM_FontChange: c$ = "%WM_FontChange"
      Case %WM_GetDLGCode: c$ = "%WM_GetDLGCode"
      Case %WM_GetFont: c$ = "%WM_GetFont"
      Case %WM_GetHotkey: c$ = "%WM_GetHotkey"
      Case %WM_GetIcon: c$ = "%WM_GetIcon"
      Case %WM_GetMinMaxInfo: c$ = "%WM_GetMinMaxInfo"
      Case %WM_GetObject: c$ = "%WM_GetObject"
      Case %WM_GetText: c$ = "%WM_GetText"
      Case %WM_GetTextLength: c$ = "%WM_GetTextLength"
      Case %WM_HandheldFirst: c$ = "%WM_HandheldFirst"
      Case %WM_HandheldLast: c$ = "%WM_HandheldLast"
      Case %WM_Help: c$ = "%WM_Help"
      Case %WM_Hotkey: c$ = "%WM_Hotkey"
      Case %WM_HScroll: c$ = "%WM_HSScroll"
      Case %WM_HScrollClipboard: c$ = "%WM_HSScrollClipboard"
      Case %WM_IconEraseBKGnd: c$ = "%WM_IconEraseBKGnd"
      Case %WM_InitDialog: c$ = "%WM_InitDialog"
      Case %WM_InitMenu: c$ = "%WM_InitMenu"
      Case %WM_InitMenuPopup: c$ = "%WM_InitMenuPopup"
      Case %WM_Input: c$ = "%WM_Input"
      Case %WM_InputLangChange: c$ = "%WM_InputLangChange"
      Case %WM_InputLangChangeRequest: c$ = "%WM_InputLangChangeRequest"
'      Case %WM_InputLanguageChange: c$ = "%WM_InputLanguageChange"
'      Case %WM_InputLanguageChangeRequest: c$ = "%WM_InputLanguageChangeRequest"
      Case %WM_KeyDown: c$ = "%WM_KeyDown"
      Case %WM_KeyFirst: c$ = "%WM_KeyFirst"
      Case %WM_KeyLast: c$ = "%WM_KeyLast"
      Case %WM_KeyUp: c$ = "%WM_KeyUp"
      Case %WM_KillFocus: c$ = "%WM_KillFocus"
      Case %WM_LButtonDblClk: c$ = "%WM_LButtonDBLClk"
      Case %WM_LButtonDown: c$ = "%WM_LButtonDown"
      Case %WM_LButtonUp: c$ = "%WM_LButtonUp"
      Case %WM_MButtonDblClk: c$ = "%WM_MButtonDBLClk"
      Case %WM_MButtonDown: c$ = "%WM_MButtonDown"
      Case %WM_MButtonUp: c$ = "%WM_MButtonUp"
      Case %WM_MDIActivate: c$ = "%WM_MDIActivate"
      Case %WM_MDICascade: c$ = "%WM_MDICascade"
      Case %WM_MDICreate: c$ = "%WM_MDICreate"
      Case %WM_MDIDestroy: c$ = "%WM_MDIDestroy"
      Case %WM_MDIGetActive: c$ = "%WM_MDIGetActive"
      Case %WM_MDIIconArrange: c$ = "%WM_MDIIconArrange"
      Case %WM_MDIMaximize: c$ = "%WM_MDIMaximize"
      Case %WM_MDINext: c$ = "%WM_MDINext"
      Case %WM_MDIRefreshMenu: c$ = "%WM_MDIRefreshMenu"
      Case %WM_MDIRestore: c$ = "%WM_MDIRestore"
      Case %WM_MDISetMenu: c$ = "%WM_MDISetMenu"
      Case %WM_MDITile: c$ = "%WM_MDITile"
      Case %WM_MeasureItem: c$ = "%WM_MeasureItem"
      Case %WM_MenuChar: c$ = "%WM_MenuChar"
      Case %WM_MenuCommand: c$ = "%WM_MenuCommand"
      Case %WM_MenuDrag: c$ = "%WM_MenuDrag"
      Case %WM_MenuGetobject: c$ = "%WM_MenuGetobject"
      Case %WM_MenuRButtonup: c$ = "%WM_MenuRButtonup"
      Case %WM_MenuSelect: c$ = "%WM_MenuSelect"
      Case %WM_MouseActivate: c$ = "%WM_MouseActivate"
      Case %WM_MouseFirst: c$ = "%WM_MouseFirst"
      Case %WM_MouseLast: c$ = "%WM_MouseLlast"
      Case %WM_MouseMove: c$ = "%WM_MouseMove"
      Case %WM_MouseWheel: c$ = "%WM_MouseWheel"
      Case %WM_Move: c$ = "%WM_Move"
      Case %WM_Moving: c$ = "%WM_Moving"
      Case %WM_NCActivate: c$ = "%WM_NCActivate"
      Case %WM_NCCalcsize: c$ = "%WM_NCCalcSize"
      Case %WM_NCCreate: c$ = "%WM_NCCreate"
      Case %WM_NCDestroy: c$ = "%WM_NCDestroy"
      Case %WM_NCHitTest: c$ = "%WM_NCHitTest"
      Case %WM_NCLButtonDblClk: c$ = "%WM_NCLButtonDBLClk"
      Case %WM_NCLButtonDown: c$ = "%WM_NCLButtonDown"
      Case %WM_NCLButtonUp: c$ = "%WM_NCLButtonUp"
      Case %WM_NCMButtonDblClk: c$ = "%WM_NCMButtonDBLClk"
      Case %WM_NCMButtonDown: c$ = "%WM_NCMButtonDown"
      Case %WM_NCMButtonUp: c$ = "%WM_NCMButtonUp"
      Case %WM_NCMouseMove: c$ = "%WM_NCMouseMove"
      Case %WM_NCPaint: c$ = "%WM_NCPaint"
      Case %WM_NCRButtonDblClk: c$ = "%WM_NCRButtonDBLClk"
      Case %WM_NCRButtonDown: c$ = "%WM_NCRButtonDown"
      Case %WM_NCRButtonUp: c$ = "%WM_NCRButtonUp"
      Case %WM_NCXButtonDblClk: c$ = "%WM_NCXBbuttonDBLClk"
      Case %WM_NCXButtonDown: c$ = "%WM_NCXxButtonDown"
      Case %WM_NCXButtonUp: c$ = "%WM_NCXButtonUp"
      Case %WM_NextDLGCtl: c$ = "%WM_NextDLGCtl"
      Case %WM_Notify: c$ = "%WM_Notify"
      Case %WM_NotifyFormat: c$ = "%WM_NotifyFormat"
      Case %WM_Null: c$ = "%WM_Null"
'      Case %WM_OtherWindowCreated: c$ = "%WM_OtherWindowCreated"
'      Case %WM_OtherWindowDestroyed: c$ = "%WM_OtherWindowDestroyed"
      Case %WM_Paint: c$ = "%WM_Paint"
      Case %WM_PaintClipboard: c$ = "%WM_PaintClipboard"
      Case %WM_PaintIcon: c$ = "%WM_PaintIcon"
      Case %WM_PaletteChanged: c$ = "%WM_PaletteChanged"
      Case %WM_PaletteIsChanging: c$ = "%WM_PaletteIsChanging"
      Case %WM_ParentNotify: c$ = "%WM_ParentNotify"
      Case %WM_Paste: c$ = "%WM_Paste"
      Case %WM_PenWinFirst: c$ = "%WM_PenWinFirst"
      Case %WM_PenWinLast: c$ = "%WM_PenWinLast"
      Case %WM_Power: c$ = "%WM_Power"
      Case %WM_PowerBroadcast: c$ = "%WM_PowerBroadcast"
      Case %WM_Print: c$ = "%WM_Print"
      Case %WM_PrintClient: c$ = "%WM_PrintClient"
      Case %WM_QueryDragIcon: c$ = "%WM_QueryDragIcon"
      Case %WM_QueryEndSession: c$ = "%WM_QueryEndSsession"
      Case %WM_QueryNewPalette: c$ = "%WM_QueryNewPalette"
      Case %WM_QueryOpen: c$ = "%WM_QueryOpen"
      Case %WM_QueryUIState: c$ = "%WM_QueryUIState"
      Case %WM_QueueSync: c$ = "%WM_QueueSync"
      Case %WM_Quit: c$ = "%WM_Quit"
      Case %WM_RButtonDblClk: c$ = "%WM_RButtonDBLClk"
      Case %WM_RButtonDown: c$ = "%WM_RButtonDown"
      Case %WM_RButtonUp: c$ = "%WM_RButtonUp"
      Case %WM_RenderAllFormats: c$ = "%WM_RenderAllFormats"
      Case %WM_RenderFormat: c$ = "%WM_RenderFormat"
      Case %WM_SetCursor: c$ = "%WM_SetCursor"
      Case %WM_SetFocus: c$ = "%WM_SetFocus"
      Case %WM_SetFont: c$ = "%WM_SetFont"
      Case %WM_SetHotkey: c$ = "%WM_SetHotkey"
      Case %WM_SetIcon: c$ = "%WM_SetIcon"
      Case %WM_SetRedraw: c$ = "%WM_SetRedraw"
      Case %WM_SetText: c$ = "%WM_SetText"
      Case %WM_SettingChange: c$ = "%WM_SettingChange"
      Case %WM_ShowWindow: c$ = "%WM_ShowWindow"
      Case %WM_Size: c$ = "%WM_Size"
      Case %WM_SizeClipboard: c$ = "%WM_SizeClipboard"
      Case %WM_Sizing: c$ = "%WM_Sizing"
      Case %WM_SpoolerStatus: c$ = "%WM_SpoolerStatus"
      Case %WM_StyleChanged: c$ = "%WM_StyleChanged"
      Case %WM_StyleChanging: c$ = "%WM_StyleChanging"
      Case %WM_SyncPaint: c$ = "%WM_SyncPaint"
      Case %WM_SysChar: c$ = "%WM_SysChar"
      Case %WM_SysColorChange: c$ = "%WM_SysColorChange"
      Case %WM_SysCommand: c$ = "%WM_SysCommand"
      Case %WM_SysDeadChar: c$ = "%WM_SysDeadChar"
      Case %WM_SysKeyDown: c$ = "%WM_SysKeyDown"
      Case %WM_SysKeyUp: c$ = "%WM_SysKeyUp"
      Case %WM_Tablet_First: c$ = "%WM_Tablet_First"
      Case %WM_Tablet_Last: c$ = "%WM_Tablet_Last"
      Case %WM_TCard: c$ = "%WM_TCard"
      Case %WM_ThemeChanged: c$ = "%WM_ThemeChanged"
      Case %WM_TimeChange: c$ = "%WM_TimeChange"
      Case %WM_Timer: c$ = "%WM_Timer"
      Case %WM_Undo: c$ = "%WM_Undo"
      Case %WM_UniChar: c$ = "%WM_UniChar"
      Case %WM_UnInitMenuPopup: c$ = "%WM_UnInitMenuPopup"
      Case %WM_UpdateUIState: c$ = "%WM_UpdateUIState"
      Case %WM_User: c$ = "%WM_User"
      Case %WM_UserChanged: c$ = "%WM_UserChanged"
      Case %WM_VKeyToItem: c$ = "%WM_VKeyToItem"
      Case %WM_VScroll: c$ = "%WM_VScroll"
      Case %WM_VScrollClipboard: c$ = "%WM_VScrollClipboard"
      Case %WM_WindowPosChanged: c$ = "%WM_WindowPosChanged"
      Case %WM_WindowPosChanging: c$ = "%WM_WindowPosChanging"
      Case %WM_WinIniChange: c$ = "%WM_WinIniChange"
      Case %WM_WTSSession_Change: c$ = "%WM_WTSSession_Change"
      Case %WM_XButtonDBLClk: c$ = "%WM_XButtonDBLClk"
      Case %WM_XButtonDown: c$ = "%WM_XButtonDown"
      Case %WM_XButtonUp: c$ = "%WM_XButtonUp"
      Case Else: c$="   &H"+Hex$(Msg&)   'catches anything missed above
   End Select
   Function = c$
End Function
 
'gbs_00113
'Date: 03-10-2012


created by gbSnippets
http://www.garybeene.com/sw/gbsnippets.htm