|
Subject:
|
hot keys in C++
|
|
Posted By:
|
carl.dufresne@sita.aero
|
Post Date:
|
12/23/2005 12:19:51 PM
|
I wrote a C++ program using .NET that dynamically displays push buttons in a window by reading a list of shortcuts (.lnk files) in a specific folder. Clicking on these push buttons start the corresponding program linked to the shortcut.
I now need to implement hotkeys for each of them and I've had some problems.
I need to know how to implement hotkeys. I've been trying a combination of CHotKeyCtrl.Create() and RegisterHotKey(). My program compiles without errors but I just don't know if the controls I create are even good and how to capture the hotkeys.
I would like the 1st program to be listed in my array of CButton to start by pressing CTRL-1, the 2nd program with CTRL-2, and so on.
Any help would be appreciated. Carl
|
|
Reply By:
|
Ankur_Verma
|
Reply Date:
|
12/24/2005 3:07:28 PM
|
Hi Carl,
I presume that you are also catching WM_HOTKEY message and trying to start the programs listed in the file, identifying the hot key associated with the window for each program by its identity. Are you?
If you are then where you are facing the problem? If you want your code examined for problems, post your code also.
Regards Ankur Verma
|
|
Reply By:
|
carl.dufresne@sita.aero
|
Reply Date:
|
1/4/2006 1:20:53 PM
|
Here is sample of my code where the array of CButtons is created. As you'll see this sample only uses RegisterHotKey(). I am not sure if I have to use any other hot key function.
int i; int y1 = 90; int y2 = 110; HBITMAP hBitmap; CWnd* hwndOwner; CString StrLabel, StrBitmap; DWORD dwStyle, dwHotKeyStyle; RECT resizerect; hwndOwner = this;
GetWindowRect (&resizerect); ScreenToClient (&resizerect); resizerect.left += 200; resizerect.right +=200; resizerect.top += 100; resizerect.bottom += 100; MoveWindow (&resizerect, true); UpdateData(); dwStyle = WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_CENTER; dwHotKeyStyle = CCS_LEFT;
// Establish the bitmap to put on the button // ------------------- StrBitmap = "d:\\shortcuts\\"+LoggedOnUser+"\\Start\\"+LoggedOnUser + ".BMP"; hBitmap = (HBITMAP)LoadImage(NULL, StrBitmap, IMAGE_BITMAP, 100, 50, LR_LOADFROMFILE); // if(hBitmap == NULL) // MessageBox("No se puede cargar el bitmap.");
m_AirlineBMP.SetBitmap(hBitmap);
for(i=1; i<=nbShortcuts; i++) { // Create Push Buttons // Use the Applications data struct to extract the corresponding // Executable name and display it in the button // ------------------- MyButtons[i].Create(Applications[i-1].ExeName, dwStyle, CRect(10, y1-5, 220, y2-5), hwndOwner, i+2);
// Create Hotkeys // Use the loop index to create the hot key so that button #1 is access by pressing Alt-1 // -------------------- RegisterHotKey(HWND(hwndOwner),i+2,MOD_CONTROL, i+2);
// Change button's y position y1 = y1 + 30; y2 = y2 + 30;
if(i > 2) resizerect.bottom += 35; MoveWindow (&resizerect, true); UpdateData(FALSE); }
I'm also using the DefWindowProc() to capture the PushButton's WM_COMMAND and BN_CLICKED messages as such:
if(message == WM_COMMAND) { if(HIWORD(wParam) == BN_CLICKED) {
How would I add the code to capture the WM_HOTKEY message?
Thanks
|
|
Reply By:
|
Ankur_Verma
|
Reply Date:
|
1/5/2006 1:28:35 AM
|
U can catch WM_HOTKEY just like you did BN_CLICKED. The WPARAM with WM_HOTKEY contains the id of hotkey (the second parameter of RegisterHotKey, while registring the hotkey) with which you can idenfiy it and process it
int Id = (int)wp;
if (Id != KEYID) { AfxMessageBox("Not Caught"); return 1; } AfxMessageBox("Caught"); return 0;
Regards Ankur Verma
|