Announcement

Collapse
No announcement yet.

HotKey question

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

  • HotKey question

    greetings,

    in this source code forum post: http://www.powerbasic.com/support/pb...ad.php?t=22653 semen shows how to use alt-f10 as a windows hotkey. does anyone know how to modify this to use other control keys such as control-d, or control-m.......? i tried 4& (for ctrl-d) unsuccessfully. thanks,

    ken

  • #2
    RegisterHotKey CbHndl, nAtom, 0, Asc("D") ' D
    RegisterHotKey CbHndl, nAtom, 1, Asc("D") ' Alt-D
    RegisterHotKey CbHndl, nAtom, 2, Asc("D") ' Ctrl-D
    RegisterHotKey CbHndl, nAtom, 4, Asc("D") ' Shift-D
    RegisterHotKey CbHndl, nAtom, 1 + 2, Asc("D") ' Ctrl-Alt-D

    ------------------

    Comment


    • #3
      Semen:

      WOW !!!
      What -fast- service ! Thanks very much.

      - ken

      ------------------

      Comment


      • #4
        Semen, Lance, Eric, whomever.
        This type of question may have been answered in a previous post
        and I just didn't understand but here goes.

        I have a menu program made with pbdll6.0
        It's merely a modal dialog with buttons. (not using menu
        statments just control add button - etc).
        Some of the buttons use hot keys - "E&xit" for examplt for
        Alt-x to exit the program.

        Now, the menu works fine, the hot keys all work with one
        excepttion. If you have just started the program and have
        not chosen to do anything (click a button), then the hot keys
        either do not work or do something else i.e. call up one of
        the other options that does not have a hot key for it.

        Now, once you've done something, seems it doesnt matter what
        you choose to do, then the hot keys work just as they are supposed
        to, Alt-x asks if you want to exit (as it's programmed to do)
        for example.

        It's no big deal really just wondered why it does that.
        Here is a snippet of what i am doing

        function winmain....
        .
        .
        dialog new ....
        .
        control add button ....
        .
        dialog show modal hdlg, call propcallback
        .
        callback function propcallback
        CID&=CBCTL
        SELECT CASE cid&

        CASE 11
        .
        case %Xit
        xit=MSGBOX ("Are You Sure ?",4 OR %MB_ICONQUESTION,"Exit Client Writeup")
        if xit=6 then
        close
        DIALOG END CBHNDL, 0
        end if
        end select
        end function



        ------------------
        Client Writeup for the CPA

        buffs.proboards2.com

        Links Page

        Comment


        • #5
          It sounds like you are not testing for the %WM_COMMAND message before testing the value in CBCTL.

          ie:
          Code:
          CALLBACK FUNCTION DlgCallback
            IF CBMSG <> %WM_COMMAND THEN EXIT FUNCTION
            SELECT CASE CBCTL
              CASE %ID_BUTTON1
                IF CBCTLMSG = %BN_CLICKED THEN
                  MSGBOX "A control was clicked!"
                  FUNCTION = 1 ' signal we handled the message
                END IF
              CASE %ID_BUTTON2
                ...
            END SELECT
          END FUNCTION
          Essentially, never just assume that you are processing a %WM_COMMAND message, and that the actual notification message is in response to a "click"... always explicitly test for that set of circumstances.

          In the above example, the MSGBOX statement is only executed if CBMSG = %WM_COMMAND and CBCTLMSG = %BN_CLICKED and CBCTL = <the control ID value>.

          Clear as mud?


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            Should note that RegisterHotKey have nothing common with accelerators.

            RegisterHotKey is global and sends certain message to it's owner.
            Windows, for example, uses this API function for shortcuts.


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

            Comment


            • #7
              Thanks again Lance I'll do that. Im sure you are exactly right.


              ------------------
              Client Writeup for the CPA

              buffs.proboards2.com

              Links Page

              Comment


              • #8
                After putting in the line
                IF CBMSG <> %WM_COMMAND THEN EXIT FUNCTION
                in the callback that stopped it from going to other things
                rather than the correct one when the menu is initially called
                up. It, however, also stopped it from doing anything until
                an option was accessed so here it what I did.
                Before the above line i put in,
                if CBMSG=%WM_SYSKEYDOWN then
                select case CBCTL
                case 66 'Alt+B
                dowhatever
                case 67 'Alt+C
                end select
                end if
                That fixed it both ways. now all works as it should

                BTW how do I get it to indent on the forum here (looks like a
                <PRE> html coding is used) but it always tells me html is
                turned off so can i use it anyway ?




                ------------------
                Client Writeup for the CPA

                buffs.proboards2.com

                Links Page

                Comment


                • #9
                  Fred,

                  Just put CODE inside of square brackets [] before your code,
                  and /CODE in square brackets after it, so that it will look this way...

                  Code:
                  if CBMSG=%WM_SYSKEYDOWN then
                    select case CBCTL
                       case 66 'Alt+B
                          dowhatever
                       case 67 'Alt+C
                    end select
                  end if

                  ------------------


                  [This message has been edited by Charles Dietz (edited October 14, 2000).]

                  Comment


                  • #10
                    BBS message formatting options: http://www.powerbasic.com/support/forums/ubbcode.html

                    ------------------
                    Lance
                    PowerBASIC Support
                    mailto:[email protected][email protected]</A>
                    Lance
                    mailto:[email protected]

                    Comment


                    • #11
                      Thanks

                      ------------------
                      Client Writeup for the CPA

                      buffs.proboards2.com

                      Links Page

                      Comment

                      Working...
                      X