ok. for use menu shorcuts i must create a table accelerator and change my message loop. but can i process the table accelerator without use the HWND?

Recommended Answers

All 4 Replies

No. All (normal) messages go to a window event handler.

The functions you write to handle events can, of course, be as window agnostic as you like.

commented: thanks +3

by several reasons i'm doing my own table accelerator code ;)
thanks for all
(after finish, i will show the code)

i need ask 1 thing:

//Message Loop
WPARAM MessageLoop()
{
    MSG msgEvents;
    while(GetMessage(&msgEvents, NULL, 0, 0) > 0)
    {
        if(IsChild(GetForegroundWindow(),msgEvents.hwnd)==TRUE || GetForegroundWindow()==msgEvents.hwnd)
        {
            if(IsDialogMessage(GetForegroundWindow(), &msgEvents) == TRUE)
            {
                 TranslateMessage(&msgEvents);
                 DispatchMessage(&msgEvents);
            }
        }
    }
    return msgEvents.wParam;
}

how the IsDialogMessage() can affect the Alt key?
i need use the IsDialogMessage() function for work with keyboard(when we have the child controls), but can affect the Alt key:
1 - press the Alt key: the underline, on menu(the menubar items), is showed;
2 - unpress the Alt key: the underline isn't showed.
why these behavor?

now it's working nice ;)
i did a diferent tool for make menu shortcuts and works fine:

struct MenuShortCuts
{
    //inicializate structure values
    MenuShortCuts() : MenuPointer(NULL), key(-1), alt(false), control(false), shift(false) {}
    ULONG_PTR MenuPointer;
    char  key;
    bool alt;
    bool control;
    bool shift;
};

vector<MenuShortCuts>  TableMenuShortCuts;//global variable

//on my class menus, after show the menus:
//detetcting the shortcut from caption
        String b=UpperCase(strCaption);//is like the normal string, but have the separewordssymbols() and more functions
        vector<string> c;
        bool HasShortCut=false;
        c=b.separewordssymbols();//geting the string separed by '\t' and words

        //testing if the caption have '\t' for use the menus shortcuts
        for(int i=(c.size()-1); i>0; i--)
        {
            if(c[i] =="\t")
            {
                HasShortCut=true;
                break;
            }
        }
        if(HasShortCut==true)
        {
            TableMenuShortCuts.resize(TableMenuShortCuts.size()+1);//have more 1 menu, then more 1 shortcut on list
            TableMenuShortCuts[TableMenuShortCuts.size()-1].MenuPointer=(ULONG_PTR)this; 
            TableMenuShortCuts[TableMenuShortCuts.size()-1].key=(c[c.size()-1])[0]; //recives the 1st letter form right
            //testing the control/alt/shit keys
            for(int i=(c.size()-1); i>0; i--)
            {
                if(c[i] =="CTRL")
                {
                    TableMenuShortCuts[TableMenuShortCuts.size()-1].control=true;
                }
                else if(c[i] =="ALT")
                {
                    TableMenuShortCuts[TableMenuShortCuts.size()-1].alt=true;
                }

                else if(c[i] =="SHIFT")
                {
                    TableMenuShortCuts[TableMenuShortCuts.size()-1].shift=true;
                }
                else if(c[i] =="\t")
                    break;
            }
        }
 //window procedure:
 case WM_KEYUP:
                {
                    int a=TableMenuShortCuts.size();

                    for(int i=0; i<a;i++ )
                    {
                        if(keyboard[TableMenuShortCuts[i].key]==true &&(keyboard[VK_CONTROL]==TableMenuShortCuts[i].control)&&(keyboard[VK_SHIFT]==TableMenuShortCuts[i].shift) &&(keyboard[VK_MENU]==TableMenuShortCuts[i].alt))
                        {
                            Menu *mMenu = (Menu *)TableMenuShortCuts[i].MenuPointer;
                            if (mMenu!=NULL)
                            {
                                mMenu->Click();
                            }
                        }

                    }
                    KeyPressed=false;
                    inst->KeyUp(keyboard,KeyDownCount);
                    return DefWindowProc(HandleWindow, msg, wParam, lParam);
                }
                break;

it's a nice way for do the menu shortcuts ;)
i was getting problems with AcceleratorTable functions for my situation ;)

readers: please, i did that mistake with Alt key and now i know why, never forget when the windows messages needs return a value.
WM_KEYUP: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646281%28v=vs.85%29.aspx

"An application should return zero if it processes this message."
ok i did in a diferent way, but i accept new information ;)
thanks for all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.