Advertisement

Windows Coding Question

Started by August 17, 2001 10:07 PM
2 comments, last by steveharper101 23 years, 6 months ago
I am new to Windows API programming because I usually use MFC for Apps and Glut for OpenGL. But I have a question: I have a main program loop which takes messages from the que and deals with them ie if escape has been pressed quit the application. I also have a WndProc but why do you need a WndProc when you can use your main program loop in WinMain. Is it because all Window related and process related stuff such as resizing or closing a window can only be caught in WndProc? Or are all windows messages caught in the programs main loop in WinMain and then sent to WndProc to be handled? Thanks Alot!! Hope someone can shed some light on this for me ~Steve~ Edited by - steveharper101 on August 17, 2001 11:10:02 PM
The message loop is a hang over from Windows 1 (16 bit 80286) days. DO NOT PROCESS ANY MESSAGES HERE. Well you can, cus if you screw up and crash the application 32 Windows will clean up all the dead bodies for you.

The wndprocs for each window should handle all the the messages. If you want to exit add the following to your main window proc:
    case WM_KEYUP:   {    switch (wParam)     {      case VK_ESCAPE :	DestroyWindow(hWnd);	break;    }  break;  }  case WM_DESTROY :  {    CleanupApplication();    PostQuitMessage(0);    break;  }  


ALL messages go throw the message dispatch, once dispatched they will go to the CORRECT wndproc so that you may process them correctly.
D.V.Carpe Diem
Advertisement
The message loop is a hang over from Windows 1 (16 bit 80286) days. DO NOT PROCESS ANY MESSAGES HERE. Well you can, cus if you screw up and crash the application 32 Windows will clean up all the dead bodies for you.

The wndprocs for each window should handle all the the messages. If you want to exit add the following to your main window proc:
    case WM_KEYUP:   {    switch (wParam)     {      case VK_ESCAPE :	DestroyWindow(hWnd);	break;    }  break;  }  case WM_DESTROY :  {    CleanupApplication();    PostQuitMessage(0);    break;  }  


ALL messages go throw the message dispatch, once dispatched they will go to the CORRECT wndproc so that you may process them correctly.


D.V.
D.V.Carpe Diem
Hey thanks alot man. So I use WndProc for my programs messages and the main loop for the actual game and OpenGL stuff.

One more question:

Whats the TranslateMessage function do?

Thanks Alot for the previous post!!

Later

~Steve~

This topic is closed to new replies.

Advertisement