Solved

Dynamicly add accelerator keys to dynamic menu items

Posted on 2002-07-01
6
466 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 66
Macro to save highlighted rows as a separate file 5 43
string initialization in java 11 113
Work with App store 7 51
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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 a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

785 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