Home > Software engineering >  MFC message loop
MFC message loop

Time:09-24

MFC program how to add the code in the message loop functionality? To play a game in the message loop to realize the scene move,

CodePudding user response:

Fyi:
//OpenGL application framework. The CPP: Defines the entry point for the application. The 
//learning programs compiled game series
//Tang Mingli E_mail: [email protected]
//====================================================================
# include "stdafx. H"
# include "OpenGL. H"
//////////////////////////////////////////////////////////
OpenGL * m_OpenGL;
HDC HDC.//the device handle, GDI connect window to GDI (graphics device interface)
HGLRC hRC=NULL;//handle to render description, connect the OpenGL calls to device context
HWND HWND=NULL;//save the window handle of the Windows are assigned to program
Int Width=800;//window wide
Int Height=600;//window high
Int bits=16;//color depth
Void GameLoop ()
{MSG MSG.
BOOL fMessage;
PeekMessage (& amp; U MSG, NULL, 0, 0, u PM_NOREMOVE);
While (MSG) message!=WM_QUIT)//message loop
{fMessage=PeekMessage (& amp; U MSG, NULL, 0, 0, u PM_REMOVE);
If (fMessage)//the message
{TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
The else m_OpenGL - & gt; Render ();//no message
}
}
LRESULT WINAPI MsgProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)//message processing
{switch (the message)
{case WM_CREATE message handler://build window
HDC=GetDC (hWnd);//device for the current window handle
M_OpenGL - & gt; SetupPixelFormat (hDC);//display mode installation function call
return 0; break;
Case WM_CLOSE://close the window
M_OpenGL - & gt; The CleanUp ();//end processing
The PostQuitMessage (0);
return 0; break;
Case WM_SIZE://window size change
Height=HIWORD (lParam);//window high
Width=LOWORD (lParam);//window wide
If (Height==0) Height=1;//prevent by 0
M_OpenGL - & gt; Init (Width, Height);
return 0; break;
Case WM_DESTROY://exit message
The PostQuitMessage (0);
return 0; break;
Case WM_KEYUP://press ESC to exit full screen mode must join exit way,
The switch (wParam)
{case VK_ESCAPE:
M_OpenGL - & gt; The CleanUp ();//end processing
The PostQuitMessage (0);
return 0; break;
}
Default: break;
}
Return (DefWindowProc (hWnd, message, wParam, lParam));
}
INT WINAPI WinMain (HINSTANCE hInst, HINSTANCE, LPSTR, INT)//WinMain routine entry
{//registered window class
Bool fullScreen=TRUE;
DWORD dwExStyle;//Window extension style
DWORD dwStyle;//Window Window style
The RECT windowRect;//window size
Int nX=0, nY=0;
DwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;//make the window has a 3 d look
DwStyle=WS_OVERLAPPEDWINDOW;//use the standard window
//WS_OVERLAPPEDWINDOW has the title bar, the window menu, the biggest, the small button and can adjust the size of the window
Int the wid=GetSystemMetrics (SM_CXSCREEN);//gets the current screen width
Int hei=GetSystemMetrics (SM_CYSCREEN);//gets the current screen high
NX=(wid - Width)/2; NY=(hei - Height)/2;//calculation window centered with
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
AdjustWindowRectEx (& amp; WindowRect dwStyle, FALSE, dwExStyle);
//according to the size of the window style to adjust the window size is achieved
Char cc []="HTML";
Modifed WNDCLASSEX wc={sizeof (modifed WNDCLASSEX), CS_CLASSDC, MsgProc, 0 l, 0 l,
GetModuleHandle (NULL), NULL, NULL, NULL, NULL,
Cc, NULL};
RegisterClassEx (& amp; Wc);
M_OpenGL=new OpenGL ();//
HWnd=CreateWindowEx (NULL, cc, "learning OpenGL make up 3 d game [1. OpenGL application framework])",
DwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
NX, nY, Width, Height,
NULL, NULL, hInst, NULL);//create a window
ShowWindow (hWnd, SW_SHOWDEFAULT);//display window
UpdateWindow (hWnd);//refresh window
GameLoop ();//entering the message loop
return 0;
}

CodePudding user response:

Refer to http://blog.sina.com.cn/s/blog_a2aa00d70101im9b.html

CodePudding user response:

Thank you very much, although now no MFC

CodePudding user response:

The WM_TIMER + OnTimer??

CodePudding user response:

Create a timer,
In WM_TIMER event in the callback function (or use) to modify parameters scenario, call Invalidate () function
According to the scenario in the WM_PAINT parameters painting scene
  • Related