C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 300,579 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,219 people online right now. Registration is fast and FREE... Join Now!




Get symbolic name of key combination code

 

Get symbolic name of key combination code, WinAPI

miksayer

2 Jul, 2009 - 01:42 PM
Post #1

New D.I.C Head
*

Joined: 2 Jul, 2009
Posts: 6

I want to get symbolic name of some key combination code(this key combination code i've got from hotkey control). How i can do it?

User is offlineProfile CardPM
+Quote Post


NickDMax

RE: Get Symbolic Name Of Key Combination Code

2 Jul, 2009 - 02:03 PM
Post #2

Can grep dead trees!
Group Icon

Joined: 18 Feb, 2007
Posts: 5,216



Thanked: 285 times
Dream Kudos: 1175
Expert In: Java/C++

My Contributions
Can you expand on what you mean... I think your talking about COM/ActiveX objects but I am not sure.
User is offlineProfile CardPM
+Quote Post

miksayer

RE: Get Symbolic Name Of Key Combination Code

2 Jul, 2009 - 11:36 PM
Post #3

New D.I.C Head
*

Joined: 2 Jul, 2009
Posts: 6

QUOTE(NickDMax @ 2 Jul, 2009 - 02:03 PM) *

Can you expand on what you mean... I think your talking about COM/ActiveX objects but I am not sure.

no, for example: i can get code of key combination from hotkey control using HKM_GETHOTKEY(for example, 577 for Ctrl+A). I want to get symbolic name of this key combination(for example, i want get from code "577" his name "Ctrl+A")
I know, that i can use API functions such as GetKeyNameText, MapVirtualKey, but i don't know how to do it.
User is offlineProfile CardPM
+Quote Post

miksayer

RE: Get Symbolic Name Of Key Combination Code

2 Jul, 2009 - 11:54 PM
Post #4

New D.I.C Head
*

Joined: 2 Jul, 2009
Posts: 6

i've got this functions from MFC, but i want to rewrite it using std::string(or std::wstring)
CODE

CString CHotKeyCtrl::GetKeyName(UINT vk, BOOL fExtended)
{
    LONG lScan = MapVirtualKey(vk, 0) << 16;

    // if it's an extended key, add the extended flag
    if (fExtended)
        lScan |= 0x01000000L;

    CString str;
    int nBufferLen = 64;
    int nLen;
    do
    {
        nBufferLen *= 2;
        LPTSTR psz = str.GetBufferSetLength(nBufferLen);
        nLen = ::GetKeyNameText(lScan, psz, nBufferLen + 1);
        str.ReleaseBuffer(nLen);
    }
    while (nLen == nBufferLen);
    return str;
}

CString CHotKeyCtrl::GetHotKeyName() const
{
    ASSERT(::IsWindow(m_hWnd));

    CString strKeyName;
    WORD wCode;
    WORD wModifiers;

    GetHotKey(wCode, wModifiers);
    if (wCode != 0 || wModifiers != 0)
    {
        if (wModifiers & HOTKEYF_CONTROL)
        {
            strKeyName += GetKeyName(VK_CONTROL, FALSE);
            strKeyName += szPlus;
        }

        if (wModifiers & HOTKEYF_SHIFT)
        {
            strKeyName += GetKeyName(VK_SHIFT, FALSE);
            strKeyName += szPlus;
        }

        if (wModifiers & HOTKEYF_ALT)
        {
            strKeyName += GetKeyName(VK_MENU, FALSE);
            strKeyName += szPlus;
        }

        strKeyName += GetKeyName(wCode, wModifiers & HOTKEYF_EXT);
    }

    return strKeyName;
}

but i can't rewrite it using std::string(in my program i use std::string instead CString), because i don't know std::string protypes for CString::GetBufferSetLength and CString::ReleaseBuffer

This post has been edited by miksayer: 3 Jul, 2009 - 12:15 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 11/8/09 08:20AM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month