Click to See Complete Forum and Search --> : WIN GDI (WIN32) - Window


inbugable
March 30th, 2008, 03:26 PM
Hello,

I have made in win32 window.
This compiles with dev-c 4 complete without errors but when i start the program it will do nothing.

Can anyone help me with this please ?

greetz,

inbugable


#include <windows.h>

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

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char * szCmdLine, int iCmdShow)
{
char szAppName[] = "My window";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wndclass.lpszMenuName = NULL;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;

//register class
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, "Window registration failed!", szAppName, MB_OK);
return 0;
}

//create window
hwnd = CreateWindow(szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);


//messageloop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

//window procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT lpps;
RECT lprect;

switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &lpps);

GetClientRect(hwnd, &lprect);
DrawText(hdc, "Hello World!", -1, &lprect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

EndPaint(hwnd, &lpps);
return 0;


case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, lParam, wParam);
}