Sure, I post now.
The first code is for the message loop:
<br />
WPARAM TemplateWindow::MessageLoop()<br />
{<br />
while(!m_bQuit)<br />
{<br />
if(PeekMessage(&msg, m_hwnd, NULL, NULL, PM_REMOVE))<br />
{<br />
if(msg.message == WM_QUIT)<br />
{<br />
if(m_uiType == MDI)DestroyWindow(m_hwndFrame);<br />
m_bQuit = true;<br />
break;<br />
}<br />
else<br />
{<br />
if(m_uiType == MDI)<br />
{<br />
if(!TranslateMDISysAccel(m_hwndFrame, &msg))<br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
}<br />
if(m_uiType == SDI)<br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
}<br />
}<br />
else<br />
if(m_uiChildCount > 0)<br />
{<br />
SendMessage(childsInfo[0].hwnd, WM_PAINT, NULL, NULL);<br />
}<br />
SwapBuffers(m_hdc);<br />
}<br />
return msg.wParam;<br />
}<br />
And the following codes is the callback for my windows. Look at the codes. Again, thanks for your help.
<br />
#ifndef CALLBACKS_H<br />
#define CALLBACKS_H<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <RichEdit.h><br />
#include <time.h><br />
<br />
WindowInfo windowInfos;
GLUquadricObj * Cilinder;<br />
unsigned int uiList = 0;<br />
int iValueSelected = -1;<br />
<br />
HINSTANCE hRichEdit;
<br />
HWND g_hwndClient, FrameHwnd, RenderHwnd, InstructHwnd, DialogHwnd;<br />
<br />
LRESULT CALLBACK MainWindowCallback(HWND, UINT, WPARAM, LPARAM);<br />
LRESULT CALLBACK InstructorWindowCallback(HWND, UINT, WPARAM, LPARAM);<br />
LRESULT CALLBACK RenderWindowCallback(HWND, UINT, WPARAM, LPARAM);<br />
LRESULT CALLBACK DialogWindowCallback(HWND, UINT, WPARAM, LPARAM);<br />
<br />
static bool bShow = false, bTrue = false;<br />
<br />
<br />
LRESULT CALLBACK InstructorWindowCallback(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)<br />
{<br />
HWND textBox = NULL, editBox = NULL;<br />
HFONT textFont = 0;<br />
switch(uiMessage)<br />
{<br />
case WM_CREATE:<br />
{<br />
RECT richEditSize;<br />
hRichEdit = LoadLibrary("RichEd20.dll");<br />
InstructHwnd = hwnd;<br />
GetClientRect(hwnd, &richEditSize);<br />
HINSTANCE hInst = ((LPCREATESTRUCT)lParam)->hInstance;<br />
if(hRichEdit != NULL)<br />
{ <br />
editBox = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("RICHEDIT20A"), "", WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_MULTILINE, 0, 0, richEditSize.right, richEditSize.bottom, hwnd, HMENU(IDC_EDITBOX), hInst, NULL);<br />
if(editBox != NULL)<br />
{<br />
HDC editHdc = GetDC(editBox);<br />
int iSize = -MulDiv(10, GetDeviceCaps(GetDC(hwnd), LOGPIXELSY), 72);<br />
textFont = CreateFont(iSize, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Courier");<br />
if(textFont == 0)<br />
{<br />
MessageBox(NULL, "Fonte não criada", "Erro", MB_OK|MB_ICONERROR);<br />
break;<br />
}<br />
SetBkMode(editHdc, TRANSPARENT);<br />
SelectObject(editHdc, textFont);<br />
ShowWindow(editBox, SW_SHOW);<br />
ReleaseDC(editBox, editHdc);<br />
SendMessage(editBox, WM_SETFONT,(WPARAM)textFont, (LPARAM)TRUE);<br />
}<br />
}<br />
HMENU hSysMenu = GetSystemMenu(hwnd, false);<br />
EnableMenuItem(hSysMenu, SC_CLOSE, MF_GRAYED|MF_BYCOMMAND);<br />
if(DialogHwnd != NULL)ShowWindow(DialogHwnd, SW_HIDE);<br />
break;<br />
}<br />
case WM_GETMINMAXINFO:<br />
{<br />
RECT instructSize;<br />
GetClientRect(GetParent(hwnd), &instructSize);<br />
MINMAXINFO * minMax = (MINMAXINFO*)lParam;<br />
minMax->ptMinTrackSize.x = instructSize.right;<br />
minMax->ptMinTrackSize.y = (instructSize.bottom/5);<br />
break;<br />
}<br />
case WM_INSTRUCTOR:<br />
{<br />
<br />
CHARFORMAT2 textFormat;<br />
textFormat.cbSize = sizeof(CHARFORMAT2);<br />
textFormat.dwMask = CFM_COLOR|CFM_FACE|CFM_CHARSET;<br />
textFormat.dwEffects = 0;<br />
textFormat.bCharSet = ANSI_CHARSET;<br />
strcpy(textFormat.szFaceName, "Courier");<br />
HWND editHw = GetDlgItem(hwnd, IDC_EDITBOX);<br />
int iLength = GetWindowTextLength(editHw);<br />
SendMessage(editHw, EM_SETSEL, (WPARAM)iLength, (LPARAM)iLength);<br />
SendMessage(editHw, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&textFormat);<br />
<br />
SendMessage(editHw, EM_REPLACESEL, (WPARAM)FALSE, lParam);<br />
int iLineCount = (int)SendMessage(editHw, EM_GETLINECOUNT, NULL, NULL);<br />
SendMessage(editHw, EM_LINESCROLL, NULL, (LPARAM)(iLineCount-(iLineCount-1)));<br />
int iLines = 0;<br />
while(iLines < iLineCount - 1)<br />
{<br />
char cString[256];<br />
SendMessage(editHw, EM_GETLINE, (WPARAM)iLines, (LPARAM)cString);<br />
iLines++;<br />
}<br />
break;<br />
}<br />
case WM_MOVE:<br />
{<br />
RECT instructSize;<br />
GetClientRect(GetParent(hwnd), &instructSize);<br />
SetWindowPos(hwnd, HWND_TOPMOST, 0, instructSize.bottom-(instructSize.bottom/5), 0, 0, SWP_NOZORDER);<br />
break;<br />
}<br />
case WM_NCACTIVATE:<br />
{<br />
return DefMDIChildProc(hwnd, uiMessage, true, lParam);<br />
}<br />
default: return DefMDIChildProc(hwnd, uiMessage, wParam, lParam);<br />
}<br />
}<br />
<br />
<br />
LRESULT CALLBACK RenderWindowCallback(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)<br />
{<br />
static POINT currentPosition, oldPosition, mousePos;<br />
static unsigned int uiTex[20];<br />
static float fTest = -0.3;<br />
static bool bMousing = false;<br />
static unsigned int uiCount = 0;<br />
RECT windowRect;<br />
switch(uiMessage)<br />
{<br />
case WM_CREATE:<br />
{<br />
RenderHwnd = hwnd;<br />
windowInfos.hwnd = hwnd;<br />
GetClientRect(hwnd, &windowRect);<br />
windowInfos.hdc = GetDC(windowInfos.hwnd);<br />
OpenGLInitialization::EnableGL(windowInfos.hwnd, &windowInfos.hdc, &windowInfos.hrc);<br />
OpenGLInitialization::InitializeGL();<br />
OpenGLInitialization::SetFieldOfView(windowRect);<br />
currentPosition.x = oldPosition.x = NULL;<br />
currentPosition.y = oldPosition.y = NULL;<br />
fXNeedle = fYNeedle = fZNeedle = 0.0f; HMENU hSysMenu = GetSystemMenu(hwnd, false);<br />
EnableMenuItem(hSysMenu, SC_CLOSE, MF_GRAYED|MF_BYCOMMAND);<br />
break;<br />
}<br />
case WM_PAINT:<br />
{<br />
PAINTSTRUCT ps;<br />
HDC hdc = BeginPaint(hwnd, &ps);<br />
GetClientRect(hwnd, &windowRect);<br />
OpenGLInitialization::SetFieldOfView(windowRect);<br />
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);<br />
glMatrixMode(GL_PROJECTION);<br />
glPushMatrix();<br />
glLoadIdentity();<br />
gluOrtho2D(0, windowRect.right, windowRect.bottom, 0);<br />
glPopMatrix(); <br />
glMatrixMode(GL_MODELVIEW);<br />
glPushMatrix();<br />
glLoadIdentity();<br />
glPopMatrix();<br />
EndPaint(hwnd, &ps);<br />
SwapBuffers(hdc);<br />
break;<br />
}<br />
case WM_MOVE:<br />
{<br />
RECT renderRect;<br />
GetClientRect(GetParent(hwnd), &renderRect);<br />
SetWindowPos(hwnd, HWND_TOPMOST, renderRect.left, renderRect.top, 0, 0, SWP_NOZORDER);<br />
break;<br />
}<br />
case WM_GETMINMAXINFO:<br />
{<br />
RECT renderRect;<br />
GetClientRect(GetParent(hwnd), &renderRect);<br />
MINMAXINFO * minMax = (MINMAXINFO*)lParam;<br />
minMax->ptMinTrackSize.x = renderRect.right;<br />
minMax->ptMinTrackSize.y = renderRect.bottom-(renderRect.bottom/5);<br />
break;<br />
}<br />
case WM_LBUTTONDOWN:<br />
{<br />
if(!bMousing)<br />
{<br />
currentPosition.x = oldPosition.x = LOWORD(lParam);<br />
currentPosition.y = oldPosition.y = HIWORD(lParam);<br />
bMousing = true;<br />
}<br />
else<br />
{<br />
currentPosition.x = LOWORD(lParam);<br />
currentPosition.y = HIWORD(lParam);<br />
bMousing = false;<br />
}<br />
break;<br />
}<br />
case WM_NCACTIVATE:<br />
{<br />
return DefMDIChildProc(hwnd, uiMessage, true, lParam);<br />
}<br />
default: return DefMDIChildProc(hwnd, uiMessage, wParam, lParam);<br />
}<br />
}<br />
<br />
<br />
LRESULT CALLBACK MainWindowCallback(HWND hwnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)<br />
{<br />
HMENU hMainMenu;<br />
hMainMenu = CreateMenu();<br />
static int siRuler = IDM_NEWRULER, siText = IDM_NEWTEXT, siNodule = IDM_NEWNODULE, siPath = IDM_NEWRULERPATH;<br />
switch(uiMessage)<br />
{<br />
case WM_CREATE:<br />
{<br />
fXNeedle = fYNeedle = 0.0f;<br />
fZNeedle = -0.3f;<br />
FrameHwnd = hwnd;<br />
RulerMenu = new DynamicMenu();<br />
TextMenu = new DynamicMenu();<br />
PathMenu = new DynamicMenu();<br />
NoduleMenu = new DynamicMenu();<br />
ProceedingMenu = new DynamicMenu();<br />
ScreenShotMenu = new DynamicMenu();<br />
ImageListMenu = new DynamicMenu();<br />
AppendMenu(hMainMenu, MF_STRING|MF_POPUP, 0, NULL);<br />
SetMenu(hwnd, hMainMenu);<br />
break;<br />
}<br />
case WM_CLOSE:<br />
{<br />
delete TextMenu;<br />
delete RulerMenu;<br />
delete PathMenu;<br />
delete NoduleMenu;<br />
delete ProceedingMenu;<br />
delete ScreenShotMenu;<br />
return DefFrameProc(hwnd, g_hwndClient, uiMessage, wParam, lParam);<br />
}<br />
case WM_NCDESTROY:<br />
{<br />
PostQuitMessage(0);<br />
break;<br />
}<br />
case WM_GETMINMAXINFO:<br />
{<br />
MINMAXINFO * mainWindowSizes = (MINMAXINFO*)lParam;<br />
mainWindowSizes->ptMinTrackSize.x = WIDTH;<br />
mainWindowSizes->ptMinTrackSize.y = HEIGHT;<br />
break;<br />
}<br />
case WM_KEYDOWN:<br />
{<br />
switch(wParam)<br />
{<br />
case VK_ESCAPE:<br />
{<br />
FreeLibrary(hRichEdit);<br />
PostQuitMessage(0);<br />
break;<br />
}<br />
}<br />
break;<br />
}<br />
case WM_COMMAND:<br />
{<br />
break;<br />
}<br />
default: break;<br />
}<br />
return DefFrameProc(hwnd, g_hwndClient, uiMessage, wParam, lParam);<br />
}<br />
<br />
#endif CALLBACKS_H<br />
|