MFC Question

Started by
16 comments, last by Hedos 20 years, 5 months ago
Ugh.. I would opt for the second option... but.. I only have one choice: "Using MFC in a shared DLL"

What's wrong ?

[edited by - Hedos on November 10, 2003 11:42:50 AM]
Advertisement
I believe the MFC DLLs are distributed with the OS (unless I''m mistaken). However, I think it is only the "retail" or "release" DLLs that are there, and not the debug versions. Try recompiling your code by under the release version and send it to your friend (Build menu option -> Set Active Configuration). If that doesn''t work, then you will need to statically link the library.
What version of MSVC++ are you using? I know the option is there in the Professional and Enterprise editions. I guess if all else fails you can just redistribute the DLL.

[edited by - CodeMunkie on November 10, 2003 11:50:16 AM]
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
In regards to your hotkey question...

A better solution than the one I mentioned ealier would simply be to use the "RegisterHotKey" windows function. You basically pass the window you want to receive notification as a parameter. Then, whenever your hotkey is pressed, the window you specified will receive a WM_HOTKEY message. Then, in your app, just handle this message.

Now with VC++ 6.0, this message is not among the list of available windows messages when you right click on your class in the class view. An easy work around is to override the virtual function WindProc (should be listed if you right click in the class view and select Add Virtual Function). In this function, just check and see if the message is WM_HOTKEY. If it is, do your processing, otherwise, pass the message on to the base class method.

Don''t know why I didn''t write this earlier, must be lack of sleep.

Mike
CodeMunkie: I''m using MVC++ 6.0 professionnal:

MJB: Thanks, it seems to be on the correct way.. But it doesn''t work perfectly yet..

Here is my WindowProc code:
LRESULT CFirstTestDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {	// TODO: Add your specialized code here and/or call the base class		if(message==WM_HOTKEY)	{		if(wParam==''W'')		{			AfxMessageBox("BOU!!!");		}		return 0;	}	else		return CDialog::WindowProc(message, wParam, lParam);} 


That doesn''t work... I guess wParam doesn''t hold the value of the key pressed
So, how can I check wich key has been pressed?
Here's some of the documentation for the WM_HOTKEY message

WM_HOTKEY idHotKey = (int) wParam;              // identifier of hot key fuModifiers = (UINT) LOWORD(lParam);  // key-modifier flags uVirtKey = (UINT) HIWORD(lParam);     // virtual-key code   


So basically if you are just looking at the wParam, this value is the ID value you set. Since this ID value has to be unique for every hotkey, you can just check this against the value you set. Otherwise, check the virtual key code.

There is more information in the SDK if you look up WM_HOTKEY or RegisterHotKey. If you don't have all the help files on the HD, you can get them online(http://msdn.microsoft.com/).

Mike

[edited by - MJB on November 10, 2003 12:20:45 PM]
First I should probably make sure you registered your hotkey using RegisterHotKey(), though you probably wouldn''t be getting a WM_HOTKEY if you didn''t, but it''s worth asking.

That being asked, you need to use the hotkey ID, not the character value, to check against. That should be the ID that you put in when you called RegisterHotKey. You might want to look at the RegisterHotKey helpfile so you don''t register wrong, as there are numerical limits depending on what you''re using the stuff for, and you should probably use GlobalAddAtom to get a good ID.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
oh.. Right, by using the ID I registered with, it works perfectly
Thanks a lot

This topic is closed to new replies.

Advertisement