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

xBot no Titlebar Maximize Button

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

  • xBot no Titlebar Maximize Button

    All,
    Here is an example of building an app that has no maximize button on the titlebar.

    Click image for larger version

Name:	ScreenCapture.jpg
Views:	1
Size:	30.3 KB
ID:	776444


    xBot MobileApp Example
    SDK Version 1

    by Jim Fritts

    Works with PBWIN 10.4 and Jose' includes.

    In response to this post...
    https://forum.powerbasic.com/forum/U...NLY#post774617

    This source code was released to the public domain on 23 NOV 2018
    It makes use of many contributors Borje, Pierre, Jose' among others.
    Thank you all

    NOTE: if you are using PBWIN 9 or below you will need to
    replace all POINT references with POINTAPI.

    Code Objective:
    Produce a Windows 10 foundation SDK example that has no Nonclient
    area and replicates default Nonclient area behavior with easily
    configurable bitmaps to fill the titlebar area. As intended the
    titlebar only has a minimize [-] button and a close [X] button.

    This example demonstrates an app with:
    No NonClient Area.
    No window sizing.
    No maximizing.
    No Maximize button.
    A background gradient surrounding the dialog.
    An OwnerDrawn popup menu with Icons.
    Popup menu that has only Move, Minimize, and Close as options.

    A Subclassed Titlebar.

    Even though the XPTheme is applied for the buttons not much else
    benefits from it. Typically I do not like themed buttons but for
    simplicities sake I used them here.

    Yes, Dorothy you can have just what you want.

    Hopefully this provides an adequate example for those SDK types.
    Have FUN!


    xBot.zip

    Code:
    
    'xBot MobileApp Example
    'SDK Version 1
    
    'Compilable Example:
    'Works with PBWIN 10.4 and Jose' includes.
    
    'by: Jim Fritts
    
    'In response to this post...
    'https://forum.powerbasic.com/forum/USER-TO-USER-discussions/powerbasic-FOR-windows/774617-DIALOG-WITH-MINIMIZE-AND-CLOSE-ONLY#post774617
    
    'This source code was released to the public domain on 23 NOV 2018
    'It makes use of many contributors Borje, Pierre, Jose' among others.
    'Thank you all
    
    'NOTE: if you are using PBWIN 9 or below you will need to
    'replace all POINT references with POINTAPI.
    
    'Code Objective:
    'Produce a Windows 10 foundation SDK example that has no Nonclient
    'area and replicates default Nonclient area behavior with easily
    'configurable bitmaps to fill the titlebar area. As intended the
    'titlebar only has a minimize [-] button and a close [X] button.
    
    'This example demonstrates an app with:
    '  No NonClient Area.
    '  No window sizing.
    '  No maximizing.
    '  No Maximize button.
    '  A background gradient surrounding the dialog.
    '  An OwnerDrawn popup menu with Icons.
    '  Popup menu that has only Move, Minimize, and Close as options.
    
    '  A Subclassed Titlebar.
    
    'Even though the XPTheme is applied for the buttons not much else
    'benefits from it. Typically I do not like themed buttons but for
    'simplicities sake I used them here.
    
    'Yes, Dorothy you can have just what you want.
    
    'Hopefully this provides an adequate example for those SDK types.
    'Have FUN!
    
    
      '%TRUE  = 1
      '%FALSE = 0
      '%NULL  = 0
    
    
    #COMPILE EXE "xBot.exe"
    #DIM ALL
    
    #INCLUDE "Win32Api.inc"
    #INCLUDE "ComDlg32.inc"
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ENUM Equates SINGULAR
        IDC_Reset = 500
        IDC_Show
        ID_Move       'move
        ID_Minimize   'minimize
        IDM_Sep       'menu separator
        IDM_EXI10     'close
        ID_IMAGE
        ID_CAPTIONBAR
        ID_TITLEBAR1
        ID_TITLELABEL
        ID_LabelListen
        ID_LabelDictation
        ID_LabelTitle
        ID_LabelAttention
        ID_LabelTalk
        ID_IDNOTE
        ID_TITLEBAR2
        ID_IDNOTE2
        IDC_Timer0
        ID_CaptureIconRect
    END ENUM
    
    TYPE PROP
        usefont        AS DWORD
        hinstance      AS DWORD
    '    isrecmodified  AS LONG
    '    isfilemodified AS LONG
    '    currententry   AS LONG
    '    maxentries     AS LONG
    '    findtext       AS ASCIIZ * %MAX_PATH
    END TYPE
    
    TYPE PopMenuItemType
      SizeA    AS SizeL
      zItem    AS ASCIIZ * 255            'Menu Text to display
      MenuType AS ASCIIZ * %MAX_PATH      'MOV MIN CLO
      ED       AS LONG                    'Enabled Disabled
    END TYPE
    
    GLOBAL hWndMain                 AS DWORD
    GLOBAL giCancelProgram          AS LONG
    GLOBAL ghNCA                    AS DWORD
    GLOBAL ghInst                   AS DWORD
    
    GLOBAL ghBmpNCA0                AS DWORD
    GLOBAL ghBmpNCA1                AS DWORD
    GLOBAL ghBmpNCA2                AS DWORD
    GLOBAL ghBmpNCA3                AS DWORD
    GLOBAL ghBmpNCA4                AS DWORD
    GLOBAL ghBmpNCA5                AS DWORD
    
    GLOBAL ghIconCM00               AS DWORD
    GLOBAL ghIconCM01               AS DWORD
    GLOBAL ghIconCM02               AS DWORD
    GLOBAL ghIconCM03               AS DWORD
    GLOBAL ghIconCM04               AS DWORD
    GLOBAL ghIconCM05               AS DWORD
    
    GLOBAL hCaptionBar              AS DWORD
    GLOBAL dwLabelStyle             AS DWORD
    GLOBAL dwNBLabelStyle           AS DWORD
    GLOBAL dwLeftLabelStyle         AS DWORD
    GLOBAL dwNoRetMLTextBoxStyle    AS DWORD
    GLOBAL hMouseHook               AS DWORD
    GLOBAL hContext                 AS DWORD
    GLOBAL hForeGroundPrior         AS DWORD
    GLOBAL hPopup                   AS DWORD
    GLOBAL ghCtl_Edit_X             AS DWORD
    GLOBAL ghWndSaveFocus           AS DWORD
    GLOBAL hMutex                   AS DWORD
    
    GLOBAL gP                       AS PROP
    
    GLOBAL InitialMessage           AS STRING
    GLOBAL gsBannerListen           AS STRING
    GLOBAL gsBannerTitle            AS STRING
    GLOBAL gsBannerTalk             AS STRING
    GLOBAL gsBannerAttention        AS STRING
    GLOBAL gsBannerDictation        AS STRING
    GLOBAL gsMousePosition          AS STRING
    GLOBAL gsCmdMessages            AS STRING
    GLOBAL NCACTIVATE               AS STRING
    GLOBAL ACTIVATE                 AS STRING
    GLOBAL ACTIVATEAPP              AS STRING
    
    GLOBAL giCaptionBar             AS LONG
    GLOBAL giTheReturn              AS LONG
    GLOBAL hBrushPearl              AS LONG
    GLOBAL giPRTDMessage            AS LONG
    GLOBAL giGettingMousePosition   AS LONG
    GLOBAL gfTrackLeave             AS LONG
    GLOBAL giActiveTitlebar         AS LONG
    GLOBAL giLeftMouseDown          AS LONG  'used to track mouse clicks on titlebar
    GLOBAL giMinimizeClose          AS LONG
    GLOBAL giLeftButtonDown         AS LONG  'used to track mouse dragging on titlebar
    GLOBAL giAppIsMinimized         AS LONG
    GLOBAL giAppIsDisabled          AS LONG
    GLOBAL giShowDocumentCursor     AS LONG
    GLOBAL giShowHandCursor         AS LONG
    GLOBAL giShowArrowCursor        AS LONG
    GLOBAL giShowWaitCursor         AS LONG
    GLOBAL giShowMoveCursor         AS LONG
    GLOBAL hCursorArrow             AS LONG
    GLOBAL hCursorBar               AS LONG
    GLOBAL hCursorHand              AS LONG
    GLOBAL hCursorWait              AS LONG
    GLOBAL hCursorMove              AS LONG
    GLOBAL giMoving                 AS LONG
    GLOBAL giView                   AS LONG
    GLOBAL giCloseDialog            AS LONG
    GLOBAL giRightMouseButtonDown   AS LONG
    GLOBAL giRightMouseToggled      AS LONG
    GLOBAL giLeftMouseButtonDown    AS LONG
    GLOBAL giLeftMouseToggled       AS LONG
    GLOBAL giFindNewActiveWindow    AS LONG
    GLOBAL giActivationComplete     AS LONG
    GLOBAL giDeactivationComplete   AS LONG
    GLOBAL iLOCx                    AS LONG
    GLOBAL iLOCy                    AS LONG
    
    GLOBAL MyCurPos                 AS POINT   'in screen coordinates
    
    GLOBAL rcMainSub                AS RECT
    GLOBAL TaskbarAppRect           AS RECT
    GLOBAL TitlebarRect             AS RECT
    GLOBAL TaskbarRect              AS RECT
    GLOBAL DesktopRect              AS RECT
    GLOBAL WindowMinimizeRect       AS RECT
    
    
    #RESOURCE BITMAP,     110, "NC_Base.bmp"           'its size is 220x20 active no highlighted buttons
    #RESOURCE BITMAP,     111, "NC_Gray.bmp"           'its size is 220x20 inactive no highlighted buttons
    #RESOURCE BITMAP,     112, "NC_Min.bmp"            'its size is 220x20 active minimize button highlighted
    #RESOURCE BITMAP,     113, "NC_X.bmp"              'its size is 220x20 active close button highlighted
    #RESOURCE BITMAP,     114, "NC_Min_Gray.bmp"       'its size is 220x20 inactive minimize button highlighted
    #RESOURCE BITMAP,     115, "NC_X_Gray.bmp"         'its size is 220x20 inactive close button highlighted
    
    #RESOURCE ICON,     3000, "xBot.ICO"
    
    #RESOURCE ICON,     3500, "CM00.ICO"
    #RESOURCE ICON,     3501, "CM01.ICO"    'not needed
    #RESOURCE ICON,     3502, "CM02.ICO"
    #RESOURCE ICON,     3503, "CM03.ICO"    'not needed
    #RESOURCE ICON,     3504, "CM04.ICO"
    #RESOURCE ICON,     3505, "CM05.ICO"    'not needed
    
    #RESOURCE MANIFEST,     1, "xptheme.XML"
    
    #RESOURCE VERSIONINFO
    #RESOURCE FILEFLAGS      0
    #RESOURCE FILEVERSION    1, 0, 0, 0
    #RESOURCE PRODUCTVERSION 1, 0, 0, 0
    #RESOURCE STRINGINFO     "0409", "0000"
    #RESOURCE VERSION$       "CompanyName",      "LocalApp, Inc."
    #RESOURCE VERSION$       "FileDescription",  "xBot"
    #RESOURCE VERSION$       "FileVersion",      "1.0"
    #RESOURCE VERSION$       "InternalName",     "xBot"
    #RESOURCE VERSION$       "OriginalFilename", "xBot.exe"
    #RESOURCE VERSION$       "LegalCopyright",   "© by James R. Fritts 2018"
    #RESOURCE VERSION$       "LegalTrademarks",  "HSI"
    #RESOURCE VERSION$       "ProductName",      "XBOT"
    #RESOURCE VERSION$       "ProductVersion",   "1.0"
    
    
    DECLARE THREAD FUNCTION MinimizeDialogThread(BYVAL yyy AS LONG) AS LONG           'temporary
    DECLARE THREAD FUNCTION CheckMouseThread(BYVAL yyy AS LONG) AS LONG               'full time
    DECLARE FUNCTION GetWindowMinimizeRect LIB "user32.dll" ALIAS "GetWindowMinimizeRect" _
    (BYVAL hWindow AS DWORD, pRect AS RECT) AS LONG 'Vista+
    
    '_________________________________________________________________
    '
    ' Program entrance                                            xBot
    '_________________________________________________________________
    
    FUNCTION WINMAIN (BYVAL hInstance AS DWORD, _
                      BYVAL hPrevInstance AS DWORD, _
                      BYVAL lpCmdLine AS ASCIIZ PTR, _
                      BYVAL iCmdShow AS LONG) AS LONG
    
        LOCAL Msg          AS tagMsg
        LOCAL W            AS WndClassEx
        LOCAL szAppName    AS ASCIIZ * 80
        LOCAL szClassName  AS ASCIIZ * 80
        LOCAL hWndButton   AS DWORD
        LOCAL hAccel       AS DWORD
        LOCAL WndStyle     AS LONG
        LOCAL WndStyleX    AS LONG
    
        LOCAL ResX               AS LONG
    
        ResX = CheckForMutex("xBot", hMutex)
        IF ResX > 0 THEN WinBeep 300,200 : EXIT FUNCTION
    
        giShowArrowCursor = 1
        CALL SELECT_MOUSE_CURSOR
    
        'register window class
        szAppName = "xBot"
        szClassName = "Mobileapp" '"#32770"
    
        W.cbSize        = SIZEOF(W)
        W.Style         = %CS_HREDRAW OR %CS_VREDRAW   '%WS_OverlappedWindow Or %WS_HScroll Or %WS_VScroll  '
        W.lpfnWndProc   = CODEPTR(WndProc)
        W.cbClsExtra    = 0
        W.cbWndExtra    = 0
        W.hInstance     = hInstance
        W.hIcon         = LoadImage(hInstance, BYVAL 3000, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        W.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
        W.hbrBackground = GetStockObject(%DKGRAY_BRUSH) '(%LTGRAY_BRUSH) '%COLOR_3DDKSHADOW 'COLOR_BTNSHADOW'%Color_BtnFace+1
        W.lpszMenuName  = %NULL
        W.lpszClassName = VARPTR(szClassName)
        W.hIconSm       = W.hIcon
        RegisterClassEx W
    
        'create window of that class
        WndStyle  = %WS_VISIBLE OR %WS_POPUP OR %WS_BORDER 'OR %WS_DLGFRAME '%WS_SYSMENU OR %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_OVERLAPPED
        WndStyleX = %WS_EX_LEFT OR %WS_EX_APPWINDOW OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
    
        hWndMain = CreateWindowEx( _
            WndStyleX,     _  ' extended styles
            szClassName,   _  ' window class name
            szAppName,     _  ' caption
            WndStyle,      _  ' window styles
            300,           _  ' left
            300,           _  ' top
            340,           _  ' width    was 790
            340,           _  ' height
            %HWND_DESKTOP, _  ' parent window handle
            %NULL,         _  ' window menu handle
            hInstance,     _  ' program instance handle
            BYVAL %NULL)      ' creation parameters
    
        ghInst = hInstance
        gP.hinstance = hInstance
    
        CreateButtons
    
        ShowWindow hWndMain, iCmdShow   'controls how window is to be shown. 1st must use iCmdShow
        UpdateWindow hWndMain           'sends the window it's first WM_Create to display the window on the screen
    
        'message pump - calls WndProc whenever an application-specific message is received
        'WndProc can process the message, or pass it on to a the default window procedure that is built into Windows.
        WHILE GetMessage(Msg, %NULL, 0, 0) > 0
           IF ISFALSE TranslateAccelerator (hWndMain, hAccel, Msg) THEN
              IF ISFALSE ISDialogMessage (hWndMain, Msg) THEN
                 TranslateMessage Msg
                 DispatchMessage  Msg
              END IF
           END IF
        WEND
    END FUNCTION
    
    FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
        LOCAL hDC AS DWORD, pPaint AS PAINTSTRUCT, tRect  AS RECT
        LOCAL pnmhdr         AS NMHDR PTR
        LOCAL CurPos         AS POINT
    
        InitialMessage = $CRLF + _
                         "    This area is to provide user messages." + $CRLF + $CRLF + _
                         "    Reset Button:    clear this screen." + $CRLF + _
                         "    Show Button:     display app messages" + $CRLF + _
                         "                    or not display app messages." + $CRLF + $CRLF + _
                         "    See app notes for other info."
    
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'Create a timer event every 1/4 Sec = 250
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'SetTimer hWnd, %IDC_Timer0, 250, BYVAL %NULL
    
        SELECT CASE wMsg
    
            CASE %WM_CREATE          'when an application requests that a window be created
                                     'after window is created, but before it becomes visible
                gsCmdMessages = $CRLF + "Now ready to show messages." + $CRLF + _
                "NOTE: " + $CRLF + _
                "The newest messages will be listed first."
    
                giView = -1
                'Captures location of the application icon on the Taskbar
                CALL CHECK_MOUSE
    
                CALL LOAD_BRUSHES
                CALL LOAD_CURSORS
                CALL ASSIGN_WINDOW_STYLES
                CenterWindow hWnd            ' center on desktop
    
            CASE %WM_INITDIALOG      'immediately before a dialog box is displayed
                                     'typically used to initialize controls and carry out any other
                                     'initialization tasks that affect the appearance of the dialog box.
    
            CASE %WM_LBUTTONUP
                'lbuttonup commands
                '? "main left button up"
                'CALL LButtonUpCommand(wParam, lParam)
                FUNCTION = 1    'ignored
                EXIT FUNCTION
    
            CASE %WM_LBUTTONDOWN
                'lbuttondn commands
                '? "main left button down"
                'CALL LButtonDnCommand(wParam, lParam)
                FUNCTION = 1    'ignored
                EXIT FUNCTION
    
            CASE %WM_RBUTTONDOWN
                '? "main right button down"
                FUNCTION = 1    'ignored
                EXIT FUNCTION
    
            CASE %WM_MOVE
                'move commands
                'call MoveCommand(wParam, lParam)
                IF IsWindowEnabled(hWndMain) THEN
                    giCaptionBar = 0
                    SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
                END IF
                FUNCTION = 0  '=o if processed
                EXIT FUNCTION
    
            CASE %WM_CLOSE
                DestroyWindow hWndMain
    
            CASE %WM_DESTROY         'window is being destroyed
                                     'after windows is removed from screen (children still exist)
                RemoveWindowSubclass(GetDlgItem(hWndMain, %ID_CAPTIONBAR), CODEPTR(TitlebarProc), 99)
                IF hBrushPearl     THEN CALL DeleteObject( hBrushPearl )
    
                IF ghIconCM00 THEN DestroyIcon(ghIconCM00)
                IF ghIconCM01 THEN DestroyIcon(ghIconCM01)
                IF ghIconCM02 THEN DestroyIcon(ghIconCM02)
                IF ghIconCM03 THEN DestroyIcon(ghIconCM03)
                IF ghIconCM04 THEN DestroyIcon(ghIconCM04)
                IF ghIconCM05 THEN DestroyIcon(ghIconCM05)
    
                IF hCursorWait  THEN CALL DestroyCursor(hCursorWait)  'DeleteObject(hCursorWait)
                IF hCursorHand  THEN CALL DestroyCursor(hCursorHand)  'DeleteObject(hCursorHand)
                IF hCursorArrow THEN CALL DestroyCursor(hCursorArrow) 'DeleteObject(hCursorArrow)
                IF hCursorBar   THEN CALL DestroyCursor(hCursorBar)   'DeleteObject(hCursorBar)
                IF hCursorMove  THEN CALL DestroyCursor(hCursorMove)  'DeleteObject(hCursorMove)
    
                IF hMouseHook <> 0 THEN UnhookWindowsHookEx(hMouseHook)
    
                IF IsMenu(hPopUp) THEN DestroyMenu(hPopUp)
                giCancelProgram = 1
                SLEEP 100
                PostQuitMessage 0
                EXIT FUNCTION
    
            CASE %WM_COMMAND         'user selects a command item from a menu
                                     'control sends a notification message to its parent window
                                     'accelerator keystroke is translated.
                'main command functions
                CALL ChooseCommand(wParam, lParam)
                FUNCTION = 1
                EXIT FUNCTION
    
            CASE %WM_NOTIFY          'by control to its parent window when an event has occurred
                pnmhdr = lParam
                SELECT CASE @pnmhdr.idFrom
                    'CASE %IDC_Button              'Control ID
                    '    SELECT CASE @pnmhdr.code  'Notification code
                    '        CASE %NM_CLICK        'typical notification code
                    '    END SELECT
    
                END SELECT
    
            CASE %WM_SIZE
                IF wParam = %SIZE_MAXIMIZED THEN    'do not allow maximized display
                    ShowWindow hWndMain, %SW_SHOWNORMAL
                END IF
                FUNCTION = 0
                EXIT FUNCTION
    
            CASE %WM_CTLCOLORSTATIC
                'A static control, or an edit control that is read-only or disabled
                'ctlcolorstatic functions
                CALL CCSCommand(wParam, lParam)
                FUNCTION = giTheReturn
                EXIT FUNCTION
    
            'mouse click
            'CASE %WM_PARENTNOTIFY    'sent to parent when child window is created/destroyed
                                     'sent to parent when user clicks mouse button over child
    
            'mouse movement
            CASE %WM_SETCURSOR       'sent if mouse causes cursor to move
                CALL SetCursorCommand(wParam, lParam)
                FUNCTION = giTheReturn
                EXIT FUNCTION
    
            'CASE %WM_MOUSEMOVE       'when cursor moves
    
            'keyboard
            'CASE %WM_CHAR            'to window with keyboard focus when WM_KEYDOWN message is translated
                                     'by the TranslateMessage function. contains the character code of the
                                     'key that was pressed.
    
            'CASE %WM_GETDLGCODE    'intercept keyboard input to child control
            '    FUNCTION = %DLGC_WANTARROWS '%DLGC_WANTCHARS OR %DLGC_WANTALLKEYS OR %DLGC_WANTMESSAGE
            '    EXIT FUNCTION
    
            'CASE %WM_KEYDOWN
    
            'graphic/drawing events
            CASE %WM_ERASEBKGND      'sent when the window background must be erased (such as resizing)
                hDC = wParam
                DrawGradient hDC     'Pass the DC of the region to repaint
                FUNCTION = 1 : EXIT FUNCTION
    
            CASE %WM_PAINT           'set when request is made to paint a portion of an application's window.
    
            'recurring events
            CASE %WM_TIMER           'when a timer expires (does not keep accurate timing)
                CALL TimerCommand(wParam, lParam)
                FUNCTION = 0
                EXIT FUNCTION
    
            'user action
            CASE %WM_PASTE           'application sends a WM_PASTE message to an edit control or combobox
            CASE %WM_DROPFILES       'sent when user drops file on application that's is registered as file recipient
    
            'application status
            CASE %WM_ACTIVATE        'sent to both the window being activated and the window
                                     'being deactivated.
                                     'activate functions
                                     'fires when ap gains and loses focus
    
                'If an application processes this message, it should return zero.
                CALL ActivateCommand(wParam, lParam)
                FUNCTION = 1    'apparently xBot is not admitting that it processed this message
                '**** EXIT FUNCTION CANNOT BE USED HERE ****
    
            CASE %WM_NCACTIVATE      'sent to window when its nonclient area needs to be changed
                                     'to indicate an active or inactive state.
                                     'If an application does process this message, it must
                                     'return TRUE to direct the system to complete the change
                                     'of active window
                CALL NCActivateCommand(wParam, lParam)
                FUNCTION = %TRUE 'giTheReturn
                '**** EXIT FUNCTION CANNOT BE USED HERE ****
    
            CASE %WM_ACTIVATEAPP
                SELECT CASE wParam
                    CASE %TRUE
    
                        CALL StartActivation
    
                    CASE %FALSE
    
                        CALL EndDeactivation
    
                END SELECT
    
                'If an application processes this message, it should return zero.
                FUNCTION = 0
                EXIT FUNCTION
    
            CASE %WM_SYSCOMMAND
                'system command functions
                CALL SystemCommand(wParam, lParam)
                'If an application processes this message, it should return zero.
                FUNCTION = 0
                EXIT FUNCTION
    
        END SELECT
    
        FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)   'if not handled above, pass to Windows default message handler.
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' SUB DrawGradient
    '_________________________________________________________________
    
    SUB DrawGradient (BYVAL hDC AS DWORD)
       LOCAL rectFill AS RECT, rectClient AS RECT, fStep AS SINGLE, hBrush AS DWORD, lOnBand AS LONG
       GetClientRect WindowFromDC(hDC), rectClient
       fStep = rectClient.nbottom / 200
       FOR lOnBand = 0 TO 199
          SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
          hBrush = CreateSolidBrush(RGB(140 - lOnBand, 140 - lOnBand, 140 - lOnBand))
          Fillrect hDC, rectFill, hBrush
          DeleteObject hBrush
       NEXT
    END SUB
    
    
    '_________________________________________________________________
    '
    ' SUB CreateButtons                                           xBot
    '_________________________________________________________________
    
    SUB CreateButtons
      LOCAL WndStyle AS LONG, hWnd, hInstance AS DWORD
    
      'create window of existing class "Button"
      WndStyle  = %WS_TABSTOP OR %WS_VISIBLE OR %WS_CHILD OR %BS_DEFPUSHBUTTON
      hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
      hWnd= CreateWindow( _
         "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
         "Reset",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
         WndStyle,   _    'dwStyle        style of window
         30,         _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
         296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
         80,         _    'nWidth         width in device units
         30,         _    'nHeight        height in device units
         hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
         %IDC_Reset, _    'hMenu          handle to a menu or child window control ID
         hInstance,  _    'handle to instance of the module to be associated with the window
         BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
    
      hWnd= CreateWindow( _
         "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
         "Show",     _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
         WndStyle,   _    'dwStyle        style of window
         115,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
         296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
         80,         _    'nWidth         width in device units
         30,         _    'nHeight        height in device units
         hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
         %IDC_Show,  _    'hMenu          handle to a menu or child window control ID
         hInstance,  _    'handle to instance of the module to be associated with the window
         BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
    
      WndStyle  = %WS_VISIBLE OR %WS_CHILD OR %SS_BITMAP OR %SS_NOTIFY 'OR %BS_DEFPUSHBUTTON
      hCaptionBar= CreateWindow( _
         "Static",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
         BYVAL %NULL,  _       'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
         WndStyle,   _    'dwStyle        style of window
         2,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
         2,          _   'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
         220,         _    'nWidth         width in device units
         20,         _    'nHeight        height in device units
         hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
         %ID_CAPTIONBAR,_     'hMenu          handle to a menu or child window control ID
         hInstance,  _    'handle to instance of the module to be associated with the window
         BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
    
      'use the new subclass process and pass the window handle
      CALL SetWindowSubclass(hCaptionBar, CODEPTR(TitlebarProc), 99, 0)
    
      ghBmpNCA0 = LoadImage(hInstance, "#110", _ 'NCA base
                  %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghBmpNCA1 = LoadImage(hInstance, "#111", _ 'NCA gray
                  %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghBmpNCA2 = LoadImage(hInstance, "#112", _ 'NCA Min
                  %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghBmpNCA3 = LoadImage(hInstance, "#113", _ 'NCA X
                  %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghBmpNCA4 = LoadImage(hInstance, "#114", _ 'NCA Min gray
                  %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghBmpNCA5 = LoadImage(hInstance, "#115", _ 'NCA X gray
                  %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
    
      SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
      giCaptionBar = 0
    
      CALL BUILD_MARQUEE
      CALL LOAD_ICONS
    
    END SUB
    
    '_________________________________________________________________
    '
    ' FUNCTION TitlebarProc                                       xBot
    '_________________________________________________________________
    
    FUNCTION TitlebarProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, _
              BYVAL lParam AS LONG, BYVAL spID AS DWORD, BYVAL RefData AS DWORD) AS LONG
    
      LOCAL Xe               AS LONG
      LOCAL My_Return        AS LONG
    
      LOCAL pPopItemSize             AS MEASUREITEMSTRUCT POINTER
      LOCAL pPopItemDrawInfo         AS DRAWITEMSTRUCT POINTER
      LOCAL CurPos                   AS POINT
      LOCAL shFileInf                AS SHFILEINFO
      LOCAL pPopItem                 AS PopMenuItemType POINTER
      LOCAL zWinDir                  AS ASCIIZ * %MAX_PATH
      LOCAL zSysDir                  AS ASCIIZ * %MAX_PATH
      DIM   PopItem(1 TO 3)          AS STATIC PopMenuItemType
      LOCAL hdc                      AS DWORD
      LOCAL hBrush                   AS DWORD
      LOCAL hImg                     AS DWORD
      LOCAL Looper                   AS LONG
    
      SELECT CASE wMsg
    
          CASE %WM_GETDLGCODE    'intercept keyboard input to child control
              FUNCTION = %DLGC_WANTARROWS '%DLGC_WANTCHARS OR %DLGC_WANTALLKEYS OR %DLGC_WANTMESSAGE
              EXIT FUNCTION
    
          CASE %WM_KEYDOWN    'supports moving dialog when move is selected from
                              'popup menu
              IF giMoving = 1 THEN
                  SELECT CASE wParam
                      CASE %VK_LEFT 'LEFT ARROW key pressed
                          'locate mouse position
                          IF giView <> 0 THEN
                              gsCmdMessages = "Move dialog left." + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          CALL MoveWindowLeft10
                          IF hMouseHook = 0 THEN
                              hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                          END IF
    
                      CASE %VK_RIGHT 'RIGHT ARROW key pressed
                          IF giView <> 0 THEN
                              gsCmdMessages = "Move dialog right." + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          CALL MoveWindowRight10
                          IF hMouseHook = 0 THEN
                              hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                          END IF
    
                      CASE %VK_UP 'UP ARROW key pressed
                          IF giView <> 0 THEN
                              gsCmdMessages = "Move dialog up." + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          CALL MoveWindowUp10
                          IF hMouseHook = 0 THEN
                              hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                          END IF
    
                      CASE %VK_DOWN 'DOWN ARROW key pressed
                          IF giView <> 0 THEN
                              gsCmdMessages = "Move dialog down." + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          CALL MoveWindowDown10
                          IF hMouseHook = 0 THEN
                              hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                          END IF
    
                  END SELECT
              END IF
              FUNCTION = 0 : EXIT FUNCTION
    
          CASE %WM_COMMAND
              SELECT CASE LO(WORD, wParam)
                  CASE 1102
                      IF giView <> 0 THEN
                          gsCmdMessages = "Popup Menu Move selected." + $CRLF + $CRLF + _
                          gsCmdMessages
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      END IF
                      PostMessage hWndMain, %WM_COMMAND, %ID_Move, 0
    
                  CASE 1103
                      IF giView <> 0 THEN
                          gsCmdMessages = "Popup Menu Minimize selected." + $CRLF + $CRLF + _
                          gsCmdMessages
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      END IF
                      PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
    
                  CASE 1105
                      '? "close"
                      PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0
              END SELECT
    
          CASE %WM_LBUTTONDOWN 'do dragging if mouse down on titlebar
              '***NOTE:
              '***If left mouse button is down/up on the icon part of the
              '***titlebar then the popup menu should appear.
    
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Left button down on titlebar." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
    
              CurPos.x = GET_X_LPARAM(lParam)   'in client coordinates
              CurPos.y = GET_Y_LPARAM(lParam)   'in client coordinates
    
              iLOCx = CurPos.x + 2  'added in the edge
              iLOCy = CurPos.y + 2  'added in the edge
    
              IF (CurPos.x > 1 AND  CurPos.x < 245) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                  giLeftButtonDown = 1    'Left mouse button is down on title bar
                  IF hMouseHook = 0 THEN
                      hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                      IF giView <> 0 THEN
                          gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                          gsCmdMessages
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      END IF
                  END IF
    
              ELSEIF (CurPos.x > 244 AND  CurPos.x < 288) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                  giLeftMouseDown = 1
                  giMinimizeClose = 0
    
              ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                  giLeftMouseDown = 1
                  giMinimizeClose = 1
              END IF
              FUNCTION = 0 : EXIT FUNCTION
    
          CASE %WM_LBUTTONUP 'stop dragging if mouse is up on titlebar
              '***NOTE:
              '***If left mouse button is down/up on the icon part of the
              '***titlebar then the popup menu should appear.
    
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Left button up on titlebar." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
    
              IF giMoving = 1 THEN
                  giMoving = 0
                  giShowMoveCursor = 0
                  giShowArrowCursor = 1
                  SELECT_MOUSE_CURSOR
              END IF
    
              giLeftButtonDown = 0
              IF hMouseHook <> 0 THEN
                  UnhookWindowsHookEx(hMouseHook)
                  hMouseHook = 0
                  IF giView <> 0 THEN
                      gsCmdMessages = "Mouse hook released." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
              END IF
    
              IF giLeftMouseDown = 1 THEN
                  giLeftMouseDown = 0
                  SELECT CASE giMinimizeClose
                      CASE 0 'minimize button clicked
                          IF giView <> 0 THEN
                              gsCmdMessages = "Minimize button pressed." + $CRLF + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
                      CASE 1 'close button clicked
                          PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0 'close dialog
    
                  END SELECT
                  giMinimizeClose = 0
    
              END IF
              FUNCTION = 0 : EXIT FUNCTION
    
          CASE %WM_RBUTTONDOWN 'for context menu on titlebar
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Right button down on titlebar." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              FUNCTION = 0 : EXIT FUNCTION
    
          CASE %WM_RBUTTONUP
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Right button up on titlebar." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              'FUNCTION = 0 : EXIT FUNCTION 'do not use this if you want the default process to produce context menu
    
          CASE %WM_CONTEXTMENU
              'https://forum.powerbasic.com/forum/user-to-user-discussions/programming/753120-is-there-a-way-to-put-a-button-on-a-menu-not-popup-dropdown?p=753130#post753130
              LOCAL MyItemName1 AS STRING
              LOCAL MyItemName2 AS STRING
              LOCAL MyItemName3 AS STRING
    
              MyItemName1 = "Move"
              MyItemName2 = "Minimize"
              MyItemName3 = "Close          Alt+F4"
    
              CALL GetMousePosition   'Get cursor screen location
              CurPos = MyCurPos
    
              'CaptionBar 3 and 5 have the Close [X] button highlighted
              'Based on some testing the default Windows behavior
              'is to not allow the popup menu when the Close button
              'is highlighted.
              IF giCaptionBar = 3 OR giCaptionBar = 5 THEN EXIT FUNCTION
    
              IF hPopup = 0 THEN
                  hPopup = CreatePopupMenu
    
                  PopItem(1).zItem    = MyItemName1
                  PopItem(1).MenuType = "MOV"
                  PopItem(1).ED = %MF_ENABLED
    
                  PopItem(2).zItem    = MyItemName2
                  PopItem(2).MenuType = "MIN"
                  PopItem(2).ED = %MF_ENABLED
    
                  PopItem(3).zItem    = MyItemName3
                  PopItem(3).MenuType = "CLO"
                  PopItem(3).ED = %MF_ENABLED
    
                  InsertMenu(hPopup, 0, %MF_BYCOMMAND OR %MF_STRING, 1102, MyItemName1 + $NUL)
                  InsertMenu(hPopup, 1, %MF_BYCOMMAND OR %MF_STRING, 1103, MyItemName2 + $NUL)
                  InsertMenu(hPopup, 2, %MF_BYCOMMAND OR %MF_SEPARATOR, 1104, "-")
                  InsertMenu(hPopup, 3, %MF_BYCOMMAND OR %MF_STRING, 1105, MyItemName3 + $NUL)
                  'SetMenu(hWnd, hPopup)
    
    
                  ModifyMenu(hPopup, 1102, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1102, BYVAL VARPTR(PopItem(1)))
                  ModifyMenu(hPopup, 1103, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1103, BYVAL VARPTR(PopItem(2)))
                  ModifyMenu(hPopup, 1105, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1105, BYVAL VARPTR(PopItem(3)))
    
              END IF
              TrackPopupMenu(hPopup, %TPM_LEFTALIGN OR %TPM_RIGHTBUTTON, _
                             CurPos.x, CurPos.y, BYVAL 0, hWnd, BYVAL 0)
    
          CASE %WM_MEASUREITEM 'wParam is control identifier, lParam is item-size information
              '- 9 in item length is important here to make the right menu edge appear correctly
              'not inflated
              hdc          = GetDC(hWnd)
              pPopItemSize = lParam
              pPopItem     = @pPopItemSize.itemData
              GetTextExtentPoint32(hdc, @pPopItem.zItem, LEN(@pPopItem.zItem) - 9, @pPopItem.SizeA)
              @pPopItemSize.itemWidth  = 4 + GetSystemMetrics(%SM_CYSMICON) + @pPopItem.sizeA.cx
              @pPopItemSize.itemHeight = 3 + MAX(GetSystemMetrics(%SM_CYSMICON), @pPopItem.sizeA.cy)
              ReleaseDC(hWnd, hdc)
              FUNCTION = %TRUE
    
          CASE %WM_DRAWITEM 'wParam is control id, lParam is item-drawing info
              pPopItemDrawInfo = lParam
              pPopItem         = @pPopItemDrawInfo.itemData
              IF (@pPopItemDrawInfo.itemState AND %ODS_SELECTED) THEN
                  SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHTTEXT))
                  SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHT))
                  hBrush = GetSysColorBrush(%COLOR_HIGHLIGHT)
              ELSE 'Item is not selected
                  SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENUTEXT))
                  SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENU))
                  hBrush = GetSysColorBrush(%COLOR_MENU)
              END IF
              FillRect(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem, hBrush)
    
    
              SELECT CASE @pPopItem.MenuType
                  CASE ""
                      'no icon for this item
    
                  CASE "MOV"
                      '<> move icon
                      SELECT CASE @pPopItem.ED
                          CASE %MF_ENABLED
                              DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                         ghIconCM00, 16, 16, 0, BYVAL 0, %DI_NORMAL)
    
                          CASE %MF_DISABLED
                              'no disabled icon
                              DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                         ghIconCM01, 16, 16, 0, BYVAL 0, %DI_NORMAL)
    
                      END SELECT
    
                  CASE "MIN"
                      '- minimize icon
                      SELECT CASE @pPopItem.ED
                          CASE %MF_ENABLED
                              DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                         ghIconCM02, 16, 16, 0, BYVAL 0, %DI_NORMAL)
    
                          CASE %MF_DISABLED
                              DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                         ghIconCM03, 16, 16, 0, BYVAL 0, %DI_NORMAL)
    
                      END SELECT
    
                  CASE "CLO"
                      'X close icon
                      SELECT CASE @pPopItem.ED
                          CASE %MF_ENABLED
                              DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                         ghIconCM04, 16, 16, 0, BYVAL 0, %DI_NORMAL)
    
                          CASE %MF_DISABLED
                              DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                         ghIconCM05, 16, 16, 0, BYVAL 0, %DI_NORMAL)
    
                      END SELECT
    
              END SELECT
    
              @pPopItemDrawInfo.rcItem.nLeft = 4 + @pPopItemDrawInfo.rcItem.nLeft + GetSystemMetrics(%SM_CXSMICON)
              DrawText(@pPopItemDrawInfo.hDC, @pPopItem.zItem, LEN(@pPopItem.zItem), _
                       @pPopItemDrawInfo.rcItem, %DT_SINGLELINE)
    
              FUNCTION = %TRUE
    
    
          CASE %WM_SETCURSOR
              'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "Setcursor is being processed."
              'setcursor functions
              CALL SetCursorCommandTitlebar(wParam, lParam)
    
              IF giTheReturn = 1 THEN  ' If the parent window returns TRUE, further processing is halted.
                  FUNCTION = 1
                  EXIT FUNCTION
              END IF
    
      END SELECT
    
      FUNCTION = DefSubclassProc(hWnd, wMsg, wParam, lParam)
    END FUNCTION
    
    
    
    '_________________________________________________________________
    '
    ' SUB CenterWindow
    '_________________________________________________________________
    
    SUB CenterWindow (BYVAL hAnyWnd AS LONG)
      DIM WndRect AS RECT
      DIM x       AS LONG
      DIM y       AS LONG
      GetWindowRect hAnyWnd, WndRect
      x = (GetSystemMetrics(%SM_CXSCREEN)-(WndRect.nRight-WndRect.nLeft))\2
      y = (GetSystemMetrics(%SM_CYSCREEN)-(WndRect.nBottom-WndRect.nTop+GetSystemMetrics(%SM_CYCAPTION)))\2
      SetWindowPos hAnyWnd, %NULL, x, y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB BUILD_MARQUEE                                           xBot
    '_________________________________________________________________
    
    SUB BUILD_MARQUEE
      LOCAL MyCtrl   AS DWORD
      LOCAL OffsetX   AS LONG
      LOCAL OffsetY   AS LONG
      LOCAL InitialMessage AS STRING
    
      gsBannerListen = "="
      gsBannerTalk   = CHR$(239)
      gsBannerAttention = "!"   'app is fully paying attention
      gsBannerDictation = "^"   'initial behavior
    
      OffsetX = 2
      OffsetY = 22
      MyCtrl = addLabelT(hWndMain, %ID_TITLEBAR1, "", 0 + OffsetX, 0 + OffsetY, 334, 4, dwNBLabelStyle)
      MyCtrl = addLabelT(hWndMain, %ID_TITLELABEL, "Xbot Personal Assistant", 0 + OffsetX, 4 + OffsetY, 334, 20, dwNBLabelStyle)
    
      MyCtrl = addLabelE(hWndMain, %ID_LabelListen, gsBannerListen + $NUL, 0 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
      MyCtrl = addLabelE(hWndMain, %ID_LabelDictation, gsBannerDictation + $NUL, 20 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
    
      MyCtrl = addLabelE(hWndMain, %ID_LabelTitle, "", 40, 24 + OffsetY, 254 + OffsetX, 20, dwLabelStyle OR %SS_NOTIFY)
    
      MyCtrl = addLabelE(hWndMain, %ID_LabelAttention, gsBannerAttention + $NUL, 294 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
      MyCtrl = addLabelE(hWndMain, %ID_LabelTalk, gsBannerTalk + $NUL, 314 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
    
      MyCtrl = addLabelE(hWndMain, %ID_IDNOTE, "", 0 + OffsetX, 44 + OffsetY, 334, 20, dwLabelStyle)
    
      MyCtrl = addLabelT(hWndMain, %ID_TITLEBAR2, "", 0 + OffsetX, 64 + OffsetY, 339, 2, dwLabelStyle)
    
      MyCtrl = addTextBox(hWndMain, %ID_IDNOTE2, gsCmdMessages + $NUL, 0 + OffsetX, 70 + OffsetY, 334, 200, dwNoRetMLTextBoxStyle OR %WS_HSCROLL)
    
          ghCtl_Edit_X = MyCtrl
    
          SendMessage ghCtl_Edit_X, %EM_SETLIMITTEXT, &H200000&, 0 'set text limit to 2 Meg
          'SendMessage ghCtl_Edit_X, %EM_AUTOURLDETECT, %True, 0
          'SendMessage ghCtl_Edit_X, %EM_SETEVENTMASK, 0, %ENM_UPDATE OR %ENM_LINK OR %ENM_CHANGE OR %ENM_SELCHANGE OR %ENM_KEYEVENTS 'mask is set to produce the EN_UPDATE message
    
          'use the new subclass process and pass the dialog handle
          'CALL SetWindowSubclass(ghCtl_Edit_X, CODEPTR(EditProc), 29, 0)
    
          'ghCtl_Edit_X = GetDlgItem(hWndMain, %ID_IDNOTE2)
    END SUB
    
    '_________________________________________________________________
    '
    ' FUNCTION addLabelT                                          xBot
    '_________________________________________________________________
    
    FUNCTION addLabelT(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
        LOCAL hCtrl AS DWORD
        hCtrl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING, "Static", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
        'IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
        FUNCTION = hCtrl
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' FUNCTION addLabelE                                          xBot
    '_________________________________________________________________
    
    FUNCTION addLabelE(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
        LOCAL hCtrl AS DWORD
        hCtrl = CreateWindowEx(%WS_EX_STATICEDGE, "Static", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
        'IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
        FUNCTION = hCtrl
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' FUNCTION addTextBox                                         xBot
    '_________________________________________________________________
    
    FUNCTION addTextBox(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
        LOCAL hCtrl AS DWORD
        hCtrl = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
        DisableXPThemeControl hCtrl
        IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
        FUNCTION = hCtrl
    END FUNCTION
    
    
    '_________________________________________________________________
    '
    ' SUB ASSIGN_WINDOW_STYLES                                    xBot
    '_________________________________________________________________
    
    SUB ASSIGN_WINDOW_STYLES
      dwLabelStyle           = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_CENTER OR %WS_BORDER
      dwNBLabelStyle         = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_CENTER        'no border
      dwLeftLabelStyle       = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_LEFT OR %WS_BORDER
      dwNoRetMLTextBoxStyle  = %WS_CHILD OR %WS_VISIBLE OR %ES_AUTOHSCROLL OR %WS_VSCROLL OR _
                               %ES_NOHIDESEL OR %ES_READONLY OR %ES_MULTILINE OR %WS_BORDER
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB CCSCommand                                              xBot
    '_________________________________________________________________
    
    SUB CCSCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      'wParamX = Handle to the device context for the static control window.
      'lParamX = Handle to the static control.
    
      LOCAL myReturn  AS LONG
    
      giTheReturn = 0
    
      IF lParamX <> 0 THEN
          myReturn = GetDlgCtrlID(lParamX)
          GOTO ContinueOn
      END IF
      EXIT SUB
    
      ContinueOn:
      SELECT CASE myReturn      '= control id
    
          CASE %ID_TITLEBAR1, _
               %ID_TITLEBAR2, _
               %ID_IDNOTE, _
               %ID_IDNOTE2, _
               %ID_TITLELABEL
               SetTextColor (wParamX, RGB(0,0,0))                    'Label color text
               SetBkColor   (wParamX, RGB(255,255,255))              'Label background color
               giTheReturn = hBrushPearl
    
    
          CASE %ID_LabelTitle, _          'screen title
               %ID_LabelAttention, _      'is app paying attention symbol
               %ID_LabelDictation, _      'is dictation grammar enabled symbol
               %ID_LabelListen, _         'is recognition enabled symbol
               %ID_LabelTalk              'is server or client talking symbol
    
               SetTextColor (wParamX, RGB(0,0,0))                    'Label text color
    
               'IF giLoginStatus = 0 OR _
               '   (gsThisClient = "Client" AND giReceivedUpdate = 0) THEN
                   SetBkColor   (wParamX, RGB(255,255,255))
                   giTheReturn = hBrushPearl
               '    EXIT SUB
               'END IF
      END SELECT
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB LOAD_BRUSHES                                            xBot
    '_________________________________________________________________
    
    SUB LOAD_BRUSHES
      STATIC Lb AS LOGBRUSH
    
      Lb.lbStyle  = %BS_SOLID                            'Lb.lbStyle = 0 = BS_SOLID ( 1 = BS_HOLLOW, BS_NULL)
      Lb.lbColor  = RGB(255,255,255)                     'Dialog background color (Solid or Hollow ~ Lb.lbHatch ignored)
      hBrushPearl = CreateBrushIndirect(Lb)
    
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB MoveWindowToHere        Dialog follows mouse movement   xBot
    '_________________________________________________________________
    
    SUB MoveWindowToHere
      LOCAL CurPos      AS POINT
      LOCAL CP_Old      AS POINT  'CenterPoint Old
    
      'Moving dialog with mouse after Arrow keys were used once.
      'Works ok if you want the dialog to be moved to a position where
      'the mouse cursor is located at the center of the titlebar.
    
      'This must be here to get a smooth motion of dialog dragging
      GetCursorPos(CurPos)   'in screen coordinates
    
      GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
    
      CP_Old.x = (rcMainSub.nRight - rcMainSub.nLeft)/ 2 + rcMainSub.nLeft
      CP_Old.y = (24)/ 2 + rcMainSub.nTop
    
      MoveWindow(hWndMain, rcMainSub.nLeft + CurPos.x - CP_Old.x, rcMainSub.nTop + CurPos.y - CP_Old.y, _
                            rcMainSub.nRight  - rcMainSub.nLeft, _
                            rcMainSub.nBottom - rcMainSub.nTop, %TRUE)
    
    END SUB
    
    
    '_________________________________________________________________
    '
    ' SUB MoveWindowToHereEx     Dialog follows mouse movement    xBot
    '_________________________________________________________________
    
    SUB MoveWindowToHereEx
      LOCAL CurPos      AS POINT
      LOCAL StartX      AS LONG
      LOCAL StartY      AS LONG
      LOCAL OffsetX     AS LONG
      LOCAL OffsetY     AS LONG
    
      'Move a dialog smoothly by mouse movement
      'Designed to move dialog from any point on titlebar
      'left of the Minimize button.
    
      'This must be here to get a smooth motion of dialog dragging
      GetCursorPos(CurPos)   'in screen coordinates
    
      GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
    
      StartX = rcMainSub.nLeft + iLOCx
      StartY = rcMainSub.nTop + iLOCy
    
      OffsetX = CurPos.x - StartX
      OffsetY = CurPos.y - StartY
    
      MoveWindow(hWndMain, rcMainSub.nLeft + OffsetX, rcMainSub.nTop + OffsetY, _
                            rcMainSub.nRight  - rcMainSub.nLeft, _
                            rcMainSub.nBottom - rcMainSub.nTop, %TRUE)
    
    END SUB
    
    
    '_________________________________________________________________
    '
    ' SUB MoveWindowLeft10                                        xBot
    '_________________________________________________________________
    
    SUB MoveWindowLeft10
      LOCAL WinRec      AS RECT
    
      GetWindowRect hWndMain, WinRec
      MoveWindow(hWndMain, WinRec.nLeft - 10, WinRec.nTop, _
                            WinRec.nRight  - WinRec.nLeft, _
                            WinRec.nBottom - WinRec.nTop, %TRUE)
    
      CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB MoveWindowRight10                                       xBot
    '_________________________________________________________________
    
    SUB MoveWindowRight10
      LOCAL WinRec      AS RECT
    
      GetWindowRect hWndMain, WinRec
      MoveWindow(hWndMain, WinRec.nLeft + 10, WinRec.nTop, _
                            WinRec.nRight  - WinRec.nLeft, _
                            WinRec.nBottom - WinRec.nTop, %TRUE)
    
      CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB MoveWindowUp10                                          xBot
    '_________________________________________________________________
    
    SUB MoveWindowUp10
      LOCAL WinRec      AS RECT
    
      GetWindowRect hWndMain, WinRec
      MoveWindow(hWndMain, WinRec.nLeft, WinRec.nTop - 10, _
                            WinRec.nRight  - WinRec.nLeft, _
                            WinRec.nBottom - WinRec.nTop, %TRUE)
    
      CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB MoveWindowDown10                                        xBot
    '_________________________________________________________________
    
    SUB MoveWindowDown10
      LOCAL WinRec      AS RECT
    
      GetWindowRect hWndMain, WinRec
      MoveWindow(hWndMain, WinRec.nLeft, WinRec.nTop + 10, _
                            WinRec.nRight  - WinRec.nLeft, _
                            WinRec.nBottom - WinRec.nTop, %TRUE)
    
      CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
    END SUB
    
    
    '_________________________________________________________________
    '
    ' SUB CHECK_MOUSE                                             xBot
    '_________________________________________________________________
    
    SUB CHECK_MOUSE
      LOCAL idThreadCheckMouse        AS LONG
      LOCAL idThreadMouseButtonToggle AS LONG
    
      THREAD CREATE CheckMouseThread(1) TO idThreadCheckMouse
      THREAD CLOSE idThreadCheckMouse TO idThreadCheckMouse
    
      THREAD CREATE MouseButtonToggleThread(1) TO idThreadMouseButtonToggle
      THREAD CLOSE idThreadMouseButtonToggle TO idThreadMouseButtonToggle
    
    END SUB
    
    '_________________________________________________________________
    '
    '   FUNCTION  CheckMouseThread            full time           xBot
    '_________________________________________________________________
    
    THREAD FUNCTION CheckMouseThread(BYVAL yyy AS LONG) AS LONG
        LOCAL CurPos   AS POINT
    
        'Wait until app is visible.
        TryAgain:
        IF IsWindowVisible(hWndmain) THEN
            'continue processing
        ELSE
            SLEEP 100
            IF giCancelProgram = 0 THEN GOTO TryAgain
        END IF
        SLEEP 200
        PostMessage hWndMain, %WM_COMMAND, %ID_CaptureIconRect, 0
    
        DO WHILE giCancelProgram = 0
            CALL GetMousePosition
            CurPos = MyCurPos
    
            IF ISFALSE IsRectEmpty(WindowMinimizeRect) THEN
                IF PtInRect(WindowMinimizeRect, CurPos) > 0 THEN
                    CALL ACT_ON_TASKBAR_ICON_TOGGLE
                END IF
            END IF
            SLEEP 100
        LOOP
    
    END FUNCTION
    
    '_________________________________________________________________
    '
    '   FUNCTION  MouseButtonToggleThread        full time        xBot
    '_________________________________________________________________
    
    THREAD FUNCTION MouseButtonToggleThread(BYVAL yyy AS LONG) AS LONG
        LOCAL CurPos   AS POINT
    
    
        'Wait until app is visible.
        TryAgain:
        IF IsWindowVisible(hWndmain) THEN
            'continue processing
        ELSE
            SLEEP 100
            IF giCancelProgram = 0 THEN GOTO TryAgain
        END IF
        SLEEP 300
    
        DO WHILE giCancelProgram = 0
            IF IsRectEmpty(WindowMinimizeRect) THEN
                PostMessage hWndMain, %WM_COMMAND, %ID_CaptureIconRect, 0
            ELSE
                GetCursorPos(CurPos)
    
                IF PtInRect(WindowMinimizeRect, CurPos) > 0 THEN
                    'Mouse is located on the taskbar icon
                    CALL WAS_MOUSE_BUTTON_TOGGLED
                ELSE
                    'Mouse is not located on the taskbar icon
                    giDeactivationComplete = 0
                    giActivationComplete = 0
                    CALL CLEAR_MOUSE_TOGGLE
    
                END IF
            END IF
            SLEEP 100
        LOOP
    
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' SUB WAS_MOUSE_BUTTON_TOGGLED                                xBot
    '_________________________________________________________________
    
    SUB WAS_MOUSE_BUTTON_TOGGLED
      LOCAL k           AS LONG         ' Key status
      LOCAL btnDown     AS LONG
    
      k = GetAsyncKeyState(%VK_RBUTTON)   'not used
      btnDown =  BIT(k, 15)
      SELECT CASE btnDown
          CASE 1
              'right mouse button is down.
              CALL RIGHT_MOUSE_PRESSED
    
          CASE 0
              IF giRightMouseButtonDown = 1 THEN
                  CALL CLEAR_MOUSE_TOGGLE
                  'right mouse button was down then up.
                  giRightMouseToggled = 1
    
              END IF
    
      END SELECT
    
      k = GetAsyncKeyState(%VK_LBUTTON)
      btnDown =  BIT(k, 15)
      SELECT CASE btnDown
          CASE 1
              'left mouse button is down.
              CALL LEFT_MOUSE_PRESSED
    
          CASE 0
              'left mouse button is up.
              IF giLeftMouseButtonDown = 1 THEN
                  CALL CLEAR_MOUSE_TOGGLE
                  giLeftMouseToggled = 1
    
              END IF
    
      END SELECT
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB ACT_ON_TASKBAR_ICON_TOGGLE                              xBot
    '_________________________________________________________________
    
    SUB ACT_ON_TASKBAR_ICON_TOGGLE
      LOCAL CurPos      AS POINT
    
      GetCursorPos(CurPos)
    
      IF giDeactivationComplete = 1 THEN
          giDeactivationComplete = 0
    
          SLEEP 200
    
          IF giLeftMouseToggled = 1 THEN
              giLeftMouseToggled = 0
    
              SELECT CASE IsIconic(hWndMain)
                  CASE 0 'Is Not Iconic
                      IF giAppIsDisabled = 1 THEN
                          ShowWindow hWndMain, %SW_RESTORE
                          giCaptionBar = 0
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
    
                          giActiveTitlebar = 1
    
    
                          giAppIsDisabled = 0
                          giFindNewActiveWindow = 1
    
                          giAppIsMinimized = 0
    
                          IF giView <> 0 THEN
                              gsCmdMessages = _ gsCmdMessages + _
                              "Mouse was toggled on Taskbar icon." + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          SLEEP 200
                          CALL FindNewActiveWindow
                          CALL SIMPLE_MINIMIZE
                      END IF
    
                  CASE 1 'Is Iconic
                      'Normally windows default behavior is to bring the app forward
    
              END SELECT
          END IF
          GOTO LeaveEarly
      END IF
    
      IF giActivationComplete = 1 THEN
          giActivationComplete = 0
    
          IF giLeftMouseToggled = 1 THEN
              giLeftMouseToggled = 0
    
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Ready to deactivate." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
          END IF
          GOTO LeaveEarly
      END IF
    
      IF giActivationComplete = 0 AND giDeactivationComplete = 0 THEN
          IF giLeftMouseToggled = 1 THEN
              giLeftMouseToggled = 0
    
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Minimizing Dialog." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              CALL SIMPLE_MINIMIZE
          END IF
      END IF
      LeaveEarly:
    END SUB
    
    
    '_________________________________________________________________
    '
    ' FUNCTION GetMousePosition                                   xBot
    '_________________________________________________________________
    
    SUB GetMousePosition
      LOCAL CurPos      AS POINT
    
      IF giGettingMousePosition = 1 THEN CALL MyPumpMessages(10): EXIT SUB
      giGettingMousePosition = 1
    
      GetCursorPos(MyCurPos)
    
      gsMousePosition = " X=" + STR$(MyCurPos.x) + " Y=" + STR$(MyCurPos.y)
    
      GetWindowRect hWndMain, rcMainSub
      SetRect(TitlebarRect, rcMainSub.nLeft + 2, rcMainSub.nTop + 2, rcMainSub.nRight - 2, rcMainSub.nTop + 22)
    
      SELECT CASE IsIconic(hWndMain)
          CASE 1 'Is iconic
              giAppIsMinimized = 1
    
          CASE 0 'Not iconic
              giAppIsMinimized = 0
    
      END SELECT
    
    
      'check to see if mouse is on Titlebar
      IF PtInRect(TitlebarRect, MyCurPos) > 0 THEN
          'mouse is inside titlebar
    
          CurPos = MyCurPos
          ScreenToClient(hCaptionBar, CurPos) 'Convert from screen to titlebar coordinates
          'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "X" + STR$(CurPos.x) + " Y=" + STR$(CurPos.y)
    
          SELECT CASE giActiveTitlebar
              CASE 1 'active titlebar
                  IF (CurPos.x > 244 AND CurPos.x < 288) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                      IF giCaptionBar <> 2 THEN
                          giCaptionBar = 2
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA2)
                      END IF
                  ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                      IF giCaptionBar <> 3 THEN
                          giCaptionBar = 3
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA3)
                      END IF
                  ELSE
                      IF giCaptionBar <> 0 THEN
                          giCaptionBar = 0
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
                      END IF
                  END IF
    
              CASE 0 'inactive titlebar
                  IF (CurPos.x > 244 AND CurPos.x < 288) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                      IF giCaptionBar <> 4 THEN
                          giCaptionBar = 4
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA4)
                      END IF
                  ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                      IF giCaptionBar <> 5 THEN
                          giCaptionBar = 5
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA5)
                      END IF
                  ELSE
                      IF giCaptionBar <> 1 THEN
                          giCaptionBar = 1
                          SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
                      END IF
                  END IF
          END SELECT
      ELSE
          'mouse pointer is outside the titlebar
    
          IF (giCaptionBar = 5 OR giCaptionBar = 4) AND giCaptionBar <> 1 THEN
              giCaptionBar = 1 'NCA gray
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
          END IF
          IF (giCaptionBar = 3 OR giCaptionBar = 2) AND giCaptionBar <> 0 THEN
              giCaptionBar = 0 'NCA base
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
          END IF
    
      END IF
    
      giGettingMousePosition = 0
    END SUB
    
    
    '_________________________________________________________________
    '
    ' FUNCTION TitlebarMouseProc                                  xBot
    '_________________________________________________________________
    
    FUNCTION TitlebarMouseProc(BYVAL nCode AS LONG, BYVAL wParam AS LONG, _
                       BYVAL lParam AS MSLLHOOKSTRUCT POINTER) AS LONG
     SELECT CASE nCode
       CASE %HC_ACTION
         SELECT CASE wParam
          CASE %WM_MOUSEMOVE
              IF giMoving = 1 THEN
                  'Moving dialog with mouse after Arrow keys were used once.
                  CALL MoveWindowToHere
              ELSE
                  CALL MoveWindowToHereEx
              END IF
         END SELECT
     END SELECT
     FUNCTION = CallNextHookEx(hMouseHook, nCode, wParam, lParam) 'Forward message
    
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' SUB SetCursorCommandTitlebar                                xBot
    '_________________________________________________________________
    
    SUB SetCursorCommandTitlebar(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      LOCAL iReturn         AS LONG
    
      giTheReturn = 0
    
      IF wParamX = hCaptionBar THEN                   ' handle to titlebar
          IF giMoving = 1 THEN
              'giShowWaitCursor = 0  'not altered
              giShowHandCursor = 0
              giShowArrowCursor = 0
              giShowDocumentCursor = 0
              giShowMoveCursor = 1
          ELSE
              'giShowWaitCursor = 0  'not altered
              giShowHandCursor = 0
              giShowArrowCursor = 1
              giShowDocumentCursor = 0
              giShowMoveCursor = 0
          END IF
          CALL SELECT_MOUSE_CURSOR
    
      END IF
      'If an application processes this message, it should return TRUE
      'to halt further processing or FALSE to continue
      giTheReturn = %TRUE
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB SetCursorCommand                                        xBot
    '_________________________________________________________________
    
    SUB SetCursorCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
    
      giTheReturn = 0
    
      'Anywhere on client area except Titlebar
      IF LO(WORD, lParamX) = %HTCLIENT THEN       ' cursor is in client area
    
          SELECT CASE GetDlgCtrlID (wParamX)
              CASE %IDC_Reset, _   'BUTTONS
                   %IDC_Show
                  IF giMoving = 1 THEN
                      'giShowWaitCursor = 0  'not altered
                      giShowHandCursor = 0
                      giShowArrowCursor = 0
                      giShowDocumentCursor = 0
                      giShowMoveCursor = 1
                  ELSE
                      CALL ERASE_PREVIOUS_ASSIGNMENTS
                  END IF
                  CALL SELECT_MOUSE_CURSOR
    
              CASE %ID_IDNOTE2   'text
                  IF giMoving = 1 THEN
                      'giShowWaitCursor = 0  'not altered
                      giShowHandCursor = 0
                      giShowArrowCursor = 0
                      giShowDocumentCursor = 0
                      giShowMoveCursor = 1
                  ELSE
                      giShowDocumentCursor = 0
                      giShowHandCursor = 0
                      giShowArrowCursor = 0
                      giShowMoveCursor = 0
                  END IF
                  CALL SELECT_MOUSE_CURSOR
    
              CASE ELSE
                  IF giMoving = 1 THEN
                      'giShowWaitCursor = 0  'not altered
                      giShowHandCursor = 0
                      giShowArrowCursor = 0
                      giShowDocumentCursor = 0
                      giShowMoveCursor = 1
                  ELSE
                      giShowDocumentCursor = 0
                      giShowHandCursor = 0
                      giShowArrowCursor = 1
                      giShowMoveCursor = 0
                  END IF
                  CALL SELECT_MOUSE_CURSOR
    
          END SELECT
      END IF
      'If an application processes this message, it should return TRUE
      'to halt further processing or FALSE to continue
      giTheReturn = %TRUE
    END SUB
    
    
    '_________________________________________________________________
    '
    '   SUB  ERASE_PREVIOUS_ASSIGNMENTS                           xBot
    '_________________________________________________________________
    
    SUB ERASE_PREVIOUS_ASSIGNMENTS
    
      giShowHandCursor = 1
      giShowDocumentCursor = 0
      giShowArrowCursor = 0
      giShowMoveCursor = 0
    END SUB
    
    
    '_________________________________________________________________
    '
    ' SUB ActivateCommand                                         xBot
    '_________________________________________________________________
    
    SUB ActivateCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      LOCAL CurPos         AS POINT
    
      CALL GetMousePosition
      CurPos = MyCurPos
    
      SELECT CASE LO(WORD, wParamX)
          CASE %WA_INACTIVE
              'Deactivated.
    
              'inactive titlebar
              giCaptionBar = 1
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
              giActiveTitlebar = 0
    
              giAppIsDisabled = 1
              'giOnDialog = 0
    
              CALL DeactivationStep2
    
          CASE %WA_CLICKACTIVE
              'Activated by a mouse click.
              'CALL BRING_MAIN_WINDOW_FORWARD
    
              'gNewFocus = hWndMain
              'gOldFocus = gNewFocus
    
              'SetFocus hWndMain
              'giOnDialog = 1
              'PostMessage hWndMain, %WM_COMMAND, %ID_RefreshVolumeGraphics, 0
    
              'active titlebar
              'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "Active titlebar."
              ShowWindow hWndMain, %SW_RESTORE
              giCaptionBar = 0
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
    
              giActiveTitlebar = 1
    
              CALL EndActivation
    
              giAppIsDisabled = 0
              giFindNewActiveWindow = 1
    
              'lParamX = is the handle to the window being deactivated. Usually 0
    
          CASE %WA_ACTIVE
              'Activated by some method other than a mouse
              'click (for example, by a call to the
              'SetActiveWindow function or by use of the
              'keyboard interface to select the window).
              giCaptionBar = 0
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
    
              giActiveTitlebar = 1
    
              CALL EndActivation
    
              giAppIsDisabled = 0
              giFindNewActiveWindow = 1
    
              'lParamX = is the handle to the window being deactivated. Usually 0
    
      END SELECT
    
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB NCActivateCommand
    '_________________________________________________________________
    
    SUB NCActivateCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)   'looks good
      LOCAL CurPos         AS POINT
    
      CALL GetMousePosition
      CurPos = MyCurPos
      giTheReturn = %TRUE
    
      SELECT CASE wParamX
          CASE %TRUE
              'active titlebar
              giCaptionBar = 0
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
              giActiveTitlebar = 1
    
              CALL ActivationStep2
    
              IF ghWndSaveFocus THEN
                  ' Restore control focus
                  SetFocus(ghWndSaveFocus)
                  ghWndSaveFocus = 0
              END IF
    
          CASE %FALSE
              'inactive titlebar
              'giTheReturn = %FALSE  use this if you want to prevent inactivation
              giCaptionBar = 1
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
              giActiveTitlebar = 0
    
              CALL StartDeactivation
    
              ' Save control focus
              ghWndSaveFocus = GetFocus()
              'use this if you want to prevent inactivation
              'giTheReturn = %FALSE
    
          CASE 2097153   'handled as a true value
              'dialog is being activated from the taskbar
              'This happens only when dialog is minimized.
              'Hex value 200001
    
              'active titlebar
              giCaptionBar = 0
              SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
              giActiveTitlebar = 1
    
    
              CALL ActivationStep3    'seems like this should be the start of activation
    
              IF ghWndSaveFocus THEN
                  ' Restore control focus
                  SetFocus(ghWndSaveFocus)
                  ghWndSaveFocus = 0
              END IF
    
      END SELECT
    END SUB
    
    
    '_________________________________________________________________
    '
    ' SUB LOAD_ICONS                                              xBot
    '_________________________________________________________________
    
    SUB LOAD_ICONS
      LOCAL hInstance AS DWORD
    
      hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
    
      ghIconCM00 = LoadImage(hInstance, BYVAL 3500, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghIconCM01 = LoadImage(hInstance, BYVAL 3501, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghIconCM02 = LoadImage(hInstance, BYVAL 3502, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghIconCM03 = LoadImage(hInstance, BYVAL 3503, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghIconCM04 = LoadImage(hInstance, BYVAL 3504, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      ghIconCM05 = LoadImage(hInstance, BYVAL 3505, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB FindNewActiveWindow                                     xBot
    '_________________________________________________________________
    
    SUB FindNewActiveWindow
        LOCAL hNext1             AS DWORD
        LOCAL NumberX            AS LONG
        LOCAL lsNextWindowHandle AS STRING
    
        hNext1 = hWndMain
        NumberX = 0
        DO 'Enumerate desktop windows
            IF IsWindowOnDesktop(hNext1) THEN
                INCR NumberX
                IF NumberX = 2 THEN
                    lsNextWindowHandle = PARSE$(WindowSpec(hNext1), " ", 1)
                    hForeGroundPrior = VAL("&H0" + lsNextWindowHandle)  'returns unsigned decimal value from hex value
                    gsCmdMessages = _ gsCmdMessages + _
                    STR$(NumberX) + "  " + WindowSpec(hNext1) + $CRLF + _
                    gsCmdMessages
                    GOTO ShowResults
                END IF
            END IF
            hNext1 = GetNextWindow(hNext1, %GW_HWNDNEXT)
        LOOP UNTIL hNext1 = 0
    
        ShowResults:
        'hNext1 = GetTopWindow(hForeGroundPrior)  'looks at child windows
        'IF hNext1 <> 0 THEN
        '    hForeGroundPrior = hNext1
        'END IF
    
        IF giView <> 0 THEN
            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
        END IF
    
    END SUB
    
    
    '_________________________________________________________________
    '
    '   FUNCTION  MinimizeDialogThread                            xBot
    '_________________________________________________________________
    
    THREAD FUNCTION MinimizeDialogThread(BYVAL yyy AS LONG) AS LONG
    
        CALL SIMPLE_MINIMIZE
    
        IF giCloseDialog = 1 THEN
            DIALOG POST hWndMain, %WM_CLOSE, %NULL, %NULL   'asynchronous command
        END IF
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' SUB MINIMIZE_DIALOG                                         xBot
    '_________________________________________________________________
    
    SUB MINIMIZE_DIALOG
      LOCAL idThreadMinimizeDialog        AS LONG
    
      THREAD CREATE MinimizeDialogThread(1) TO idThreadMinimizeDialog
      THREAD CLOSE idThreadMinimizeDialog TO idThreadMinimizeDialog
    
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB SIMPLE_MINIMIZE                                         xBot
    '_________________________________________________________________
    
    SUB SIMPLE_MINIMIZE
      LOCAL CurPos         AS POINT
      LOCAL PriorPoint     AS POINT
      LOCAL rcPriorWindow  AS RECT
    
      giCaptionBar = 1
      SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
      giActiveTitlebar = 0
    
      'where is the mouse pointer?
      GetCursorPos(CurPos)
    
      'NOTE: This will work for most apps to bring them forward.
      'Yes, even the Edge Browser.
    
      IF IsWindow(hForeGroundPrior) THEN
          GetWindowRect hForeGroundPrior, rcPriorWindow
    
          PriorPoint.x = rcPriorWindow.nLeft + 40
          PriorPoint.y = rcPriorWindow.nTop + 10
    
          'Move mouse pointer to prior dialog top left corner
          'to the right of the icon area
          SetCursorPos PriorPoint.x, PriorPoint.y
    
          IF giView <> 0 THEN
              gsCmdMessages = _ gsCmdMessages + _
              "Prior Window point to click: " + _
              " X=" + STR$(PriorPoint.x) + " Y=" + STR$(PriorPoint.y) + $CRLF + _
              gsCmdMessages
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
    
          'Send left mouse click
          CALL SendLeftMouseClick
    
          'SLEEP 80
          'return mouse pointer to previous location
          SetCursorPos CurPos.x, CurPos.y
      END IF
    
      'Minimize our dialog
      ShowWindow hWndMain, %SW_MINIMIZE
    
      IF giView <> 0 THEN
          gsCmdMessages = _ gsCmdMessages + _
          "Dialog Minimized." + $CRLF + _
          gsCmdMessages
          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
      END IF
    
    END SUB
    
    '_________________________________________________________________
    '
    ' FUNCTION SendLeftMouseClick
    '_________________________________________________________________
    
    FUNCTION SendLeftMouseClick () AS LONG 'pt is in screen coordinates
      DIM ipt(1) AS InputAPI '2 mouse events: down-up
    
      'first mouse event - mousedown
      ipt(0).dtype = %INPUT_MOUSE
      ipt(0).mi.dx = 0 'pt.x '65535 / (wDesktop/pt.x)
      ipt(0).mi.dy = 0 'pt.y '65535 / (hDesktop/pt.y)
      ipt(0).mi.MouseData = 0
      ipt(0).mi.dwFlags = %MOUSEEVENTF_ABSOLUTE OR %MOUSEEVENTF_LEFTDOWN OR %MOUSEEVENTF_MOVE
      ipt(0).mi.dtime = 0
      ipt(0).mi.dwExtraInfo = 0
    
      'second mouse event - mouseup
      ipt(1) = ipt(0)
      ipt(1).mi.dwFlags = %MOUSEEVENTF_LEFTUP
      FUNCTION = SendInput (UBOUND(ipt)+1, BYVAL VARPTR(ipt(0)), SIZEOF(InputAPI))
    END FUNCTION
    
    
    '_________________________________________________________________
    '
    ' SUB SELECT_MOUSE_CURSOR                                     xBot
    '_________________________________________________________________
    
    SUB SELECT_MOUSE_CURSOR
      IF giShowWaitCursor = 1 THEN
          MOUSEPTR hCursorWait
      ELSEIF giShowArrowCursor = 1 THEN
          MOUSEPTR hCursorArrow
      ELSEIF giShowHandCursor = 1 THEN
          MOUSEPTR hCursorHand
      ELSEIF giShowMoveCursor = 1 THEN
          MOUSEPTR hCursorMove
      ELSEIF giShowDocumentCursor = 0 THEN
          MOUSEPTR hCursorBar
      END IF
    END SUB
    
    '_________________________________________________________________
    '
    ' SUB LOAD_CURSORS                                            xBot
    '_________________________________________________________________
    
    SUB LOAD_CURSORS
      'New method that replaces LoadCursorA( %NULL, BYVAL %IDC_HAND )
      hCursorHand =  LoadImageA(%NULL, BYVAL %OCR_HAND,    %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
      hCursorArrow = LoadImageA(%NULL, BYVAL %OCR_NORMAL,  %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
      hCursorWait =  LoadImageA(%NULL, BYVAL %OCR_WAIT,    %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
      hCursorBar =   LoadImageA(%NULL, BYVAL %OCR_IBEAM,   %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
      hCursorMove =  LoadImageA(%NULL, BYVAL %OCR_SIZEALL, %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
    
    'from WinUser.inc
    '%OCR_IBEAM
    '%OCR_WAIT
    '%OCR_HAND
    '%OCR_NORMAL
    '%OCR_SIZEALL
    END SUB
    
    
    '------------------------------------------------------------------------------
    'Purpose: by calling SetWindowTheme with an empty string your control
    '         (button/checkbox/combo etc) will not be painted with the XP Theme.
    '
    'Example: LOCAL hButton AS DWORD
    '         hButton = GetDlgItem( CBHNDL, %IDOK )
    '         lRes = DisableXPThemeControl ( hbutton )
    '         InvalidateRect hButton,BYVAL %NULL,%TRUE
    '------------------------------------------------------------------------------
    FUNCTION DisableXPThemeControl(BYVAL hControl AS DWORD) AS LONG
        LOCAL hLib AS DWORD, pProc AS DWORD, lRes AS LONG
        hLib = LoadLibrary("UxTheme.dll")
        IF hLib THEN
             pProc = GetProcAddress(hLib, "SetWindowTheme")
             IF pProc THEN
                  CALL DWORD pProc USING SetWindowTheme(hControl, " ", " ")  TO lRes
                  FUNCTION = lRes
             END IF
             FreeLibrary hLib
        END IF
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' FUNCTION WindowSpec                                         xBot
    '_________________________________________________________________
    
    FUNCTION WindowSpec(hWin AS DWORD) AS STRING
        LOCAL zCaption AS ASCIIZ * %MAX_PATH
        LOCAL zClass   AS ASCIIZ * 32 'aka %MAX_CLASS_NAME_LEN
    
        GetClassName(hWin, zClass, SIZEOF(zClass))
        GetWindowText(hWin, zCaption, SIZEOF(zCaption))
        FUNCTION = HEX$(hWin) & $SPC & zCaption & " - Class: " & zClass
    END FUNCTION
    
    '_________________________________________________________________
    '
    ' FUNCTION IsWindowOnDesktop                                  xBot
    '_________________________________________________________________
    
    FUNCTION IsWindowOnDesktop(hWin AS DWORD) AS LONG
        LOCAL WinRect AS RECT
    
        IF ISFALSE(IsIconic(hWin)) THEN    'not iconic
            IF IsWindow(hWin) THEN
                IF GetParent(hWin) = %HWND_DESKTOP THEN
                    IF IsWindowVisible(hWin) THEN
                        GetWindowRect(hWin, WinRect)
                        IF WinRect.nLeft < WinRect.nRight THEN 'hWnd x-axis size is not zero
                            IF WinRect.nTop < WinRect.nBottom THEN 'hWnd y-axis size is not zero
                                'May also check to see if window is outside screen
                                'Note that topMost windows will have effect on the zOrder
                                FUNCTION = %TRUE
                            END IF
                        END IF
                    END IF
                END IF
            END IF
        END IF
    END FUNCTION
    
    
    '_________________________________________________________________
    '
    ' Processes pending Windows messages.                         xBot
    ' Call this procedure if you are performing a tight
    ' FOR/NEXT or DO/LOOP and need to allow
    ' your application to be responsive to user input.
    ' Modified version of AfxPumpMessages
    '_________________________________________________________________
    
    SUB MyPumpMessages(BYVAL xTimes AS LONG) EXPORT
      LOCAL Ix AS LONG
    
      IF xTimes <= 0 THEN xTimes = 1
      FOR Ix = 1 TO xTimes
          'if GlobalVariableTest86 = 1 then EXIT SUB
          CALL PeekRemoveTranslateDispatchMessage
      NEXT Ix
    
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  PeekRemoveTranslateDispatchMessage
    '_________________________________________________________________
    
    SUB PeekRemoveTranslateDispatchMessage
      IF giPRTDMessage = 1 THEN EXIT SUB
      giPRTDMessage = 1
    
      STATIC Msg AS tagMsg
      IF PeekMessageA(Msg, %NULL, %NULL, %NULL, %PM_REMOVE) THEN
          TranslateMessage Msg
          DispatchMessage Msg
      END IF
    
      giPRTDMessage = 0
    END SUB
    
    
    
    '_________________________________________________________________
    '
    '   SUB  SystemCommand                                        xBot
    '_________________________________________________________________
    
    SUB SystemCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      ' This is the system commands broken out
      ' Capture this message and send a WM_DESTROY message
      ' or the program will remain in memory
      SELECT CASE wParamX AND &HFFF0
          CASE %SC_MAXIMIZE
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "WM_SYSCOMMAND - Maximize." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              ShowWindow hWndMain, %SW_NORMAL  'do not use maximize
    
          CASE %SC_CLOSE
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "WM_SYSCOMMAND - Close." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0
    
          CASE %SC_MINIMIZE
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "WM_SYSCOMMAND - Minimize." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
    
          CASE %SC_RESTORE
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "xBot is restoring to normal." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              ShowWindow hWndMain, %SW_NORMAL
    
      END SELECT
    END SUB
    
    
    '_________________________________________________________________
    '
    '   SUB  TimerCommand                                         xBot
    '_________________________________________________________________
    
    SUB TimerCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      'Not used for anything. Not dependable enough.
    
      'WM_SETCURSOR has higher priority than a timer.
      'A timer will not get refreshed until the mouse cursor stops
      'moving.
    
    END SUB
    
    '_________________________________________________________________
    '
    '   FUNCTION  CheckForMutex                                   xBot
    '_________________________________________________________________
    
    FUNCTION CheckForMutex(MutexName AS ASCIIZ, hMutex AS DWORD) AS LONG
     LOCAL hWin, hForWnd  AS DWORD
     LOCAL ThisID, ForeID AS LONG
     LOCAL fwi            AS FLASHWINFO 'FlashWindowApi        ' FLASHWINFO structure
    
      hMutex = CreateMutex(BYVAL %NULL, 0, MutexName)
      IF hMutex = %NULL THEN FUNCTION = 0 : EXIT FUNCTION      ' Failed to create mutex
    
      IF GetLastError = %ERROR_ALREADY_EXISTS THEN             ' App already running!
        hWin = FindWindowEx (%NULL, %NULL, "MobileApp", "xBot")    ' Find handle of program's window
    
        IF hWin THEN                                           ' Bring window into view
          fwi.cbSize    = SIZEOF(fwi)
          fwi.hwnd      = hWin
          fwi.dwFlags   = %FLASHW_ALL
          fwi.uCount    = 5
          fwi.dwTimeout = 40
          FlashWindowEx fwi
    
          ThisID = GetCurrentThreadID()                        ' Get this thread ID
          'hForWnd = GetForegroundWindow                       ' Get Thread ID of current foreground window
    
          ForeID = GetWindowThreadProcessID(GetForeGroundWindow, 0)
          AttachThreadInput(ThisID, ForeID, %TRUE)             ' Attach / share the current foreground thread input states
          SetForegroundWindow hWin                             ' Set our window to foreground window (OLD METHOD)
          AttachThreadInput(ThisID, ForeID, %FALSE)            ' Detach sharing
          'ShowWindow(hWin, %SW_RESTORE)                       ' Restore in case minimized
          ShowWindow hWin, %SW_NORMAL
    
        END IF
        FUNCTION = 1 : EXIT FUNCTION
      END IF
    
    END FUNCTION
    
    
    '_________________________________________________________________
    '
    '   SUB  GWForceSetForegroundWindow
    '_________________________________________________________________
    
    SUB GWForceSetForegroundWindow (BYVAL hwnd AS DWORD)   ' Add COMMON if needed in SLL
        ' V1.0
        ' ========================================================================================
        ' Replacement for the SetForegroundWindow API function. Thanks to Jose Roca.
        ' Changes by GV: Do loop added. No action, if hwnd is in focus.
        ' ========================================================================================
    
        LOCAL hFg, dwThreadId, dwProcessId, dwCurThreadId AS DWORD
    
            hFg = GetForegroundWindow
    
        IF hFg <> hwnd THEN
            dwThreadId = GetWindowThreadProcessId(hFg, dwProcessId)
            dwCurThreadId = GetCurrentThreadId
            AttachThreadInput(dwCurThreadId, dwThreadId, %TRUE)
            SetForegroundWindow(hwnd)
            BringWindowToTop(hwnd)
            SetFocus(hwnd)
            AttachThreadInput(dwCurThreadId, dwThreadId, %FALSE)
        END IF
    
    END SUB
    
    
    '_________________________________________________________________
    '
    '   SUB  SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR                xBot
    '_________________________________________________________________
    
    SUB SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
      LOCAL CenterPoint AS POINT   'in screen coordinates
    
      GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
    
      CenterPoint.x = (rcMainSub.nRight - rcMainSub.nLeft)/ 2 + rcMainSub.nLeft
      CenterPoint.y = (22)/ 2 + rcMainSub.nTop
    
      SetCursorPos CenterPoint.x, CenterPoint.y
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  StartActivation                                      xBot
    '_________________________________________________________________
    
    SUB StartActivation
      ACTIVATEAPP = "ACTIVATION"           '=A
      NCACTIVATE =  ""                     '=A
      ACTIVATE =    ""                     '=A
      giActivationComplete = 0
      giDeactivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  ActivationStep2                                      xBot
    '_________________________________________________________________
    
    SUB ActivationStep2
      NCACTIVATE =  "ACTIVE TITLEBAR"      '=B
      giActivationComplete = 0
      giDeactivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  ActivationStep3                                      xBot
    '_________________________________________________________________
    
    SUB ActivationStep3
      NCACTIVATE =  "ACTIVE TITLEBAR"      '=B
      giActivationComplete = 0
      giDeactivationComplete = 0
      CALL CLEAR_MOUSE_TOGGLE
    
      IF giView <> 0 THEN
          gsCmdMessages = _ gsCmdMessages + _
          "Activation from Taskbar Icon." + $CRLF + $CRLF + _
          gsCmdMessages
          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
      END IF
    END SUB
    
    
    '_________________________________________________________________
    '
    '   SUB  EndActivation                                        xBot
    '_________________________________________________________________
    
    SUB EndActivation
      ACTIVATE =    "ACTIVE DIALOG"        '=C
    
      IF ACTIVATEAPP = "ACTIVATION" AND _
         NCACTIVATE =  "ACTIVE TITLEBAR" AND _
         ACTIVATE =    "ACTIVE DIALOG" THEN
          giActivationComplete = 1
    
          IF giView <> 0 THEN
              gsCmdMessages = _ gsCmdMessages + _
              $CRLF + "Activation Completed." + $CRLF + _
              gsCmdMessages
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
    
      END IF
      giDeactivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  StartDeactivation                                    xBot
    '_________________________________________________________________
    
    SUB StartDeactivation
      NCACTIVATE =  "INACTIVE TITLEBAR"    '=D
      ACTIVATE =    ""                     '=D
      ACTIVATEAPP = ""                     '=D
      giDeactivationComplete = 0
      giActivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  DeactivationStep2                                    xBot
    '_________________________________________________________________
    
    SUB DeactivationStep2
      ACTIVATE =    "DEACTIVATE DIALOG"    '=E
      giDeactivationComplete = 0
      giActivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  EndDeactivation                                      xBot
    '_________________________________________________________________
    
    SUB EndDeactivation
      ACTIVATEAPP = "DEACTIVATION"         '=F
    
      IF NCACTIVATE =  "INACTIVE TITLEBAR" AND _
         ACTIVATE =    "DEACTIVATE DIALOG" AND _
         ACTIVATEAPP = "DEACTIVATION" THEN
          giDeactivationComplete = 1
    
          IF giView <> 0 THEN
              gsCmdMessages = _ gsCmdMessages + _
              $CRLF + _
              "Deactivation Completed." + $CRLF + _
              gsCmdMessages
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
      END IF
      giActivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  CLEAR_DEACTIVATION    not used                       xBot
    '_________________________________________________________________
    
    SUB CLEAR_DEACTIVATION
      NCACTIVATE =  ""
      ACTIVATE =    ""
      ACTIVATEAPP = ""
      giDeactivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  CLEAR_ACTIVATION      not used                       xBot
    '_________________________________________________________________
    
    SUB CLEAR_ACTIVATION
      ACTIVATEAPP = ""
      NCACTIVATE =  ""
      ACTIVATE =    ""
      giActivationComplete = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  CLEAR_MOUSE_TOGGLE                                   xBot
    '_________________________________________________________________
    
    SUB CLEAR_MOUSE_TOGGLE
      giRightMouseButtonDown = 0
      giRightMouseToggled = 0
      giLeftMouseButtonDown = 0
      giLeftMouseToggled = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  RIGHT_MOUSE_PRESSED                                  xBot
    '_________________________________________________________________
    
    SUB RIGHT_MOUSE_PRESSED
      giRightMouseButtonDown = 1
      giLeftMouseButtonDown = 0
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  LEFT_MOUSE_PRESSED                                   xBot
    '_________________________________________________________________
    
    SUB LEFT_MOUSE_PRESSED
      giRightMouseButtonDown = 0
      giLeftMouseButtonDown = 1
    END SUB
    
    '_________________________________________________________________
    '
    '   SUB  ChooseCommand                                        xBot
    '_________________________________________________________________
    
    SUB ChooseCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      SELECT CASE LO(WORD,wParamX)
    
          CASE %ID_CaptureIconRect
              GetWindowMinimizeRect(hWndMain, WindowMinimizeRect)
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                         $CRLF + _
                         "Taskbar Icon Size:" + $CRLF + _
                         " L=" + STR$(WindowMinimizeRect.nLeft)  + _
                         ", T=" + STR$(WindowMinimizeRect.nTop)   + _
                         ", R=" + STR$(WindowMinimizeRect.nRight) + _
                         ", B=" + STR$(WindowMinimizeRect.nBottom)+ $CRLF + _
                         gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
    
          CASE %IDC_Reset    'reset messages
              SELECT CASE HI(WORD, wParamX)
                  CASE %BN_CLICKED
                      IF giView <> 0 THEN
                          gsCmdMessages = ""
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      END IF
              END SELECT
    
          CASE %IDC_Show      'show all messages
              SELECT CASE HI(WORD, wParamX)
                  CASE %BN_CLICKED
                      gsCmdMessages = $CRLF + "Now ready to show messages." + $CRLF + _
                      "NOTE: " + $CRLF + _
                      "The newest messages will be listed first."
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      giView = NOT giView    'values are 0=False and -1=True
                      IF giView = 0 THEN
                          gsCmdMessages = InitialMessage
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      END IF
              END SELECT
    
          CASE %ID_Minimize
              CALL MINIMIZE_DIALOG
    
          CASE %ID_Move
              CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
              'change mouse cursor for hCaptionBar to move cursor
              'and enable mouse tracking
              giMoving = 1
              SetFocus GetDlgItem(hWndMain, %ID_CAPTIONBAR)
    
          CASE %IDM_EXI10, %IDCANCEL
              SELECT CASE HI(WORD, wParamX)
                  CASE %BN_CLICKED
                      giCloseDialog = 1
                      CALL MINIMIZE_DIALOG
              END SELECT
    
      END SELECT
    END SUB
    
    '******************************************************************************
    'The End
    '******************************************************************************

  • #2
    Example of Popup Menu.

    Click image for larger version

Name:	PopupMenu.jpg
Views:	1
Size:	12.3 KB
ID:	776449

    Comment


    • #3
      xBot Version 2

      Click image for larger version

Name:	Version 2.jpg
Views:	1
Size:	32.9 KB
ID:	776485

      Code:
      
      'xBot MobileApp Example
      'SDK Version 2
      'This version allows you to turn on/off the Captionbar and Marquee.
      'Set giHasCaptionAndMarquee = 1 'to view them
      'Set giHasCaptionAndMarquee = 0 'to not view them
      
      'Compilable Example:
      'Works with PBWIN 10.4 and Jose' includes.
      
      'by: Jim Fritts
      
      'Version 1 In response to this post...
      'https://forum.powerbasic.com/forum/USER-TO-USER-discussions/powerbasic-FOR-windows/774617-DIALOG-WITH-MINIMIZE-AND-CLOSE-ONLY#post774617
      
      'Version 2 In response to this post...
      'https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/776457-remove-the-top-portion-of-a-dialog#post776457
      
      'This source code was released to the public domain on 23 NOV 2018
      'It makes use of many contributors Borje, Pierre, Jose' among others.
      'Thank you all
      
      'NOTE: if you are using PBWIN 9 or below you will need to
      'replace all POINT references with POINTAPI.
      
      'Code Objective:
      'Version 1
      'Produce a Windows 10 foundation SDK example that has no Nonclient
      'area and replicates default Nonclient area behavior with easily
      'configurable bitmaps to fill the titlebar area. As intended the
      'titlebar only has a minimize [-] button and a close [X] button.
      
      'Version 2
      'Allow user to go rogue and turn On/Off the Captionbar and Marquee
      'to suit their programming needs.
      'Make bitmaps owner drawn and provide no drawing support for that.
      'Remove minimize [-] and close [X] functionality from
      'Captionbar.
      
      'This example demonstrates an app with:
      '  No NonClient Area.
      '  No window sizing.
      '  No maximizing.
      '  No Maximize button.
      '  A background gradient surrounding the dialog.
      '  An OwnerDrawn popup menu with Icons.
      '  Popup menu that has only Move, Minimize, and Close as options.
      
      '  A Subclassed Titlebar.
      
      'Even though the XPTheme is applied for the buttons not much else
      'benefits from it. Typically I do not like themed buttons but for
      'simplicities sake I used them here.
      
      'Yes, Dorothy you can have just what you want.
      
      'Hopefully this provides an adequate example for those SDK types.
      'Have FUN!
      
        '%TRUE  = 1
        '%FALSE = 0
        '%NULL  = 0
      
      
      #COMPILE EXE "xBot.exe"
      #DIM ALL
      
      #INCLUDE "Win32Api.inc"
      #INCLUDE "ComDlg32.inc"
      
      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ENUM Equates SINGULAR
          IDC_Reset = 500
          IDC_Show
          ID_Move       'move
          ID_Minimize   'minimize
          IDM_Sep       'menu separator
          IDM_EXI10     'close
          ID_IMAGE
          ID_CAPTIONBAR
          ID_TITLEBAR1
          ID_TITLELABEL
          ID_LabelListen
          ID_LabelDictation
          ID_LabelTitle
          ID_LabelAttention
          ID_LabelTalk
          ID_IDNOTE
          ID_TITLEBAR2
          ID_IDNOTE2
          IDC_Timer0
          ID_CaptureIconRect
      END ENUM
      
      TYPE PROP
          usefont        AS DWORD
          hinstance      AS DWORD
      '    isrecmodified  AS LONG
      '    isfilemodified AS LONG
      '    currententry   AS LONG
      '    maxentries     AS LONG
      '    findtext       AS ASCIIZ * %MAX_PATH
      END TYPE
      
      TYPE PopMenuItemType
        SizeA    AS SizeL
        zItem    AS ASCIIZ * 255            'Menu Text to display
        MenuType AS ASCIIZ * %MAX_PATH      'MOV MIN CLO
        ED       AS LONG                    'Enabled Disabled
      END TYPE
      
      GLOBAL hWndMain                 AS DWORD
      GLOBAL giCancelProgram          AS LONG
      GLOBAL ghNCA                    AS DWORD
      GLOBAL ghInst                   AS DWORD
      
      GLOBAL ghBmpNCA0                AS DWORD
      GLOBAL ghBmpNCA1                AS DWORD
      GLOBAL ghBmpNCA2                AS DWORD
      GLOBAL ghBmpNCA3                AS DWORD
      GLOBAL ghBmpNCA4                AS DWORD
      GLOBAL ghBmpNCA5                AS DWORD
      
      GLOBAL ghIconCM00               AS DWORD
      GLOBAL ghIconCM01               AS DWORD
      GLOBAL ghIconCM02               AS DWORD
      GLOBAL ghIconCM03               AS DWORD
      GLOBAL ghIconCM04               AS DWORD
      GLOBAL ghIconCM05               AS DWORD
      
      GLOBAL hCaptionBar              AS DWORD
      GLOBAL dwLabelStyle             AS DWORD
      GLOBAL dwNBLabelStyle           AS DWORD
      GLOBAL dwLeftLabelStyle         AS DWORD
      GLOBAL dwNoRetMLTextBoxStyle    AS DWORD
      GLOBAL hMouseHook               AS DWORD
      GLOBAL hContext                 AS DWORD
      GLOBAL hForeGroundPrior         AS DWORD
      GLOBAL hPopup                   AS DWORD
      GLOBAL ghCtl_Edit_X             AS DWORD
      GLOBAL ghWndSaveFocus           AS DWORD
      GLOBAL hMutex                   AS DWORD
      
      GLOBAL gP                       AS PROP
      
      GLOBAL InitialMessage           AS STRING
      GLOBAL gsBannerListen           AS STRING
      GLOBAL gsBannerTitle            AS STRING
      GLOBAL gsBannerTalk             AS STRING
      GLOBAL gsBannerAttention        AS STRING
      GLOBAL gsBannerDictation        AS STRING
      GLOBAL gsMousePosition          AS STRING
      GLOBAL gsCmdMessages            AS STRING
      GLOBAL NCACTIVATE               AS STRING
      GLOBAL ACTIVATE                 AS STRING
      GLOBAL ACTIVATEAPP              AS STRING
      
      GLOBAL giCaptionBar             AS LONG
      GLOBAL giTheReturn              AS LONG
      GLOBAL hBrushPearl              AS LONG
      GLOBAL giPRTDMessage            AS LONG
      GLOBAL giGettingMousePosition   AS LONG
      GLOBAL gfTrackLeave             AS LONG
      GLOBAL giActiveTitlebar         AS LONG
      GLOBAL giLeftMouseDown          AS LONG  'used to track mouse clicks on titlebar
      GLOBAL giMinimizeClose          AS LONG
      GLOBAL giLeftButtonDown         AS LONG  'used to track mouse dragging on titlebar
      GLOBAL giAppIsMinimized         AS LONG
      GLOBAL giAppIsDisabled          AS LONG
      GLOBAL giShowDocumentCursor     AS LONG
      GLOBAL giShowHandCursor         AS LONG
      GLOBAL giShowArrowCursor        AS LONG
      GLOBAL giShowWaitCursor         AS LONG
      GLOBAL giShowMoveCursor         AS LONG
      GLOBAL hCursorArrow             AS LONG
      GLOBAL hCursorBar               AS LONG
      GLOBAL hCursorHand              AS LONG
      GLOBAL hCursorWait              AS LONG
      GLOBAL hCursorMove              AS LONG
      GLOBAL giMoving                 AS LONG
      GLOBAL giView                   AS LONG
      GLOBAL giCloseDialog            AS LONG
      GLOBAL giRightMouseButtonDown   AS LONG
      GLOBAL giRightMouseToggled      AS LONG
      GLOBAL giLeftMouseButtonDown    AS LONG
      GLOBAL giLeftMouseToggled       AS LONG
      GLOBAL giFindNewActiveWindow    AS LONG
      GLOBAL giActivationComplete     AS LONG
      GLOBAL giDeactivationComplete   AS LONG
      GLOBAL iLOCx                    AS LONG
      GLOBAL iLOCy                    AS LONG
      GLOBAL giHasCaptionAndMarquee   AS LONG  'Turn on/Off Captionbar and Marquee Banner
      
      GLOBAL MyCurPos                 AS POINT   'in screen coordinates
      
      GLOBAL rcMainSub                AS RECT
      GLOBAL TaskbarAppRect           AS RECT
      GLOBAL TitlebarRect             AS RECT
      GLOBAL TaskbarRect              AS RECT
      GLOBAL DesktopRect              AS RECT
      GLOBAL WindowMinimizeRect       AS RECT
      
      
      #RESOURCE BITMAP,     110, "NC_Base.bmp"           'its size is 220x20 active no highlighted buttons
      #RESOURCE BITMAP,     111, "NC_Gray.bmp"           'its size is 220x20 inactive no highlighted buttons
      #RESOURCE BITMAP,     112, "NC_Min.bmp"            'its size is 220x20 active minimize button highlighted
      #RESOURCE BITMAP,     113, "NC_X.bmp"              'its size is 220x20 active close button highlighted
      #RESOURCE BITMAP,     114, "NC_Min_Gray.bmp"       'its size is 220x20 inactive minimize button highlighted
      #RESOURCE BITMAP,     115, "NC_X_Gray.bmp"         'its size is 220x20 inactive close button highlighted
      
      #RESOURCE ICON,     3000, "xBot.ICO"
      
      #RESOURCE ICON,     3500, "CM00.ICO"
      #RESOURCE ICON,     3501, "CM01.ICO"    'not needed
      #RESOURCE ICON,     3502, "CM02.ICO"
      #RESOURCE ICON,     3503, "CM03.ICO"    'not needed
      #RESOURCE ICON,     3504, "CM04.ICO"
      #RESOURCE ICON,     3505, "CM05.ICO"    'not needed
      
      #RESOURCE MANIFEST,     1, "xptheme.XML"
      
      #RESOURCE VERSIONINFO
      #RESOURCE FILEFLAGS      0
      #RESOURCE FILEVERSION    1, 0, 0, 0
      #RESOURCE PRODUCTVERSION 1, 0, 0, 0
      #RESOURCE STRINGINFO     "0409", "0000"
      #RESOURCE VERSION$       "CompanyName",      "LocalApp, Inc."
      #RESOURCE VERSION$       "FileDescription",  "xBot"
      #RESOURCE VERSION$       "FileVersion",      "2.0"
      #RESOURCE VERSION$       "InternalName",     "xBot"
      #RESOURCE VERSION$       "OriginalFilename", "xBot.exe"
      #RESOURCE VERSION$       "LegalCopyright",   "© by James R. Fritts 2018"
      #RESOURCE VERSION$       "LegalTrademarks",  "HSI"
      #RESOURCE VERSION$       "ProductName",      "XBOT"
      #RESOURCE VERSION$       "ProductVersion",   "2.0"
      
      
      DECLARE THREAD FUNCTION MinimizeDialogThread(BYVAL yyy AS LONG) AS LONG           'temporary
      DECLARE THREAD FUNCTION CheckMouseThread(BYVAL yyy AS LONG) AS LONG               'full time
      DECLARE FUNCTION GetWindowMinimizeRect LIB "user32.dll" ALIAS "GetWindowMinimizeRect" _
      (BYVAL hWindow AS DWORD, pRect AS RECT) AS LONG 'Vista+
      
      '_________________________________________________________________
      '
      ' Program entrance                                            xBot
      '_________________________________________________________________
      
      FUNCTION WINMAIN (BYVAL hInstance AS DWORD, _
                        BYVAL hPrevInstance AS DWORD, _
                        BYVAL lpCmdLine AS ASCIIZ PTR, _
                        BYVAL iCmdShow AS LONG) AS LONG
      
          LOCAL Msg          AS tagMsg
          LOCAL W            AS WndClassEx
          LOCAL szAppName    AS ASCIIZ * 80
          LOCAL szClassName  AS ASCIIZ * 80
          LOCAL hWndButton   AS DWORD
          LOCAL hAccel       AS DWORD
          LOCAL WndStyle     AS LONG
          LOCAL WndStyleX    AS LONG
      
          LOCAL ResX               AS LONG
      
          ResX = CheckForMutex("xBot", hMutex)
          IF ResX > 0 THEN WinBeep 300,200 : EXIT FUNCTION
      
          giShowArrowCursor = 1
          CALL SELECT_MOUSE_CURSOR
      
          'register window class
          szAppName = "xBot"
          szClassName = "Mobileapp" '"#32770"
      
          W.cbSize        = SIZEOF(W)
          W.Style         = %CS_HREDRAW OR %CS_VREDRAW   '%WS_OverlappedWindow Or %WS_HScroll Or %WS_VScroll  '
          W.lpfnWndProc   = CODEPTR(WndProc)
          W.cbClsExtra    = 0
          W.cbWndExtra    = 0
          W.hInstance     = hInstance
          W.hIcon         = LoadImage(hInstance, BYVAL 3000, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
          W.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
          W.hbrBackground = GetStockObject(%DKGRAY_BRUSH) '(%LTGRAY_BRUSH) '%COLOR_3DDKSHADOW 'COLOR_BTNSHADOW'%Color_BtnFace+1 (%COLOR_ACTIVEBORDER)
          W.lpszMenuName  = %NULL
          W.lpszClassName = VARPTR(szClassName)
          W.hIconSm       = W.hIcon
          RegisterClassEx W
      
          'create window of that class
          WndStyle  = %WS_VISIBLE OR %WS_POPUP OR %WS_BORDER OR %DS_MODALFRAME OR %DS_NOFAILCREATE
                      ' OR %DS_SETFONT OR %WS_CAPTION
          WndStyleX = %WS_EX_LEFT OR %WS_EX_WINDOWEDGE OR %WS_EX_APPWINDOW
      
          hWndMain = CreateWindowEx( _
              WndStyleX,     _  ' extended styles
              szClassName,   _  ' window class name
              szAppName,     _  ' caption
              WndStyle,      _  ' window styles
              300,           _  ' left
              300,           _  ' top
              340,           _  ' width    was 790
              340,           _  ' height
              %HWND_DESKTOP, _  ' parent window handle
              %NULL,         _  ' window menu handle
              hInstance,     _  ' program instance handle
              BYVAL %NULL)      ' creation parameters
      
          ghInst = hInstance
          gP.hinstance = hInstance
      
          CALL ASSIGN_WINDOW_STYLES
          CALL CreateButtons
          giHasCaptionAndMarquee = 0  '1= yes 0=no determines whether a Captionbar - titlebar and Marguee are shown
          CALL CreateTitlebar
          CALL BUILD_MARQUEE
          CALL LOAD_ICONS
          CALL BUILD_TEXTBOX
      
          ShowWindow hWndMain, iCmdShow   'controls how window is to be shown. 1st must use iCmdShow
          UpdateWindow hWndMain           'sends the window it's first WM_Create to display the window on the screen
      
          'message pump - calls WndProc whenever an application-specific message is received
          'WndProc can process the message, or pass it on to a the default window procedure that is built into Windows.
          WHILE GetMessage(Msg, %NULL, 0, 0) > 0
             IF ISFALSE TranslateAccelerator (hWndMain, hAccel, Msg) THEN
                IF ISFALSE ISDialogMessage (hWndMain, Msg) THEN
                   TranslateMessage Msg
                   DispatchMessage  Msg
                END IF
             END IF
          WEND
      END FUNCTION
      
      FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
          LOCAL hDC AS DWORD, pPaint AS PAINTSTRUCT, tRect  AS RECT
          LOCAL pnmhdr         AS NMHDR PTR
          LOCAL CurPos         AS POINT
      
          InitialMessage = $CRLF + _
                           "  This area is to provide user messages." + $CRLF + $CRLF + _
                           "  Reset Button:    clear this screen." + $CRLF + _
                           "  Show Button:     display app messages" + $CRLF + _
                           "                  or not display app messages." + $CRLF + $CRLF + _
                           "  See app notes for other info."
      
          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          'Create a timer event every 1/4 Sec = 250
          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          'SetTimer hWnd, %IDC_Timer0, 250, BYVAL %NULL
      
          SELECT CASE wMsg
      
              CASE %WM_CREATE          'when an application requests that a window be created
                                       'after window is created, but before it becomes visible
                  gsCmdMessages = $CRLF + "Now ready to show messages." + $CRLF + _
                  "NOTE: " + $CRLF + _
                  "The newest messages will be listed first."
      
                  'Initial View state (can be 0 or -1) if -1 then View messages if 0 then do not view messages
                  giView = -1
      
                  'Captures location of the application icon on the Taskbar
                  CALL CHECK_MOUSE
      
                  CALL LOAD_BRUSHES
                  CALL LOAD_CURSORS
                  CenterWindow hWnd            ' center on desktop
      
              CASE %WM_INITDIALOG      'immediately before a dialog box is displayed
                                       'typically used to initialize controls and carry out any other
                                       'initialization tasks that affect the appearance of the dialog box.
      
              CASE %WM_LBUTTONUP
                  'lbuttonup commands
                  '? "main left button up"
                  'CALL LButtonUpCommand(wParam, lParam)
                  FUNCTION = 1    'ignored
                  EXIT FUNCTION
      
              CASE %WM_LBUTTONDOWN
                  'lbuttondn commands
                  '? "main left button down"
                  'CALL LButtonDnCommand(wParam, lParam)
                  FUNCTION = 1    'ignored
                  EXIT FUNCTION
      
              CASE %WM_RBUTTONDOWN
                  '? "main right button down"
                  FUNCTION = 1    'ignored
                  EXIT FUNCTION
      
              CASE %WM_MOVE
                  'move commands
                  'call MoveCommand(wParam, lParam)
                  IF IsWindowEnabled(hWndMain) THEN
                      CALL Captionbar0
                  END IF
                  FUNCTION = 0  '=o if processed
                  EXIT FUNCTION
      
              CASE %WM_CLOSE
                  DestroyWindow hWndMain
      
              CASE %WM_DESTROY         'window is being destroyed
                                       'after windows is removed from screen (children still exist)
                  RemoveWindowSubclass(GetDlgItem(hWndMain, %ID_CAPTIONBAR), CODEPTR(TitlebarProc), 99)
                  IF hBrushPearl     THEN CALL DeleteObject( hBrushPearl )
      
                  IF ghIconCM00 THEN DestroyIcon(ghIconCM00)
                  IF ghIconCM01 THEN DestroyIcon(ghIconCM01)
                  IF ghIconCM02 THEN DestroyIcon(ghIconCM02)
                  IF ghIconCM03 THEN DestroyIcon(ghIconCM03)
                  IF ghIconCM04 THEN DestroyIcon(ghIconCM04)
                  IF ghIconCM05 THEN DestroyIcon(ghIconCM05)
      
                  IF hCursorWait  THEN CALL DestroyCursor(hCursorWait)  'DeleteObject(hCursorWait)
                  IF hCursorHand  THEN CALL DestroyCursor(hCursorHand)  'DeleteObject(hCursorHand)
                  IF hCursorArrow THEN CALL DestroyCursor(hCursorArrow) 'DeleteObject(hCursorArrow)
                  IF hCursorBar   THEN CALL DestroyCursor(hCursorBar)   'DeleteObject(hCursorBar)
                  IF hCursorMove  THEN CALL DestroyCursor(hCursorMove)  'DeleteObject(hCursorMove)
      
                  IF hMouseHook <> 0 THEN UnhookWindowsHookEx(hMouseHook)
      
                  IF IsMenu(hPopUp) THEN DestroyMenu(hPopUp)
                  giCancelProgram = 1
                  SLEEP 100
                  PostQuitMessage 0
                  EXIT FUNCTION
      
              CASE %WM_COMMAND         'user selects a command item from a menu
                                       'control sends a notification message to its parent window
                                       'accelerator keystroke is translated.
                  'main command functions
                  CALL ChooseCommand(wParam, lParam)
                  FUNCTION = 1
                  EXIT FUNCTION
      
              CASE %WM_NOTIFY          'by control to its parent window when an event has occurred
                  pnmhdr = lParam
                  SELECT CASE @pnmhdr.idFrom
                      'CASE %IDC_Button              'Control ID
                      '    SELECT CASE @pnmhdr.code  'Notification code
                      '        CASE %NM_CLICK        'typical notification code
                      '    END SELECT
      
                  END SELECT
      
              CASE %WM_SIZE
                  IF wParam = %SIZE_MAXIMIZED THEN    'do not allow maximized display
                      ShowWindow hWndMain, %SW_SHOWNORMAL
                  END IF
                  FUNCTION = 0
                  EXIT FUNCTION
      
              CASE %WM_CTLCOLORSTATIC
                  'A static control, or an edit control that is read-only or disabled
                  'ctlcolorstatic functions
                  CALL CCSCommand(wParam, lParam)
                  FUNCTION = giTheReturn
                  EXIT FUNCTION
      
              'mouse click
              'CASE %WM_PARENTNOTIFY    'sent to parent when child window is created/destroyed
                                       'sent to parent when user clicks mouse button over child
      
              'mouse movement
              CASE %WM_SETCURSOR       'sent if mouse causes cursor to move
                  CALL SetCursorCommand(wParam, lParam)
                  FUNCTION = giTheReturn
                  EXIT FUNCTION
      
              'CASE %WM_MOUSEMOVE       'when cursor moves
      
              'keyboard
              'CASE %WM_CHAR            'to window with keyboard focus when WM_KEYDOWN message is translated
                                       'by the TranslateMessage function. contains the character code of the
                                       'key that was pressed.
      
              'CASE %WM_GETDLGCODE    'intercept keyboard input to child control
              '    FUNCTION = %DLGC_WANTARROWS '%DLGC_WANTCHARS OR %DLGC_WANTALLKEYS OR %DLGC_WANTMESSAGE
              '    EXIT FUNCTION
      
              'CASE %WM_KEYDOWN
      
              'graphic/drawing events
              CASE %WM_ERASEBKGND      'sent when the window background must be erased (such as resizing)
                  hDC = wParam
                  DrawGradient hDC     'Pass the DC of the region to repaint
                  FUNCTION = 1 : EXIT FUNCTION
      
              CASE %WM_PAINT           'set when request is made to paint a portion of an application's window.
      
              'recurring events
              CASE %WM_TIMER           'when a timer expires (does not keep accurate timing)
                  CALL TimerCommand(wParam, lParam)
                  FUNCTION = 0
                  EXIT FUNCTION
      
              'user action
              CASE %WM_PASTE           'application sends a WM_PASTE message to an edit control or combobox
              CASE %WM_DROPFILES       'sent when user drops file on application that's is registered as file recipient
      
              'application status
              CASE %WM_ACTIVATE        'sent to both the window being activated and the window
                                       'being deactivated.
                                       'activate functions
                                       'fires when ap gains and loses focus
      
                  'If an application processes this message, it should return zero.
                  CALL ActivateCommand(wParam, lParam)
                  FUNCTION = 1    'apparently xBot is not admitting that it processed this message
                  '**** EXIT FUNCTION CANNOT BE USED HERE ****
      
              CASE %WM_NCACTIVATE      'sent to window when its nonclient area needs to be changed
                                       'to indicate an active or inactive state.
                                       'If an application does process this message, it must
                                       'return TRUE to direct the system to complete the change
                                       'of active window
                  CALL NCActivateCommand(wParam, lParam)
                  FUNCTION = %TRUE 'giTheReturn
                  '**** EXIT FUNCTION CANNOT BE USED HERE ****
      
              CASE %WM_ACTIVATEAPP
                  SELECT CASE wParam
                      CASE %TRUE
      
                          CALL StartActivation
      
                      CASE %FALSE
      
                          CALL EndDeactivation
      
                  END SELECT
      
                  'If an application processes this message, it should return zero.
                  FUNCTION = 0
                  EXIT FUNCTION
      
              CASE %WM_SYSCOMMAND
                  'system command functions
                  CALL SystemCommand(wParam, lParam)
                  'If an application processes this message, it should return zero.
                  FUNCTION = 0
                  EXIT FUNCTION
      
          END SELECT
      
          FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)   'if not handled above, pass to Windows default message handler.
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' SUB DrawGradient
      '_________________________________________________________________
      
      SUB DrawGradient (BYVAL hDC AS DWORD)
         LOCAL rectFill AS RECT, rectClient AS RECT, fStep AS SINGLE, hBrush AS DWORD, lOnBand AS LONG
         GetClientRect WindowFromDC(hDC), rectClient
         fStep = rectClient.nbottom / 200
         FOR lOnBand = 0 TO 199
            SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
            hBrush = CreateSolidBrush(RGB(140 - lOnBand, 140 - lOnBand, 140 - lOnBand))
            Fillrect hDC, rectFill, hBrush
            DeleteObject hBrush
         NEXT
      END SUB
      
      
      '_________________________________________________________________
      '
      ' SUB CreateButtons                                           xBot
      '_________________________________________________________________
      
      SUB CreateButtons
        LOCAL WndStyle AS LONG, hWnd, hInstance AS DWORD
      
        'create window of existing class "Button"
        WndStyle  = %WS_TABSTOP OR %WS_VISIBLE OR %WS_CHILD OR %BS_DEFPUSHBUTTON
        hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
      
        IF giHasCaptionAndMarquee = 1 THEN
            hWnd= CreateWindow( _
               "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
               "Reset",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
               WndStyle,   _    'dwStyle        style of window
               30,         _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
               296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
               80,         _    'nWidth         width in device units
               30,         _    'nHeight        height in device units
               hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
               %IDC_Reset, _    'hMenu          handle to a menu or child window control ID
               hInstance,  _    'handle to instance of the module to be associated with the window
               BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
      
            hWnd= CreateWindow( _
               "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
               "Show",     _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
               WndStyle,   _    'dwStyle        style of window
               115,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
               296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
               80,         _    'nWidth         width in device units
               30,         _    'nHeight        height in device units
               hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
               %IDC_Show,  _    'hMenu          handle to a menu or child window control ID
               hInstance,  _    'handle to instance of the module to be associated with the window
               BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        ELSE
            hWnd= CreateWindow( _
               "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
               "Reset",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
               WndStyle,   _    'dwStyle        style of window
               30,         _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
               30,         _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
               80,         _    'nWidth         width in device units
               30,         _    'nHeight        height in device units
               hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
               %IDC_Reset, _    'hMenu          handle to a menu or child window control ID
               hInstance,  _    'handle to instance of the module to be associated with the window
               BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
      
            hWnd= CreateWindow( _
               "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
               "Show",     _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
               WndStyle,   _    'dwStyle        style of window
               115,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
               30,         _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
               80,         _    'nWidth         width in device units
               30,         _    'nHeight        height in device units
               hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
               %IDC_Show,  _    'hMenu          handle to a menu or child window control ID
               hInstance,  _    'handle to instance of the module to be associated with the window
               BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
      
            hWnd= CreateWindow( _
               "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
               "Close",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
               WndStyle,   _    'dwStyle        style of window
               236,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
               296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
               80,         _    'nWidth         width in device units
               30,         _    'nHeight        height in device units
               hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
               %IDM_EXI10, _    'hMenu          handle to a menu or child window control ID
               hInstance,  _    'handle to instance of the module to be associated with the window
               BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        END IF
      END SUB
      '_________________________________________________________________
      '
      ' SUB CreateTitlebar                                           xBot
      '_________________________________________________________________
      
      SUB CreateTitlebar
        LOCAL WndStyle AS LONG, hWnd, hInstance AS DWORD
      
        IF giHasCaptionAndMarquee = 1 THEN
            WndStyle  = %WS_VISIBLE OR %WS_CHILD OR %SS_NOTIFY OR %SS_BITMAP
        ELSE
            WndStyle  = %WS_VISIBLE OR %WS_CHILD OR %SS_NOTIFY OR %SS_OWNERDRAW 'or  OR %SS_BITMAP
        END IF
      
        hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
        hCaptionBar= CreateWindow( _
           "Static",      _ 'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
           BYVAL %NULL,   _ 'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
           WndStyle,      _ 'dwStyle        style of window
           2,             _ 'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
           2,             _ 'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
           333,           _ 'nWidth         width in device units
           20,            _ 'nHeight        height in device units
           hWndMain,      _ 'hWndParent     handle to parent window (optional for a pop-up window)
           %ID_CAPTIONBAR,_ 'hMenu          handle to a menu or child window control ID
           hInstance,     _ 'handle to instance of the module to be associated with the window
           BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
      
        'use the new subclass process and pass the window handle
        CALL SetWindowSubclass(hCaptionBar, CODEPTR(TitlebarProc), 99, 0)
      
        ghBmpNCA0 = LoadImage(hInstance, "#110", _ 'NCA base
                    %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghBmpNCA1 = LoadImage(hInstance, "#111", _ 'NCA gray
                    %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghBmpNCA2 = LoadImage(hInstance, "#112", _ 'NCA Min
                    %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghBmpNCA3 = LoadImage(hInstance, "#113", _ 'NCA X
                    %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghBmpNCA4 = LoadImage(hInstance, "#114", _ 'NCA Min gray
                    %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghBmpNCA5 = LoadImage(hInstance, "#115", _ 'NCA X gray
                    %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        CALL Captionbar0
      END SUB
      
      '_________________________________________________________________
      '
      ' FUNCTION TitlebarProc                                       xBot
      '_________________________________________________________________
      
      FUNCTION TitlebarProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, _
                BYVAL lParam AS LONG, BYVAL spID AS DWORD, BYVAL RefData AS DWORD) AS LONG
      
        LOCAL Xe               AS LONG
        LOCAL My_Return        AS LONG
      
        LOCAL pPopItemSize             AS MEASUREITEMSTRUCT POINTER
        LOCAL pPopItemDrawInfo         AS DRAWITEMSTRUCT POINTER
        LOCAL CurPos                   AS POINT
        LOCAL shFileInf                AS SHFILEINFO
        LOCAL pPopItem                 AS PopMenuItemType POINTER
        LOCAL zWinDir                  AS ASCIIZ * %MAX_PATH
        LOCAL zSysDir                  AS ASCIIZ * %MAX_PATH
        DIM   PopItem(1 TO 3)          AS STATIC PopMenuItemType
        LOCAL hdc                      AS DWORD
        LOCAL hBrush                   AS DWORD
        LOCAL hImg                     AS DWORD
        LOCAL Looper                   AS LONG
      
        SELECT CASE wMsg
      
            CASE %WM_GETDLGCODE    'intercept keyboard input to child control
                FUNCTION = %DLGC_WANTARROWS '%DLGC_WANTCHARS OR %DLGC_WANTALLKEYS OR %DLGC_WANTMESSAGE
                EXIT FUNCTION
      
            CASE %WM_KEYDOWN    'supports moving dialog when move is selected from
                                'popup menu
                IF giMoving = 1 THEN
                    SELECT CASE wParam
                        CASE %VK_LEFT 'LEFT ARROW key pressed
                            'locate mouse position
                            IF giView <> 0 THEN
                                gsCmdMessages = "Move dialog left." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                            CALL MoveWindowLeft10
                            IF hMouseHook = 0 THEN
                                hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                IF giView <> 0 THEN
                                    gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                    gsCmdMessages
                                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                END IF
                            END IF
      
                        CASE %VK_RIGHT 'RIGHT ARROW key pressed
                            IF giView <> 0 THEN
                                gsCmdMessages = "Move dialog right." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                            CALL MoveWindowRight10
                            IF hMouseHook = 0 THEN
                                hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                IF giView <> 0 THEN
                                    gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                    gsCmdMessages
                                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                END IF
                            END IF
      
                        CASE %VK_UP 'UP ARROW key pressed
                            IF giView <> 0 THEN
                                gsCmdMessages = "Move dialog up." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                            CALL MoveWindowUp10
                            IF hMouseHook = 0 THEN
                                hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                IF giView <> 0 THEN
                                    gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                    gsCmdMessages
                                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                END IF
                            END IF
      
                        CASE %VK_DOWN 'DOWN ARROW key pressed
                            IF giView <> 0 THEN
                                gsCmdMessages = "Move dialog down." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                            CALL MoveWindowDown10
                            IF hMouseHook = 0 THEN
                                hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                IF giView <> 0 THEN
                                    gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                    gsCmdMessages
                                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                END IF
                            END IF
      
                    END SELECT
                END IF
                FUNCTION = 0 : EXIT FUNCTION
      
            CASE %WM_COMMAND
                SELECT CASE LO(WORD, wParam)
                    CASE 1102
                        IF giView <> 0 THEN
                            gsCmdMessages = "Popup Menu Move selected." + $CRLF + $CRLF + _
                            gsCmdMessages
                            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                        END IF
                        PostMessage hWndMain, %WM_COMMAND, %ID_Move, 0
      
                    CASE 1103
                        IF giView <> 0 THEN
                            gsCmdMessages = "Popup Menu Minimize selected." + $CRLF + $CRLF + _
                            gsCmdMessages
                            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                        END IF
                        PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
      
                    CASE 1105
                        '? "close"
                        PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0
                END SELECT
      
            CASE %WM_LBUTTONDOWN 'do dragging if mouse down on titlebar
                '***NOTE:
                '***If left mouse button is down/up on the icon part of the
                '***titlebar then the popup menu should appear.
      
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "Left button down on titlebar." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
      
                CurPos.x = GET_X_LPARAM(lParam)   'in client coordinates
                CurPos.y = GET_Y_LPARAM(lParam)   'in client coordinates
      
                iLOCx = CurPos.x + 2  'added in the edge
                iLOCy = CurPos.y + 2  'added in the edge
      
                IF giHasCaptionAndMarquee = 1 THEN
                    IF (CurPos.x > 1 AND  CurPos.x < 245) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                        giLeftButtonDown = 1    'Left mouse button is down on title bar
                        IF hMouseHook = 0 THEN
                            hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                            IF giView <> 0 THEN
                                gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                        END IF
      
                    ELSEIF (CurPos.x > 244 AND  CurPos.x < 288) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                        giLeftMouseDown = 1
                        giMinimizeClose = 0
      
                    ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                        giLeftMouseDown = 1
                        giMinimizeClose = 1
                    END IF
                ELSE
                    IF (CurPos.x > 1 AND  CurPos.x < 333) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                        giLeftButtonDown = 1    'Left mouse button is down on title bar
                        IF hMouseHook = 0 THEN
                            hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                            IF giView <> 0 THEN
                                gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                        END IF
                        giLeftMouseDown = 0
                     END IF
                END IF
                FUNCTION = 0 : EXIT FUNCTION
      
            CASE %WM_LBUTTONUP 'stop dragging if mouse is up on titlebar
                '***NOTE:
                '***If left mouse button is down/up on the icon part of the
                '***titlebar then the popup menu should appear.
      
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "Left button up on titlebar." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
      
                IF giMoving = 1 THEN
                    giMoving = 0
                    giShowMoveCursor = 0
                    giShowArrowCursor = 1
                    SELECT_MOUSE_CURSOR
                END IF
      
                giLeftButtonDown = 0
                IF hMouseHook <> 0 THEN
                    UnhookWindowsHookEx(hMouseHook)
                    hMouseHook = 0
                    IF giView <> 0 THEN
                        gsCmdMessages = "Mouse hook released." + $CRLF + _
                        gsCmdMessages
                        CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                    END IF
                END IF
      
                IF giHasCaptionAndMarquee = 1 THEN
                    IF giLeftMouseDown = 1 THEN
                        giLeftMouseDown = 0
                        SELECT CASE giMinimizeClose
                            CASE 0 'minimize button clicked
                                IF giView <> 0 THEN
                                    gsCmdMessages = "Minimize button pressed." + $CRLF + $CRLF + _
                                    gsCmdMessages
                                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                END IF
                                PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
                            CASE 1 'close button clicked
                                PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0 'close dialog
      
                        END SELECT
      
                        giMinimizeClose = 0
                    END IF
                END IF
                FUNCTION = 0 : EXIT FUNCTION
      
            CASE %WM_RBUTTONDOWN 'for context menu on titlebar
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "Right button down on titlebar." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                FUNCTION = 0 : EXIT FUNCTION
      
            CASE %WM_RBUTTONUP
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "Right button up on titlebar." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                'FUNCTION = 0 : EXIT FUNCTION 'do not use this if you want the default process to produce context menu
      
            CASE %WM_CONTEXTMENU
                'https://forum.powerbasic.com/forum/user-to-user-discussions/programming/753120-is-there-a-way-to-put-a-button-on-a-menu-not-popup-dropdown?p=753130#post753130
                LOCAL MyItemName1 AS STRING
                LOCAL MyItemName2 AS STRING
                LOCAL MyItemName3 AS STRING
      
                MyItemName1 = "Move"
                MyItemName2 = "Minimize"
                MyItemName3 = "Close          Alt+F4"
      
                CALL GetMousePosition   'Get cursor screen location
                CurPos = MyCurPos
      
                'CaptionBar 3 and 5 have the Close [X] button highlighted
                'Based on some testing the default Windows behavior
                'is to not allow the popup menu when the Close button
                'is highlighted.
                IF giCaptionBar = 3 OR giCaptionBar = 5 THEN EXIT FUNCTION
      
                IF hPopup = 0 THEN
                    hPopup = CreatePopupMenu
      
                    PopItem(1).zItem    = MyItemName1
                    PopItem(1).MenuType = "MOV"
                    PopItem(1).ED = %MF_ENABLED
      
                    PopItem(2).zItem    = MyItemName2
                    PopItem(2).MenuType = "MIN"
                    PopItem(2).ED = %MF_ENABLED
      
                    PopItem(3).zItem    = MyItemName3
                    PopItem(3).MenuType = "CLO"
                    PopItem(3).ED = %MF_ENABLED
      
                    InsertMenu(hPopup, 0, %MF_BYCOMMAND OR %MF_STRING, 1102, MyItemName1 + $NUL)
                    InsertMenu(hPopup, 1, %MF_BYCOMMAND OR %MF_STRING, 1103, MyItemName2 + $NUL)
                    InsertMenu(hPopup, 2, %MF_BYCOMMAND OR %MF_SEPARATOR, 1104, "-")
                    InsertMenu(hPopup, 3, %MF_BYCOMMAND OR %MF_STRING, 1105, MyItemName3 + $NUL)
                    'SetMenu(hWnd, hPopup)
      
      
                    ModifyMenu(hPopup, 1102, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1102, BYVAL VARPTR(PopItem(1)))
                    ModifyMenu(hPopup, 1103, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1103, BYVAL VARPTR(PopItem(2)))
                    ModifyMenu(hPopup, 1105, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1105, BYVAL VARPTR(PopItem(3)))
      
                END IF
                TrackPopupMenu(hPopup, %TPM_LEFTALIGN OR %TPM_RIGHTBUTTON, _
                               CurPos.x, CurPos.y, BYVAL 0, hWnd, BYVAL 0)
      
            CASE %WM_MEASUREITEM 'wParam is control identifier, lParam is item-size information
                '- 9 in item length is important here to make the right menu edge appear correctly
                'not inflated
                hdc          = GetDC(hWnd)
                pPopItemSize = lParam
                pPopItem     = @pPopItemSize.itemData
                GetTextExtentPoint32(hdc, @pPopItem.zItem, LEN(@pPopItem.zItem) - 9, @pPopItem.SizeA)
                @pPopItemSize.itemWidth  = 4 + GetSystemMetrics(%SM_CYSMICON) + @pPopItem.sizeA.cx
                @pPopItemSize.itemHeight = 3 + MAX(GetSystemMetrics(%SM_CYSMICON), @pPopItem.sizeA.cy)
                ReleaseDC(hWnd, hdc)
                FUNCTION = %TRUE
      
            CASE %WM_DRAWITEM 'wParam is control id, lParam is item-drawing info
                pPopItemDrawInfo = lParam
                pPopItem         = @pPopItemDrawInfo.itemData
                IF (@pPopItemDrawInfo.itemState AND %ODS_SELECTED) THEN
                    SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHTTEXT))
                    SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHT))
                    hBrush = GetSysColorBrush(%COLOR_HIGHLIGHT)
                ELSE 'Item is not selected
                    SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENUTEXT))
                    SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENU))
                    hBrush = GetSysColorBrush(%COLOR_MENU)
                END IF
                FillRect(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem, hBrush)
      
      
                SELECT CASE @pPopItem.MenuType
                    CASE ""
                        'no icon for this item
      
                    CASE "MOV"
                        '<> move icon
                        SELECT CASE @pPopItem.ED
                            CASE %MF_ENABLED
                                DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                           ghIconCM00, 16, 16, 0, BYVAL 0, %DI_NORMAL)
      
                            CASE %MF_DISABLED
                                'no disabled icon
                                DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                           ghIconCM01, 16, 16, 0, BYVAL 0, %DI_NORMAL)
      
                        END SELECT
      
                    CASE "MIN"
                        '- minimize icon
                        SELECT CASE @pPopItem.ED
                            CASE %MF_ENABLED
                                DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                           ghIconCM02, 16, 16, 0, BYVAL 0, %DI_NORMAL)
      
                            CASE %MF_DISABLED
                                DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                           ghIconCM03, 16, 16, 0, BYVAL 0, %DI_NORMAL)
      
                        END SELECT
      
                    CASE "CLO"
                        'X close icon
                        SELECT CASE @pPopItem.ED
                            CASE %MF_ENABLED
                                DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                           ghIconCM04, 16, 16, 0, BYVAL 0, %DI_NORMAL)
      
                            CASE %MF_DISABLED
                                DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                           ghIconCM05, 16, 16, 0, BYVAL 0, %DI_NORMAL)
      
                        END SELECT
      
                END SELECT
      
                @pPopItemDrawInfo.rcItem.nLeft = 4 + @pPopItemDrawInfo.rcItem.nLeft + GetSystemMetrics(%SM_CXSMICON)
                DrawText(@pPopItemDrawInfo.hDC, @pPopItem.zItem, LEN(@pPopItem.zItem), _
                         @pPopItemDrawInfo.rcItem, %DT_SINGLELINE)
      
                FUNCTION = %TRUE
      
      
            CASE %WM_SETCURSOR
                'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "Setcursor is being processed."
                'setcursor functions
                CALL SetCursorCommandTitlebar(wParam, lParam)
      
                IF giTheReturn = 1 THEN  ' If the parent window returns TRUE, further processing is halted.
                    FUNCTION = 1
                    EXIT FUNCTION
                END IF
      
        END SELECT
      
        FUNCTION = DefSubclassProc(hWnd, wMsg, wParam, lParam)
      END FUNCTION
      
      
      
      '_________________________________________________________________
      '
      ' SUB CenterWindow
      '_________________________________________________________________
      
      SUB CenterWindow (BYVAL hAnyWnd AS LONG)
        DIM WndRect AS RECT
        DIM x       AS LONG
        DIM y       AS LONG
        GetWindowRect hAnyWnd, WndRect
        x = (GetSystemMetrics(%SM_CXSCREEN)-(WndRect.nRight-WndRect.nLeft))\2
        y = (GetSystemMetrics(%SM_CYSCREEN)-(WndRect.nBottom-WndRect.nTop+GetSystemMetrics(%SM_CYCAPTION)))\2
        SetWindowPos hAnyWnd, %NULL, x, y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB BUILD_MARQUEE                                           xBot
      '_________________________________________________________________
      
      SUB BUILD_MARQUEE
        LOCAL MyCtrl   AS DWORD
        LOCAL OffsetX   AS LONG
        LOCAL OffsetY   AS LONG
      
        gsBannerListen = "="
        gsBannerTalk   = CHR$(239)
        gsBannerAttention = "!"   'app is fully paying attention
        gsBannerDictation = "^"   'initial behavior
      
        IF giHasCaptionAndMarquee = 1 THEN
            OffsetX = 2
            OffsetY = 22
            MyCtrl = addLabelT(hWndMain, %ID_TITLEBAR1, "", 0 + OffsetX, 0 + OffsetY, 334, 4, dwNBLabelStyle)
            MyCtrl = addLabelT(hWndMain, %ID_TITLELABEL, "Xbot Personal Assistant", 0 + OffsetX, 4 + OffsetY, 334, 20, dwNBLabelStyle)
      
            MyCtrl = addLabelE(hWndMain, %ID_LabelListen, gsBannerListen + $NUL, 0 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
            MyCtrl = addLabelE(hWndMain, %ID_LabelDictation, gsBannerDictation + $NUL, 20 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
      
            MyCtrl = addLabelE(hWndMain, %ID_LabelTitle, "", 40, 24 + OffsetY, 254 + OffsetX, 20, dwLabelStyle OR %SS_NOTIFY)
      
            MyCtrl = addLabelE(hWndMain, %ID_LabelAttention, gsBannerAttention + $NUL, 294 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
            MyCtrl = addLabelE(hWndMain, %ID_LabelTalk, gsBannerTalk + $NUL, 314 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
      
            MyCtrl = addLabelE(hWndMain, %ID_IDNOTE, "", 0 + OffsetX, 44 + OffsetY, 334, 20, dwLabelStyle)
      
            MyCtrl = addLabelT(hWndMain, %ID_TITLEBAR2, "", 0 + OffsetX, 64 + OffsetY, 339, 2, dwLabelStyle)
        END IF
      
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB BUILD_TEXTBOX                                           xBot
      '_________________________________________________________________
      
      SUB BUILD_TEXTBOX
        LOCAL MyCtrl   AS DWORD
        LOCAL OffsetX   AS LONG
        LOCAL OffsetY   AS LONG
      
        OffsetX = 2
        OffsetY = 22
        IF giHasCaptionAndMarquee = 1 THEN
            MyCtrl = addTextBox(hWndMain, %ID_IDNOTE2, gsCmdMessages + $NUL, 0 + OffsetX, 70 + OffsetY, 334, 200, dwNoRetMLTextBoxStyle OR %WS_HSCROLL)
      
                ghCtl_Edit_X = MyCtrl
      
                SendMessage ghCtl_Edit_X, %EM_SETLIMITTEXT, &H200000&, 0 'set text limit to 2 Meg
                'SendMessage ghCtl_Edit_X, %EM_AUTOURLDETECT, %True, 0
                'SendMessage ghCtl_Edit_X, %EM_SETEVENTMASK, 0, %ENM_UPDATE OR %ENM_LINK OR %ENM_CHANGE OR %ENM_SELCHANGE OR %ENM_KEYEVENTS 'mask is set to produce the EN_UPDATE message
      
                'use the new subclass process and pass the dialog handle
                'CALL SetWindowSubclass(ghCtl_Edit_X, CODEPTR(EditProc), 29, 0)
      
                'ghCtl_Edit_X = GetDlgItem(hWndMain, %ID_IDNOTE2)
        ELSE
            MyCtrl = addTextBox(hWndMain, %ID_IDNOTE2, gsCmdMessages + $NUL, 0 + OffsetX + 20, 70 + OffsetY - 15, 334 - 40, 200, dwNoRetMLTextBoxStyle OR %WS_HSCROLL)
      
                ghCtl_Edit_X = MyCtrl
      
                SendMessage ghCtl_Edit_X, %EM_SETLIMITTEXT, &H200000&, 0 'set text limit to 2 Meg
                'SendMessage ghCtl_Edit_X, %EM_AUTOURLDETECT, %True, 0
                'SendMessage ghCtl_Edit_X, %EM_SETEVENTMASK, 0, %ENM_UPDATE OR %ENM_LINK OR %ENM_CHANGE OR %ENM_SELCHANGE OR %ENM_KEYEVENTS 'mask is set to produce the EN_UPDATE message
      
                'use the new subclass process and pass the dialog handle
                'CALL SetWindowSubclass(ghCtl_Edit_X, CODEPTR(EditProc), 29, 0)
      
                'ghCtl_Edit_X = GetDlgItem(hWndMain, %ID_IDNOTE2)
        END IF
      END SUB
      '_________________________________________________________________
      '
      ' FUNCTION addLabelT                                          xBot
      '_________________________________________________________________
      
      FUNCTION addLabelT(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
          LOCAL hCtrl AS DWORD
          hCtrl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING, "Static", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
          'IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
          FUNCTION = hCtrl
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' FUNCTION addLabelE                                          xBot
      '_________________________________________________________________
      
      FUNCTION addLabelE(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
          LOCAL hCtrl AS DWORD
          hCtrl = CreateWindowEx(%WS_EX_STATICEDGE, "Static", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
          'IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
          FUNCTION = hCtrl
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' FUNCTION addTextBox                                         xBot
      '_________________________________________________________________
      
      FUNCTION addTextBox(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
          LOCAL hCtrl AS DWORD
          hCtrl = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
          DisableXPThemeControl hCtrl
          IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
          FUNCTION = hCtrl
      END FUNCTION
      
      
      '_________________________________________________________________
      '
      ' SUB ASSIGN_WINDOW_STYLES                                    xBot
      '_________________________________________________________________
      
      SUB ASSIGN_WINDOW_STYLES
        dwLabelStyle           = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_CENTER OR %WS_BORDER
        dwNBLabelStyle         = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_CENTER        'no border
        dwLeftLabelStyle       = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_LEFT OR %WS_BORDER
        dwNoRetMLTextBoxStyle  = %WS_CHILD OR %WS_VISIBLE OR %ES_AUTOHSCROLL OR %WS_VSCROLL OR _
                                 %ES_NOHIDESEL OR %ES_READONLY OR %ES_MULTILINE OR %WS_BORDER
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB CCSCommand                                              xBot
      '_________________________________________________________________
      
      SUB CCSCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        'wParamX = Handle to the device context for the static control window.
        'lParamX = Handle to the static control.
      
        LOCAL myReturn  AS LONG
      
        giTheReturn = 0
      
        IF lParamX <> 0 THEN
            myReturn = GetDlgCtrlID(lParamX)
            GOTO ContinueOn
        END IF
        EXIT SUB
      
        ContinueOn:
        SELECT CASE myReturn      '= control id
      
            CASE %ID_TITLEBAR1, _
                 %ID_TITLEBAR2, _
                 %ID_IDNOTE, _
                 %ID_IDNOTE2, _
                 %ID_TITLELABEL
                 SetTextColor (wParamX, RGB(0,0,0))                    'Label color text
                 SetBkColor   (wParamX, RGB(255,255,255))              'Label background color
                 giTheReturn = hBrushPearl
      
      
            CASE %ID_LabelTitle, _          'screen title
                 %ID_LabelAttention, _      'is app paying attention symbol
                 %ID_LabelDictation, _      'is dictation grammar enabled symbol
                 %ID_LabelListen, _         'is recognition enabled symbol
                 %ID_LabelTalk              'is server or client talking symbol
      
                 SetTextColor (wParamX, RGB(0,0,0))                    'Label text color
      
                 'IF giLoginStatus = 0 OR _
                 '   (gsThisClient = "Client" AND giReceivedUpdate = 0) THEN
                     SetBkColor   (wParamX, RGB(255,255,255))
                     giTheReturn = hBrushPearl
                 '    EXIT SUB
                 'END IF
        END SELECT
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB LOAD_BRUSHES                                            xBot
      '_________________________________________________________________
      
      SUB LOAD_BRUSHES
        STATIC Lb AS LOGBRUSH
      
        Lb.lbStyle  = %BS_SOLID                            'Lb.lbStyle = 0 = BS_SOLID ( 1 = BS_HOLLOW, BS_NULL)
        Lb.lbColor  = RGB(255,255,255)                     'Dialog background color (Solid or Hollow ~ Lb.lbHatch ignored)
        hBrushPearl = CreateBrushIndirect(Lb)
      
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB MoveWindowToHere        Dialog follows mouse movement   xBot
      '_________________________________________________________________
      
      SUB MoveWindowToHere
        LOCAL CurPos      AS POINT
        LOCAL CP_Old      AS POINT  'CenterPoint Old
      
        'Moving dialog with mouse after Arrow keys were used once.
        'Works ok if you want the dialog to be moved to a position where
        'the mouse cursor is located at the center of the titlebar.
      
        'This must be here to get a smooth motion of dialog dragging
        GetCursorPos(CurPos)   'in screen coordinates
      
        GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
      
        CP_Old.x = (rcMainSub.nRight - rcMainSub.nLeft)/ 2 + rcMainSub.nLeft
        CP_Old.y = (24)/ 2 + rcMainSub.nTop
      
        MoveWindow(hWndMain, rcMainSub.nLeft + CurPos.x - CP_Old.x, rcMainSub.nTop + CurPos.y - CP_Old.y, _
                              rcMainSub.nRight  - rcMainSub.nLeft, _
                              rcMainSub.nBottom - rcMainSub.nTop, %TRUE)
      
      END SUB
      
      
      '_________________________________________________________________
      '
      ' SUB MoveWindowToHereEx     Dialog follows mouse movement    xBot
      '_________________________________________________________________
      
      SUB MoveWindowToHereEx
        LOCAL CurPos      AS POINT
        LOCAL StartX      AS LONG
        LOCAL StartY      AS LONG
        LOCAL OffsetX     AS LONG
        LOCAL OffsetY     AS LONG
      
        'Move a dialog smoothly by mouse movement
        'Designed to move dialog from any point on titlebar
        'left of the Minimize button.
      
        'This must be here to get a smooth motion of dialog dragging
        GetCursorPos(CurPos)   'in screen coordinates
      
        GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
      
        StartX = rcMainSub.nLeft + iLOCx
        StartY = rcMainSub.nTop + iLOCy
      
        OffsetX = CurPos.x - StartX
        OffsetY = CurPos.y - StartY
      
        MoveWindow(hWndMain, rcMainSub.nLeft + OffsetX, rcMainSub.nTop + OffsetY, _
                              rcMainSub.nRight  - rcMainSub.nLeft, _
                              rcMainSub.nBottom - rcMainSub.nTop, %TRUE)
      
      END SUB
      
      
      '_________________________________________________________________
      '
      ' SUB MoveWindowLeft10                                        xBot
      '_________________________________________________________________
      
      SUB MoveWindowLeft10
        LOCAL WinRec      AS RECT
      
        GetWindowRect hWndMain, WinRec
        MoveWindow(hWndMain, WinRec.nLeft - 10, WinRec.nTop, _
                              WinRec.nRight  - WinRec.nLeft, _
                              WinRec.nBottom - WinRec.nTop, %TRUE)
      
        CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB MoveWindowRight10                                       xBot
      '_________________________________________________________________
      
      SUB MoveWindowRight10
        LOCAL WinRec      AS RECT
      
        GetWindowRect hWndMain, WinRec
        MoveWindow(hWndMain, WinRec.nLeft + 10, WinRec.nTop, _
                              WinRec.nRight  - WinRec.nLeft, _
                              WinRec.nBottom - WinRec.nTop, %TRUE)
      
        CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB MoveWindowUp10                                          xBot
      '_________________________________________________________________
      
      SUB MoveWindowUp10
        LOCAL WinRec      AS RECT
      
        GetWindowRect hWndMain, WinRec
        MoveWindow(hWndMain, WinRec.nLeft, WinRec.nTop - 10, _
                              WinRec.nRight  - WinRec.nLeft, _
                              WinRec.nBottom - WinRec.nTop, %TRUE)
      
        CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB MoveWindowDown10                                        xBot
      '_________________________________________________________________
      
      SUB MoveWindowDown10
        LOCAL WinRec      AS RECT
      
        GetWindowRect hWndMain, WinRec
        MoveWindow(hWndMain, WinRec.nLeft, WinRec.nTop + 10, _
                              WinRec.nRight  - WinRec.nLeft, _
                              WinRec.nBottom - WinRec.nTop, %TRUE)
      
        CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
      END SUB
      
      
      '_________________________________________________________________
      '
      ' SUB CHECK_MOUSE                                             xBot
      '_________________________________________________________________
      
      SUB CHECK_MOUSE
        LOCAL idThreadCheckMouse        AS LONG
        LOCAL idThreadMouseButtonToggle AS LONG
      
        THREAD CREATE CheckMouseThread(1) TO idThreadCheckMouse
        THREAD CLOSE idThreadCheckMouse TO idThreadCheckMouse
      
        THREAD CREATE MouseButtonToggleThread(1) TO idThreadMouseButtonToggle
        THREAD CLOSE idThreadMouseButtonToggle TO idThreadMouseButtonToggle
      
      END SUB
      
      '_________________________________________________________________
      '
      '   FUNCTION  CheckMouseThread            full time           xBot
      '_________________________________________________________________
      
      THREAD FUNCTION CheckMouseThread(BYVAL yyy AS LONG) AS LONG
          LOCAL CurPos   AS POINT
      
          'Wait until app is visible.
          TryAgain:
          IF IsWindowVisible(hWndmain) THEN
              'continue processing
          ELSE
              SLEEP 100
              IF giCancelProgram = 0 THEN GOTO TryAgain
          END IF
          SLEEP 200
          PostMessage hWndMain, %WM_COMMAND, %ID_CaptureIconRect, 0
      
          DO WHILE giCancelProgram = 0
              CALL GetMousePosition
              CurPos = MyCurPos
      
              IF ISFALSE IsRectEmpty(WindowMinimizeRect) THEN
                  IF PtInRect(WindowMinimizeRect, CurPos) > 0 THEN
                      CALL ACT_ON_TASKBAR_ICON_TOGGLE
                  END IF
              END IF
              SLEEP 100
          LOOP
      
      END FUNCTION
      
      '_________________________________________________________________
      '
      '   FUNCTION  MouseButtonToggleThread        full time        xBot
      '_________________________________________________________________
      
      THREAD FUNCTION MouseButtonToggleThread(BYVAL yyy AS LONG) AS LONG
          LOCAL CurPos   AS POINT
      
      
          'Wait until app is visible.
          TryAgain:
          IF IsWindowVisible(hWndmain) THEN
              'continue processing
          ELSE
              SLEEP 100
              IF giCancelProgram = 0 THEN GOTO TryAgain
          END IF
          SLEEP 300
      
          DO WHILE giCancelProgram = 0
              IF IsRectEmpty(WindowMinimizeRect) THEN
                  PostMessage hWndMain, %WM_COMMAND, %ID_CaptureIconRect, 0
              ELSE
                  GetCursorPos(CurPos)
      
                  IF PtInRect(WindowMinimizeRect, CurPos) > 0 THEN
                      'Mouse is located on the taskbar icon
                      CALL WAS_MOUSE_BUTTON_TOGGLED
                  ELSE
                      'Mouse is not located on the taskbar icon
                      giDeactivationComplete = 0
                      giActivationComplete = 0
                      CALL CLEAR_MOUSE_TOGGLE
      
                  END IF
              END IF
              SLEEP 100
          LOOP
      
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' SUB WAS_MOUSE_BUTTON_TOGGLED                                xBot
      '_________________________________________________________________
      
      SUB WAS_MOUSE_BUTTON_TOGGLED
        LOCAL k           AS LONG         ' Key status
        LOCAL btnDown     AS LONG
      
        k = GetAsyncKeyState(%VK_RBUTTON)   'not used
        btnDown =  BIT(k, 15)
        SELECT CASE btnDown
            CASE 1
                'right mouse button is down.
                CALL RIGHT_MOUSE_PRESSED
      
            CASE 0
                IF giRightMouseButtonDown = 1 THEN
                    CALL CLEAR_MOUSE_TOGGLE
                    'right mouse button was down then up.
                    giRightMouseToggled = 1
      
                END IF
      
        END SELECT
      
        k = GetAsyncKeyState(%VK_LBUTTON)
        btnDown =  BIT(k, 15)
        SELECT CASE btnDown
            CASE 1
                'left mouse button is down.
                CALL LEFT_MOUSE_PRESSED
      
            CASE 0
                'left mouse button is up.
                IF giLeftMouseButtonDown = 1 THEN
                    CALL CLEAR_MOUSE_TOGGLE
                    giLeftMouseToggled = 1
      
                END IF
      
        END SELECT
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB ACT_ON_TASKBAR_ICON_TOGGLE                              xBot
      '_________________________________________________________________
      
      SUB ACT_ON_TASKBAR_ICON_TOGGLE
        LOCAL CurPos      AS POINT
      
        GetCursorPos(CurPos)
      
        IF giDeactivationComplete = 1 THEN
            giDeactivationComplete = 0
      
            SLEEP 200
      
            IF giLeftMouseToggled = 1 THEN
                giLeftMouseToggled = 0
      
                SELECT CASE IsIconic(hWndMain)
                    CASE 0 'Is Not Iconic
                        IF giAppIsDisabled = 1 THEN
                            ShowWindow hWndMain, %SW_RESTORE
                            CALL Captionbar0
      
                            giActiveTitlebar = 1
      
      
                            giAppIsDisabled = 0
                            giFindNewActiveWindow = 1
      
                            giAppIsMinimized = 0
      
                            IF giView <> 0 THEN
                                gsCmdMessages = _ gsCmdMessages + _
                                "Mouse was toggled on Taskbar icon." + $CRLF + _
                                gsCmdMessages
                                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                            END IF
                            SLEEP 200
                            CALL FindNewActiveWindow
                            CALL SIMPLE_MINIMIZE
                        END IF
      
                    CASE 1 'Is Iconic
                        'Normally windows default behavior is to bring the app forward
      
                END SELECT
            END IF
            GOTO LeaveEarly
        END IF
      
        IF giActivationComplete = 1 THEN
            giActivationComplete = 0
      
            IF giLeftMouseToggled = 1 THEN
                giLeftMouseToggled = 0
      
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "Ready to deactivate." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
            END IF
            GOTO LeaveEarly
        END IF
      
        IF giActivationComplete = 0 AND giDeactivationComplete = 0 THEN
            IF giLeftMouseToggled = 1 THEN
                giLeftMouseToggled = 0
      
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "Minimizing Dialog." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                CALL SIMPLE_MINIMIZE
            END IF
        END IF
        LeaveEarly:
      END SUB
      
      
      '_________________________________________________________________
      '
      ' FUNCTION GetMousePosition                                   xBot
      '_________________________________________________________________
      
      SUB GetMousePosition
        LOCAL CurPos      AS POINT
      
        IF giGettingMousePosition = 1 THEN CALL MyPumpMessages(10): EXIT SUB
        giGettingMousePosition = 1
      
        GetCursorPos(MyCurPos)
      
        gsMousePosition = " X=" + STR$(MyCurPos.x) + " Y=" + STR$(MyCurPos.y)
      
        GetWindowRect hWndMain, rcMainSub
        SetRect(TitlebarRect, rcMainSub.nLeft + 2, rcMainSub.nTop + 2, rcMainSub.nRight - 2, rcMainSub.nTop + 22)
      
        SELECT CASE IsIconic(hWndMain)
            CASE 1 'Is iconic
                giAppIsMinimized = 1
      
            CASE 0 'Not iconic
                giAppIsMinimized = 0
      
        END SELECT
      
      
        'check to see if mouse is on Titlebar
        IF PtInRect(TitlebarRect, MyCurPos) > 0 THEN
            'mouse is inside titlebar
      
            CurPos = MyCurPos
            ScreenToClient(hCaptionBar, CurPos) 'Convert from screen to titlebar coordinates
            'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "X" + STR$(CurPos.x) + " Y=" + STR$(CurPos.y)
      
            SELECT CASE giActiveTitlebar
                CASE 1 'active titlebar
                    IF giHasCaptionAndMarquee = 1 THEN
                        IF (CurPos.x > 244 AND CurPos.x < 288) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                            'mouse is over titlebar minimize button
                            IF giCaptionBar <> 2 THEN
                                CALL Captionbar2
                            END IF
                        ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                            'mouse is over titlebar close button
                            IF giCaptionBar <> 3 THEN
                                CALL Captionbar3
                            END IF
                        ELSE
                            IF giCaptionBar <> 0 THEN
                                CALL Captionbar0
                            END IF
                        END IF
                    ELSE
                        IF (CurPos.x > 1 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                            'mouse is over titlebar
                            IF giCaptionBar <> 2 THEN
                                CALL Captionbar2
                            END IF
                        ELSE
                            IF giCaptionBar <> 0 THEN
                                CALL Captionbar0
                            END IF
                        END IF
                    END IF
      
                CASE 0 'inactive titlebar
                    IF giHasCaptionAndMarquee = 1 THEN
                        IF (CurPos.x > 244 AND CurPos.x < 288) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                            'mouse is over titlebar minimize button
                            IF giCaptionBar <> 4 THEN
                                CALL Captionbar4
                            END IF
                        ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                            'mouse is over titlebar close button
                            IF giCaptionBar <> 5 THEN
                                CALL Captionbar5
                            END IF
                        ELSE
                            IF giCaptionBar <> 1 THEN
                                CALL Captionbar1
                            END IF
                        END IF
                    ELSE
                        IF (CurPos.x > 1 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                            'mouse is over titlebar
                            IF giCaptionBar <> 4 THEN
                                CALL Captionbar4
                            END IF
                        ELSE
                            IF giCaptionBar <> 1 THEN
                                CALL Captionbar1
                            END IF
                        END IF
                    END IF
            END SELECT
        ELSE
            'mouse pointer is outside the titlebar
      
            IF (giCaptionBar = 5 OR giCaptionBar = 4) AND giCaptionBar <> 1 THEN
                CALL Captionbar1
            END IF
            IF (giCaptionBar = 3 OR giCaptionBar = 2) AND giCaptionBar <> 0 THEN
                CALL Captionbar0
            END IF
      
        END IF
      
        giGettingMousePosition = 0
      END SUB
      
      
      '_________________________________________________________________
      '
      ' FUNCTION TitlebarMouseProc                                  xBot
      '_________________________________________________________________
      
      FUNCTION TitlebarMouseProc(BYVAL nCode AS LONG, BYVAL wParam AS LONG, _
                         BYVAL lParam AS MSLLHOOKSTRUCT POINTER) AS LONG
       SELECT CASE nCode
         CASE %HC_ACTION
           SELECT CASE wParam
            CASE %WM_MOUSEMOVE
                IF giMoving = 1 THEN
                    'Moving dialog with mouse after Arrow keys were used once.
                    CALL MoveWindowToHere
                ELSE
                    CALL MoveWindowToHereEx
                END IF
           END SELECT
       END SELECT
       FUNCTION = CallNextHookEx(hMouseHook, nCode, wParam, lParam) 'Forward message
      
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' SUB SetCursorCommandTitlebar                                xBot
      '_________________________________________________________________
      
      SUB SetCursorCommandTitlebar(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        LOCAL iReturn         AS LONG
      
        giTheReturn = 0
      
        IF wParamX = hCaptionBar THEN                   ' handle to titlebar
            IF giMoving = 1 THEN
                'giShowWaitCursor = 0  'not altered
                giShowHandCursor = 0
                giShowArrowCursor = 0
                giShowDocumentCursor = 0
                giShowMoveCursor = 1
            ELSE
                'giShowWaitCursor = 0  'not altered
                giShowHandCursor = 0
                giShowArrowCursor = 1
                giShowDocumentCursor = 0
                giShowMoveCursor = 0
            END IF
            CALL SELECT_MOUSE_CURSOR
      
        END IF
        'If an application processes this message, it should return TRUE
        'to halt further processing or FALSE to continue
        giTheReturn = %TRUE
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB SetCursorCommand                                        xBot
      '_________________________________________________________________
      
      SUB SetCursorCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
      
        giTheReturn = 0
      
        'Anywhere on client area except Titlebar
        IF LO(WORD, lParamX) = %HTCLIENT THEN       ' cursor is in client area
      
            SELECT CASE GetDlgCtrlID (wParamX)
                CASE %IDC_Reset, _   'BUTTONS
                     %IDC_Show
                    IF giMoving = 1 THEN
                        'giShowWaitCursor = 0  'not altered
                        giShowHandCursor = 0
                        giShowArrowCursor = 0
                        giShowDocumentCursor = 0
                        giShowMoveCursor = 1
                    ELSE
                        CALL ERASE_PREVIOUS_ASSIGNMENTS
                    END IF
                    CALL SELECT_MOUSE_CURSOR
      
                CASE %ID_IDNOTE2   'text
                    IF giMoving = 1 THEN
                        'giShowWaitCursor = 0  'not altered
                        giShowHandCursor = 0
                        giShowArrowCursor = 0
                        giShowDocumentCursor = 0
                        giShowMoveCursor = 1
                    ELSE
                        giShowDocumentCursor = 0
                        giShowHandCursor = 0
                        giShowArrowCursor = 0
                        giShowMoveCursor = 0
                    END IF
                    CALL SELECT_MOUSE_CURSOR
      
                CASE ELSE
                    IF giMoving = 1 THEN
                        'giShowWaitCursor = 0  'not altered
                        giShowHandCursor = 0
                        giShowArrowCursor = 0
                        giShowDocumentCursor = 0
                        giShowMoveCursor = 1
                    ELSE
                        giShowDocumentCursor = 0
                        giShowHandCursor = 0
                        giShowArrowCursor = 1
                        giShowMoveCursor = 0
                    END IF
                    CALL SELECT_MOUSE_CURSOR
      
            END SELECT
        END IF
        'If an application processes this message, it should return TRUE
        'to halt further processing or FALSE to continue
        giTheReturn = %TRUE
      END SUB
      
      
      '_________________________________________________________________
      '
      '   SUB  ERASE_PREVIOUS_ASSIGNMENTS                           xBot
      '_________________________________________________________________
      
      SUB ERASE_PREVIOUS_ASSIGNMENTS
      
        giShowHandCursor = 1
        giShowDocumentCursor = 0
        giShowArrowCursor = 0
        giShowMoveCursor = 0
      END SUB
      
      
      '_________________________________________________________________
      '
      ' SUB ActivateCommand                                         xBot
      '_________________________________________________________________
      
      SUB ActivateCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        LOCAL CurPos         AS POINT
      
        CALL GetMousePosition
        CurPos = MyCurPos
      
        SELECT CASE LO(WORD, wParamX)
            CASE %WA_INACTIVE
                'Deactivated.
      
                'inactive titlebar
                CALL Captionbar1
                giActiveTitlebar = 0
      
                giAppIsDisabled = 1
                'giOnDialog = 0
      
                CALL DeactivationStep2
      
            CASE %WA_CLICKACTIVE
                'Activated by a mouse click.
                'CALL BRING_MAIN_WINDOW_FORWARD
      
                'gNewFocus = hWndMain
                'gOldFocus = gNewFocus
      
                'SetFocus hWndMain
                'giOnDialog = 1
                'PostMessage hWndMain, %WM_COMMAND, %ID_RefreshVolumeGraphics, 0
      
                'active titlebar
                'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "Active titlebar."
                ShowWindow hWndMain, %SW_RESTORE
                CALL Captionbar0
      
                giActiveTitlebar = 1
      
                CALL EndActivation
      
                giAppIsDisabled = 0
                giFindNewActiveWindow = 1
      
                'lParamX = is the handle to the window being deactivated. Usually 0
      
            CASE %WA_ACTIVE
                'Activated by some method other than a mouse
                'click (for example, by a call to the
                'SetActiveWindow function or by use of the
                'keyboard interface to select the window).
                CALL Captionbar0
      
                giActiveTitlebar = 1
      
                CALL EndActivation
      
                giAppIsDisabled = 0
                giFindNewActiveWindow = 1
      
                'lParamX = is the handle to the window being deactivated. Usually 0
      
        END SELECT
      
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB NCActivateCommand
      '_________________________________________________________________
      
      SUB NCActivateCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)   'looks good
        LOCAL CurPos         AS POINT
      
        CALL GetMousePosition
        CurPos = MyCurPos
        giTheReturn = %TRUE
      
        SELECT CASE wParamX
            CASE %TRUE
                'active titlebar
                CALL Captionbar0
                giActiveTitlebar = 1
      
                CALL ActivationStep2
      
                IF ghWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(ghWndSaveFocus)
                    ghWndSaveFocus = 0
                END IF
      
            CASE %FALSE
                'inactive titlebar
                'giTheReturn = %FALSE  use this if you want to prevent inactivation
                CALL Captionbar1
                giActiveTitlebar = 0
      
                CALL StartDeactivation
      
                ' Save control focus
                ghWndSaveFocus = GetFocus()
                'use this if you want to prevent inactivation
                'giTheReturn = %FALSE
      
            CASE 2097153   'handled as a true value
                'dialog is being activated from the taskbar
                'This happens only when dialog is minimized.
                'Hex value 200001
      
                'active titlebar
                CALL Captionbar0
                giActiveTitlebar = 1
      
      
                CALL ActivationStep3    'seems like this should be the start of activation
      
                IF ghWndSaveFocus THEN
                    ' Restore control focus
                    SetFocus(ghWndSaveFocus)
                    ghWndSaveFocus = 0
                END IF
      
        END SELECT
      END SUB
      
      
      '_________________________________________________________________
      '
      ' SUB LOAD_ICONS                                              xBot
      '_________________________________________________________________
      
      SUB LOAD_ICONS
        LOCAL hInstance AS DWORD
      
        hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
      
        ghIconCM00 = LoadImage(hInstance, BYVAL 3500, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghIconCM01 = LoadImage(hInstance, BYVAL 3501, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghIconCM02 = LoadImage(hInstance, BYVAL 3502, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghIconCM03 = LoadImage(hInstance, BYVAL 3503, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghIconCM04 = LoadImage(hInstance, BYVAL 3504, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        ghIconCM05 = LoadImage(hInstance, BYVAL 3505, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB FindNewActiveWindow                                     xBot
      '_________________________________________________________________
      
      SUB FindNewActiveWindow
          LOCAL hNext1             AS DWORD
          LOCAL NumberX            AS LONG
          LOCAL lsNextWindowHandle AS STRING
      
          hNext1 = hWndMain
          NumberX = 0
          DO 'Enumerate desktop windows
              IF IsWindowOnDesktop(hNext1) THEN
                  INCR NumberX
                  IF NumberX = 2 THEN
                      lsNextWindowHandle = PARSE$(WindowSpec(hNext1), " ", 1)
                      hForeGroundPrior = VAL("&H0" + lsNextWindowHandle)  'returns unsigned decimal value from hex value
                      gsCmdMessages = _ gsCmdMessages + _
                      STR$(NumberX) + "  " + WindowSpec(hNext1) + $CRLF + _
                      gsCmdMessages
                      GOTO ShowResults
                  END IF
              END IF
              hNext1 = GetNextWindow(hNext1, %GW_HWNDNEXT)
          LOOP UNTIL hNext1 = 0
      
          ShowResults:
          'hNext1 = GetTopWindow(hForeGroundPrior)  'looks at child windows
          'IF hNext1 <> 0 THEN
          '    hForeGroundPrior = hNext1
          'END IF
      
          IF giView <> 0 THEN
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
      
      END SUB
      
      
      '_________________________________________________________________
      '
      '   FUNCTION  MinimizeDialogThread                            xBot
      '_________________________________________________________________
      
      THREAD FUNCTION MinimizeDialogThread(BYVAL yyy AS LONG) AS LONG
      
          CALL SIMPLE_MINIMIZE
      
          IF giCloseDialog = 1 THEN
              DIALOG POST hWndMain, %WM_CLOSE, %NULL, %NULL   'asynchronous command
          END IF
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' SUB MINIMIZE_DIALOG                                         xBot
      '_________________________________________________________________
      
      SUB MINIMIZE_DIALOG
        LOCAL idThreadMinimizeDialog        AS LONG
      
        THREAD CREATE MinimizeDialogThread(1) TO idThreadMinimizeDialog
        THREAD CLOSE idThreadMinimizeDialog TO idThreadMinimizeDialog
      
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB SIMPLE_MINIMIZE                                         xBot
      '_________________________________________________________________
      
      SUB SIMPLE_MINIMIZE
        LOCAL CurPos         AS POINT
        LOCAL PriorPoint     AS POINT
        LOCAL rcPriorWindow  AS RECT
      
        CALL Captionbar1
        giActiveTitlebar = 0
      
        'where is the mouse pointer?
        GetCursorPos(CurPos)
      
        'NOTE: This will work for most apps to bring them forward.
        'Yes, even the Edge Browser.
      
        IF IsWindow(hForeGroundPrior) THEN
            GetWindowRect hForeGroundPrior, rcPriorWindow
      
            PriorPoint.x = rcPriorWindow.nLeft + 40
            PriorPoint.y = rcPriorWindow.nTop + 10
      
            'Move mouse pointer to prior dialog top left corner
            'to the right of the icon area
            SetCursorPos PriorPoint.x, PriorPoint.y
      
            IF giView <> 0 THEN
                gsCmdMessages = _ gsCmdMessages + _
                "Prior Window point to click: " + _
                " X=" + STR$(PriorPoint.x) + " Y=" + STR$(PriorPoint.y) + $CRLF + _
                gsCmdMessages
                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
            END IF
      
            'Send left mouse click
            CALL SendLeftMouseClick
      
            'SLEEP 80
            'return mouse pointer to previous location
            SetCursorPos CurPos.x, CurPos.y
        END IF
      
        'Minimize our dialog
        ShowWindow hWndMain, %SW_MINIMIZE
      
        IF giView <> 0 THEN
            gsCmdMessages = _ gsCmdMessages + _
            "Dialog Minimized." + $CRLF + _
            gsCmdMessages
            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
        END IF
      
      END SUB
      
      '_________________________________________________________________
      '
      ' FUNCTION SendLeftMouseClick
      '_________________________________________________________________
      
      FUNCTION SendLeftMouseClick () AS LONG 'pt is in screen coordinates
        DIM ipt(1) AS InputAPI '2 mouse events: down-up
      
        'first mouse event - mousedown
        ipt(0).dtype = %INPUT_MOUSE
        ipt(0).mi.dx = 0 'pt.x '65535 / (wDesktop/pt.x)
        ipt(0).mi.dy = 0 'pt.y '65535 / (hDesktop/pt.y)
        ipt(0).mi.MouseData = 0
        ipt(0).mi.dwFlags = %MOUSEEVENTF_ABSOLUTE OR %MOUSEEVENTF_LEFTDOWN OR %MOUSEEVENTF_MOVE
        ipt(0).mi.dtime = 0
        ipt(0).mi.dwExtraInfo = 0
      
        'second mouse event - mouseup
        ipt(1) = ipt(0)
        ipt(1).mi.dwFlags = %MOUSEEVENTF_LEFTUP
        FUNCTION = SendInput (UBOUND(ipt)+1, BYVAL VARPTR(ipt(0)), SIZEOF(InputAPI))
      END FUNCTION
      
      
      '_________________________________________________________________
      '
      ' SUB SELECT_MOUSE_CURSOR                                     xBot
      '_________________________________________________________________
      
      SUB SELECT_MOUSE_CURSOR
        IF giShowWaitCursor = 1 THEN
            MOUSEPTR hCursorWait
        ELSEIF giShowArrowCursor = 1 THEN
            MOUSEPTR hCursorArrow
        ELSEIF giShowHandCursor = 1 THEN
            MOUSEPTR hCursorHand
        ELSEIF giShowMoveCursor = 1 THEN
            MOUSEPTR hCursorMove
        ELSEIF giShowDocumentCursor = 0 THEN
            MOUSEPTR hCursorBar
        END IF
      END SUB
      
      '_________________________________________________________________
      '
      ' SUB LOAD_CURSORS                                            xBot
      '_________________________________________________________________
      
      SUB LOAD_CURSORS
        'New method that replaces LoadCursorA( %NULL, BYVAL %IDC_HAND )
        hCursorHand =  LoadImageA(%NULL, BYVAL %OCR_HAND,    %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
        hCursorArrow = LoadImageA(%NULL, BYVAL %OCR_NORMAL,  %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
        hCursorWait =  LoadImageA(%NULL, BYVAL %OCR_WAIT,    %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
        hCursorBar =   LoadImageA(%NULL, BYVAL %OCR_IBEAM,   %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
        hCursorMove =  LoadImageA(%NULL, BYVAL %OCR_SIZEALL, %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
      
      'from WinUser.inc
      '%OCR_IBEAM
      '%OCR_WAIT
      '%OCR_HAND
      '%OCR_NORMAL
      '%OCR_SIZEALL
      END SUB
      
      
      '------------------------------------------------------------------------------
      'Purpose: by calling SetWindowTheme with an empty string your control
      '         (button/checkbox/combo etc) will not be painted with the XP Theme.
      '
      'Example: LOCAL hButton AS DWORD
      '         hButton = GetDlgItem( CBHNDL, %IDOK )
      '         lRes = DisableXPThemeControl ( hbutton )
      '         InvalidateRect hButton,BYVAL %NULL,%TRUE
      '------------------------------------------------------------------------------
      FUNCTION DisableXPThemeControl(BYVAL hControl AS DWORD) AS LONG
          LOCAL hLib AS DWORD, pProc AS DWORD, lRes AS LONG
          hLib = LoadLibrary("UxTheme.dll")
          IF hLib THEN
               pProc = GetProcAddress(hLib, "SetWindowTheme")
               IF pProc THEN
                    CALL DWORD pProc USING SetWindowTheme(hControl, " ", " ")  TO lRes
                    FUNCTION = lRes
               END IF
               FreeLibrary hLib
          END IF
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' FUNCTION WindowSpec                                         xBot
      '_________________________________________________________________
      
      FUNCTION WindowSpec(hWin AS DWORD) AS STRING
          LOCAL zCaption AS ASCIIZ * %MAX_PATH
          LOCAL zClass   AS ASCIIZ * 32 'aka %MAX_CLASS_NAME_LEN
      
          GetClassName(hWin, zClass, SIZEOF(zClass))
          GetWindowText(hWin, zCaption, SIZEOF(zCaption))
          FUNCTION = HEX$(hWin) & $SPC & zCaption & " - Class: " & zClass
      END FUNCTION
      
      '_________________________________________________________________
      '
      ' FUNCTION IsWindowOnDesktop                                  xBot
      '_________________________________________________________________
      
      FUNCTION IsWindowOnDesktop(hWin AS DWORD) AS LONG
          LOCAL WinRect AS RECT
      
          IF ISFALSE(IsIconic(hWin)) THEN    'not iconic
              IF IsWindow(hWin) THEN
                  IF GetParent(hWin) = %HWND_DESKTOP THEN
                      IF IsWindowVisible(hWin) THEN
                          GetWindowRect(hWin, WinRect)
                          IF WinRect.nLeft < WinRect.nRight THEN 'hWnd x-axis size is not zero
                              IF WinRect.nTop < WinRect.nBottom THEN 'hWnd y-axis size is not zero
                                  'May also check to see if window is outside screen
                                  'Note that topMost windows will have effect on the zOrder
                                  FUNCTION = %TRUE
                              END IF
                          END IF
                      END IF
                  END IF
              END IF
          END IF
      END FUNCTION
      
      
      '_________________________________________________________________
      '
      ' Processes pending Windows messages.                         xBot
      ' Call this procedure if you are performing a tight
      ' FOR/NEXT or DO/LOOP and need to allow
      ' your application to be responsive to user input.
      ' Modified version of AfxPumpMessages
      '_________________________________________________________________
      
      SUB MyPumpMessages(BYVAL xTimes AS LONG) EXPORT
        LOCAL Ix AS LONG
      
        IF xTimes <= 0 THEN xTimes = 1
        FOR Ix = 1 TO xTimes
            'if GlobalVariableTest86 = 1 then EXIT SUB
            CALL PeekRemoveTranslateDispatchMessage
        NEXT Ix
      
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  PeekRemoveTranslateDispatchMessage
      '_________________________________________________________________
      
      SUB PeekRemoveTranslateDispatchMessage
        IF giPRTDMessage = 1 THEN EXIT SUB
        giPRTDMessage = 1
      
        STATIC Msg AS tagMsg
        IF PeekMessageA(Msg, %NULL, %NULL, %NULL, %PM_REMOVE) THEN
            TranslateMessage Msg
            DispatchMessage Msg
        END IF
      
        giPRTDMessage = 0
      END SUB
      
      
      
      '_________________________________________________________________
      '
      '   SUB  SystemCommand                                        xBot
      '_________________________________________________________________
      
      SUB SystemCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        ' This is the system commands broken out
        ' Capture this message and send a WM_DESTROY message
        ' or the program will remain in memory
        SELECT CASE wParamX AND &HFFF0
            CASE %SC_MAXIMIZE
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "WM_SYSCOMMAND - Maximize." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                ShowWindow hWndMain, %SW_NORMAL  'do not use maximize
      
            CASE %SC_CLOSE
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "WM_SYSCOMMAND - Close." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0
      
            CASE %SC_MINIMIZE
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "WM_SYSCOMMAND - Minimize." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
      
            CASE %SC_RESTORE
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                    "xBot is restoring to normal." + $CRLF + _
                    gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
                ShowWindow hWndMain, %SW_NORMAL
      
        END SELECT
      END SUB
      
      
      '_________________________________________________________________
      '
      '   SUB  TimerCommand                                         xBot
      '_________________________________________________________________
      
      SUB TimerCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        'Not used for anything. Not dependable enough.
      
        'WM_SETCURSOR has higher priority than a timer.
        'A timer will not get refreshed until the mouse cursor stops
        'moving.
      
      END SUB
      
      '_________________________________________________________________
      '
      '   FUNCTION  CheckForMutex                                   xBot
      '_________________________________________________________________
      
      FUNCTION CheckForMutex(MutexName AS ASCIIZ, hMutex AS DWORD) AS LONG
       LOCAL hWin, hForWnd  AS DWORD
       LOCAL ThisID, ForeID AS LONG
       LOCAL fwi            AS FLASHWINFO 'FlashWindowApi        ' FLASHWINFO structure
      
        hMutex = CreateMutex(BYVAL %NULL, 0, MutexName)
        IF hMutex = %NULL THEN FUNCTION = 0 : EXIT FUNCTION      ' Failed to create mutex
      
        IF GetLastError = %ERROR_ALREADY_EXISTS THEN             ' App already running!
          hWin = FindWindowEx (%NULL, %NULL, "MobileApp", "xBot")    ' Find handle of program's window
      
          IF hWin THEN                                           ' Bring window into view
            fwi.cbSize    = SIZEOF(fwi)
            fwi.hwnd      = hWin
            fwi.dwFlags   = %FLASHW_ALL
            fwi.uCount    = 5
            fwi.dwTimeout = 40
            FlashWindowEx fwi
      
            ThisID = GetCurrentThreadID()                        ' Get this thread ID
            'hForWnd = GetForegroundWindow                       ' Get Thread ID of current foreground window
      
            ForeID = GetWindowThreadProcessID(GetForeGroundWindow, 0)
            AttachThreadInput(ThisID, ForeID, %TRUE)             ' Attach / share the current foreground thread input states
            SetForegroundWindow hWin                             ' Set our window to foreground window (OLD METHOD)
            AttachThreadInput(ThisID, ForeID, %FALSE)            ' Detach sharing
            'ShowWindow(hWin, %SW_RESTORE)                       ' Restore in case minimized
            ShowWindow hWin, %SW_NORMAL
      
          END IF
          FUNCTION = 1 : EXIT FUNCTION
        END IF
      
      END FUNCTION
      
      
      '_________________________________________________________________
      '
      '   SUB  GWForceSetForegroundWindow
      '_________________________________________________________________
      
      SUB GWForceSetForegroundWindow (BYVAL hwnd AS DWORD)   ' Add COMMON if needed in SLL
          ' V1.0
          ' ========================================================================================
          ' Replacement for the SetForegroundWindow API function. Thanks to Jose Roca.
          ' Changes by GV: Do loop added. No action, if hwnd is in focus.
          ' ========================================================================================
      
          LOCAL hFg, dwThreadId, dwProcessId, dwCurThreadId AS DWORD
      
              hFg = GetForegroundWindow
      
          IF hFg <> hwnd THEN
              dwThreadId = GetWindowThreadProcessId(hFg, dwProcessId)
              dwCurThreadId = GetCurrentThreadId
              AttachThreadInput(dwCurThreadId, dwThreadId, %TRUE)
              SetForegroundWindow(hwnd)
              BringWindowToTop(hwnd)
              SetFocus(hwnd)
              AttachThreadInput(dwCurThreadId, dwThreadId, %FALSE)
          END IF
      
      END SUB
      
      
      '_________________________________________________________________
      '
      '   SUB  SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR                xBot
      '_________________________________________________________________
      
      SUB SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
        LOCAL CenterPoint AS POINT   'in screen coordinates
      
        GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
      
        CenterPoint.x = (rcMainSub.nRight - rcMainSub.nLeft)/ 2 + rcMainSub.nLeft
        CenterPoint.y = (22)/ 2 + rcMainSub.nTop
      
        SetCursorPos CenterPoint.x, CenterPoint.y
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  StartActivation                                      xBot
      '_________________________________________________________________
      
      SUB StartActivation
        ACTIVATEAPP = "ACTIVATION"           '=A
        NCACTIVATE =  ""                     '=A
        ACTIVATE =    ""                     '=A
        giActivationComplete = 0
        giDeactivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  ActivationStep2                                      xBot
      '_________________________________________________________________
      
      SUB ActivationStep2
        NCACTIVATE =  "ACTIVE TITLEBAR"      '=B
        giActivationComplete = 0
        giDeactivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  ActivationStep3                                      xBot
      '_________________________________________________________________
      
      SUB ActivationStep3
        NCACTIVATE =  "ACTIVE TITLEBAR"      '=B
        giActivationComplete = 0
        giDeactivationComplete = 0
        CALL CLEAR_MOUSE_TOGGLE
      
        IF giView <> 0 THEN
            gsCmdMessages = _ gsCmdMessages + _
            "Activation from Taskbar Icon." + $CRLF + $CRLF + _
            gsCmdMessages
            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
        END IF
      END SUB
      
      
      '_________________________________________________________________
      '
      '   SUB  EndActivation                                        xBot
      '_________________________________________________________________
      
      SUB EndActivation
        ACTIVATE =    "ACTIVE DIALOG"        '=C
      
        IF ACTIVATEAPP = "ACTIVATION" AND _
           NCACTIVATE =  "ACTIVE TITLEBAR" AND _
           ACTIVATE =    "ACTIVE DIALOG" THEN
            giActivationComplete = 1
      
            IF giView <> 0 THEN
                gsCmdMessages = _ gsCmdMessages + _
                $CRLF + "Activation Completed." + $CRLF + _
                gsCmdMessages
                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
            END IF
      
        END IF
        giDeactivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  StartDeactivation                                    xBot
      '_________________________________________________________________
      
      SUB StartDeactivation
        NCACTIVATE =  "INACTIVE TITLEBAR"    '=D
        ACTIVATE =    ""                     '=D
        ACTIVATEAPP = ""                     '=D
        giDeactivationComplete = 0
        giActivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  DeactivationStep2                                    xBot
      '_________________________________________________________________
      
      SUB DeactivationStep2
        ACTIVATE =    "DEACTIVATE DIALOG"    '=E
        giDeactivationComplete = 0
        giActivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  EndDeactivation                                      xBot
      '_________________________________________________________________
      
      SUB EndDeactivation
        ACTIVATEAPP = "DEACTIVATION"         '=F
      
        IF NCACTIVATE =  "INACTIVE TITLEBAR" AND _
           ACTIVATE =    "DEACTIVATE DIALOG" AND _
           ACTIVATEAPP = "DEACTIVATION" THEN
            giDeactivationComplete = 1
      
            IF giView <> 0 THEN
                gsCmdMessages = _ gsCmdMessages + _
                $CRLF + _
                "Deactivation Completed." + $CRLF + _
                gsCmdMessages
                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
            END IF
        END IF
        giActivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  CLEAR_DEACTIVATION    not used                       xBot
      '_________________________________________________________________
      
      SUB CLEAR_DEACTIVATION
        NCACTIVATE =  ""
        ACTIVATE =    ""
        ACTIVATEAPP = ""
        giDeactivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  CLEAR_ACTIVATION      not used                       xBot
      '_________________________________________________________________
      
      SUB CLEAR_ACTIVATION
        ACTIVATEAPP = ""
        NCACTIVATE =  ""
        ACTIVATE =    ""
        giActivationComplete = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  CLEAR_MOUSE_TOGGLE                                   xBot
      '_________________________________________________________________
      
      SUB CLEAR_MOUSE_TOGGLE
        giRightMouseButtonDown = 0
        giRightMouseToggled = 0
        giLeftMouseButtonDown = 0
        giLeftMouseToggled = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  RIGHT_MOUSE_PRESSED                                  xBot
      '_________________________________________________________________
      
      SUB RIGHT_MOUSE_PRESSED
        giRightMouseButtonDown = 1
        giLeftMouseButtonDown = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  LEFT_MOUSE_PRESSED                                   xBot
      '_________________________________________________________________
      
      SUB LEFT_MOUSE_PRESSED
        giRightMouseButtonDown = 0
        giLeftMouseButtonDown = 1
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  ChooseCommand                                        xBot
      '_________________________________________________________________
      
      SUB ChooseCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        SELECT CASE LO(WORD,wParamX)
      
            CASE %ID_CaptureIconRect
                GetWindowMinimizeRect(hWndMain, WindowMinimizeRect)
                IF giView <> 0 THEN
                    gsCmdMessages = _ gsCmdMessages + _
                           $CRLF + _
                           "Taskbar Icon Size:" + $CRLF + _
                           " L=" + STR$(WindowMinimizeRect.nLeft)  + _
                           ", T=" + STR$(WindowMinimizeRect.nTop)   + _
                           ", R=" + STR$(WindowMinimizeRect.nRight) + _
                           ", B=" + STR$(WindowMinimizeRect.nBottom)+ $CRLF + _
                           gsCmdMessages
                    CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                END IF
      
            CASE %IDC_Reset    'reset messages
                SELECT CASE HI(WORD, wParamX)
                    CASE %BN_CLICKED
                        IF giView <> 0 THEN
                            gsCmdMessages = ""
                            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                        END IF
                END SELECT
      
            CASE %IDC_Show      'show all messages
                SELECT CASE HI(WORD, wParamX)
                    CASE %BN_CLICKED
                        gsCmdMessages = $CRLF + "Now ready to show messages." + $CRLF + _
                        "NOTE: " + $CRLF + _
                        "The newest messages will be listed first."
                        CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                        giView = NOT giView    'values are 0=False and -1=True
                        IF giView = 0 THEN
                            gsCmdMessages = InitialMessage
                            CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                        END IF
                END SELECT
      
            CASE %ID_Minimize
                CALL MINIMIZE_DIALOG
      
            CASE %ID_Move
                CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
                'change mouse cursor for hCaptionBar to move cursor
                'and enable mouse tracking
                giMoving = 1
                SetFocus GetDlgItem(hWndMain, %ID_CAPTIONBAR)
      
            CASE %IDM_EXI10, %IDCANCEL
                SELECT CASE HI(WORD, wParamX)
                    CASE %BN_CLICKED
                        giCloseDialog = 1
                        CALL MINIMIZE_DIALOG
                END SELECT
      
        END SELECT
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  Captionbar0                                          xBot
      '_________________________________________________________________
      
      SUB Captionbar0
        IF giHasCaptionAndMarquee = 1 THEN
           SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
        END IF
        giCaptionBar = 0
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  Captionbar1                                          xBot
      '_________________________________________________________________
      
      SUB Captionbar1
        IF giHasCaptionAndMarquee = 1 THEN
            SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
        END IF
        giCaptionBar = 1
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  Captionbar2                                          xBot
      '_________________________________________________________________
      
      SUB Captionbar2
        IF giHasCaptionAndMarquee = 1 THEN
            SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA2)
        END IF
        giCaptionBar = 2
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  Captionbar3                                          xBot
      '_________________________________________________________________
      
      SUB Captionbar3
        IF giHasCaptionAndMarquee = 1 THEN
            SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA3)
        END IF
        giCaptionBar = 3
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  Captionbar4                                          xBot
      '_________________________________________________________________
      
      SUB Captionbar4
        IF giHasCaptionAndMarquee = 1 THEN
            SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA4)
        END IF
        giCaptionBar = 4
      END SUB
      
      '_________________________________________________________________
      '
      '   SUB  Captionbar5                                          xBot
      '_________________________________________________________________
      
      SUB Captionbar5
        IF giHasCaptionAndMarquee = 1 THEN
            SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA5)
        END IF
        giCaptionBar = 5
      END SUB
      
      
      '******************************************************************************
      'The End
      '******************************************************************************

      Comment


      • #4
        xBot Version 3

        Click image for larger version

Name:	Version 3.jpg
Views:	1
Size:	26.7 KB
ID:	776512

        xBot3.zip

        Code:
        
        'xBot MobileApp Example
        'SDK Version 2
        'This version allows you to turn on/off the Captionbar and Marquee.
        'Set giHasCaptionAndMarquee = 1 'to view them
        'Set giHasCaptionAndMarquee = 0 'to not view them
        
        'Compilable Example:
        'Works with PBWIN 10.4 and Jose' includes.
        
        'by: Jim Fritts
        
        'Version 1 In response to this post...
        'https://forum.powerbasic.com/forum/USER-TO-USER-discussions/powerbasic-FOR-windows/774617-DIALOG-WITH-MINIMIZE-AND-CLOSE-ONLY#post774617
        
        'Version 2 In response to this post...
        'https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/776457-remove-the-top-portion-of-a-dialog#post776457
        
        'Version 3
        'for the fun of it
        
        'This source code was released to the public domain on 23 NOV 2018
        'It makes use of many contributors Borje, Pierre, Jose' among others.
        'Thank you all
        
        'NOTE: if you are using PBWIN 9 or below you will need to
        'replace all POINT references with POINTAPI.
        
        'Code Objective:
        'Version 1  23 NOV 2018
        'Produce a Windows 10 foundation SDK example that has no Nonclient
        'area and replicates default Nonclient area behavior with easily
        'configurable bitmaps to fill the titlebar area. As intended the
        'titlebar only has a minimize [-] button and a close [X] button.
        
        'Version 2  24 NOV 2018
        'Allow user to go rogue and turn On/Off the Captionbar and Marquee
        'to suit their programming needs.
        'Make bitmaps owner drawn and provide no drawing support for that.
        'Remove minimize [-] and close [X] functionality from
        'Captionbar.
        
        'Version 3  25 NOV 2018
        'Added left mouse click to Titlebar icon for popup menu.
        'Added layered window for Titlebar transparency.
        'Added a different background gradient.
        'Refinements. See these...
        '    giHasCaption = 1  '1= yes 0=no determines whether a Captionbar - titlebar is shown
        '    giHasMarquee = 1  '1= yes 0=no determines whether a Marguee is shown
        '    giCaptionBar = 99 '99=Unknown state if Titlebar
        
        'This example demonstrates an app with:
        '  No NonClient Area.
        '  No window sizing.
        '  No maximizing.
        '  No Maximize button.
        '  A background gradient surrounding the dialog.
        '  An OwnerDrawn popup menu with Icons.
        '  Popup menu that has only Move, Minimize, and Close as options.
        
        '  A Subclassed Titlebar.
        
        'Even though the XPTheme is applied for the buttons not much else
        'benefits from it. Typically I do not like themed buttons but for
        'simplicities sake I used them here.
        
        'Yes, Dorothy you can have just what you want.
        
        'Hopefully this provides an adequate example for those SDK types.
        'Have FUN!
        
          '%TRUE  = 1
          '%FALSE = 0
          '%NULL  = 0
        
        
        #COMPILE EXE "xBot.exe"
        #DIM ALL
        
        #INCLUDE "Win32Api.inc"
        #INCLUDE "ComDlg32.inc"
        
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ENUM Equates SINGULAR
            IDC_Reset = 500
            IDC_Show
            ID_Move       'move
            ID_Minimize   'minimize
            IDM_Sep       'menu separator
            IDM_EXI10     'close
            ID_IMAGE
            ID_CAPTIONBAR
            ID_TITLEBAR1
            ID_MARQUEEBAR1
            ID_MARQUEEBAR2
            ID_TITLELABEL
            ID_LabelListen
            ID_LabelDictation
            ID_LabelTitle
            ID_LabelAttention
            ID_LabelTalk
            ID_IDNOTE
            ID_IDNOTE2
            IDC_Timer0
            ID_CaptureIconRect
        END ENUM
        
        TYPE PROP
            usefont        AS DWORD
            hinstance      AS DWORD
        '    isrecmodified  AS LONG
        '    isfilemodified AS LONG
        '    currententry   AS LONG
        '    maxentries     AS LONG
        '    findtext       AS ASCIIZ * %MAX_PATH
        END TYPE
        
        TYPE PopMenuItemType
          SizeA    AS SizeL
          zItem    AS ASCIIZ * 255            'Menu Text to display
          MenuType AS ASCIIZ * %MAX_PATH      'MOV MIN CLO
          ED       AS LONG                    'Enabled Disabled
        END TYPE
        
        GLOBAL hWndMain                 AS DWORD
        GLOBAL giCancelProgram          AS LONG
        GLOBAL ghNCA                    AS DWORD
        GLOBAL ghInst                   AS DWORD
        
        GLOBAL ghBmpNCA0                AS DWORD
        GLOBAL ghBmpNCA1                AS DWORD
        GLOBAL ghBmpNCA2                AS DWORD
        GLOBAL ghBmpNCA3                AS DWORD
        GLOBAL ghBmpNCA4                AS DWORD
        GLOBAL ghBmpNCA5                AS DWORD
        
        GLOBAL ghIconCM00               AS DWORD
        GLOBAL ghIconCM01               AS DWORD
        GLOBAL ghIconCM02               AS DWORD
        GLOBAL ghIconCM03               AS DWORD
        GLOBAL ghIconCM04               AS DWORD
        GLOBAL ghIconCM05               AS DWORD
        
        GLOBAL hTitleBar                AS DWORD
        GLOBAL hCaptionBar              AS DWORD
        GLOBAL dwLabelStyle             AS DWORD
        GLOBAL dwNBLabelStyle           AS DWORD
        GLOBAL dwLeftLabelStyle         AS DWORD
        GLOBAL dwNoRetMLTextBoxStyle    AS DWORD
        GLOBAL hMouseHook               AS DWORD
        GLOBAL hContext                 AS DWORD
        GLOBAL hForeGroundPrior         AS DWORD
        GLOBAL hPopup                   AS DWORD
        GLOBAL ghCtl_Edit_X             AS DWORD
        GLOBAL ghWndSaveFocus           AS DWORD
        GLOBAL hMutex                   AS DWORD
        
        GLOBAL gP                       AS PROP
        
        GLOBAL InitialMessage           AS STRING
        GLOBAL gsBannerListen           AS STRING
        GLOBAL gsBannerTitle            AS STRING
        GLOBAL gsBannerTalk             AS STRING
        GLOBAL gsBannerAttention        AS STRING
        GLOBAL gsBannerDictation        AS STRING
        GLOBAL gsMousePosition          AS STRING
        GLOBAL gsCmdMessages            AS STRING
        GLOBAL NCACTIVATE               AS STRING
        GLOBAL ACTIVATE                 AS STRING
        GLOBAL ACTIVATEAPP              AS STRING
        
        GLOBAL giCaptionBar             AS LONG
        GLOBAL giTheReturn              AS LONG
        GLOBAL hBrushPearl              AS LONG
        GLOBAL giPRTDMessage            AS LONG
        GLOBAL giGettingMousePosition   AS LONG
        GLOBAL gfTrackLeave             AS LONG
        GLOBAL giActiveTitlebar         AS LONG
        GLOBAL giLeftMouseDown          AS LONG  'used to track mouse clicks on titlebar
        GLOBAL giMinimizeClose          AS LONG
        GLOBAL giLeftButtonDown         AS LONG  'used to track mouse dragging on titlebar
        GLOBAL giAppIsMinimized         AS LONG
        GLOBAL giAppLostFocus           AS LONG
        GLOBAL giShowDocumentCursor     AS LONG
        GLOBAL giShowHandCursor         AS LONG
        GLOBAL giShowArrowCursor        AS LONG
        GLOBAL giShowWaitCursor         AS LONG
        GLOBAL giShowMoveCursor         AS LONG
        GLOBAL hCursorArrow             AS LONG
        GLOBAL hCursorBar               AS LONG
        GLOBAL hCursorHand              AS LONG
        GLOBAL hCursorWait              AS LONG
        GLOBAL hCursorMove              AS LONG
        GLOBAL giMoving                 AS LONG
        GLOBAL giView                   AS LONG
        GLOBAL giCloseDialog            AS LONG
        GLOBAL giRightMouseButtonDown   AS LONG
        GLOBAL giRightMouseToggled      AS LONG
        GLOBAL giLeftMouseButtonDown    AS LONG
        GLOBAL giLeftMouseToggled       AS LONG
        GLOBAL giFindNewActiveWindow    AS LONG
        GLOBAL giActivationComplete     AS LONG
        GLOBAL giDeactivationComplete   AS LONG
        GLOBAL iLOCx                    AS LONG
        GLOBAL iLOCy                    AS LONG
        GLOBAL giHasCaption             AS LONG  'Turn on/Off Display of Captionbar
        GLOBAL giTitlebarIconClickDn    AS LONG
        GLOBAL giHasMarquee             AS LONG  'Turn on/Off Display of Marquee Banner
        GLOBAL giOnDialog               AS LONG
        GLOBAL giLeft                   AS LONG
        GLOBAL giTop                    AS LONG
        
        GLOBAL MyCurPos                 AS POINT   'in screen coordinates
        
        GLOBAL rcMainSub                AS RECT
        GLOBAL TaskbarAppRect           AS RECT
        GLOBAL TitlebarRect             AS RECT
        GLOBAL TaskbarRect              AS RECT
        GLOBAL DesktopRect              AS RECT
        GLOBAL WindowMinimizeRect       AS RECT
        
        GLOBAL pPopItemSize             AS MEASUREITEMSTRUCT POINTER
        GLOBAL pPopItemDrawInfo         AS DRAWITEMSTRUCT POINTER
        GLOBAL pPopItem                 AS PopMenuItemType POINTER
        
        #RESOURCE BITMAP,     110, "NC_Base.bmp"           'its size is 220x20 active no highlighted buttons
        #RESOURCE BITMAP,     111, "NC_Gray.bmp"           'its size is 220x20 inactive no highlighted buttons
        #RESOURCE BITMAP,     112, "NC_Min.bmp"            'its size is 220x20 active minimize button highlighted
        #RESOURCE BITMAP,     113, "NC_X.bmp"              'its size is 220x20 active close button highlighted
        #RESOURCE BITMAP,     114, "NC_Min_Gray.bmp"       'its size is 220x20 inactive minimize button highlighted
        #RESOURCE BITMAP,     115, "NC_X_Gray.bmp"         'its size is 220x20 inactive close button highlighted
        
        #RESOURCE ICON,     3000, "xBot.ICO"
        
        #RESOURCE ICON,     3500, "CM00.ICO"
        #RESOURCE ICON,     3501, "CM01.ICO"    'not needed
        #RESOURCE ICON,     3502, "CM02.ICO"
        #RESOURCE ICON,     3503, "CM03.ICO"    'not needed
        #RESOURCE ICON,     3504, "CM04.ICO"
        #RESOURCE ICON,     3505, "CM05.ICO"    'not needed
        
        #RESOURCE MANIFEST,     1, "xptheme.XML"
        
        #RESOURCE VERSIONINFO
        #RESOURCE FILEFLAGS      0
        #RESOURCE FILEVERSION    1, 0, 0, 0
        #RESOURCE PRODUCTVERSION 1, 0, 0, 0
        #RESOURCE STRINGINFO     "0409", "0000"
        #RESOURCE VERSION$       "CompanyName",      "LocalApp, Inc."
        #RESOURCE VERSION$       "FileDescription",  "xBot"
        #RESOURCE VERSION$       "FileVersion",      "3.0"
        #RESOURCE VERSION$       "InternalName",     "xBot"
        #RESOURCE VERSION$       "OriginalFilename", "xBot.exe"
        #RESOURCE VERSION$       "LegalCopyright",   "© by James R. Fritts 2018"
        #RESOURCE VERSION$       "LegalTrademarks",  "HSI"
        #RESOURCE VERSION$       "ProductName",      "XBOT"
        #RESOURCE VERSION$       "ProductVersion",   "3.0"
        
        
        DECLARE THREAD FUNCTION MinimizeDialogThread(BYVAL yyy AS LONG) AS LONG           'temporary
        DECLARE THREAD FUNCTION CheckMouseThread(BYVAL yyy AS LONG) AS LONG               'full time
        DECLARE FUNCTION GetWindowMinimizeRect LIB "user32.dll" ALIAS "GetWindowMinimizeRect" _
        (BYVAL hWindow AS DWORD, pRect AS RECT) AS LONG 'Vista+
        
        '_________________________________________________________________
        '
        ' Program entrance                                            xBot
        '_________________________________________________________________
        
        FUNCTION WINMAIN (BYVAL hInstance AS DWORD, _
                          BYVAL hPrevInstance AS DWORD, _
                          BYVAL lpCmdLine AS ASCIIZ PTR, _
                          BYVAL iCmdShow AS LONG) AS LONG
        
            LOCAL Msg          AS tagMsg
            LOCAL W            AS WndClassEx
            LOCAL szAppName    AS ASCIIZ * 80
            LOCAL szClassName  AS ASCIIZ * 80
            LOCAL hWndButton   AS DWORD
            LOCAL hAccel       AS DWORD
            LOCAL WndStyle     AS LONG
            LOCAL WndStyleX    AS LONG
        
            LOCAL ResX               AS LONG
        
            ResX = CheckForMutex("xBot", hMutex)
            IF ResX > 0 THEN WinBeep 300,200 : EXIT FUNCTION
        
            giShowArrowCursor = 1
            CALL SELECT_MOUSE_CURSOR
        
            'register window class
            szAppName = "xBot"
            szClassName = "Mobileapp" '"#32770"
        
            W.cbSize        = SIZEOF(W)
            W.Style         = %CS_HREDRAW OR %CS_VREDRAW   '%WS_OverlappedWindow Or %WS_HScroll Or %WS_VScroll  '
            W.lpfnWndProc   = CODEPTR(WndProc)
            W.cbClsExtra    = 0
            W.cbWndExtra    = 0
            W.hInstance     = hInstance
            W.hIcon         = LoadImage(hInstance, BYVAL 3000, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
            W.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
            W.hbrBackground = GetStockObject(%DKGRAY_BRUSH) '(%LTGRAY_BRUSH) '%COLOR_3DDKSHADOW 'COLOR_BTNSHADOW'%Color_BtnFace+1 (%COLOR_ACTIVEBORDER)
            W.lpszMenuName  = %NULL
            W.lpszClassName = VARPTR(szClassName)
            W.hIconSm       = W.hIcon
            RegisterClassEx W
        
            'create window of that class
            WndStyle  = %WS_VISIBLE OR %WS_POPUP OR %WS_BORDER OR %DS_MODALFRAME OR %DS_NOFAILCREATE
                        ' OR %DS_SETFONT OR %WS_CAPTION
            WndStyleX = %WS_EX_LEFT OR %WS_EX_WINDOWEDGE OR %WS_EX_APPWINDOW
        
            hWndMain = CreateWindowEx( _
                WndStyleX,     _  ' extended styles
                szClassName,   _  ' window class name
                szAppName,     _  ' caption
                WndStyle,      _  ' window styles
                300,           _  ' left
                300,           _  ' top
                340,           _  ' width    was 790
                340,           _  ' height
                %HWND_DESKTOP, _  ' parent window handle
                %NULL,         _  ' window menu handle
                hInstance,     _  ' program instance handle
                BYVAL %NULL)      ' creation parameters
        
            ghInst = hInstance
            gP.hinstance = hInstance
        
            CALL ASSIGN_WINDOW_STYLES
        
            giHasCaption = 1  '1= yes 0=no determines whether a Captionbar - titlebar is shown
            giHasMarquee = 0  '1= yes 0=no determines whether a Marguee is shown
            giCaptionBar = 99 '99=Unknown state if Titlebar
        
            CALL CreateButtons
            CALL CreateTitlebar
            CALL BUILD_MARQUEE
            CALL LOAD_ICONS
            CALL BUILD_TEXTBOX
        
            ShowWindow hWndMain, iCmdShow   'controls how window is to be shown. 1st must use iCmdShow
            UpdateWindow hWndMain           'sends the window it's first WM_Create to display the window on the screen
        
            'message pump - calls WndProc whenever an application-specific message is received
            'WndProc can process the message, or pass it on to a the default window procedure that is built into Windows.
            WHILE GetMessage(Msg, %NULL, 0, 0) > 0
               IF ISFALSE TranslateAccelerator (hWndMain, hAccel, Msg) THEN
                  IF ISFALSE ISDialogMessage (hWndMain, Msg) THEN
                     TranslateMessage Msg
                     DispatchMessage  Msg
                  END IF
               END IF
            WEND
        END FUNCTION
        
        FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
            LOCAL hDC AS DWORD, pPaint AS PAINTSTRUCT, tRect  AS RECT
            LOCAL pnmhdr         AS NMHDR PTR
            LOCAL CurPos         AS POINT
        
            InitialMessage = $CRLF + _
                             "  This area is to provide user messages." + $CRLF + $CRLF + _
                             "  Reset Button:    clear this screen." + $CRLF + _
                             "  Show Button:     display app messages" + $CRLF + _
                             "                  or not display app messages." + $CRLF + $CRLF + _
                             "  See app notes for other info."
        
            '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            'Create a timer event every 1/4 Sec = 250
            '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            'SetTimer hWnd, %IDC_Timer0, 250, BYVAL %NULL
        
            SELECT CASE wMsg
        
                CASE %WM_CREATE          'when an application requests that a window be created
                                         'after window is created, but before it becomes visible
                    gsCmdMessages = $CRLF + "Now ready to show messages." + $CRLF + _
                    "NOTE: " + $CRLF + _
                    "The newest messages will be listed first."
        
                    'Initial View state (can be 0 or -1) if -1 then View messages if 0 then do not view messages
                    giView = -1
        
                    'Captures location of the application icon on the Taskbar
                    CALL CHECK_MOUSE
        
                    CALL LOAD_BRUSHES
                    CALL LOAD_CURSORS
                    CenterWindow hWnd            ' center on desktop
        
                CASE %WM_INITDIALOG      'immediately before a dialog box is displayed
                                         'typically used to initialize controls and carry out any other
                                         'initialization tasks that affect the appearance of the dialog box.
        
                CASE %WM_LBUTTONUP
                    'lbuttonup commands
                    '? "main left button up"
                    'CALL LButtonUpCommand(wParam, lParam)
                    FUNCTION = 1    'ignored
                    EXIT FUNCTION
        
                CASE %WM_LBUTTONDOWN
                    'lbuttondn commands
                    '? "main left button down"
                    'CALL LButtonDnCommand(wParam, lParam)
                    FUNCTION = 1    'ignored
                    EXIT FUNCTION
        
                CASE %WM_RBUTTONDOWN
                    '? "main right button down"
                    FUNCTION = 1    'ignored
                    EXIT FUNCTION
        
                CASE %WM_MOVE
                    'move commands
                    'call MoveCommand(wParam, lParam)
                     CALL Captionbar0
                    FUNCTION = 0  '=o if processed
                    EXIT FUNCTION
        
                CASE %WM_CLOSE
                    DestroyWindow hWndMain
        
                CASE %WM_DESTROY         'window is being destroyed
                                         'after windows is removed from screen (children still exist)
                    RemoveWindowSubclass(GetDlgItem(hWndMain, %ID_TITLEBAR1), CODEPTR(TitlebarProc), 99)
                    IF hBrushPearl     THEN CALL DeleteObject( hBrushPearl )
        
                    IF ghIconCM00 THEN DestroyIcon(ghIconCM00)
                    IF ghIconCM01 THEN DestroyIcon(ghIconCM01)
                    IF ghIconCM02 THEN DestroyIcon(ghIconCM02)
                    IF ghIconCM03 THEN DestroyIcon(ghIconCM03)
                    IF ghIconCM04 THEN DestroyIcon(ghIconCM04)
                    IF ghIconCM05 THEN DestroyIcon(ghIconCM05)
        
                    IF hCursorWait  THEN CALL DestroyCursor(hCursorWait)  'DeleteObject(hCursorWait)
                    IF hCursorHand  THEN CALL DestroyCursor(hCursorHand)  'DeleteObject(hCursorHand)
                    IF hCursorArrow THEN CALL DestroyCursor(hCursorArrow) 'DeleteObject(hCursorArrow)
                    IF hCursorBar   THEN CALL DestroyCursor(hCursorBar)   'DeleteObject(hCursorBar)
                    IF hCursorMove  THEN CALL DestroyCursor(hCursorMove)  'DeleteObject(hCursorMove)
        
                    IF hMouseHook <> 0 THEN UnhookWindowsHookEx(hMouseHook)
        
                    IF IsMenu(hPopUp) THEN DestroyMenu(hPopUp)
                    giCancelProgram = 1
                    SLEEP 100
                    PostQuitMessage 0
                    EXIT FUNCTION
        
                CASE %WM_COMMAND         'user selects a command item from a menu
                                         'control sends a notification message to its parent window
                                         'accelerator keystroke is translated.
                    'main command functions
                    CALL ChooseCommand(wParam, lParam)
                    FUNCTION = 1
                    EXIT FUNCTION
        
                CASE %WM_NOTIFY          'by control to its parent window when an event has occurred
                    pnmhdr = lParam
                    SELECT CASE @pnmhdr.idFrom
                        'CASE %IDC_Button              'Control ID
                        '    SELECT CASE @pnmhdr.code  'Notification code
                        '        CASE %NM_CLICK        'typical notification code
                        '    END SELECT
        
                    END SELECT
        
                CASE %WM_SIZE
                    IF wParam = %SIZE_MAXIMIZED THEN    'do not allow maximized display
                        ShowWindow hWndMain, %SW_SHOWNORMAL
                    END IF
                    FUNCTION = 0
                    EXIT FUNCTION
        
                CASE %WM_CTLCOLORSTATIC
                    'A static control, or an edit control that is read-only or disabled
                    'ctlcolorstatic functions
                    CALL CCSCommand(wParam, lParam)
                    FUNCTION = giTheReturn
                    EXIT FUNCTION
        
                'mouse click
                'CASE %WM_PARENTNOTIFY    'sent to parent when child window is created/destroyed
                                         'sent to parent when user clicks mouse button over child
        
                'mouse movement
                CASE %WM_SETCURSOR       'sent if mouse causes cursor to move
                    CALL SetCursorCommand(wParam, lParam)
                    FUNCTION = giTheReturn
                    EXIT FUNCTION
        
                'CASE %WM_MOUSEMOVE       'when cursor moves
        
                'keyboard
                'CASE %WM_CHAR            'to window with keyboard focus when WM_KEYDOWN message is translated
                                         'by the TranslateMessage function. contains the character code of the
                                         'key that was pressed.
        
                'CASE %WM_GETDLGCODE    'intercept keyboard input to child control
                '    FUNCTION = %DLGC_WANTARROWS '%DLGC_WANTCHARS OR %DLGC_WANTALLKEYS OR %DLGC_WANTMESSAGE
                '    EXIT FUNCTION
        
                'CASE %WM_KEYDOWN
        
                'graphic/drawing events
                CASE %WM_ERASEBKGND      'sent when the window background must be erased (such as resizing)
                    hDC = wParam
                    'DrawGradient hDC     'Pass the DC of the region to repaint
                    DrawGradientX hDC     'Pass the DC of the region to repaint
                    FUNCTION = 1 : EXIT FUNCTION
        
                CASE %WM_PAINT           'set when request is made to paint a portion of an application's window.
        
                'recurring events
                CASE %WM_TIMER           'when a timer expires (does not keep accurate timing)
                    CALL TimerCommand(wParam, lParam)
                    FUNCTION = 0
                    EXIT FUNCTION
        
                'user action
                CASE %WM_PASTE           'application sends a WM_PASTE message to an edit control or combobox
                CASE %WM_DROPFILES       'sent when user drops file on application that's is registered as file recipient
        
                'application status
                CASE %WM_ACTIVATE        'sent to both the window being activated and the window
                                         'being deactivated.
                                         'activate functions
                                         'fires when ap gains and loses focus
        
                    'If an application processes this message, it should return zero.
                    CALL ActivateCommand(wParam, lParam)
                    FUNCTION = 1    'apparently xBot is not admitting that it processed this message
                    '**** EXIT FUNCTION CANNOT BE USED HERE ****
        
                CASE %WM_NCACTIVATE      'sent to window when its nonclient area needs to be changed
                                         'to indicate an active or inactive state.
                                         'If an application does process this message, it must
                                         'return TRUE to direct the system to complete the change
                                         'of active window
                    CALL NCActivateCommand(wParam, lParam)
                    FUNCTION = %TRUE 'giTheReturn
                    '**** EXIT FUNCTION CANNOT BE USED HERE ****
        
                CASE %WM_ACTIVATEAPP
                    SELECT CASE wParam
                        CASE %TRUE
        
                            CALL StartActivation
        
                        CASE %FALSE
        
                            CALL EndDeactivation
        
                    END SELECT
        
                    'If an application processes this message, it should return zero.
                    FUNCTION = 0
                    EXIT FUNCTION
        
                CASE %WM_SYSCOMMAND
                    'system command functions
                    CALL SystemCommand(wParam, lParam)
                    'If an application processes this message, it should return zero.
                    FUNCTION = 0
                    EXIT FUNCTION
        
            END SELECT
        
            FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)   'if not handled above, pass to Windows default message handler.
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' SUB DrawGradient
        '_________________________________________________________________
        
        SUB DrawGradient (BYVAL hDC AS DWORD)
           LOCAL rectFill AS RECT, rectClient AS RECT, fStep AS SINGLE, hBrush AS DWORD, lOnBand AS LONG
           GetClientRect WindowFromDC(hDC), rectClient
           fStep = rectClient.nbottom / 200
           FOR lOnBand = 0 TO 199
              SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
              hBrush = CreateSolidBrush(RGB(140 - lOnBand, 140 - lOnBand, 140 - lOnBand))
              Fillrect hDC, rectFill, hBrush
              DeleteObject hBrush
           NEXT
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB DrawGradientX
        '_________________________________________________________________
        
        SUB DrawGradientX (BYVAL hDC AS DWORD)
           LOCAL rectFill AS RECT, rectClient AS RECT, fStep AS SINGLE, hBrush AS DWORD, lOnBand AS LONG
           GetClientRect WindowFromDC(hDC), rectClient
           fStep = rectClient.nbottom / 200
           FOR lOnBand = 0 TO 99
              SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
              hBrush = CreateSolidBrush(RGB(45 + lOnBand, 45 + lOnBand, 45 + lOnBand))
              Fillrect hDC, rectFill, hBrush
              DeleteObject hBrush
           NEXT
           FOR lOnBand = 100 TO 200
              SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
              hBrush = CreateSolidBrush(RGB(240 - lOnBand, 240 - lOnBand, 240 - lOnBand))
              Fillrect hDC, rectFill, hBrush
              DeleteObject hBrush
           NEXT
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB CreateButtons                                           xBot
        '_________________________________________________________________
        
        SUB CreateButtons
          LOCAL WndStyle AS LONG, hWnd, hInstance AS DWORD
        
          'create window of existing class "Button"
          WndStyle  = %WS_TABSTOP OR %WS_VISIBLE OR %WS_CHILD OR %BS_DEFPUSHBUTTON
          hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
        
          IF giHasCaption = 1 THEN
              hWnd= CreateWindow( _
                 "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
                 "Reset",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
                 WndStyle,   _    'dwStyle        style of window
                 30,         _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
                 296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
                 80,         _    'nWidth         width in device units
                 30,         _    'nHeight        height in device units
                 hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
                 %IDC_Reset, _    'hMenu          handle to a menu or child window control ID
                 hInstance,  _    'handle to instance of the module to be associated with the window
                 BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        
              hWnd= CreateWindow( _
                 "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
                 "Show",     _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
                 WndStyle,   _    'dwStyle        style of window
                 115,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
                 296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
                 80,         _    'nWidth         width in device units
                 30,         _    'nHeight        height in device units
                 hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
                 %IDC_Show,  _    'hMenu          handle to a menu or child window control ID
                 hInstance,  _    'handle to instance of the module to be associated with the window
                 BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
          ELSE
              hWnd= CreateWindow( _
                 "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
                 "Reset",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
                 WndStyle,   _    'dwStyle        style of window
                 30,         _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
                 30,         _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
                 80,         _    'nWidth         width in device units
                 30,         _    'nHeight        height in device units
                 hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
                 %IDC_Reset, _    'hMenu          handle to a menu or child window control ID
                 hInstance,  _    'handle to instance of the module to be associated with the window
                 BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        
              hWnd= CreateWindow( _
                 "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
                 "Show",     _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
                 WndStyle,   _    'dwStyle        style of window
                 115,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
                 30,         _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
                 80,         _    'nWidth         width in device units
                 30,         _    'nHeight        height in device units
                 hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
                 %IDC_Show,  _    'hMenu          handle to a menu or child window control ID
                 hInstance,  _    'handle to instance of the module to be associated with the window
                 BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        
              hWnd= CreateWindow( _
                 "Button",   _    'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
                 "Close",    _    'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
                 WndStyle,   _    'dwStyle        style of window
                 236,        _    'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
                 296,        _    'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
                 80,         _    'nWidth         width in device units
                 30,         _    'nHeight        height in device units
                 hWndMain,   _    'hWndParent     handle to parent window (optional for a pop-up window)
                 %IDM_EXI10, _    'hMenu          handle to a menu or child window control ID
                 hInstance,  _    'handle to instance of the module to be associated with the window
                 BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
          END IF
        END SUB
        '_________________________________________________________________
        '
        ' SUB CreateTitlebar                                           xBot
        '_________________________________________________________________
        
        SUB CreateTitlebar
          LOCAL WndStyle AS LONG, hWnd, hInstance AS DWORD
        
          hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
        
          WndStyle  = %WS_VISIBLE OR %WS_CHILD OR %SS_NOTIFY OR %SS_OWNERDRAW 'or  OR %SS_BITMAP
        
          hTitleBar= CreateWindow( _
             "Static",      _ 'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
             BYVAL %NULL,   _ 'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
             WndStyle,      _ 'dwStyle        style of window
             2,             _ 'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
             2,             _ 'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
             334,           _ 'nWidth         width in device units
             20,            _ 'nHeight        height in device units
             hWndMain,      _ 'hWndParent     handle to parent window (optional for a pop-up window)
             %ID_TITLEBAR1,_ 'hMenu          handle to a menu or child window control ID
             hInstance,     _ 'handle to instance of the module to be associated with the window
             BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        
          'use the new subclass process and pass the window handle
          CALL SetWindowSubclass(hTitleBar, CODEPTR(TitlebarProc), 99, 0)
        
          IF giHasCaption = 1 THEN
              WndStyle  = %WS_VISIBLE OR %WS_CHILD OR %SS_BITMAP
          ELSE
              WndStyle  = %WS_VISIBLE OR %WS_CHILD OR %SS_OWNERDRAW 'or  OR %SS_BITMAP
          END IF
        
        
          hCaptionBar= CreateWindowEx(%WS_EX_LAYERED, _
             "Static",      _ 'lpClassName    pointer to a null-terminated string (any registered name, including predefined system class names).
             BYVAL %NULL,   _ 'lpWindowName   pointer to a null-terminated String (placed in title bar, text of the control, icon name or #identifier)
             WndStyle,      _ 'dwStyle        style of window
             2,             _ 'x              initial horizontal position (upper left screen, except for child is relative to parent window's client area)
             2,             _ 'y              initial vertical position  (upper left screen, except for child is relative to parent window's client area)
             334,           _ 'nWidth         width in device units
             20,            _ 'nHeight        height in device units
             hWndMain,      _ 'hWndParent     handle to parent window (optional for a pop-up window)
             %ID_CAPTIONBAR,_ 'hMenu          handle to a menu or child window control ID
             hInstance,     _ 'handle to instance of the module to be associated with the window
             BYVAL %Null)     'pointer to CREATESTRUCT structure pointed to by the lParam param of the WM_CREATE message.
        
          ghBmpNCA0 = LoadImage(hInstance, "#110", _ 'NCA base
                      %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        
          ghBmpNCA1 = LoadImage(hInstance, "#111", _ 'NCA gray
                      %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        
          ghBmpNCA2 = LoadImage(hInstance, "#112", _ 'NCA Min
                      %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        
          ghBmpNCA3 = LoadImage(hInstance, "#113", _ 'NCA X
                      %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        
          ghBmpNCA4 = LoadImage(hInstance, "#114", _ 'NCA Min gray
                      %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        
          ghBmpNCA5 = LoadImage(hInstance, "#115", _ 'NCA X gray
                      %IMAGE_BITMAP, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        
          CALL Captionbar0
        END SUB
        
        '_________________________________________________________________
        '
        ' FUNCTION TitlebarProc                                       xBot
        '_________________________________________________________________
        
        FUNCTION TitlebarProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, _
                  BYVAL lParam AS LONG, BYVAL spID AS DWORD, BYVAL RefData AS DWORD) AS LONG
        
          DIM   PopItem(1 TO 3)          AS STATIC PopMenuItemType
        
          LOCAL CurPos                   AS POINT
          LOCAL hdc                      AS DWORD
          LOCAL hBrush                   AS DWORD
        
          SELECT CASE wMsg
        
              CASE %WM_GETDLGCODE    'intercept keyboard input to child control
                  FUNCTION = %DLGC_WANTARROWS '%DLGC_WANTCHARS OR %DLGC_WANTALLKEYS OR %DLGC_WANTMESSAGE
                  EXIT FUNCTION
        
              CASE %WM_KEYDOWN    'supports moving dialog when move is selected from
                                  'popup menu
                  IF giMoving = 1 THEN
                      SELECT CASE wParam
                          CASE %VK_LEFT 'LEFT ARROW key pressed
                              'locate mouse position
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Move dialog left." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                              CALL MoveWindowLeft10
                              IF hMouseHook = 0 THEN
                                  hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                  IF giView <> 0 THEN
                                      gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                      gsCmdMessages
                                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                  END IF
                              END IF
        
                          CASE %VK_RIGHT 'RIGHT ARROW key pressed
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Move dialog right." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                              CALL MoveWindowRight10
                              IF hMouseHook = 0 THEN
                                  hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                  IF giView <> 0 THEN
                                      gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                      gsCmdMessages
                                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                  END IF
                              END IF
        
                          CASE %VK_UP 'UP ARROW key pressed
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Move dialog up." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                              CALL MoveWindowUp10
                              IF hMouseHook = 0 THEN
                                  hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                  IF giView <> 0 THEN
                                      gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                      gsCmdMessages
                                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                  END IF
                              END IF
        
                          CASE %VK_DOWN 'DOWN ARROW key pressed
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Move dialog down." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                              CALL MoveWindowDown10
                              IF hMouseHook = 0 THEN
                                  hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                                  IF giView <> 0 THEN
                                      gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                      gsCmdMessages
                                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                  END IF
                              END IF
        
                      END SELECT
                  END IF
                  FUNCTION = 0 : EXIT FUNCTION
        
              CASE %WM_COMMAND
                  SELECT CASE LO(WORD, wParam)
                      CASE 1102
                          IF giView <> 0 THEN
                              gsCmdMessages = "Popup Menu Move selected." + $CRLF + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          PostMessage hWndMain, %WM_COMMAND, %ID_Move, 0
        
                      CASE 1103
                          IF giView <> 0 THEN
                              gsCmdMessages = "Popup Menu Minimize selected." + $CRLF + $CRLF + _
                              gsCmdMessages
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                          PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
        
                      CASE 1105
                          '? "close"
                          PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0
                  END SELECT
        
              CASE %WM_LBUTTONDOWN 'do dragging if mouse down on titlebar
                  '***NOTE:
                  '***If left mouse button is down/up on the icon part of the
                  '***titlebar then the popup menu should appear.
        
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "Left button down on titlebar." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
        
                  CurPos.x = GET_X_LPARAM(lParam)   'in client coordinates
                  CurPos.y = GET_Y_LPARAM(lParam)   'in client coordinates
        
                  iLOCx = CurPos.x + 2  'added in the edge
                  iLOCy = CurPos.y + 2  'added in the edge
        
                  IF giHasCaption = 1 THEN
                      IF (CurPos.x > 15 AND  CurPos.x < 245) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                          giLeftButtonDown = 1    'Left mouse button is down on title bar
                          IF hMouseHook = 0 THEN
                              hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                          END IF
        
                      ELSEIF (CurPos.x > 5 AND  CurPos.x < 16) AND (CurPos.y > 3 AND  CurPos.y < 17) THEN
                          'Click detected on titlebar icon
                          'show popup menu
                          giTitlebarIconClickDn = 1
        
                      ELSEIF (CurPos.x > 244 AND  CurPos.x < 288) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                          giLeftMouseDown = 1
                          giMinimizeClose = 0
        
                      ELSEIF (CurPos.x > 287 AND CurPos.x < 334) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                          giLeftMouseDown = 1
                          giMinimizeClose = 1
                      END IF
                  ELSE
                      IF (CurPos.x > 1 AND  CurPos.x < 333) AND (CurPos.y > 0 AND  CurPos.y < 18) THEN
                          giLeftButtonDown = 1    'Left mouse button is down on title bar
                          IF hMouseHook = 0 THEN
                              hMouseHook = SetWindowsHookEx(%WH_MOUSE_LL, CODEPTR(TitlebarMouseProc), GetModuleHandle($NUL), 0)
                              IF giView <> 0 THEN
                                  gsCmdMessages = "Mouse hook enabled." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
                          END IF
                          giLeftMouseDown = 0
                       END IF
                  END IF
                  FUNCTION = 0 : EXIT FUNCTION
        
              CASE %WM_LBUTTONUP 'stop dragging if mouse is up on titlebar
                  '***NOTE:
                  '***If left mouse button is down/up on the icon part of the
                  '***titlebar then the popup menu should appear.
        
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "Left button up on titlebar." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
        
                  IF giMoving = 1 THEN
                      giMoving = 0
                      giShowMoveCursor = 0
                      giShowArrowCursor = 1
                      SELECT_MOUSE_CURSOR
                  END IF
        
                  IF giTitlebarIconClickDn = 1 THEN
                      'Click detected on titlebar icon
                      'show popup menu
                      giTitlebarIconClickDn = 0
        
                      CALL BuildContextMenu(hWnd)
                  END IF
        
                  giLeftButtonDown = 0
                  IF hMouseHook <> 0 THEN
                      UnhookWindowsHookEx(hMouseHook)
                      hMouseHook = 0
                      IF giView <> 0 THEN
                          gsCmdMessages = "Mouse hook released." + $CRLF + _
                          gsCmdMessages
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                      END IF
                  END IF
        
                  IF giHasCaption = 1 THEN
                      IF giLeftMouseDown = 1 THEN
                          giLeftMouseDown = 0
                          SELECT CASE giMinimizeClose
                              CASE 0 'minimize button clicked
                                  IF giView <> 0 THEN
                                      gsCmdMessages = "Minimize button pressed." + $CRLF + $CRLF + _
                                      gsCmdMessages
                                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                                  END IF
                                  PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
        
                              CASE 1 'close button clicked
                                  PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0 'close dialog
        
                          END SELECT
        
                          giMinimizeClose = 0
                      END IF
                  END IF
                  FUNCTION = 0 : EXIT FUNCTION
        
              CASE %WM_RBUTTONDOWN 'for context menu on titlebar
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "Right button down on titlebar." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  FUNCTION = 0 : EXIT FUNCTION
        
              CASE %WM_RBUTTONUP
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "Right button up on titlebar." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  'FUNCTION = 0 : EXIT FUNCTION 'do not use this if you want the default process to produce context menu
        
              CASE %WM_CONTEXTMENU
                  'https://forum.powerbasic.com/forum/user-to-user-discussions/programming/753120-is-there-a-way-to-put-a-button-on-a-menu-not-popup-dropdown?p=753130#post753130
                  CALL BuildContextMenu(hWnd)
        
              CASE %WM_MEASUREITEM 'wParam is control identifier, lParam is item-size information
                  '- 9 in item length is important here to make the right menu edge appear correctly
                  'not inflated
                  hdc          = GetDC(hWnd)
                  pPopItemSize = lParam
                  pPopItem     = @pPopItemSize.itemData
                  GetTextExtentPoint32(hdc, @pPopItem.zItem, LEN(@pPopItem.zItem) - 9, @pPopItem.SizeA)
                  @pPopItemSize.itemWidth  = 4 + GetSystemMetrics(%SM_CYSMICON) + @pPopItem.sizeA.cx
                  @pPopItemSize.itemHeight = 3 + MAX(GetSystemMetrics(%SM_CYSMICON), @pPopItem.sizeA.cy)
                  ReleaseDC(hWnd, hdc)
                  FUNCTION = %TRUE
        
              CASE %WM_DRAWITEM 'wParam is control id, lParam is item-drawing info
                  pPopItemDrawInfo = lParam
                  pPopItem         = @pPopItemDrawInfo.itemData
                  IF (@pPopItemDrawInfo.itemState AND %ODS_SELECTED) THEN
                      SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHTTEXT))
                      SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_HIGHLIGHT))
                      hBrush = GetSysColorBrush(%COLOR_HIGHLIGHT)
                  ELSE 'Item is not selected
                      SetTextColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENUTEXT))
                      SetBkColor(@pPopItemDrawInfo.hDC, GetSysColor(%COLOR_MENU))
                      hBrush = GetSysColorBrush(%COLOR_MENU)
                  END IF
                  FillRect(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem, hBrush)
        
        
                  SELECT CASE @pPopItem.MenuType
                      CASE ""
                          'no icon for this item
        
                      CASE "MOV"
                          '<> move icon
                          SELECT CASE @pPopItem.ED
                              CASE %MF_ENABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM00, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                              CASE %MF_DISABLED
                                  'no disabled icon
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM01, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                          END SELECT
        
                      CASE "MIN"
                          '- minimize icon
                          SELECT CASE @pPopItem.ED
                              CASE %MF_ENABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM02, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                              CASE %MF_DISABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM03, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                          END SELECT
        
                      CASE "CLO"
                          'X close icon
                          SELECT CASE @pPopItem.ED
                              CASE %MF_ENABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM04, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                              CASE %MF_DISABLED
                                  DrawIconEx(@pPopItemDrawInfo.hDC, @pPopItemDrawInfo.rcItem.nleft, @pPopItemDrawInfo.rcItem.nTop, _
                                             ghIconCM05, 16, 16, 0, BYVAL 0, %DI_NORMAL)
        
                          END SELECT
        
                  END SELECT
        
                  @pPopItemDrawInfo.rcItem.nLeft = 4 + @pPopItemDrawInfo.rcItem.nLeft + GetSystemMetrics(%SM_CXSMICON)
                  DrawText(@pPopItemDrawInfo.hDC, @pPopItem.zItem, LEN(@pPopItem.zItem), _
                           @pPopItemDrawInfo.rcItem, %DT_SINGLELINE)
        
                  FUNCTION = %TRUE
        
        
              CASE %WM_SETCURSOR
                  'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "Setcursor is being processed."
                  'setcursor functions
                  CALL SetCursorCommandTitlebar(wParam, lParam)
        
                  IF giTheReturn = 1 THEN  ' If the parent window returns TRUE, further processing is halted.
                      FUNCTION = 1
                      EXIT FUNCTION
                  END IF
        
          END SELECT
        
          FUNCTION = DefSubclassProc(hWnd, wMsg, wParam, lParam)
        END FUNCTION
        
        
        '_________________________________________________________________
        '
        ' SUB BuildContextMenu
        '_________________________________________________________________
        
        SUB BuildContextMenu(BYVAL hWndX AS DWORD)
          LOCAL MyItemName1 AS STRING
          LOCAL MyItemName2 AS STRING
          LOCAL MyItemName3 AS STRING
          LOCAL CurPos      AS POINT
          DIM   PopItem(1 TO 3)          AS STATIC PopMenuItemType
        
          MyItemName1 = "Move"
          MyItemName2 = "Minimize"
          MyItemName3 = "Close          Alt+F4"
        
          CALL GetMousePosition   'Get cursor screen location
          CurPos = MyCurPos
        
          'CaptionBar 3 and 5 have the Close [X] button highlighted
          'Based on some testing the default Windows behavior
          'is to not allow the popup menu when the Close button
          'is highlighted.
          IF giCaptionBar = 3 OR giCaptionBar = 5 THEN EXIT SUB
        
          IF hPopup = 0 THEN
              hPopup = CreatePopupMenu
        
              PopItem(1).zItem    = MyItemName1
              PopItem(1).MenuType = "MOV"
              PopItem(1).ED = %MF_ENABLED
        
              PopItem(2).zItem    = MyItemName2
              PopItem(2).MenuType = "MIN"
              PopItem(2).ED = %MF_ENABLED
        
              PopItem(3).zItem    = MyItemName3
              PopItem(3).MenuType = "CLO"
              PopItem(3).ED = %MF_ENABLED
        
              InsertMenu(hPopup, 0, %MF_BYCOMMAND OR %MF_STRING, 1102, MyItemName1 + $NUL)
              InsertMenu(hPopup, 1, %MF_BYCOMMAND OR %MF_STRING, 1103, MyItemName2 + $NUL)
              InsertMenu(hPopup, 2, %MF_BYCOMMAND OR %MF_SEPARATOR, 1104, "-")
              InsertMenu(hPopup, 3, %MF_BYCOMMAND OR %MF_STRING, 1105, MyItemName3 + $NUL)
              'SetMenu(hWnd, hPopup)
        
        
              ModifyMenu(hPopup, 1102, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1102, BYVAL VARPTR(PopItem(1)))
              ModifyMenu(hPopup, 1103, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1103, BYVAL VARPTR(PopItem(2)))
              ModifyMenu(hPopup, 1105, %MF_BYCOMMAND OR %MF_OWNERDRAW, 1105, BYVAL VARPTR(PopItem(3)))
        
          END IF
          TrackPopupMenu(hPopup, %TPM_LEFTALIGN OR %TPM_RIGHTBUTTON, _
                         CurPos.x, CurPos.y, BYVAL 0, hWndX, BYVAL 0)
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB CenterWindow
        '_________________________________________________________________
        
        SUB CenterWindow (BYVAL hAnyWnd AS LONG)
          DIM WndRect AS RECT
          DIM x       AS LONG
          DIM y       AS LONG
          GetWindowRect hAnyWnd, WndRect
          x = (GetSystemMetrics(%SM_CXSCREEN)-(WndRect.nRight-WndRect.nLeft))\2
          y = (GetSystemMetrics(%SM_CYSCREEN)-(WndRect.nBottom-WndRect.nTop+GetSystemMetrics(%SM_CYCAPTION)))\2
          SetWindowPos hAnyWnd, %NULL, x, y, 0, 0, %SWP_NOSIZE OR %SWP_NOZORDER
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB BUILD_MARQUEE                                           xBot
        '_________________________________________________________________
        
        SUB BUILD_MARQUEE
          LOCAL MyCtrl   AS DWORD
          LOCAL OffsetX   AS LONG
          LOCAL OffsetY   AS LONG
        
          gsBannerListen = "="
          gsBannerTalk   = CHR$(239)
          gsBannerAttention = "!"   'app is fully paying attention
          gsBannerDictation = "^"   'initial behavior
        
          IF giHasMarquee = 1 THEN
              OffsetX = 2
              OffsetY = 22
              MyCtrl = addLabelT(hWndMain, %ID_MARQUEEBAR1, "", 0 + OffsetX, 0 + OffsetY, 334, 4, dwNBLabelStyle)
              MyCtrl = addLabelT(hWndMain, %ID_TITLELABEL, "Xbot Personal Assistant", 0 + OffsetX, 4 + OffsetY, 334, 20, dwNBLabelStyle)
        
              MyCtrl = addLabelE(hWndMain, %ID_LabelListen, gsBannerListen + $NUL, 0 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
              MyCtrl = addLabelE(hWndMain, %ID_LabelDictation, gsBannerDictation + $NUL, 20 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
        
              MyCtrl = addLabelE(hWndMain, %ID_LabelTitle, "", 40, 24 + OffsetY, 254 + OffsetX, 20, dwLabelStyle OR %SS_NOTIFY)
        
              MyCtrl = addLabelE(hWndMain, %ID_LabelAttention, gsBannerAttention + $NUL, 294 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
              MyCtrl = addLabelE(hWndMain, %ID_LabelTalk, gsBannerTalk + $NUL, 314 + OffsetX, 24 + OffsetY, 20, 20, dwLabelStyle OR %SS_NOTIFY)
        
              MyCtrl = addLabelE(hWndMain, %ID_IDNOTE, "", 0 + OffsetX, 44 + OffsetY, 334, 20, dwLabelStyle)
        
              MyCtrl = addLabelT(hWndMain, %ID_MARQUEEBAR2, "", 0 + OffsetX, 64 + OffsetY, 339, 2, dwLabelStyle)
          END IF
        
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB BUILD_TEXTBOX                                           xBot
        '_________________________________________________________________
        
        SUB BUILD_TEXTBOX
          LOCAL MyCtrl   AS DWORD
          LOCAL OffsetX   AS LONG
          LOCAL OffsetY   AS LONG
        
          OffsetX = 2
          OffsetY = 22
          IF giHasCaption = 1 THEN
              MyCtrl = addTextBox(hWndMain, %ID_IDNOTE2, gsCmdMessages + $NUL, 0 + OffsetX + 20, 70 + OffsetY, 334 - 40, 200, dwNoRetMLTextBoxStyle OR %WS_HSCROLL)
        
                  ghCtl_Edit_X = MyCtrl
        
                  SendMessage ghCtl_Edit_X, %EM_SETLIMITTEXT, &H200000&, 0 'set text limit to 2 Meg
                  'SendMessage ghCtl_Edit_X, %EM_AUTOURLDETECT, %True, 0
                  'SendMessage ghCtl_Edit_X, %EM_SETEVENTMASK, 0, %ENM_UPDATE OR %ENM_LINK OR %ENM_CHANGE OR %ENM_SELCHANGE OR %ENM_KEYEVENTS 'mask is set to produce the EN_UPDATE message
        
                  'use the new subclass process and pass the dialog handle
                  'CALL SetWindowSubclass(ghCtl_Edit_X, CODEPTR(EditProc), 29, 0)
        
                  'ghCtl_Edit_X = GetDlgItem(hWndMain, %ID_IDNOTE2)
          ELSE
              MyCtrl = addTextBox(hWndMain, %ID_IDNOTE2, gsCmdMessages + $NUL, 0 + OffsetX + 20, 70 + OffsetY - 15, 334 - 40, 200, dwNoRetMLTextBoxStyle OR %WS_HSCROLL)
        
                  ghCtl_Edit_X = MyCtrl
        
                  SendMessage ghCtl_Edit_X, %EM_SETLIMITTEXT, &H200000&, 0 'set text limit to 2 Meg
                  'SendMessage ghCtl_Edit_X, %EM_AUTOURLDETECT, %True, 0
                  'SendMessage ghCtl_Edit_X, %EM_SETEVENTMASK, 0, %ENM_UPDATE OR %ENM_LINK OR %ENM_CHANGE OR %ENM_SELCHANGE OR %ENM_KEYEVENTS 'mask is set to produce the EN_UPDATE message
        
                  'use the new subclass process and pass the dialog handle
                  'CALL SetWindowSubclass(ghCtl_Edit_X, CODEPTR(EditProc), 29, 0)
        
                  'ghCtl_Edit_X = GetDlgItem(hWndMain, %ID_IDNOTE2)
          END IF
        END SUB
        '_________________________________________________________________
        '
        ' FUNCTION addLabelT                                          xBot
        '_________________________________________________________________
        
        FUNCTION addLabelT(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
            LOCAL hCtrl AS DWORD
            hCtrl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING, "Static", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
            'IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
            FUNCTION = hCtrl
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' FUNCTION addLabelE                                          xBot
        '_________________________________________________________________
        
        FUNCTION addLabelE(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
            LOCAL hCtrl AS DWORD
            hCtrl = CreateWindowEx(%WS_EX_STATICEDGE, "Static", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
            'IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
            FUNCTION = hCtrl
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' FUNCTION addTextBox                                         xBot
        '_________________________________________________________________
        
        FUNCTION addTextBox(BYVAL hParent AS DWORD, BYVAL nID AS LONG, zCaption AS ASCIIZ, BYVAL x AS LONG, BYVAL y AS LONG, BYVAL w AS LONG, BYVAL h AS LONG, BYVAL dwStyle AS DWORD) AS DWORD
            LOCAL hCtrl AS DWORD
            hCtrl = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", zCaption, dwStyle, x, y, w, h, hParent, nID, gP.hinstance, BYVAL %NULL)
            DisableXPThemeControl hCtrl
            IF hCtrl THEN SendMessage(hCtrl, %WM_SETFONT, gP.usefont, 0)
            FUNCTION = hCtrl
        END FUNCTION
        
        
        '_________________________________________________________________
        '
        ' SUB ASSIGN_WINDOW_STYLES                                    xBot
        '_________________________________________________________________
        
        SUB ASSIGN_WINDOW_STYLES
          dwLabelStyle           = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_CENTER OR %WS_BORDER
          dwNBLabelStyle         = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_CENTER        'no border
          dwLeftLabelStyle       = %WS_CHILD OR %WS_VISIBLE OR %ES_READONLY OR %SS_NOPREFIX OR %ES_LEFT OR %WS_BORDER
          dwNoRetMLTextBoxStyle  = %WS_CHILD OR %WS_VISIBLE OR %ES_AUTOHSCROLL OR %WS_VSCROLL OR _
                                   %ES_NOHIDESEL OR %ES_READONLY OR %ES_MULTILINE OR %WS_BORDER
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB CCSCommand                                              xBot
        '_________________________________________________________________
        
        SUB CCSCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          'wParamX = Handle to the device context for the static control window.
          'lParamX = Handle to the static control.
        
          LOCAL myReturn  AS LONG
        
          giTheReturn = 0
        
          IF lParamX <> 0 THEN
              myReturn = GetDlgCtrlID(lParamX)
              GOTO ContinueOn
          END IF
          EXIT SUB
        
          ContinueOn:
          SELECT CASE myReturn      '= control id
        
              CASE %ID_MARQUEEBAR1, _
                   %ID_MARQUEEBAR2, _
                   %ID_IDNOTE, _
                   %ID_IDNOTE2, _
                   %ID_TITLELABEL
                   SetTextColor (wParamX, RGB(0,0,0))                    'Label color text
                   SetBkColor   (wParamX, RGB(255,255,255))              'Label background color
                   giTheReturn = hBrushPearl
        
        
              CASE %ID_LabelTitle, _          'screen title
                   %ID_LabelAttention, _      'is app paying attention symbol
                   %ID_LabelDictation, _      'is dictation grammar enabled symbol
                   %ID_LabelListen, _         'is recognition enabled symbol
                   %ID_LabelTalk              'is server or client talking symbol
        
                   SetTextColor (wParamX, RGB(0,0,0))                    'Label text color
        
                   'IF giLoginStatus = 0 OR _
                   '   (gsThisClient = "Client" AND giReceivedUpdate = 0) THEN
                       SetBkColor   (wParamX, RGB(255,255,255))
                       giTheReturn = hBrushPearl
                   '    EXIT SUB
                   'END IF
          END SELECT
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB LOAD_BRUSHES                                            xBot
        '_________________________________________________________________
        
        SUB LOAD_BRUSHES
          STATIC Lb AS LOGBRUSH
        
          Lb.lbStyle  = %BS_SOLID                            'Lb.lbStyle = 0 = BS_SOLID ( 1 = BS_HOLLOW, BS_NULL)
          Lb.lbColor  = RGB(255,255,255)                     'Dialog background color (Solid or Hollow ~ Lb.lbHatch ignored)
          hBrushPearl = CreateBrushIndirect(Lb)
        
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB MoveWindowToHere        Dialog follows mouse movement   xBot
        '_________________________________________________________________
        
        SUB MoveWindowToHere
          LOCAL CurPos      AS POINT
          LOCAL CP_Old      AS POINT  'CenterPoint Old
        
          'Moving dialog with mouse after Arrow keys were used once.
          'Works ok if you want the dialog to be moved to a position where
          'the mouse cursor is located at the center of the titlebar.
        
          'This must be here to get a smooth motion of dialog dragging
          GetCursorPos(CurPos)   'in screen coordinates
        
          GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
        
          CP_Old.x = (rcMainSub.nRight - rcMainSub.nLeft)/ 2 + rcMainSub.nLeft
          CP_Old.y = (24)/ 2 + rcMainSub.nTop
        
          MoveWindow(hWndMain, rcMainSub.nLeft + CurPos.x - CP_Old.x, rcMainSub.nTop + CurPos.y - CP_Old.y, _
                                rcMainSub.nRight  - rcMainSub.nLeft, _
                                rcMainSub.nBottom - rcMainSub.nTop, %TRUE)
        
        END SUB
        
        
        '_________________________________________________________________
        '
        ' SUB MoveWindowToHereEx     Dialog follows mouse movement    xBot
        '_________________________________________________________________
        
        SUB MoveWindowToHereEx
          LOCAL CurPos      AS POINT
          LOCAL StartX      AS LONG
          LOCAL StartY      AS LONG
          LOCAL OffsetX     AS LONG
          LOCAL OffsetY     AS LONG
        
          'Move a dialog smoothly by mouse movement
          'Designed to move dialog from any point on titlebar
          'left of the Minimize button.
        
          'This must be here to get a smooth motion of dialog dragging
          GetCursorPos(CurPos)   'in screen coordinates
        
          GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
        
          StartX = rcMainSub.nLeft + iLOCx
          StartY = rcMainSub.nTop + iLOCy
        
          OffsetX = CurPos.x - StartX
          OffsetY = CurPos.y - StartY
        
          MoveWindow(hWndMain, rcMainSub.nLeft + OffsetX, rcMainSub.nTop + OffsetY, _
                                rcMainSub.nRight  - rcMainSub.nLeft, _
                                rcMainSub.nBottom - rcMainSub.nTop, %TRUE)
        
        END SUB
        
        
        '_________________________________________________________________
        '
        ' SUB MoveWindowLeft10                                        xBot
        '_________________________________________________________________
        
        SUB MoveWindowLeft10
          LOCAL WinRec      AS RECT
        
          GetWindowRect hWndMain, WinRec
          MoveWindow(hWndMain, WinRec.nLeft - 10, WinRec.nTop, _
                                WinRec.nRight  - WinRec.nLeft, _
                                WinRec.nBottom - WinRec.nTop, %TRUE)
        
          CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB MoveWindowRight10                                       xBot
        '_________________________________________________________________
        
        SUB MoveWindowRight10
          LOCAL WinRec      AS RECT
        
          GetWindowRect hWndMain, WinRec
          MoveWindow(hWndMain, WinRec.nLeft + 10, WinRec.nTop, _
                                WinRec.nRight  - WinRec.nLeft, _
                                WinRec.nBottom - WinRec.nTop, %TRUE)
        
          CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB MoveWindowUp10                                          xBot
        '_________________________________________________________________
        
        SUB MoveWindowUp10
          LOCAL WinRec      AS RECT
        
          GetWindowRect hWndMain, WinRec
          MoveWindow(hWndMain, WinRec.nLeft, WinRec.nTop - 10, _
                                WinRec.nRight  - WinRec.nLeft, _
                                WinRec.nBottom - WinRec.nTop, %TRUE)
        
          CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB MoveWindowDown10                                        xBot
        '_________________________________________________________________
        
        SUB MoveWindowDown10
          LOCAL WinRec      AS RECT
        
          GetWindowRect hWndMain, WinRec
          MoveWindow(hWndMain, WinRec.nLeft, WinRec.nTop + 10, _
                                WinRec.nRight  - WinRec.nLeft, _
                                WinRec.nBottom - WinRec.nTop, %TRUE)
        
          CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
        END SUB
        
        
        '_________________________________________________________________
        '
        ' SUB CHECK_MOUSE                                             xBot
        '_________________________________________________________________
        
        SUB CHECK_MOUSE
          LOCAL idThreadCheckMouse        AS LONG
          LOCAL idThreadMouseButtonToggle AS LONG
        
          THREAD CREATE CheckMouseThread(1) TO idThreadCheckMouse
          THREAD CLOSE idThreadCheckMouse TO idThreadCheckMouse
        
          THREAD CREATE MouseButtonToggleThread(1) TO idThreadMouseButtonToggle
          THREAD CLOSE idThreadMouseButtonToggle TO idThreadMouseButtonToggle
        
        END SUB
        
        '_________________________________________________________________
        '
        '   FUNCTION  CheckMouseThread            full time           xBot
        '_________________________________________________________________
        
        THREAD FUNCTION CheckMouseThread(BYVAL yyy AS LONG) AS LONG
            LOCAL CurPos   AS POINT
        
            'Wait until app is visible.
            TryAgain:
            IF IsWindowVisible(hWndmain) THEN
                'continue processing
            ELSE
                SLEEP 100
                IF giCancelProgram = 0 THEN GOTO TryAgain
            END IF
            SLEEP 200
            PostMessage hWndMain, %WM_COMMAND, %ID_CaptureIconRect, 0
        
            DO WHILE giCancelProgram = 0
                CALL GetMousePosition
                CurPos = MyCurPos
        
                IF ISFALSE IsRectEmpty(WindowMinimizeRect) THEN
                    IF PtInRect(WindowMinimizeRect, CurPos) > 0 THEN
                        CALL ACT_ON_TASKBAR_ICON_TOGGLE
                    END IF
                END IF
                SLEEP 100
            LOOP
        
        END FUNCTION
        
        '_________________________________________________________________
        '
        '   FUNCTION  MouseButtonToggleThread        full time        xBot
        '_________________________________________________________________
        
        THREAD FUNCTION MouseButtonToggleThread(BYVAL yyy AS LONG) AS LONG
            LOCAL CurPos   AS POINT
        
        
            'Wait until app is visible.
            TryAgain:
            IF IsWindowVisible(hWndmain) THEN
                'continue processing
            ELSE
                SLEEP 100
                IF giCancelProgram = 0 THEN GOTO TryAgain
            END IF
            SLEEP 300
        
            DO WHILE giCancelProgram = 0
                IF IsRectEmpty(WindowMinimizeRect) THEN
                    PostMessage hWndMain, %WM_COMMAND, %ID_CaptureIconRect, 0
                ELSE
                    GetCursorPos(CurPos)
        
                    IF PtInRect(WindowMinimizeRect, CurPos) > 0 THEN
                        'Mouse is located on the taskbar icon
                        CALL WAS_MOUSE_BUTTON_TOGGLED
                    ELSE
                        'Mouse is not located on the taskbar icon
                        giDeactivationComplete = 0
                        giActivationComplete = 0
                        CALL CLEAR_MOUSE_TOGGLE
        
                    END IF
                END IF
                SLEEP 100
            LOOP
        
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' SUB WAS_MOUSE_BUTTON_TOGGLED                                xBot
        '_________________________________________________________________
        
        SUB WAS_MOUSE_BUTTON_TOGGLED
          LOCAL k           AS LONG         ' Key status
          LOCAL btnDown     AS LONG
        
          k = GetAsyncKeyState(%VK_RBUTTON)   'not used
          btnDown =  BIT(k, 15)
          SELECT CASE btnDown
              CASE 1
                  'right mouse button is down.
                  CALL RIGHT_MOUSE_PRESSED
        
              CASE 0
                  IF giRightMouseButtonDown = 1 THEN
                      CALL CLEAR_MOUSE_TOGGLE
                      'right mouse button was down then up.
                      giRightMouseToggled = 1
        
                  END IF
        
          END SELECT
        
          k = GetAsyncKeyState(%VK_LBUTTON)
          btnDown =  BIT(k, 15)
          SELECT CASE btnDown
              CASE 1
                  'left mouse button is down.
                  CALL LEFT_MOUSE_PRESSED
        
              CASE 0
                  'left mouse button is up.
                  IF giLeftMouseButtonDown = 1 THEN
                      CALL CLEAR_MOUSE_TOGGLE
                      giLeftMouseToggled = 1
        
                  END IF
        
          END SELECT
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB ACT_ON_TASKBAR_ICON_TOGGLE                              xBot
        '_________________________________________________________________
        
        SUB ACT_ON_TASKBAR_ICON_TOGGLE
          LOCAL CurPos      AS POINT
        
          GetCursorPos(CurPos)
        
          IF giDeactivationComplete = 1 THEN
              giDeactivationComplete = 0
        
              SLEEP 200
        
              IF giLeftMouseToggled = 1 THEN
                  giLeftMouseToggled = 0
        
                  SELECT CASE IsIconic(hWndMain)
                      CASE 0 'Is Not Iconic
                          IF giAppLostFocus = 1 THEN
                              IF giView <> 0 THEN
                                  gsCmdMessages = _ gsCmdMessages + _
                                  "Mouse was toggled on Taskbar icon." + $CRLF + _
                                  gsCmdMessages
                                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                              END IF
        
                              ShowWindow hWndMain, %SW_RESTORE
        
                              SLEEP 200
                              CALL Captionbar0
        
                              giFindNewActiveWindow = 1
                              CALL FindNewActiveWindow
        
                              CALL SIMPLE_MINIMIZE
                          END IF
        
                      CASE 1 'Is Iconic
                          'Normally windows default behavior is to bring the app forward
                          CALL Captionbar0
        
                  END SELECT
              END IF
              GOTO LeaveEarly
          END IF
        
          IF giActivationComplete = 1 THEN
              giActivationComplete = 0
        
              IF giLeftMouseToggled = 1 THEN
                  giLeftMouseToggled = 0
        
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "Ready to deactivate." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
              END IF
              GOTO LeaveEarly
          END IF
        
          IF giActivationComplete = 0 AND giDeactivationComplete = 0 THEN
              IF giLeftMouseToggled = 1 THEN
                  giLeftMouseToggled = 0
        
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "Minimizing Dialog." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  CALL SIMPLE_MINIMIZE
              END IF
          END IF
          LeaveEarly:
        END SUB
        
        
        '_________________________________________________________________
        '
        ' FUNCTION GetMousePosition                                   xBot
        '_________________________________________________________________
        
        SUB GetMousePosition
          LOCAL CurPos      AS POINT
        
          IF giGettingMousePosition = 1 THEN CALL MyPumpMessages(10): EXIT SUB
          giGettingMousePosition = 1
        
          GetCursorPos(MyCurPos)
        
          gsMousePosition = " X=" + STR$(MyCurPos.x) + " Y=" + STR$(MyCurPos.y)
        
          GetWindowRect hWndMain, rcMainSub
          SetRect(TitlebarRect, rcMainSub.nLeft + 2, rcMainSub.nTop + 2, rcMainSub.nRight - 2, rcMainSub.nTop + 22)
        
          SELECT CASE IsIconic(hWndMain)
              CASE 1 'Is iconic
                  giAppIsMinimized = 1
        
              CASE 0 'Not iconic
                  giAppIsMinimized = 0
        
          END SELECT
        
        
          'check to see if mouse is on Titlebar
          IF PtInRect(TitlebarRect, MyCurPos) > 0 THEN
              'mouse is inside titlebar
        
              CurPos = MyCurPos
              ScreenToClient(hCaptionBar, CurPos) 'Convert from screen to titlebar coordinates
              'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "X=" + STR$(CurPos.x) + " Y=" + STR$(CurPos.y)
        
              SELECT CASE giActiveTitlebar
                  CASE 1 'active titlebar
                      IF giHasCaption = 1 THEN
                          IF (CurPos.x > 244 AND CurPos.x < 288) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                              'mouse is over titlebar minimize button
                              CALL Captionbar2
                          ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                              'mouse is over titlebar close button
                              CALL Captionbar3
                          ELSE
                              CALL Captionbar0
                          END IF
                      ELSE
                          IF (CurPos.x > 1 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                              'mouse is over titlebar
                              CALL Captionbar2
                          ELSE
                              CALL Captionbar0
                          END IF
                      END IF
        
                  CASE 0 'inactive titlebar
                      IF giHasCaption = 1 THEN
                          IF (CurPos.x > 244 AND CurPos.x < 288) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                              'mouse is over titlebar minimize button
                              CALL Captionbar4
                          ELSEIF (CurPos.x > 287 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                              'mouse is over titlebar close button
                              CALL Captionbar5
                          ELSE
                              CALL Captionbar1
                          END IF
                      ELSE
                          IF (CurPos.x > 1 AND CurPos.x < 333) AND (CurPos.y > 0 AND CurPos.y < 18) THEN
                              'mouse is over titlebar
                              CALL Captionbar4
                          ELSE
                              CALL Captionbar1
                          END IF
                      END IF
              END SELECT
          ELSE
              'mouse pointer is outside the titlebar
        
              IF (giCaptionBar = 5 OR giCaptionBar = 4) THEN
                  CALL Captionbar1
              END IF
              IF (giCaptionBar = 3 OR giCaptionBar = 2) THEN
                  CALL Captionbar0
              END IF
        
          END IF
        
          giGettingMousePosition = 0
        END SUB
        
        
        '_________________________________________________________________
        '
        ' FUNCTION TitlebarMouseProc                                  xBot
        '_________________________________________________________________
        
        FUNCTION TitlebarMouseProc(BYVAL nCode AS LONG, BYVAL wParam AS LONG, _
                           BYVAL lParam AS MSLLHOOKSTRUCT POINTER) AS LONG
         SELECT CASE nCode
           CASE %HC_ACTION
             SELECT CASE wParam
              CASE %WM_MOUSEMOVE
                  IF giMoving = 1 THEN
                      'Moving dialog with mouse after Arrow keys were used once.
                      CALL MoveWindowToHere
                  ELSE
                      CALL MoveWindowToHereEx
                  END IF
             END SELECT
         END SELECT
         FUNCTION = CallNextHookEx(hMouseHook, nCode, wParam, lParam) 'Forward message
        
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' SUB SetCursorCommandTitlebar                                xBot
        '_________________________________________________________________
        
        SUB SetCursorCommandTitlebar(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          LOCAL iReturn         AS LONG
        
          giTheReturn = 0
        
          IF wParamX = hCaptionBar THEN                   ' handle to titlebar
              IF giMoving = 1 THEN
                  'giShowWaitCursor = 0  'not altered
                  giShowHandCursor = 0
                  giShowArrowCursor = 0
                  giShowDocumentCursor = 0
                  giShowMoveCursor = 1
              ELSE
                  'giShowWaitCursor = 0  'not altered
                  giShowHandCursor = 0
                  giShowArrowCursor = 1
                  giShowDocumentCursor = 0
                  giShowMoveCursor = 0
              END IF
              CALL SELECT_MOUSE_CURSOR
        
          END IF
          'If an application processes this message, it should return TRUE
          'to halt further processing or FALSE to continue
          giTheReturn = %TRUE
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB SetCursorCommand                                        xBot
        '_________________________________________________________________
        
        SUB SetCursorCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
        
          giTheReturn = 0
        
          'Anywhere on client area except Titlebar
          IF LO(WORD, lParamX) = %HTCLIENT THEN       ' cursor is in client area
        
              SELECT CASE GetDlgCtrlID (wParamX)
                  CASE %IDC_Reset, _   'BUTTONS
                       %IDC_Show
                      IF giMoving = 1 THEN
                          'giShowWaitCursor = 0  'not altered
                          giShowHandCursor = 0
                          giShowArrowCursor = 0
                          giShowDocumentCursor = 0
                          giShowMoveCursor = 1
                      ELSE
                          CALL ERASE_PREVIOUS_ASSIGNMENTS
                      END IF
                      CALL SELECT_MOUSE_CURSOR
        
                  CASE %ID_IDNOTE2   'text
                      IF giMoving = 1 THEN
                          'giShowWaitCursor = 0  'not altered
                          giShowHandCursor = 0
                          giShowArrowCursor = 0
                          giShowDocumentCursor = 0
                          giShowMoveCursor = 1
                      ELSE
                          giShowDocumentCursor = 0
                          giShowHandCursor = 0
                          giShowArrowCursor = 0
                          giShowMoveCursor = 0
                      END IF
                      CALL SELECT_MOUSE_CURSOR
        
                  CASE ELSE
                      IF giMoving = 1 THEN
                          'giShowWaitCursor = 0  'not altered
                          giShowHandCursor = 0
                          giShowArrowCursor = 0
                          giShowDocumentCursor = 0
                          giShowMoveCursor = 1
                      ELSE
                          giShowDocumentCursor = 0
                          giShowHandCursor = 0
                          giShowArrowCursor = 1
                          giShowMoveCursor = 0
                      END IF
                      CALL SELECT_MOUSE_CURSOR
        
              END SELECT
          END IF
          'If an application processes this message, it should return TRUE
          'to halt further processing or FALSE to continue
          giTheReturn = %TRUE
        END SUB
        
        
        '_________________________________________________________________
        '
        '   SUB  ERASE_PREVIOUS_ASSIGNMENTS                           xBot
        '_________________________________________________________________
        
        SUB ERASE_PREVIOUS_ASSIGNMENTS
        
          giShowHandCursor = 1
          giShowDocumentCursor = 0
          giShowArrowCursor = 0
          giShowMoveCursor = 0
        END SUB
        
        
        '_________________________________________________________________
        '
        ' SUB ActivateCommand                                         xBot
        '_________________________________________________________________
        
        SUB ActivateCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          LOCAL CurPos         AS POINT
        
          CALL GetMousePosition
          CurPos = MyCurPos
        
          SELECT CASE LO(WORD, wParamX)
              CASE %WA_INACTIVE
                  'Deactivated.
        
                  giOnDialog = 0
        
                  CALL DeactivationStep2
        
              CASE %WA_CLICKACTIVE
                  'Activated by a mouse click.
                  'CALL BRING_MAIN_WINDOW_FORWARD
        
                  'gNewFocus = hWndMain
                  'gOldFocus = gNewFocus
        
                  'SetFocus hWndMain
                  giOnDialog = 1
                  'PostMessage hWndMain, %WM_COMMAND, %ID_RefreshVolumeGraphics, 0
        
                  'active titlebar
                  'CONTROL SET TEXT hWndMain, %ID_IDNOTE, "Active titlebar."
                  ShowWindow hWndMain, %SW_RESTORE
        
                  giFindNewActiveWindow = 1
        
                  CALL EndActivation
        
                  'lParamX = is the handle to the window being deactivated. Usually 0
        
              CASE %WA_ACTIVE
                  'Activated by some method other than a mouse
                  'click (for example, by a call to the
                  'SetActiveWindow function or by use of the
                  'keyboard interface to select the window).
        
                  giFindNewActiveWindow = 1
        
                  CALL EndActivation
        
        
                  'lParamX = is the handle to the window being deactivated. Usually 0
        
          END SELECT
        
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB NCActivateCommand
        '_________________________________________________________________
        
        SUB NCActivateCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)   'looks good
          LOCAL CurPos         AS POINT
        
          CALL GetMousePosition
          CurPos = MyCurPos
          giTheReturn = %TRUE
        
          SELECT CASE wParamX
              CASE %TRUE
                  'active titlebar
                  CALL ActivationStep2
        
                  IF ghWndSaveFocus THEN
                      ' Restore control focus
                      SetFocus(ghWndSaveFocus)
                      ghWndSaveFocus = 0
                  END IF
        
              CASE %FALSE
                  'inactive titlebar
                  'giTheReturn = %FALSE  use this if you want to prevent inactivation
        
                  CALL StartDeactivation
        
                  ' Save control focus
                  ghWndSaveFocus = GetFocus()
                  'use this if you want to prevent inactivation
                  'giTheReturn = %FALSE
        
              CASE 2097153   'handled as a true value
                  'dialog is being activated from the taskbar
                  'This happens only when dialog is minimized.
                  'Hex value 200001
        
                  'active titlebar
                  CALL ActivationStep3    'seems like this should be the start of activation
        
                  IF ghWndSaveFocus THEN
                      ' Restore control focus
                      SetFocus(ghWndSaveFocus)
                      ghWndSaveFocus = 0
                  END IF
        
          END SELECT
        END SUB
        
        
        '_________________________________________________________________
        '
        ' SUB LOAD_ICONS                                              xBot
        '_________________________________________________________________
        
        SUB LOAD_ICONS
          LOCAL hInstance AS DWORD
        
          hInstance = GetWindowLong(hWndMain, %GWL_HINSTANCE)
        
          ghIconCM00 = LoadImage(hInstance, BYVAL 3500, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
          ghIconCM01 = LoadImage(hInstance, BYVAL 3501, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
          ghIconCM02 = LoadImage(hInstance, BYVAL 3502, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
          ghIconCM03 = LoadImage(hInstance, BYVAL 3503, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
          ghIconCM04 = LoadImage(hInstance, BYVAL 3504, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
          ghIconCM05 = LoadImage(hInstance, BYVAL 3505, %IMAGE_ICON, 0, 0, %LR_LOADMAP3DCOLORS OR %LR_DEFAULTSIZE)
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB FindNewActiveWindow                                     xBot
        '_________________________________________________________________
        
        SUB FindNewActiveWindow
            LOCAL hNext1             AS DWORD
            LOCAL NumberX            AS LONG
            LOCAL lsNextWindowHandle AS STRING
        
            hNext1 = hWndMain
            NumberX = 0
            DO 'Enumerate desktop windows
                IF IsWindowOnDesktop(hNext1) THEN
                    INCR NumberX
                    IF NumberX = 2 THEN
                        lsNextWindowHandle = PARSE$(WindowSpec(hNext1), " ", 1)
                        hForeGroundPrior = VAL("&H0" + lsNextWindowHandle)  'returns unsigned decimal value from hex value
                        gsCmdMessages = _ gsCmdMessages + _
                        STR$(NumberX) + "  " + WindowSpec(hNext1) + $CRLF + _
                        gsCmdMessages
                        GOTO ShowResults
                    END IF
                END IF
                hNext1 = GetNextWindow(hNext1, %GW_HWNDNEXT)
            LOOP UNTIL hNext1 = 0
        
            ShowResults:
            'hNext1 = GetTopWindow(hForeGroundPrior)  'looks at child windows
            'IF hNext1 <> 0 THEN
            '    hForeGroundPrior = hNext1
            'END IF
        
            IF giView <> 0 THEN
                CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
            END IF
        
        END SUB
        
        
        '_________________________________________________________________
        '
        '   FUNCTION  MinimizeDialogThread                            xBot
        '_________________________________________________________________
        
        THREAD FUNCTION MinimizeDialogThread(BYVAL yyy AS LONG) AS LONG
        
            CALL SIMPLE_MINIMIZE
        
            IF giCloseDialog = 1 THEN
                DIALOG POST hWndMain, %WM_CLOSE, %NULL, %NULL   'asynchronous command
            END IF
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' SUB MINIMIZE_DIALOG                                         xBot
        '_________________________________________________________________
        
        SUB MINIMIZE_DIALOG
          LOCAL idThreadMinimizeDialog        AS LONG
        
          THREAD CREATE MinimizeDialogThread(1) TO idThreadMinimizeDialog
          THREAD CLOSE idThreadMinimizeDialog TO idThreadMinimizeDialog
        
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB SIMPLE_MINIMIZE                                         xBot
        '_________________________________________________________________
        
        SUB SIMPLE_MINIMIZE
          LOCAL CurPos         AS POINT
          LOCAL PriorPoint     AS POINT
          LOCAL rcPriorWindow  AS RECT
        
          CALL Captionbar1
        
          'where is the mouse pointer?
          GetCursorPos(CurPos)
        
          'NOTE: This will work for most apps to bring them forward.
          'Yes, even the Edge Browser.
        
          IF IsWindow(hForeGroundPrior) THEN
              GetWindowRect hForeGroundPrior, rcPriorWindow
        
              PriorPoint.x = rcPriorWindow.nLeft + 40
              PriorPoint.y = rcPriorWindow.nTop + 10
        
              'Move mouse pointer to prior dialog top left corner
              'to the right of the icon area
              SetCursorPos PriorPoint.x, PriorPoint.y
        
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  "Prior Window point to click: " + _
                  " X=" + STR$(PriorPoint.x) + " Y=" + STR$(PriorPoint.y) + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
        
              'Send left mouse click
              CALL SendLeftMouseClick
        
              'SLEEP 80
              'return mouse pointer to previous location
              SetCursorPos CurPos.x, CurPos.y
          END IF
        
          'Minimize our dialog
          ShowWindow hWndMain, %SW_MINIMIZE
        
          IF giView <> 0 THEN
              gsCmdMessages = _ gsCmdMessages + _
              "Dialog Minimized." + $CRLF + _
              gsCmdMessages
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
          CALL Captionbar1
        
        END SUB
        
        '_________________________________________________________________
        '
        ' FUNCTION SendLeftMouseClick
        '_________________________________________________________________
        
        FUNCTION SendLeftMouseClick () AS LONG 'pt is in screen coordinates
          DIM ipt(1) AS InputAPI '2 mouse events: down-up
        
          'first mouse event - mousedown
          ipt(0).dtype = %INPUT_MOUSE
          ipt(0).mi.dx = 0 'pt.x '65535 / (wDesktop/pt.x)
          ipt(0).mi.dy = 0 'pt.y '65535 / (hDesktop/pt.y)
          ipt(0).mi.MouseData = 0
          ipt(0).mi.dwFlags = %MOUSEEVENTF_ABSOLUTE OR %MOUSEEVENTF_LEFTDOWN OR %MOUSEEVENTF_MOVE
          ipt(0).mi.dtime = 0
          ipt(0).mi.dwExtraInfo = 0
        
          'second mouse event - mouseup
          ipt(1) = ipt(0)
          ipt(1).mi.dwFlags = %MOUSEEVENTF_LEFTUP
          FUNCTION = SendInput (UBOUND(ipt)+1, BYVAL VARPTR(ipt(0)), SIZEOF(InputAPI))
        END FUNCTION
        
        
        '_________________________________________________________________
        '
        ' SUB SELECT_MOUSE_CURSOR                                     xBot
        '_________________________________________________________________
        
        SUB SELECT_MOUSE_CURSOR
          IF giShowWaitCursor = 1 THEN
              MOUSEPTR hCursorWait
          ELSEIF giShowArrowCursor = 1 THEN
              MOUSEPTR hCursorArrow
          ELSEIF giShowHandCursor = 1 THEN
              MOUSEPTR hCursorHand
          ELSEIF giShowMoveCursor = 1 THEN
              MOUSEPTR hCursorMove
          ELSEIF giShowDocumentCursor = 0 THEN
              MOUSEPTR hCursorBar
          END IF
        END SUB
        
        '_________________________________________________________________
        '
        ' SUB LOAD_CURSORS                                            xBot
        '_________________________________________________________________
        
        SUB LOAD_CURSORS
          'New method that replaces LoadCursorA( %NULL, BYVAL %IDC_HAND )
          hCursorHand =  LoadImageA(%NULL, BYVAL %OCR_HAND,    %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
          hCursorArrow = LoadImageA(%NULL, BYVAL %OCR_NORMAL,  %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
          hCursorWait =  LoadImageA(%NULL, BYVAL %OCR_WAIT,    %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
          hCursorBar =   LoadImageA(%NULL, BYVAL %OCR_IBEAM,   %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
          hCursorMove =  LoadImageA(%NULL, BYVAL %OCR_SIZEALL, %IMAGE_CURSOR, 0, 0, %LR_SHARED OR %LR_DEFAULTSIZE)
        
        'from WinUser.inc
        '%OCR_IBEAM
        '%OCR_WAIT
        '%OCR_HAND
        '%OCR_NORMAL
        '%OCR_SIZEALL
        END SUB
        
        
        '------------------------------------------------------------------------------
        'Purpose: by calling SetWindowTheme with an empty string your control
        '         (button/checkbox/combo etc) will not be painted with the XP Theme.
        '
        'Example: LOCAL hButton AS DWORD
        '         hButton = GetDlgItem( CBHNDL, %IDOK )
        '         lRes = DisableXPThemeControl ( hbutton )
        '         InvalidateRect hButton,BYVAL %NULL,%TRUE
        '------------------------------------------------------------------------------
        FUNCTION DisableXPThemeControl(BYVAL hControl AS DWORD) AS LONG
            LOCAL hLib AS DWORD, pProc AS DWORD, lRes AS LONG
            hLib = LoadLibrary("UxTheme.dll")
            IF hLib THEN
                 pProc = GetProcAddress(hLib, "SetWindowTheme")
                 IF pProc THEN
                      CALL DWORD pProc USING SetWindowTheme(hControl, " ", " ")  TO lRes
                      FUNCTION = lRes
                 END IF
                 FreeLibrary hLib
            END IF
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' FUNCTION WindowSpec                                         xBot
        '_________________________________________________________________
        
        FUNCTION WindowSpec(hWin AS DWORD) AS STRING
            LOCAL zCaption AS ASCIIZ * %MAX_PATH
            LOCAL zClass   AS ASCIIZ * 32 'aka %MAX_CLASS_NAME_LEN
        
            GetClassName(hWin, zClass, SIZEOF(zClass))
            GetWindowText(hWin, zCaption, SIZEOF(zCaption))
            FUNCTION = HEX$(hWin) & $SPC & zCaption & " - Class: " & zClass
        END FUNCTION
        
        '_________________________________________________________________
        '
        ' FUNCTION IsWindowOnDesktop                                  xBot
        '_________________________________________________________________
        
        FUNCTION IsWindowOnDesktop(hWin AS DWORD) AS LONG
            LOCAL WinRect AS RECT
        
            IF ISFALSE(IsIconic(hWin)) THEN    'not iconic
                IF IsWindow(hWin) THEN
                    IF GetParent(hWin) = %HWND_DESKTOP THEN
                        IF IsWindowVisible(hWin) THEN
                            GetWindowRect(hWin, WinRect)
                            IF WinRect.nLeft < WinRect.nRight THEN 'hWnd x-axis size is not zero
                                IF WinRect.nTop < WinRect.nBottom THEN 'hWnd y-axis size is not zero
                                    'May also check to see if window is outside screen
                                    'Note that topMost windows will have effect on the zOrder
                                    FUNCTION = %TRUE
                                END IF
                            END IF
                        END IF
                    END IF
                END IF
            END IF
        END FUNCTION
        
        
        '_________________________________________________________________
        '
        ' Processes pending Windows messages.                         xBot
        ' Call this procedure if you are performing a tight
        ' FOR/NEXT or DO/LOOP and need to allow
        ' your application to be responsive to user input.
        ' Modified version of AfxPumpMessages
        '_________________________________________________________________
        
        SUB MyPumpMessages(BYVAL xTimes AS LONG) EXPORT
          LOCAL Ix AS LONG
        
          IF xTimes <= 0 THEN xTimes = 1
          FOR Ix = 1 TO xTimes
              'if GlobalVariableTest86 = 1 then EXIT SUB
              CALL PeekRemoveTranslateDispatchMessage
          NEXT Ix
        
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  PeekRemoveTranslateDispatchMessage
        '_________________________________________________________________
        
        SUB PeekRemoveTranslateDispatchMessage
          IF giPRTDMessage = 1 THEN EXIT SUB
          giPRTDMessage = 1
        
          STATIC Msg AS tagMsg
          IF PeekMessageA(Msg, %NULL, %NULL, %NULL, %PM_REMOVE) THEN
              TranslateMessage Msg
              DispatchMessage Msg
          END IF
        
          giPRTDMessage = 0
        END SUB
        
        
        
        '_________________________________________________________________
        '
        '   SUB  SystemCommand                                        xBot
        '_________________________________________________________________
        
        SUB SystemCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          ' This is the system commands broken out
          ' Capture this message and send a WM_DESTROY message
          ' or the program will remain in memory
          SELECT CASE wParamX AND &HFFF0
              CASE %SC_MAXIMIZE
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "WM_SYSCOMMAND - Maximize." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  ShowWindow hWndMain, %SW_NORMAL  'do not use maximize
        
              CASE %SC_CLOSE
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "WM_SYSCOMMAND - Close." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  PostMessage hWndMain, %WM_COMMAND, %IDM_EXI10, 0
        
              CASE %SC_MINIMIZE
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "WM_SYSCOMMAND - Minimize." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  PostMessage hWndMain, %WM_COMMAND, %ID_Minimize, 0
        
              CASE %SC_RESTORE
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                      "xBot is restoring to normal." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  giCaptionBar = 99 '99=Unknown state if Titlebar
                  ShowWindow hWndMain, %SW_NORMAL
          END SELECT
        END SUB
        
        
        '_________________________________________________________________
        '
        '   SUB  TimerCommand                                         xBot
        '_________________________________________________________________
        
        SUB TimerCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          'Not used for anything. Not dependable enough.
        
          'WM_SETCURSOR has higher priority than a timer.
          'A timer will not get refreshed until the mouse cursor stops
          'moving.
        
        END SUB
        
        '_________________________________________________________________
        '
        '   FUNCTION  CheckForMutex                                   xBot
        '_________________________________________________________________
        
        FUNCTION CheckForMutex(MutexName AS ASCIIZ, hMutex AS DWORD) AS LONG
         LOCAL hWin, hForWnd  AS DWORD
         LOCAL ThisID, ForeID AS LONG
         LOCAL fwi            AS FLASHWINFO 'FlashWindowApi        ' FLASHWINFO structure
        
          hMutex = CreateMutex(BYVAL %NULL, 0, MutexName)
          IF hMutex = %NULL THEN FUNCTION = 0 : EXIT FUNCTION      ' Failed to create mutex
        
          IF GetLastError = %ERROR_ALREADY_EXISTS THEN             ' App already running!
            hWin = FindWindowEx (%NULL, %NULL, "MobileApp", "xBot")    ' Find handle of program's window
        
            IF hWin THEN                                           ' Bring window into view
              fwi.cbSize    = SIZEOF(fwi)
              fwi.hwnd      = hWin
              fwi.dwFlags   = %FLASHW_ALL
              fwi.uCount    = 5
              fwi.dwTimeout = 40
              FlashWindowEx fwi
        
              ThisID = GetCurrentThreadID()                        ' Get this thread ID
              'hForWnd = GetForegroundWindow                       ' Get Thread ID of current foreground window
        
              ForeID = GetWindowThreadProcessID(GetForeGroundWindow, 0)
              AttachThreadInput(ThisID, ForeID, %TRUE)             ' Attach / share the current foreground thread input states
              SetForegroundWindow hWin                             ' Set our window to foreground window (OLD METHOD)
              AttachThreadInput(ThisID, ForeID, %FALSE)            ' Detach sharing
              'ShowWindow(hWin, %SW_RESTORE)                       ' Restore in case minimized
              ShowWindow hWin, %SW_NORMAL
        
            END IF
            FUNCTION = 1 : EXIT FUNCTION
          END IF
        
        END FUNCTION
        
        
        '_________________________________________________________________
        '
        '   SUB  GWForceSetForegroundWindow
        '_________________________________________________________________
        
        SUB GWForceSetForegroundWindow (BYVAL hwnd AS DWORD)   ' Add COMMON if needed in SLL
            ' V1.0
            ' ========================================================================================
            ' Replacement for the SetForegroundWindow API function. Thanks to Jose Roca.
            ' Changes by GV: Do loop added. No action, if hwnd is in focus.
            ' ========================================================================================
        
            LOCAL hFg, dwThreadId, dwProcessId, dwCurThreadId AS DWORD
        
                hFg = GetForegroundWindow
        
            IF hFg <> hwnd THEN
                dwThreadId = GetWindowThreadProcessId(hFg, dwProcessId)
                dwCurThreadId = GetCurrentThreadId
                AttachThreadInput(dwCurThreadId, dwThreadId, %TRUE)
                SetForegroundWindow(hwnd)
                BringWindowToTop(hwnd)
                SetFocus(hwnd)
                AttachThreadInput(dwCurThreadId, dwThreadId, %FALSE)
            END IF
        
        END SUB
        
        
        '_________________________________________________________________
        '
        '   SUB  SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR                xBot
        '_________________________________________________________________
        
        SUB SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
          LOCAL CenterPoint AS POINT   'in screen coordinates
        
          GetWindowRect hWndMain, rcMainSub       'app rect in screen coordinates
        
          CenterPoint.x = (rcMainSub.nRight - rcMainSub.nLeft)/ 2 + rcMainSub.nLeft
          CenterPoint.y = (22)/ 2 + rcMainSub.nTop
        
          SetCursorPos CenterPoint.x, CenterPoint.y
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  StartActivation                                      xBot
        '_________________________________________________________________
        
        SUB StartActivation
          ACTIVATEAPP = "ACTIVATION"           '=A
          NCACTIVATE =  ""                     '=A
          ACTIVATE =    ""                     '=A
          giActivationComplete = 0
          giDeactivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  ActivationStep2                                      xBot
        '_________________________________________________________________
        
        SUB ActivationStep2
          NCACTIVATE =  "ACTIVE TITLEBAR"      '=B
          giActivationComplete = 0
          giDeactivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  ActivationStep3                                      xBot
        '_________________________________________________________________
        
        SUB ActivationStep3
          NCACTIVATE =  "ACTIVE TITLEBAR"      '=B
          giActivationComplete = 0
          giDeactivationComplete = 0
          CALL CLEAR_MOUSE_TOGGLE
        
          IF giView <> 0 THEN
              gsCmdMessages = _ gsCmdMessages + _
              "Activation from Taskbar Icon." + $CRLF + $CRLF + _
              gsCmdMessages
              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
          END IF
        
        END SUB
        
        
        '_________________________________________________________________
        '
        '   SUB  EndActivation                                        xBot
        '_________________________________________________________________
        
        SUB EndActivation
          ACTIVATE =    "ACTIVE DIALOG"        '=C
        
          IF ACTIVATEAPP = "ACTIVATION" AND _
             NCACTIVATE =  "ACTIVE TITLEBAR" AND _
             ACTIVATE =    "ACTIVE DIALOG" THEN
              giActivationComplete = 1
        
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  $CRLF + "Activation Completed." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
        
              CALL Captionbar0
        
          END IF
          giDeactivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  StartDeactivation                                    xBot
        '_________________________________________________________________
        
        SUB StartDeactivation
          NCACTIVATE =  "INACTIVE TITLEBAR"    '=D
          ACTIVATE =    ""                     '=D
          ACTIVATEAPP = ""                     '=D
          giDeactivationComplete = 0
          giActivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  DeactivationStep2                                    xBot
        '_________________________________________________________________
        
        SUB DeactivationStep2
          ACTIVATE =    "DEACTIVATE DIALOG"    '=E
          giDeactivationComplete = 0
          giActivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  EndDeactivation                                      xBot
        '_________________________________________________________________
        
        SUB EndDeactivation
          ACTIVATEAPP = "DEACTIVATION"         '=F
        
          IF NCACTIVATE =  "INACTIVE TITLEBAR" AND _
             ACTIVATE =    "DEACTIVATE DIALOG" AND _
             ACTIVATEAPP = "DEACTIVATION" THEN
              giDeactivationComplete = 1
        
              IF giView <> 0 THEN
                  gsCmdMessages = _ gsCmdMessages + _
                  $CRLF + _
                  "Deactivation Completed." + $CRLF + _
                  gsCmdMessages
                  CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
              END IF
              CALL Captionbar1
          END IF
          giActivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  CLEAR_DEACTIVATION    not used                       xBot
        '_________________________________________________________________
        
        SUB CLEAR_DEACTIVATION
          NCACTIVATE =  ""
          ACTIVATE =    ""
          ACTIVATEAPP = ""
          giDeactivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  CLEAR_ACTIVATION      not used                       xBot
        '_________________________________________________________________
        
        SUB CLEAR_ACTIVATION
          ACTIVATEAPP = ""
          NCACTIVATE =  ""
          ACTIVATE =    ""
          giActivationComplete = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  CLEAR_MOUSE_TOGGLE                                   xBot
        '_________________________________________________________________
        
        SUB CLEAR_MOUSE_TOGGLE
          giRightMouseButtonDown = 0
          giRightMouseToggled = 0
          giLeftMouseButtonDown = 0
          giLeftMouseToggled = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  RIGHT_MOUSE_PRESSED                                  xBot
        '_________________________________________________________________
        
        SUB RIGHT_MOUSE_PRESSED
          giRightMouseButtonDown = 1
          giLeftMouseButtonDown = 0
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  LEFT_MOUSE_PRESSED                                   xBot
        '_________________________________________________________________
        
        SUB LEFT_MOUSE_PRESSED
          giRightMouseButtonDown = 0
          giLeftMouseButtonDown = 1
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  ChooseCommand                                        xBot
        '_________________________________________________________________
        
        SUB ChooseCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          SELECT CASE LO(WORD,wParamX)
        
              CASE %ID_CaptureIconRect
                  GetWindowMinimizeRect(hWndMain, WindowMinimizeRect)
                  IF giView <> 0 THEN
                      gsCmdMessages = _ gsCmdMessages + _
                             $CRLF + _
                             "Taskbar Icon Size:" + $CRLF + _
                             " L=" + STR$(WindowMinimizeRect.nLeft)  + _
                             ", T=" + STR$(WindowMinimizeRect.nTop)   + _
                             ", R=" + STR$(WindowMinimizeRect.nRight) + _
                             ", B=" + STR$(WindowMinimizeRect.nBottom)+ $CRLF + _
                             gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
        
              CASE %IDC_Reset    'reset messages
                  SELECT CASE HI(WORD, wParamX)
                      CASE %BN_CLICKED
                          IF giView <> 0 THEN
                              gsCmdMessages = ""
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                  END SELECT
        
              CASE %IDC_Show      'show all messages
                  SELECT CASE HI(WORD, wParamX)
                      CASE %BN_CLICKED
                          gsCmdMessages = $CRLF + "Now ready to show messages." + $CRLF + _
                          "NOTE: " + $CRLF + _
                          "The newest messages will be listed first."
                          CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          giView = NOT giView    'values are 0=False and -1=True
                          IF giView = 0 THEN
                              gsCmdMessages = InitialMessage
                              CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                          END IF
                  END SELECT
        
              CASE %ID_Minimize
                  CALL MINIMIZE_DIALOG
        
              CASE %ID_Move
                  CALL SET_MOUSE_AT_CENTER_POINT_OF_TITLEBAR
                  'change mouse cursor for hCaptionBar to move cursor
                  'and enable mouse tracking
                  giMoving = 1
                  giShowMoveCursor = 1
                  giShowArrowCursor = 0
                  SELECT_MOUSE_CURSOR
                  SetFocus GetDlgItem(hWndMain, %ID_TITLEBAR1)
        
              CASE %IDM_EXI10, %IDCANCEL
                  SELECT CASE HI(WORD, wParamX)
                      CASE %BN_CLICKED
                          giCloseDialog = 1
                          CALL MINIMIZE_DIALOG
                  END SELECT
        
          END SELECT
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Captionbar0                                          xBot
        '_________________________________________________________________
        
        SUB Captionbar0
          IF giCaptionBar <> 0 THEN
        
              giActiveTitlebar = 1
              giAppLostFocus = 0
        
              IF giHasCaption = 1 THEN
                  IF giView <> 0 THEN
                      gsCmdMessages = "Dialog is active." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA0)
                  SetLayeredWindowAttributes(hCaptionBar, RGB(0, 96, 128), 255, %LWA_Colorkey)  '%LWA_ALPHA OR
              END IF
              giCaptionBar = 0
          END IF
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Captionbar1                                          xBot
        '_________________________________________________________________
        
        SUB Captionbar1
          IF giCaptionBar <> 1 THEN
        
              giActiveTitlebar = 0
              giAppLostFocus = 1
        
              IF giHasCaption = 1 THEN
                  IF giView <> 0 THEN
                      gsCmdMessages = "Dialog is inactive." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA1)
                  SetLayeredWindowAttributes(hCaptionBar, RGB(0, 96, 128), 255, %LWA_Colorkey)  '%LWA_ALPHA OR
              END IF
              giCaptionBar = 1
          END IF
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Captionbar2                                          xBot
        '_________________________________________________________________
        
        SUB Captionbar2
          IF giCaptionBar <> 2 THEN
              IF giHasCaption = 1 THEN
                  IF giView <> 0 THEN
                      gsCmdMessages = "Minimize highlighted." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA2)
                  SetLayeredWindowAttributes(hCaptionBar, RGB(0, 96, 128), 255, %LWA_Colorkey)  '%LWA_ALPHA OR
              END IF
              giCaptionBar = 2
          END IF
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Captionbar3                                          xBot
        '_________________________________________________________________
        
        SUB Captionbar3
          IF giCaptionBar <> 3 THEN
              IF giHasCaption = 1 THEN
                  IF giView <> 0 THEN
                      gsCmdMessages = "Close highlighted." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA3)
                  SetLayeredWindowAttributes(hCaptionBar, RGB(0, 96, 128), 255, %LWA_Colorkey)  '%LWA_ALPHA OR
              END IF
              giCaptionBar = 3
          END IF
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Captionbar4                                          xBot
        '_________________________________________________________________
        
        SUB Captionbar4
          IF giCaptionBar <> 4 THEN
              IF giHasCaption = 1 THEN
                  IF giView <> 0 THEN
                      gsCmdMessages = "Gray bar and Minimize highlighted." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA4)
                  SetLayeredWindowAttributes(hCaptionBar, RGB(0, 96, 128), 255, %LWA_Colorkey)  '%LWA_ALPHA OR
              END IF
              giCaptionBar = 4
          END IF
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Captionbar5                                          xBot
        '_________________________________________________________________
        
        SUB Captionbar5
          IF giCaptionBar <> 5 THEN
              IF giHasCaption = 1 THEN
                  IF giView <> 0 THEN
                      gsCmdMessages = "Gray bar and Close highlighted." + $CRLF + _
                      gsCmdMessages
                      CONTROL SET TEXT hWndMain, %ID_IDNOTE2, gsCmdMessages
                  END IF
                  SendDlgItemMessage(hWndMain, %ID_CAPTIONBAR, %STM_SETIMAGE, %IMAGE_BITMAP, ghBmpNCA5)
                  SetLayeredWindowAttributes(hCaptionBar, RGB(0, 96, 128), 255, %LWA_Colorkey)  '%LWA_ALPHA OR
              END IF
              giCaptionBar = 5
          END IF
        END SUB
        
        '_________________________________________________________________
        
        ' SUB  RedrawTransparentControl   NOT CURRENTLY USED
        '_________________________________________________________________
        
        SUB RedrawTransparentControl(hWin AS DWORD, hControl AS DWORD, sText AS STRING)
          'used for refreshing a %WS_EX_TRANSPARENT static control (label) on a gradient screen
          'like these:
          'addLabelT
          'addLabelTLFont
          'addClickLabel
        
          'EX: RedrawTransparentControl(hWnd, hLab, "This is the new text for the control")
          'OR
          'EX: RedrawTransparentControl(hWnd, hLab, "")
        
          LOCAL ControlRec AS RECT
        
          GetClientRect(hControl, ControlRec)
          MapWindowPoints(hControl, hWin, BYVAL VARPTR(ControlRec), 2)
          RedrawWindow(hWin, ControlRec, %NULL, %RDW_ERASE OR %RDW_INVALIDATE)
          SetWindowText(hControl, (sText))
        
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Redraw_Off                                           xBot
        '_________________________________________________________________
        
        SUB Redraw_Off(hCtrl AS LONG)
          SendMessage hCtrl, %WM_SETREDRAW, %FALSE, 0&
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  Redraw_On                                            xBot
        '_________________________________________________________________
        
        SUB Redraw_On(hCtrl AS LONG)
          SendMessage hCtrl, %WM_SETREDRAW, %TRUE, 0&
          UpdateWindow hCtrl
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  MoveCommand                                          xBot
        '_________________________________________________________________
        
        SUB MoveCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          'Resets the upper left corner of the dialog when the dialog is moved
          'this is important to consider for mouse pointer placement on the moved dialog
          giLeft = LO(WORD, lParamX)
          giTop = HI(WORD, lParamX)
        
          IF giAppIsMinimized = 0 AND IsWindowEnabled(hWndMain) AND giOnDialog = 1 THEN
              'do not redraw screen when moving application unless the moving
              'is done by the Minimize button
              'IF gsNewScreen <> "SleepTimer" then
                  CALL Redraw_Off(hWndMain)
              'end if
          END IF
        
          'NOTE: removed all Layered graphics which
          'lose the top layer when the dialog is moved around
        
          'call SHOW_NOTES_NO_WAIT("Window pos: " & FORMAT$(giLeft) & " x " & FORMAT$(giTop))
        
        END SUB
        
        '_________________________________________________________________
        '
        '   SUB  ExitSizeMoveCommand                                  xBot
        '_________________________________________________________________
        
        SUB ExitSizeMoveCommand(BYVAL wParamX AS LONG, BYVAL lParamX AS LONG)
          CALL Redraw_On(hWndMain)
        END SUB
        
        
        '******************************************************************************
        'The End
        '******************************************************************************

        Comment


        • #5
          xBot Version 4

          Click image for larger version  Name:	xBot4.jpg Views:	1 Size:	46.5 KB ID:	776565

          'Version 4 26 NOV 2018
          'Added bitmap image background.
          'Added 3D look to titlebar.
          'Added owner drawn buttons.

          xBot4.zip
          Attached Files

          Comment


          • #6
            xBot Version 5

            Click image for larger version

Name:	xBot5.jpg
Views:	1
Size:	38.0 KB
ID:	776584



            xBot5.zip

            'Added Rebar Toolbar.
            'Removed 3D buttons.
            'Changed Background to solid color.
            'Changed Marquee color to match Titlebar.

            Comment


            • #7
              xBot Version 6

              Click image for larger version

Name:	xBot6.jpg
Views:	1
Size:	33.0 KB
ID:	776610



              xBot6.zip

              'Added color changes for background, titlebar, and toolbar.
              'Use Next Color to select a color theme. 5 Colors available.
              'giHasCaption no longer changes titlebar visibility.
              'Titlebar is always shown now.

              Comment


              • #8
                xBot Version 7

                Click image for larger version

Name:	xBot7.jpg
Views:	1
Size:	37.1 KB
ID:	776654

                ' Automatic detection of microphone.
                ' Added Speech recognition with Jarvis Speech grammar.

                xBot7.zip

                Comment


                • #9
                  xBot Version 8

                  Click image for larger version

Name:	xBot8.jpg
Views:	1
Size:	29.1 KB
ID:	776879


                  ' Added Peak Meter for micophone. It is part of the Marquee now.
                  ' Added some conversational phrases to jarvis grammar.
                  ' Custom Tooltip on Titlebar for Minimize and Close buttons.
                  ' Added small DropShadow to app.
                  ' Added Auto Focus Technology. My favorite.
                  ' See: CHECK_WINDOW_ENUMERATION
                  ' If you chose you can rem it out. No harm no foul.
                  ' Why click on your app to give it focus when all you have to do is
                  ' point at it?
                  ' Added hand cursor for toolbar buttons and Marquee labels.

                  xBot8.zip

                  Comment


                  • #10
                    Note:
                    There is a minor issue with Autofocus.inc. Will be updated on the next version.

                    Comment

                    Working...
                    X