IonicWind Software

IWBasic => General Questions => Topic started by: Andy on April 05, 2020, 03:49:29 AM

Title: Accelerator question
Post by: Andy on April 05, 2020, 03:49:29 AM
Obviously I'm doing something wrong here, I can't get my program to respond to a Ctrl + C key press.

The menu is a context (right click menu), and works fine when selecting an option with the mouse, but not the keyboard.

The code here is in a sub classed rich edit control.

    case WM_RBUTTONDOWN
          POINT cursor2
          GetCursorPos(cursor2)
          ScreenToClient(w1.hwnd, cursor2)
          CONTEXTMENU w1,cursor2.x, cursor2.y
                      MENUITEM "Cut",0,201
                      MENUITEM "Copy",0,202
          ENDMENU

          ADDACCELERATOR w1,@FCONTROL|@FVIRTKEY,ASC("C"),202

Tried adding in the @FSHIFT option but still nothing...

Help any one!

Thanks,
Andy.
Title: Re: Accelerator question
Post by: Andy on April 05, 2020, 04:27:05 AM
Got a work around,

In the rich edit sub class code I have:

case WM_KEYDOWN
     IF wParam = 17 'Crtl key
        crtl = 1
     ENDIF

And...

case WM_KEYUP
     IF crtl = 1 and wParam = 67 'C
        crtl = 0
        CopyStringToClipboard(CutLine)
     ENDIF

Is the problem because it's a context menu, or is it that the rich edit control is sub classed?

Thanks,
Andy.
Title: Re: Accelerator question
Post by: h3kt0r on April 08, 2020, 08:13:34 PM
Andy,

For your shortcut key to work correctly, you need a window menu (at the top).
Then you add your Menu accelerators.
After that, you can add your popup menu and map its entries to the corresponding entries in the top menu.
This means that the popup MENUITEM number (the last parameter) must match with the top level MENUITEM number.
If you don't want the top menu to be displayed in your window, you can hide it.
Title: Re: Accelerator question
Post by: Andy on April 09, 2020, 05:37:04 AM
Thanks Hecktor,

I will have a try with it today - much appreciated.

Andy.
Title: Re: Accelerator question
Post by: Andy on April 10, 2020, 04:12:10 AM
Yes, that's the solution.

Thanks very much.
Andy.