Strange behaviour in my program... when I click the mouse button, the message box does not appear UNTIL I CLICK THE ALT KEY :confused:
What's wrong here?
filthy_mcnasty
March 4th, 2003, 09:42 PM
there's nothing wrong with your code (minus the fact that your compiler should be yelling at you to move the variable declarations outside of the switch statement) so i would look elsewhere to find the problem (some system setting maybe?)
the same code works exactly as you would expect for me anyways.
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow )
case WM_RBUTTONDOWN:
MessageBox (hwnd, "wm_rbuttondown", NULL, MB_OK);
break;
how is this working for you? I would imagine it works but may be wrong.
indiocolifa
March 5th, 2003, 12:19 AM
Bad news!
WM_RBUTTONDOWN does not work!
I'm absolutely pissed off...
My development enviroment is:
1.1 GHz AMD Athlon Thunderbird (100mhz FSB), Windows XP Pro, MS VC++ 6 and .NET (both installed), 512mB RAM, Geforce4 MX, 21GB Maxtor HD, etcetc
Why both WM_xBUTTONDOWN messages wait for ALT key?
IT's very strange...
I'm updating the Platform SDK to the latest edition to see if I can resolve the problem...
I'm searching also for a Service Pack for VS.NET...
I'm PISSED OFF
:mad:
Weird problem for a :confused: confused Win32 API beginner...
Yours...
Indiocolifa.
indiocolifa
March 5th, 2003, 12:28 AM
NEWS... *bad* :(
I've compiled the same code in the good old Visual C++ 6.0
and imagine...
same weird bug!
...still looking where it's the problem...
(code it's 100% ok, i think... but both compiled executables from 6.0 and 7.0 do the same thing!)
filthy_mcnasty
March 5th, 2003, 12:32 AM
i know your code is fine. look into some system setting on your computer or try it on another computer and see if it works there.
indiocolifa
March 5th, 2003, 08:52 AM
Tried the code at work in Visual C++6.0 w/o service pack and I get the same problem! :(
Do me a favor, guys... Copy&paste code in your compiler and tell me the results!!
yours.
Paul McKenzie
March 5th, 2003, 09:17 AM
One rule that I have: Never use message boxes as a debugging tool when you are attempting to debug program flow!
Whenever you use message boxes in a window procedure, you are introducing another window (the message box) right in the middle of your window processing.
When you process WM_LBUTTONDOWN, you usually are supposed to write a small, fast routine, and not idle the program with a message box. What if you had a WM_LBUTTONUP handler? You would screw up things with the message box, since the system will be waiting for you to release the button. Maybe (I haven't tried it), WM_LBUTTONUP gets thrown away, and possibly your WM_RBUTTONDOWN is getting messed up in the same way.
Instead, use OutputDebugString() to display messages. The message will either appear in the debugger's Output Window (if you use VC++), or it can appear in the current debugger window (get the DebugView program from www.sysinternals.com and run it when your app runs).
Regards,
Paul McKenzie
indiocolifa
March 5th, 2003, 09:39 AM
Thank you, using DebugView gives me the correct output (giving me a tip that the WM_LBUTTONDOWN is working properly)...
but what I dont know is why many Win32 API tutorials use a MessageBox in the WM_LBUTTONDOWN message, and in every place i seen, say that MessageBox works.
Suppose I WANT to display a Message Box in WM_LBUTTONDOWN...
Thank you very much
(Debugview is a very useful prog, i think)
Paul McKenzie
March 5th, 2003, 12:18 PM
Originally posted by indiocolifa
Thank you, using DebugView gives me the correct output (giving me a tip that the WM_LBUTTONDOWN is working properly)...
but what I dont know is why many Win32 API tutorials use a MessageBox in the WM_LBUTTONDOWN message, and in every place i seen, say that MessageBox works.
Suppose I WANT to display a Message Box in WM_LBUTTONDOWN...
Don't do it. You may also want to display a message box every time you get a WM_PAINT message. Is it a good idea to do it? No. There are many messages sent to your Window procedure where you do not want to idle your message processing by displaying a message box.
For Mouse / keyboard messages, you should not place a message box. Mouse and keyboard messaging in Windows is a complex system of key/mouse ups, key/mouse downs, WM_CHAR's, accelerators, etc. When you press the left mouse button, there is much more that's going on behind the scenes than just sending a WM_LBUTTONDOWN to your Window procedure. This is why Windows has a function dedicated to sending mouse and keyboard messages, SendInput() -- the nature of sending mouse messsages correctly is very complex.
Also, by displaying a message box you are temporarily stopping the processing of Windows system messages to your main app. This can potentially screw up the way Windows is handling your mouse / keyboard messages.
What you may be thinking of is the case where a message box is displayed by pressing a dialog button or some other GUI control. This is not handled by processing WM_LBUTTONDOWN. When you get to the section about dialog boxes and menus, you will see that WM_LBUTTONDOWN is not used to process user selections, menus, etc. even though you may have used the mouse.
WM_LBUTTONDOWN / WM_LBUTTONUP processing is used a lot in drawing programs, where you need to draw a line, circle, whatever, and the drawing is controlled by the user moving the mouse on a "canvas" area while holding the mouse button down. Note that in this case, there is no message box -- just "pure" code to start the drawing process (maybe set some flags, set the initial drawing point, whatever).
Regards,
Paul McKenzie
filthy_mcnasty
March 5th, 2003, 02:30 PM
at the same time paul you can create a message box w/o specifying the parent window and it wouldn't idle your normal message processing.
indiocolifa
March 5th, 2003, 09:06 PM
THIS IS INCREDIBLE (at least for me!)
remember the "ALT" key problem I was telling you?
Now it's repeating in another section of my program.
Look steps:
1) I created a menu and attached to main window with wc.lpszMenuName. It loads OK!
2) i created a dialog box to appear when I click Help/About.
3) Created (I think is coded well) all procedures.
4) You click the About/Help... and IT WAITS FOR ALT KEY! , after pressing ALT, the dialog box appears.
See my code sections I added:
LRESULT CALLBACK MainWndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch (uMsg)
{
case WM_COMMAND:
switch LOWORD(wParam)
{
case ID_HELP_ABOUT:
{
int ret = DialogBox (GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLGABOUT),
hwnd, AboutDlgProc);
break;
}
}
break;
In your loop, you are checking for > 0. A valid message is any non-zero value. Please change this, since it is possible you are not receiving all of the messages.
Regards,
Paul McKenzie
filthy_mcnasty
March 5th, 2003, 09:50 PM
your WM_PAINT handling is what's causing the message boxes to not pop up until the alt key. the same is the problem for the dialog box part. remove WM_PAINT until later.
if you do it like you are then paint messages are basically lost. you would need to at least do
BeginPaint and EndPaint
no mouse messages are lost or anything, they're all processed just like normal actually but that's the problem.
indiocolifa
March 5th, 2003, 10:04 PM
Yeeeeeeeeeeeeeeeeeeeess!!!:D :D :D
thank you very much filthy_mcnasty, that was the problem...
Removed WM_PAINT msg handling and all OK...
THANK YOU VERY MUCH FOR ALL REPLIES TO Everybody.
Indiocolifa:D :D :D :D :D
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.