Solved

Dynamicly add accelerator keys to dynamic menu items

Posted on 2002-07-01
6
451 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
Comment Utility
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
Comment Utility
Thanks for the quick response.

I'll try this now.

0
 

Author Comment

by:Michal080800
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Michal080800
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now