|
Please consider the following fragment of code from the book Programming Windows 95 with MFC
by Jeff Prosise:
CMainWindow::CMainWindow()
{
CString strWndClass = AfxRegisterWndClass ( 0, myApp.LoadStanddadCursor ( IDC_ARROW ),
(HBRUSH)(COLOR_3DFACE + 1), myApp.LoadStandardIcon( IDI_APPLICATION ) );
I do not understand why is is COLOR_3DFACE + 1, instead of COLOR_3DFACE. Since COLOR_3DFACE represents an enumeration value, it seems to me, adding 1 to it is wrong. What am I missing?
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: why is is COLOR_3DFACE + 1, instead of COLOR_3DFACE
Because the docs state that's the way it needs to be:
WNDCLASS.hbrBackground
Handle to the class background brush. This member
can be a handle to the physical brush to be used
for painting the background, or it can be a color
value. A color value must be one of the following
standard system colors (the value 1 must be added
to the chosen color).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark's answer is the good one.
The following is just a guess on the motivation:
Possibly because it avoid the following conflict
(from Winuser.h )
#define COLOR_SCROLLBAR 0
(from MSDN on WNDCLASS.hbrBackground )
When this member is NULL, an application must paint its own background whenever it is requested to paint in its client area.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Sorry, I'm quite angry with this problem ...
I tried to code a system-wide keyboard hook and send recived keyboard messages within a DLL toward an EXE ...
Everything went fine but TranslateMessage() that fails to generate WM_CHAR ...
within DLL:
------------------
struct lParamMember
{
WORD RepeatCount : 16,
ScanCode : 8,
IsExtended : 1,
Reserved : 4,
IsALTDown : 1,
WasKeyDown : 1,
IsBeingReleased : 1;
};
LRESULT CALLBACK KeyboardProc(int iCode, WPARAM wParam, LPARAM lParam)
{
if(iCode<0)
return CallNextHookEx(hKybrdHook, iCode, wParam, lParam);
lParamMember* plParam = (lParamMember*)&lParam;
if(plParam->IsBeingReleased)PostThreadMessageW(g_dwThreadID, WM_KEYDOWN, wParam, lParam);
else PostThreadMessageW(g_dwThreadID, WM_KEYUP, wParam, lParam);
return CallNextHookEx(hKybrdHook, iCode, wParam, lParam);
}
withing EXE:
-------------------
MSG msg;
while(GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
if(msg.message == WM_CHAR || msg.message == WM_DEADCHAR || msg.message == WM_SYSCHAR ||
msg.message == WM_SYSDEADCHAR)
MessageBox(0, L"Success!", 0, 0);
}
----------------------------------------------------------------
|
|
|
|
|
Jusef Marzbany wrote: if(plParam->IsBeingReleased)PostThreadMessageW(g_dwThreadID, WM_KEYDOWN, wParam, lParam);
else PostThreadMessageW(g_dwThreadID, WM_KEYUP, wParam, lParam);
Are these switched? I thought releasing a key meant keyup, not keydown.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I did as you, but it still doesn't work ...
Now it looks like this:
-----------------------
if(plParam->IsBeingReleased)PostThreadMessageW(g_dwThreadID, WM_KEYUP, wParam, lParam);
else PostThreadMessageW(g_dwThreadID, WM_KEYDOWN, wParam, lParam);
Help me PLS
|
|
|
|
|
Disclaimer: I'm only trying to help find potential problems
with the info given. Don't assume I know the solution - I don't.
Emulating system messages is always problematic.
What's happening in the debugger?
To start with, are your WM_KEY* messages actually getting to
the EXE's message loop?
Next, maybe take a look (using the debugger) at the sequence of
messages involved with a real keystroke. You're going to need
to emulate that exactly for this to work.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, I've mentioned it before ...
I recieved WM_KEYUP as well as WM_KEYDOWN in my message loop and I'm sure about that ...
The only remaining problem is TranslateMessage( ) ...
One would say It doesn't understand above messages any more! Where's Bill Gates?
|
|
|
|
|
Jusef Marzbany wrote: The only remaining problem is TranslateMessage() ...
Have you checked the return value from TranslateMessage() ?
Jusef Marzbany wrote: Where's Bill Gates?
He doesn't work full time at MS anymore, so he's probably doing charity work or something
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
Yes, I have, It returns 0 for me
|
|
|
|
|
What kind of output do you get doing something like this
in the EXE:
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_KEYDOWN || msg.message == WM_KEYUP)
{
if (msg.message == WM_KEYDOWN)
TRACE0("WM_KEYDOWN - ");
else
TRACE0("WM_KEYUP - ");
if (!TranslateMessage(&msg))
{
TRACE0("TranslateMessage() Failed!\n");
}
else
{
TRACE0("TranslateMessage() Succeeded!\n");
}
}
if(msg.message == WM_CHAR || msg.message == WM_DEADCHAR || msg.message == WM_SYSCHAR ||
msg.message == WM_SYSDEADCHAR)
{
TRACE0("WM_CHAR!\n");
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
See I press a key! according to your code (that's exactly what I did!), I got:
1- one WM_KEYDOWN notification
2- a message saying TranslateMessage() has failed
and then nothing more!
So:
1- where's WM_KEYUP?
2- Why TranslateMessage() has failed?
|
|
|
|
|
Why don't you try to go deeper with the debugger? For instance, whenever the TranslateMessage fails, check out the details of the MSG structure.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Jusef Marzbany wrote: 1- where's WM_KEYUP?
You stated:
"I recieved WM_KEYUP as well as WM_KEYDOWN in my
message loop and I'm sure about that ..."
So you weren't actually getting both the messages before?
As cPallini mentioned, you'll need to debug this.
You're trying to force messages that are system messages.
Unless you do it the exact way the system does, it's not
going to work. That's why I said it's problematic.
TranslateMessage could be failing because you're not emulating the
system messages properly.
Keyboard input was never meant for multiple targets on Windows.
Only the one window with keyboard focus should get the key messages.
You may want to try posting messages to a window instead of
a thread.
Tip: Don't use MessageBox in the message loop!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you, Great
Thank you masters!
|
|
|
|
|
Does PostThreadMessage() succeed? Is the g_dwThreadID identifier valid?
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
Yes, It is ...
As I mentioned before, everything went fine and I recieved WM_KEYDOWN and WM_KEYUP ...
But TranslateMessage( ) fails ...
|
|
|
|
|
Apologies; in that case Mark's advice seems a good way to go.
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
Hi all,
in my application i am using the GetRawInputDeviceInfo and included the winuser.h and windows.h but it is saying
GetRawInputDeviceInfo' : undeclared identifier
can anyone tell the reason for this issue?
Thanks in advance..
modified on Saturday, September 13, 2008 1:05 PM
|
|
|
|
|
Hi all,
inmy application i have used the message shwon in the following line :
ON_MESSAGE(WM_INPUT, OnInput)
I am getting the error "WM_INPUT' : undeclared identifier"
can anybody tell me wat this error is and how i need to solve this???
|
|
|
|
|
"Minimum operating systems Windows XP"
Do you have the appropriate symbols defined for OS version in your stdafx.h file? Make sure they are 0x0501 to ensure the xp specific symbols get defined during compilation. Make sure to do a "Rebuild Solution" or equivalent to prevent any false negatives.
|
|
|
|
|
can you tell me clearly how to do that?
|
|
|
|
|
Most newer VC++ IDE's will place some version defines at the appropriate place in your stdafx.h file to ensure the symbols for the version of windows or IE your targeting get defined. You mentioned that you are using VC++ 6.0 in another thread so you will need the February 2003 Platform SDK in place for Windows XP symbols. (How to get the Platform SDK and getting it installed are described elsewhere on this site).
To get the symbols defined, you need to define the correct version symbols on newer IDE's. Sometimes with the Platform SDK installed and the directories listed in the proper order, you sometimes get the symbols without needing to define the symbol. (This might be due to a default version getting defined). If you still don't get the symbols defined that you desire, you can always try defining the version symbols explicitly like newer IDE's do in the stdafx.h file (I would try putting just the WINVER in, then _WIN32_WINNT, and so on until you get the symbols you need)...
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER
#define WINVER 0x0501
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
|
|
|
|
|
Did you include Winuser.h, Windows.h?
|
|
|
|
|
Hi all,
in my MFC application i want to use the message WM_INPUT but i am not able to see this in the classs wizard,can any one suggest me how to get that????
|
|
|
|