Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 23rd, 2005, 01:19 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default hot keys in C++

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 With Quote
  #2 (permalink)  
Old December 24th, 2005, 04:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

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 With Quote
  #3 (permalink)  
Old January 4th, 2006, 02:20 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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_CE NTER;
dwHotKeyStyle = CCS_LEFT;

// Establish the bitmap to put on the button
// -------------------
StrBitmap = "d:\\shortcuts\\"+LoggedOnUser+"\\Start\\"+LoggedO nUser + ".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 With Quote
  #4 (permalink)  
Old January 5th, 2006, 02:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Session...hot to do that? Shuchik Classic ASP Basics 1 August 31st, 2007 01:49 AM
Tool Bar with hot keys venkatraman_gururaj General .NET 0 July 13th, 2006 09:06 AM
When to define primary keys and foregin keys? method SQL Server 2000 1 August 26th, 2005 09:14 AM
Hot Keys Louisa VB.NET 2002/2003 Basics 6 September 27th, 2004 09:48 AM
FAQ: Text editors and hot keys richard.york Beginning PHP 1 September 10th, 2003 06:00 AM



All times are GMT -4. The time now is 09:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.