0

Hello! I believe hotkeys or keyboard shortcuts is the correct term. (Ctrl+C is copy etc...) Well I'm having troubles trying to figure out how to do this. I'm very new to the win32 api and such And I'm just clueless. Any help is very much appreciated!

2
Contributors
1
Reply
6
Views
4 Years
Discussion Span
Last Post by dx9_programmer
0

I suggest you reading about keyboard accelerators here on MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646337%28v=vs.85%29.aspx

Keyboard accelerators is an easier way to handle combinations of keystrokss like Ctrl+Z or Ctrl+C

You define the accelerators in your resource file, assign a hotkey and give it a unique name.

// In your code, declare a handle to an accelerator table
HACCEL hAccelTable;

// Load the accelerators in your program with LoadAccelerators() function
hAccelTable = LoadAccelerators(HINSTANCE, MAKEINTRESOURCE(ACCELERATOR_RESOURCE_ID))

// Handle accelerators in a special way with TranslateAccelerator() function
while (GetMessage(&msg, NULL, 0, 0) > 0) 
{
    if (!TranslateAccelerator(msg.hwnd, CWinBase::hAccelTable, &msg))
    {
        TranslateMessage(&msg); // Convert virutal key codes to character.
        DispatchMessage(&msg);  // Passes message to window procedure.
    }
}

// Process the accelerators in your window procedure under the WM_COMMAND id
// Respond to accelerator events.
case WM_COMMAND:
{
    int accel_id = LOWORD(wParam);

    switch (accel_id) {
        case ID_EDIT_UNDO:    // Ctrl+Z
            // Undo an action
            break;

        case ID_EDIT_REDO:    // Ctrl+Y
            // Redo an action
        break;
    }
break;
}

Edited by dx9_programmer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.