Home > Net >  Winapi : How do I for my button send different message according to the key pressed?
Winapi : How do I for my button send different message according to the key pressed?

Time:12-23

I created button, that when clicked, open an .exe file and close the current application.

HWND Button= CreateWindowEx(0, L"Button", L"Exe Application, WS_BORDER | WS_VISIBLE | WS_CHILD, 500, 500, 200, 200, hWndParent, BUTTON_EXE, 0, 0); 

And in the WindProc :

switch (uMsg)
{

    case WM_COMMAND:
        switch (wParam)
        {
        case BUTTON_EXE:
            ShellExecute(hwnd, NULL, L"Module 1.exe", NULL, NULL, SW_SHOW);
            PostQuitMessage(0);
            return 0;
        }
    return 0;
}

I want that when you clicked the button with a key pressed (for exemple "maj"), the current application doesn't close.

So, I want that according to the key pressed when clicked the button, it send a different message, but I didn't find how. Is there a way to do that ? I apologize for my poor english.

CodePudding user response:

You can check whether a key is pressed while handling WM_COMMAND messages by calling the GetKeyState function. Depending on its return value you can then implement different logic.

It's important to call GetKeyState (as opposed to GetAsyncKeyState) to get the key state at the time the button was clicked.

CodePudding user response:

You can do additional processing of the message. For example:

  1. your button will sent another message (WM_BUTTON_EXE_RAW).
  2. you catch that message and resend other message (BUTTON_EXE) if button maj pressed only.
  • Related