Solved

Dynamicly add accelerator keys to dynamic menu items

Posted on 2002-07-01
6
491 Views
Last Modified: 2013-11-20
I cannot find a way to add new accelerator keys at run time.

I have a dynamic menu and i would like to assign accelerator keys to some of it's items.

So far i managed to Count the number of entries in the current table, allocate a buffer for the table, and then copy the table into the buffer.

HOWEVER, there is no function that will add new accelerator keys to the table.

I've using the 'Creating User-Editable Accelerators' article from the MSDN as a reference.


0
Comment
Question by:Michal080800
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
migel earned 300 total points
ID: 7121364
Hi!
show your code please:
// modified code from the article, mentoned above
{
///
                    haccelOld = haccel;
 
                    // Count the number of entries in the current
                    // table, allocate a buffer for the table, and
                    // then copy the table into the buffer.
 
                    cAccelerators = CopyAcceleratorTable(
                        haccelOld, NULL, 0);
// adding new accelerator
// !!!! note +1
                    lpaccelNew = (LPACCEL) LocalAlloc(LPTR, (cAccelerators+1)*sizeof(ACCEL));
 
                    if (lpaccelNew != NULL)
                    {
                        CopyAcceleratorTable(haccel, lpaccelNew,
                            cAccelerators);
                    }

// !!! add your own accelerator at the table end
                    lpaccelNew[cAccelerators].fVirt = fAccelFlags;
                    lpaccelNew[cAccelerators].key = wVKCode;
 
                    // Create the new accelerator table, and
                    // destroy the old one.
 
                    DestroyAcceleratorTable(haccelOld);
// !!! note +1
                    haccel = CreateAcceleratorTable(lpaccelNew, cAccelerators+1);
///
}
0
 

Author Comment

by:Michal080800
ID: 7121369
Thanks for the quick response.

I'll try this now.

0
 

Author Comment

by:Michal080800
ID: 7121393
Hi Migel,

How do i compute the value of wVKCode.

For example i want to add an accelerator Ctrl+F to a menu item.
The fAccelFlags is easily computed, but i'm not sure how to compute the wVKCode for the 'F' char.

(btw, i've increased the points for this question as you have been so helpful and i am very greatful).

Thanks,

Michal.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Michal080800
ID: 7121398
Hi Migel,

How do i compute the value of wVKCode.

For example i want to add an accelerator Ctrl+F to a menu item.
The fAccelFlags is easily computed, but i'm not sure how to compute the wVKCode for the 'F' char.

(btw, i've increased the points for this question as you have been so helpful and i am very greatful).

Thanks,

Michal.
0
 
LVL 12

Expert Comment

by:migel
ID: 7121496
Hi!
you can use virtual key codes

/* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
/* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
and set FVIRTKEY flag in the fVirt field;
or use just character code 'F'
0
 

Author Comment

by:Michal080800
ID: 7121498
Thank you very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question