Here is my amended code. I just found out if i hide the edit control before calling the messagebox, the messagebox can appear correctly. But i dont want to hide my edit control. Hope it provide more clues to my problem.
Code:
// function to create window
HWND mainFrame::createWindow(HINSTANCE hinst, int nCmdShow, UINT resPoolID, UINT title)
{
HWND hwnd; // handler for window to be created
TCHAR ClassName[MAX_RESOURCESTRING+1]; // window class name
TCHAR wndTitle[MAX_RESOURCESTRING+1]; // window title
HDC hDC;
HBITMAP hBit;
TEXTMETRIC tm;
// load class name into ClassName
LoadString(hinst,resPoolID,ClassName,DIM(ClassName));
// load title name into title
LoadString(hinst,title,wndTitle,DIM(wndTitle));
hwnd = CreateWindowEx(0, // extended window style
ClassName, // class name
wndTitle, // title
WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, // window style
CW_USEDEFAULT, // default x-pos of window
0, // y-pos of window, set 0 and use showWindow() to determine later
MAX_SCREENWIDTH, // width of window
MAX_SCREENHEIGHT+ GetSystemMetrics(SM_CYMENU)+GetSystemMetrics(SM_CYCAPTION), // height of window
NULL, // parent of window
LoadMenu(hinst, MAKEINTRESOURCE(resPoolID)), // handle of menu
hinst, //handle of application
this); // user defined parameters, hardly any use for it
if(!hwnd)
return NULL;
// make window appear
ShowWindow(hwnd,nCmdShow);
// Create a memory context for window
//----------------------------------------------------//
//1. get display context for window
hDC = GetDC(hwnd);
GetTextMetrics(hDC,&tm);// get textmetrics for creating window
//2. create compatible memory for window
memDC = CreateCompatibleDC(hDC);
//3. load main bitmap for window
hBit = (HBITMAP) LoadImage(GetWindowInstance(hwnd),
MAKEINTRESOURCE(IDB_MAINSCREEN),
IMAGE_BITMAP,
MAX_SCREENWIDTH,
MAX_SCREENHEIGHT,
LR_CREATEDIBSECTION|LR_VGACOLOR);
//4. select main bitmap into memory DC
//NOTE: MUST NOT DELETE BITMAP WHEN IT IS CURRENTLY SELECTED INTO A DC
hOldBit = (HBITMAP)SelectObject(memDC,hBit);
// 5. delete display context
ReleaseDC(hwnd,hDC);
//----------------------------------------------------//
// ALTERNATE METHOD IS TO USE SAVEDC!!!
// rich edit control for name input
InitCommonControls();
if(!LoadLibrary("riched20.dll"))
return 0;
hEditCtl = CreateWindowEx(0,
RICHEDIT_CLASS,
NULL,
WS_CHILD |ES_LEFT| WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL | ES_SUNKEN,
177,
284,
22*tm.tmAveCharWidth,
25,
hwnd,
(HMENU)ID_EDIT,
hinst,
NULL);
if(!hEditCtl)
MessageBox(hwnd,"Not working","not working",MB_ICONEXCLAMATION );
// limit the number of character that edit control takes
SendMessage(hEditCtl,EM_EXLIMITTEXT,0,15);
// make edit control beep when max number of character is exceeded
SendMessage(hEditCtl,EM_SETEDITSTYLE,SES_BEEPONMAXTEXT,SES_BEEPONMAXTEXT);
// create default push button
hButton = CreateWindowEx(0,
_T("button"),
_T("Start"),
WS_CHILD | WS_VISIBLE |WS_CLIPSIBLINGS |BS_DEFPUSHBUTTON,
177 +23*tm.tmAveCharWidth,
284,
50,
25,
hwnd,
(HMENU)ID_BUTTON,
hinst,
NULL);
// force main window to update
UpdateWindow(hwnd);
// set game window's parent window
gf.setParent(hwnd);
return hwnd;
}
Code:
int mainFrame::mainWindow_onPaint(HWND hwnd)
{
PAINTSTRUCT ps;
TEXTMETRIC tm;
HDC hDC;
hDC = GetDC(hEditCtl);
GetTextMetrics(hDC,&tm);
ReleaseDC(hwnd,hDC);
// copy the bitmap in memory into display context
hDC = BeginPaint(hwnd,&ps);
BitBlt(hDC,0,0,MAX_SCREENWIDTH,MAX_SCREENHEIGHT,memDC,0,0,SRCCOPY| CAPTUREBLT);
EndPaint(hwnd,&ps);
MoveWindow(hEditCtl,177,284,22*tm.tmAveCharWidth,25,TRUE);
UpdateWindow(hEditCtl);
UpdateWindow(hButton);
if(hGame)
UpdateWindow(hGame);
return 0;
}
Code:
void mainFrame::mainWindow_onCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{case ID_FILE_EXIT: DestroyWindow(hwnd);
return;
case ID_BUTTON: if( (hwndCtl == hButton) && (codeNotify == BN_CLICKED) )
{
ShowWindow(hEditCtl,SW_HIDE);
// create the game window, IGNORE THIS FIRST
//gf.createWindow(getHinst(),0,IDR_GAME,0);
MessageBox(hwndCtl,"Not working","not working",MB_ICONEXCLAMATION | MB_TOPMOST | MB_SETFOREGROUND);
}
else
FORWARD_WM_COMMAND(hwnd,id,hwndCtl,codeNotify,DefWindowProc);
break;
default: FORWARD_WM_COMMAND(hwnd,id,hwndCtl,codeNotify,DefWindowProc);
}
}