Window creation error

can anyone tell why occurs error ??


#include<windows.h>
#include<tchar.h>
#include<cstdlib>

BOOL RegClass(WNDPROC, LPCTSTR, UINT);

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

LRESULT CALLBACK WndPopup(HWND, UINT, WPARAM, LPARAM);


HINSTANCE hInstance;
TCHAR szMainClass[] = _TEXT("Main Class");
TCHAR szPopupClass[] = _TEXT("Popup Class");
TCHAR szTitle[] = _TEXT("Project No 1");

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
LPSTR lpszCmdLine, int nCmdShow)

{
HWND hWnd;
MSG msg;

hInstance=hInst;

if(!RegClass(WndProc, szMainClass, COLOR_WINDOW))
{
MessageBox(NULL,_TEXT("Error,cannot register class!"), NULL, MB_OK);
exit(EXIT_FAILURE);
}

hWnd=CreateWindow(szMainClass, szTitle,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
0,0,
hInstance, 0);

if(!hWnd)
{
MessageBox(NULL,_TEXT("Error,cannot create window!"), NULL, MB_OK);
exit(EXIT_FAILURE);
}

while( GetMessage(&msg, 0, 0, 0) )
{
//TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

BOOL RegClass(WNDPROC Proc, LPCTSTR szName, UINT brBackground)
{
WNDCLASS wc;

wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = Proc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (brBackground+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szName;

return (RegisterClass(&wc));

}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static short cxClient, cyClient, yStep, xStep;
static short left, top, Width, Height;

static HWND hwnds[5];

switch(msg)
{

case WM_CREATE:
{
yStep=GetSystemMetrics(SM_CYCAPTION);
return 0;
}

case WM_MOVE:
{
left = LOWORD(lParam);
top = HIWORD(lParam);

for(short j=0; j<5 ; ++j)
if( IsWindow(hwnds[j]) )
MoveWindow(hwnds[j],
left+cxClient-Width-xStep*j,
top+cyClient-Height-yStep*j,
Width, Height, TRUE);

return 0;

}

case WM_SIZE:
{
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);

Width = cxClient/2;
Height = cyClient - 4 * yStep;

xStep=(cxClient-Width)/4;

for(short j=0; j<5 ; ++j)
if( IsWindow(hwnds[j]) )
MoveWindow(hwnds[j],
left+cxClient-Width-xStep*j,
top+cyClient-Height-yStep*j,
Width, Height, TRUE);

return 0;

}

case WM_LBUTTONDOWN:
{
short j=0;

for(; j<5 , IsWindow(hwnds[j]); ++j);

if( j > 4) return 0;

TCHAR str[20];
_itot(j, str, 10);
_tcscat(str, _TEXT(" window") );

hwnds[j]=CreateWindow(szPopupClass, str,
WS_POPUPWINDOW | WS_CAPTION| WS_VISIBLE,
left+cxClient-Width-xStep*j,
top+cyClient-Height-yStep*j,
Width, Height, hwnd, 0,
hInstance, 0);

if(!hwnds[j])
{
MessageBox(NULL,_TEXT("Error,cannot create window!"), NULL, MB_OK);
exit(EXIT_FAILURE);
}

if( j > 0 )
{
SetWindowPos(hwnds[j], hwnds[j-1], 0, 0,
Width, Height, SWP_NOMOVE);

SetForegroundWindow(hwnds[0]);
}

break;//return 0;
}

case WM_DESTROY:
{
PostQuitMessage(0);
break;//return 0;
}
}

return DefWindowProc(hwnd, msg, wParam, lParam);
}


LRESULT CALLBACK WndPopup(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hwnd, msg, wParam, lParam);
}








Last edited on
Because you did something wrong.
You're welcome.
Topic archived. No new replies allowed.