Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Message Watch Learning App

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Message Watch Learning App

    Below is the code for what I call "Message Watch".

    It uses a Message loop and one Dialog procedure and it watches to see what messages are passed through to each. You will notice that some messages get passed through the message loop before they go to the dialog procedure, but many do not (they are sent directly to the dialog procedure).

    This app allows you to learn about what messages are pased through the message compared to the dialog procedure.

    Code:
    ' ***************************************************************
    '   This code can be used Royalty Free and Freely Distributed !
    '   Written by Chris Boss 05/11/2009
    ' ***************************************************************
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL          '  This is helpful to prevent errors in coding
    #INCLUDE "win32api.inc"   ' Must come first before other include files !
    ' *************************************************************
    '                  Constants and Declares (#1)
    ' *************************************************************
    %FORM1_BUTTON1            = 100
    %FORM1_TEXT1              = 110
    %FORM1_TEXT2              = 120
    ' --------------------------------------------------
    DECLARE SUB ShowDialog_Form1(BYVAL hParent&)
    DECLARE CALLBACK FUNCTION Form1_DLGPROC
    ' --------------------------------------------------
    ' ------------------------------------------------
    DECLARE CALLBACK FUNCTION CBF_FORM1_BUTTON1()
    ' *************************************************************
    '               Application Globals Variables (#2)
    ' *************************************************************
    GLOBAL hForm1&    ' Dialog handle
    ' *************************************************************
    '                    Application Entrance
    ' *************************************************************
    GLOBAL MT() AS STRING
    GLOBAL M2() AS LONG
    '
    FUNCTION PBMAIN
        LOCAL Count&, V&, Msg AS tagMsg, T$, X&, C$
        DIM M(0 TO %WM_USER) AS LONG
        REDIM M2(0 TO %WM_USER) AS GLOBAL LONG
        REDIM MT(0 TO %WM_USER) AS GLOBAL STRING
        FOR X&=0 TO %WM_USER
             SELECT CASE X&
                   CASE %WM_NULL:C$="WM_NULL"
                   CASE %WM_CREATE:C$="WM_CREATE"
                   CASE %WM_DESTROY:C$="WM_DESTROY"
                   CASE %WM_MOVE:C$="WM_MOVE"
                   CASE %WM_SIZE:C$="WM_SIZE"
                   CASE %WM_ACTIVATE:C$="WM_ACTIVATE"
                   CASE %WM_SETFOCUS:C$="WM_SETFOCUS"
                   CASE %WM_KILLFOCUS:C$="WM_KILLFOCUS"
                   CASE %WM_ENABLE:C$="WM_ENABLE"
                   CASE %WM_SETTEXT:C$="WM_SETTEXT"
                   CASE %WM_GETTEXT:C$="WM_GETTEXT"
                   CASE %WM_GETTEXTLENGTH:C$="WM_GETTEXTLENGTH"
                   CASE %WM_PAINT:C$="WM_PAINT"
                   CASE %WM_CLOSE:C$="WM_CLOSE"
                   CASE %WM_QUIT:C$="WM_QUIT"
                   CASE %WM_ERASEBKGND:C$="WM_ERASEBKGND"
                   CASE %WM_SHOWWINDOW:C$="WM_SHOWWINDOW"
                   CASE %WM_ACTIVATEAPP:C$="WM_ACTIVATEAPP"
                   CASE %WM_SETCURSOR:C$="WM_SETCURSOR"
                   CASE %WM_GETMINMAXINFO:C$="WM_GETMINMAXINFO"
                   CASE %WM_NEXTDLGCTL:C$="WM_NEXTDLGCTL"
                   CASE %WM_SETFONT:C$="WM_SETFONT"
                   CASE %WM_GETFONT:C$="WM_GETFONT"
                   CASE %WM_WINDOWPOSCHANGING:C$="WM_WINDOWPOSCHANGING"
                   CASE %WM_WINDOWPOSCHANGED:C$="WM_WINDOWPOSCHANGED"
                   CASE %WM_NOTIFY:C$="WM_NOTIFY"
                   CASE %WM_NCCREATE:C$="WM_NCCREATE"
                   CASE %WM_NCDESTROY:C$="WM_NCDESTROY"
                   CASE %WM_NCCALCSIZE:C$="WM_NCCALCSIZE"
                   CASE %WM_NCHITTEST:C$="WM_NCHITTEST"
                   CASE %WM_NCPAINT:C$="WM_NCPAINT"
                   CASE %WM_NCACTIVATE:C$="WM_NCACTIVATE"
                   CASE %WM_GETDLGCODE:C$="WM_GETDLGCODE"
                   CASE %WM_NCMOUSEMOVE:C$="WM_NCMOUSEMOVE"
                   CASE %WM_NCLBUTTONDOWN:C$="WM_NCLBUTTONDOWN"
                   CASE %WM_NCLBUTTONUP:C$="WM_NCLBUTTONUP"
                   CASE %WM_NCLBUTTONDBLCLK:C$="WM_NCLBUTTONDBLCLK"
                   CASE %WM_NCRBUTTONDOWN:C$="WM_NCRBUTTONDOWN"
                   CASE %WM_NCRBUTTONUP:C$="WM_NCRBUTTONUP"
                   CASE %WM_NCRBUTTONDBLCLK:C$="WM_NCRBUTTONDBLCLK"
                   CASE %WM_NCMBUTTONDOWN:C$="WM_NCMBUTTONDOWN"
                   CASE %WM_NCMBUTTONUP:C$="WM_NCMBUTTONUP"
                   CASE %WM_NCMBUTTONDBLCLK:C$="WM_NCMBUTTONDBLCLK"
                   CASE %WM_KEYFIRST:C$="WM_KEYFIRST"
                   CASE %WM_KEYDOWN:C$="WM_KEYDOWN"
                   CASE %WM_KEYUP:C$="WM_KEYUP"
                   CASE %WM_CHAR:C$="WM_CHAR"
                   CASE %WM_DEADCHAR:C$="WM_DEADCHAR"
                   CASE %WM_SYSKEYDOWN:C$="WM_SYSKEYDOWN"
                   CASE %WM_SYSKEYUP:C$="WM_SYSKEYUP"
                   CASE %WM_SYSCHAR:C$="WM_SYSCHAR"
                   CASE %WM_SYSDEADCHAR:C$="WM_SYSDEADCHAR"
                   CASE %WM_KEYLAST:C$="WM_KEYLAST"
                   CASE %WM_INITDIALOG:C$="WM_INITDIALOG"
                   CASE %WM_COMMAND:C$="WM_COMMAND"
                   CASE %WM_SYSCOMMAND:C$="WM_SYSCOMMAND"
                   CASE %WM_TIMER:C$="WM_TIMER"
                   CASE %WM_HSCROLL:C$="WM_HSCROLL"
                   CASE %WM_VSCROLL:C$="WM_VSCROLL"
                   CASE %WM_CTLCOLORMSGBOX:C$="WM_CTLCOLORMSGBOX"
                   CASE %WM_CTLCOLOREDIT:C$="WM_CTLCOLOREDIT"
                   CASE %WM_CTLCOLORLISTBOX:C$="WM_CTLCOLORLISTBOX"
                   CASE %WM_CTLCOLORBTN:C$="WM_CTLCOLORBTN"
                   CASE %WM_CTLCOLORDLG:C$="WM_CTLCOLORDLG"
                   CASE %WM_CTLCOLORSCROLLBAR:C$="WM_CTLCOLORSCROLLBAR"
                   CASE %WM_CTLCOLORSTATIC:C$="WM_CTLCOLORSTATIC"
                   CASE %WM_MOUSEFIRST:C$="WM_MOUSEFIRST"
                   CASE %WM_MOUSEMOVE:C$="WM_MOUSEMOVE"
                   CASE %WM_LBUTTONDOWN:C$="WM_LBUTTONDOWN"
                   CASE %WM_LBUTTONUP:C$="WM_LBUTTONUP"
                   CASE %WM_LBUTTONDBLCLK:C$="WM_LBUTTONDBLCLK"
                   CASE %WM_RBUTTONDOWN:C$="WM_RBUTTONDOWN"
                   CASE %WM_RBUTTONUP:C$="WM_RBUTTONUP"
                   CASE %WM_RBUTTONDBLCLK:C$="WM_RBUTTONDBLCLK"
                   CASE %WM_MBUTTONDOWN:C$="WM_MBUTTONDOWN"
                   CASE %WM_MBUTTONUP:C$="WM_MBUTTONUP"
                   CASE %WM_MBUTTONDBLCLK:C$="WM_MBUTTONDBLCLK"
                   CASE %WM_MOUSEWHEEL:C$="WM_MOUSEWHEEL"
                   CASE %WM_MOUSELAST:C$="WM_MOUSELAST"
                   CASE %WM_SIZING:C$="WM_SIZING"
                   CASE %WM_CAPTURECHANGED:C$="WM_CAPTURECHANGED"
                   CASE %WM_MOVING:C$="WM_MOVING"
                   CASE %WM_MOUSEHOVER:C$="WM_MOUSEHOVER"
                   CASE %WM_MOUSELEAVE:C$="WM_MOUSELEAVE"
                   CASE ELSE
                        C$="   &H"+HEX$(X&)
             END SELECT
             MT(X&)=C$
        NEXT X&
        ShowDialog_Form1 0
        DO
           ' must call PostQuitMessage in last forms WM_DESTROY message
           V&=GetMessage(Msg,%NULL,0,0)
           IF V&=0 THEN EXIT DO
           IF V&=-1 THEN EXIT DO
           IF Msg.message=%WM_QUIT THEN EXIT DO
           IF Msg.message>=0 AND Msg.message<=%WM_USER THEN
                IF M(Msg.message)=0 THEN    ' add to visible list
                     T$=""
                     M(Msg.message)=1
                     FOR X&=0 TO %WM_USER
                        IF M(X&)<>0 THEN
                             T$=T$+MT(X&)+ CHR$(13)+CHR$(10)
                        END IF
                     NEXT X&
                     CONTROL SET TEXT hForm1&, %FORM1_TEXT1, T$
                END IF
           END IF
           TranslateMessage Msg
           DispatchMessage Msg
        LOOP
    END FUNCTION
    ' *************************************************************
    '                    Application Dialogs (#3)
    ' *************************************************************
    SUB ShowDialog_Form1(BYVAL hParent&)
        LOCAL Style&, ExStyle&, hFont&
        LOCAL N&, CT&        '  Variables used for Reading Data in Arrays for Listbox and Combobox
        '   hParent& = 0 if no parent Dialog
        Style& = %WS_POPUP OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %DS_CENTER OR %WS_THICKFRAME
        ExStyle& = 0
        FONT NEW "Courier New", 10 TO hFont&
        DIALOG NEW hParent&, "Your Dialog", 0, 0,  420,  300, Style&, ExStyle& TO hForm1&
        CONTROL ADD "Button", hForm1&,  %FORM1_BUTTON1,  "Send %WM_USER", 24, 25, 77, 59, _
            %WS_CHILD OR %WS_VISIBLE OR %BS_PUSHBUTTON OR %WS_TABSTOP CALL CBF_FORM1_BUTTON1
        CONTROL ADD LABEL, hForm1&, -1, "Message Loop Messages", 110,15,140,10
        CONTROL ADD LABEL, hForm1&, -2, "Dialog Procedure Messages", 260,15,140,10
        CONTROL ADD TEXTBOX ,hForm1&, %FORM1_TEXT1, "", 110,25,140, 250, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %ES_MULTILINE OR %ES_READONLY OR %WS_VSCROLL
        CONTROL SET COLOR hForm1&, %FORM1_TEXT1, RGB(0,0,0), RGB(255,255,255)
        CONTROL SET FONT hForm1&, %FORM1_TEXT1, hFont&
        CONTROL ADD TEXTBOX ,hForm1&, %FORM1_TEXT2, "", 260,25,140, 250, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %ES_MULTILINE OR %ES_READONLY OR %WS_VSCROLL
        CONTROL SET COLOR hForm1&, %FORM1_TEXT2, RGB(0,0,0), RGB(255,255,255)
        CONTROL SET FONT hForm1&, %FORM1_TEXT2, hFont&
        DIALOG SHOW MODELESS hForm1& , CALL Form1_DLGPROC
    END SUB
    ' *************************************************************
    '                             Dialog Callback Procedure
    '                             for Form Form1
    '                             uses Global Handle - hForm1&
    ' *************************************************************
    %WM_UpdateList =    %WM_USER+400
    '
    CALLBACK FUNCTION Form1_DLGPROC
         LOCAL T$, X&
         IF CBMSG>=0 AND CBMSG<=%WM_USER THEN
                IF M2(CBMSG)=0 THEN    ' add to visible list
                     M2(CBMSG)=1
                     PostMessage CBHNDL, %WM_UpdateList,0,0
                END IF
           END IF
        SELECT CASE CBMSG
            CASE %WM_UpdateList
                 T$=""
                 FOR X&=0 TO %WM_USER
                      IF M2(X&)<>0 THEN
                           T$=T$+MT(X&)+ CHR$(13)+CHR$(10)
                      END IF
                 NEXT X&
                 CONTROL SET TEXT hForm1&, %FORM1_TEXT2, T$
                 FUNCTION=1
                 EXIT FUNCTION
            CASE %WM_USER    ' this will be sent message from button
                 FUNCTION=1
                 EXIT FUNCTION
            CASE %WM_DESTROY
                 PostQuitMessage 0
            CASE ELSE
        END SELECT
    END FUNCTION
    ' *************************************************************
    '   Application Callback Functions (or Subs) for Controls (#4)
    ' *************************************************************
    CALLBACK FUNCTION CBF_FORM1_BUTTON1
        IF CBCTLMSG=%BN_CLICKED THEN
              DIALOG SEND hForm1&,%WM_USER,0,0
        END IF
    END FUNCTION
    Attached Files
    Last edited by Chris Boss; 11 May 2009, 04:03 PM.
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy
Working...
X