Announcement

Collapse
No announcement yet.

Sending an ALT key notification to a Callback

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

  • Dave Biggs
    replied
    Hi Gösta,

    Glad that helped. I'm not at all sure the Sleeps are needed - seems to work without too.
    I think after all I prefer the option sugested by Semen in that thread that I posted a link for..
    Code:
    Dialog Post GetParent(hWnd), %WM_SYSCOMMAND, %SC_KEYMENU, %VK_H
    In the SubClassProc just works without needing the %WM_USER case processing in the Main Dialog. Always nice when Windows does the work for you

    Thanks for the wet wishes - it's been pretty dusty down-under of late

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Thanjs Dave. Got it working. And better yet, think I understand it.

    'In Subclass
    Code:
    '' F1 key pops up Help from Menu Bar
                Case 112: Reset Ctl_Flag:Dialog Post GetParent(hWnd), %WM_User + 501, 0, 0:Control Send hdlg, mnu_id(1, 1), %WM_COMMAND, 0, 0:Exit Function  'F1
    and in Main Callback
    Code:
      
         '***
         Case %WM_User + 501
             KeyBd_Event %VK_Menu, 0, 0, 0: Sleep 1: 'activate 
             KeyBd_Event %VK_H,    0, 0, 0: Sleep 1:
             KeyBd_Event %VK_H,    0, %KEYEVENTF_KEYUP, 0: Sleep 1 'deactivate i
             KeyBd_Event %VK_Menu, 0, %KEYEVENTF_KEYUP, 0: Sleep 1
    '>>>>>>>>> Important to deactivate - strange results otherwise - Been there ... yadayada
         '***
    Does exactly what I want (displays the Help instantly). Just curious, why the Sleeps?

    Thanks again, mate.

    ==============================================
    It's like breaking wind in a crowded room.
    You just never know who's going to get wafted.
    Swede
    ==============================================
    Last edited by Gösta H. Lovgren-2; 28 Sep 2009, 08:25 AM. Reason: Strangesness

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Runs (and Looks) exactly what I want, Dave. Thx. I'll try foding it into my program today. (Still not awake yet here on the other side of the world.) {sleepy grin}

    I wish you Rain, buddy.

    ===========================================
    "Fill the unforgiving minute
    with sixty seconds worth of distance run."
    Rudyard Kipling (1865-1936)
    ===========================================

    Leave a comment:


  • Dave Biggs
    replied
    Hi Gösta,

    This kind of does what you asked for - causes an ALT-H keyboard event in the main dialog from a notification in the SubClassProc..
    Code:
    #Dim All
    #Compile Exe
    #Include "WIN32API.INC"
     
    %BTN_OK   = 100
    %IDM_QUIT = 102
    '------------------/
     
    Function AttachMENU(ByVal hDlg As Dword) As Dword
     Local hMenu   As Dword
     Local hPopUp1 As Dword
      Menu New Bar To hMenu
       Menu New PopUp To hPopUp1
         Menu Add PopUp, hMenu, "&Hop it", hPopUp1, %MF_Enabled
         Menu Add String, hPopUp1, "Exit", %IDM_QUIT, %MF_Enabled
       Menu Attach hMenu, hDlg
     Function = hMenu
    End Function
    '------------------/AttachMenu
     
    Function SubClassProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
      Select Case wMsg
        Case %WM_KeyUp
          If wParam = %VK_Space Then
            WinBeep 400,100
            Dialog Post GetParent(hWnd), %WM_User + 501, 0, 0
          End If
        Case %WM_LButtonUp
          WinBeep 800,100
          Dialog Post GetParent(hWnd), %WM_User + 501, 0, 0
      End Select
     Function = CallWindowProc(GetProp (hWnd, "OldProc"), hWnd, wMsg, wParam, lParam)
    End Function
    '------------------/SubClassProc
     
    CallBack Function DlgProc() As Long
     Local hCtl As Dword
      Select Case CbMsg
        Case %WM_InitDialog
          hCtl = GetDlgItem(CbHndl, %BTN_OK)            ' change %IDC_CTLID to control ID
          SetProp (hCtl, "OldProc", SetWindowLong(hCtl, %GWL_WNDPROC, CodePtr(SubClassProc)))
        Case %WM_User + 501
          KeyBd_Event %VK_Menu, 0, 0, 0: Sleep 1
          KeyBd_Event %VK_H,    0, 0, 0: Sleep 1
          KeyBd_Event %VK_H,    0, %KEYEVENTF_KEYUP, 0: Sleep 1
          KeyBd_Event %VK_Menu, 0, %KEYEVENTF_KEYUP, 0: Sleep 1
        Case %WM_Command
          Select Case As Long CbCtl
            Case %IDM_QUIT
              Dialog End CbHndl, 1
          End Select
        Case %WM_Destroy
          SetWindowLong hCtl, %GWL_WNDPROC, GetProp(hCtl, "OldProc")      ' Remove subclassing and Prop
          RemoveProp (hCtl, "OldProc")
      End Select
    End Function
    '------------------/DlgProc
     
    Function PBMain() As Long
     Local hDlg As Dword
      Dialog New 0, "Test", , , 240, 150, %WS_Caption Or %WS_SysMenu, 0 To hDlg
        Control Add Button, hDlg, %BTN_OK, "Test", 85, 80, 50, 15
        AttachMENU hDlg
      Dialog Show Modal hDlg, Call DlgProc
    End Function
    '------------------/PBMain
    You might be looking for another way to send messages directly to the menu though?

    Later: Check out this thread: http://www.powerbasic.com/support/pb...ally#post44043

    (Use: Dialog Post GetParent(hWnd), %WM_SYSCOMMAND, %SC_KEYMENU, %VK_H )
    Last edited by Dave Biggs; 28 Sep 2009, 02:23 AM. Reason: There's more..!

    Leave a comment:


  • Sending an ALT key notification to a Callback

    I would like to send an Alt H to the main Callback from a subclassed Callback to trigger a File Bar menu. And I don't know how to do that. Can anyone give or point me to an *example*? I'm sure it's probably Control Send but I don't know what values to Send. I tried:

    Code:
     Control Send hdlg, mnu_id(1, 1), %WM_COMMAND, 0, 0
    but no cigar. Actually mnu(1,1) is an identifier for a submenu choice. All I really want to do is display the Menu, not trigger any submenu items.

    ===================================
    Faithless is he that says farewell
    when the road darkens.
    J. R. R. Tolkien (1892 - 1973)
    ===================================
Working...
X