Jump to content
  • Advertisement
Sign in to follow this  
CulDeVu

C++ Win32 freezing when mouse is moved

This topic is 2747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all

I've been having trouble for a while with this ever since I made a customized Window class to make be able to call functions that would easily do things like go full screen, set up child windows, changing cursors, stuff like that. Ever since then, occasionally, when my computer feels like it, all mouse movements will stop entire programming from running. All painting stops, as do frame counters. Also, much more recently, that same program will stop running just like before when a key is held down. What could be going on, if anyone has encountered this before? Does it even have anything to do with writing a custom window class?

Share this post


Link to post
Share on other sites
Advertisement
Does it even have anything to do with writing a custom window class?[/quote]
If it does not occur when you don't use the custom window class, then there's likely something wrong with that class.

Share this post


Link to post
Share on other sites
LOL why would it get stuck from just creating a class?

You clearly jacked something up with your codes outside of the class...

Share this post


Link to post
Share on other sites

Hello all

I've been having trouble for a while with this ever since I made a customized Window class to make be able to call functions that would easily do things like go full screen, set up child windows, changing cursors, stuff like that. Ever since then, occasionally, when my computer feels like it, all mouse movements will stop entire programming from running. All painting stops, as do frame counters. Also, much more recently, that same program will stop running just like before when a key is held down. What could be going on, if anyone has encountered this before? Does it even have anything to do with writing a custom window class?


I would check your winproc, Are you handling default messages? your program might be drowning in messages.

Share this post


Link to post
Share on other sites

Show your WinProc.


I copied this directly out of a book, so it should work perfectly.


// Route Windows messages to game engine member functions
switch (msg)
{
case WM_CREATE:
// Set the game window and start the game
m_pWindow->SetWindow(hWindow);
GameStart(hWindow);
return 0;

case WM_SETFOCUS:
// Activate the game and update the Sleep status
GameActivate(hWindow);
SetSleep(FALSE);
return 0;

case WM_KILLFOCUS:
// Deactivate the game and update the Sleep status
GameDeactivate(hWindow);
SetSleep(TRUE);
return 0;

case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(hWindow, &ps);

// Paint the game
GamePaint(hDC);

EndPaint(hWindow, &ps);
return 0;

case WM_LBUTTONDOWN:
// Handle left mouse button press
MouseButtonDown(LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;

case WM_LBUTTONUP:
// Handle left mouse button release
MouseButtonUp(LOWORD(lParam), HIWORD(lParam), TRUE);
return 0;

case WM_RBUTTONDOWN:
// Handle right mouse button press
MouseButtonDown(LOWORD(lParam), HIWORD(lParam), FALSE);
return 0;

case WM_RBUTTONUP:
// Handle right mouse button release
MouseButtonUp(LOWORD(lParam), HIWORD(lParam), FALSE);
return 0;

case WM_MOUSEMOVE:
// Handle mouse movement
MouseMove(LOWORD(lParam), HIWORD(lParam));
return 0;

case WM_DESTROY:
// End the game and exit the application
GameEnd();
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWindow, msg, wParam, lParam);


It does work normally when I'm not using the class, but what gets me is that sometimes it does this, and sometimes it doesn't. Like, for example, right now when I run it, it works perfectly, but 5 minutes ago when I ran it, it was messing up. Another thing to note is that I can't get stuff like Setting different cursors to work, and I don't know why...

Share this post


Link to post
Share on other sites
You need some braces on your case statements like:

case IDOK: // OK button hit!
{
//Update our last record
UpdateObjectRecord(hwndDlg, MyGame.Info.DialogObjectNumber);
EndDialog(hwndDlg, IDOK); // end this dialog box.
}return(true);


If not for function then at least for aesthetics.

Share this post


Link to post
Share on other sites
What does your message pump look like? I bet you're not processing all messages each frame, and you're just processing one message per tick. Especially if it only does it after a while.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!