Solved

Dynamicly add accelerator keys to dynamic menu items

Posted on 2002-07-01
6
481 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
Industry Leaders: 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
child constructor and parent constructor, overriding and overloading 6 93
MaxSpan challenge 9 138
ERP and the other system process verification 5 25
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

737 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