Announcement

Collapse
No announcement yet.

sending alt/key messages

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

    sending alt/key messages

    Does anyone know how to send a message to windows to force a
    menu pulldown? I have an external control panel (Rs-232) and
    want to make one of the buttons on it select one of the menus to
    pull down.

    Thanks,
    Russ Srole


    ------------------
    "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

    #2
    Russ,

    This isn't exactly what you asked for, but using a floating menu might
    be close enough for what you want. Anyway, it's the best I could do.

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.INC"
    
    GLOBAL hDlg AS LONG, hMenu AS LONG, hFileMenu AS LONG, hEditMenu AS LONG
    DECLARE SUB addMenu
    DECLARE SUB fileMenu
    DECLARE CALLBACK FUNCTION dlgProc() AS LONG
    
    FUNCTION PBMAIN() AS LONG
       LOCAL style AS LONG
       style = %WS_SYSMENU + %WS_MINIMIZEBOX
       DIALOG NEW 0, "Test", , , 200, 100, style TO hDlg
       addMenu
       CONTROL ADD BUTTON, hDlg, %IDOK, "&File", 5, 20, 90, 20
       CONTROL ADD BUTTON, hDlg, %IDCANCEL, "&Cancel", 5, 50, 90, 20
       DIALOG SHOW MODAL hDlg CALL dlgProc
    END FUNCTION
    
    CALLBACK FUNCTION dlgProc()
       LOCAL x AS LONG, y AS LONG
       SELECT CASE CBMSG
         CASE %WM_COMMAND
           SELECT CASE CBCTL
             CASE %IDOK
                fileMenu
             CASE %IDCANCEL
                DIALOG END CBHNDL
           END SELECT
         CASE %WM_DESTROY
       END SELECT
    END FUNCTION
    
    SUB addMenu()
       MENU NEW BAR TO hMenu
       MENU NEW POPUP TO hFileMenu '-----------------------------------
       MENU ADD STRING, hFileMenu, "&Open", 101, %MF_ENABLED
       MENU ADD STRING, hFileMenu, "&Save", 102, %MF_ENABLED
       MENU ADD STRING, hFileMenu, "Save&As", 103, %MF_ENABLED
       MENU ADD STRING, hFileMenu, "-", 0, 0
       MENU ADD STRING, hFileMenu, "E&xit", 104, %MF_ENABLED
       MENU ADD POPUP, hMenu, "&File", hFileMenu, %MF_ENABLED
       MENU NEW POPUP TO hEditMenu '-----------------------------------
       MENU ADD STRING, hEditMenu, "&Cut", 201, %MF_ENABLED
       MENU ADD STRING, hEditMenu, "&Copy", 202, %MF_ENABLED
       MENU ADD STRING, hEditMenu, "&Paste", 203, %MF_GRAYED
       MENU ADD STRING, hEditMenu, "-", 0, 0
       MENU ADD STRING, hEditMenu, "&Select all", 204, %MF_ENABLED
       MENU ADD POPUP, hMenu, "&Edit", hEditMenu, %MF_ENABLED
       MENU ATTACH hMenu, hDlg
    END SUB
    
    SUB fileMenu()
       LOCAL n AS LONG, x AS LONG, y AS LONG
       LOCAL pt AS POINTAPI
       pt.x = 0: pt.y = -1
       ClientToScreen hDlg, pt
       n = %TPM_RIGHTBUTTON + %TPM_LEFTALIGN
       TrackPopupMenuEx hFileMenu, 0, pt.x, pt.y, hDlg, BYVAL %NULL
    END SUB
    ------------------

    Comment


      #3
      You can imitate Alt-... by Keybd_Event.
      Code:
         #Compile Exe
         #Register None
         #Dim All
         #Include "Win32Api.INC"
      
         CallBack Function OkButton
            KeyBd_Event %VK_MENU, 0, 0, 0: Sleep 1
            KeyBd_Event &H52, 0, 0, 0: Sleep 1 ' R
            KeyBd_Event &H52, 0, %KEYEVENTF_KEYUP, 0: Sleep 1
            KeyBd_Event %VK_MENU, 0, %KEYEVENTF_KEYUP, 0: Sleep 1
         End Function
      
         Function PbMain
            Dim hDlg As Long, hMnu As Long, hmnuFile1 As Long, hmnuFile2 As Long
            Dialog New 0, "Menu Test", , , 110, 40, %WS_CAPTION Or %WS_SYSMENU To hDlg
            Control Add Button, hDlg, 101, "Press", 5, 5, 100, 15 Call OkButton
            Menu New Bar To hMnu
            Menu New Popup To hmnuFile1
            Menu Add String, hmnuFile1, "&Load", 1, %MF_ENABLED
            Menu Add String, hmnuFile1, "&Save", 2, %MF_ENABLED
            Menu Add Popup, hMnu, "&File", hmnuFile1, %MF_ENABLED
            Menu New Popup To hmnuFile2
            Menu Add String, hmnuFile2, "&Compile", 3, %MF_ENABLED
            Menu Add String, hmnuFile2, "&Debug", 4, %MF_ENABLED
            Menu Add Popup, hMnu, "&Run", hmnuFile2, %MF_ENABLED
            Menu Attach hMnu, hDlg
            Dialog Show Modal hDlg
         End Function


      ------------------
      E-MAIL: [email protected]

      Comment


        #4
        Thanks for the quick reply, guys. I'll give it a try.

        Russ

        ------------------
        "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

        Comment


          #5
          That works great. I had tried it before, but did not know
          that you have to do a press and release for each step of the
          way.

          Thanks again,
          Russ Srole

          ------------------
          "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎