Post by Trad on Jun 15, 2003 13:51:55 GMT -5
Feel free to compile and experiment with this Hello World application for Win32 C++ programming
Remmember, WNDCLASs** = WNDCLASS+EX
just replace the ** with ex and you will be ok.
#include <windows.h>
#define IDC_TEXT 100
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_CREATE[img]http://proboards8.com/boardimages/sad.gif[/img]br] {
HINSTANCE hInstance = GetModuleHandle(NULL);
HFONT ComicSans = CreateFont(20,0,0,0,700,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_DONTCARE,"Comic Sans MS");
HWND hWnd_text = CreateWindowEx(0,"STATIC","Hello World - Win32 Style!",WS_CHILD | WS_VISIBLE,50,20,200,25,hWnd,(HMENU)IDC_TEXT,hInstance,NULL);
SendMessage(hWnd_text,WM_SETFONT,(WPARAM)ComicSans,(LPARAM)true);
HBRUSH hbrWhite = CreateSolidBrush(RGB(255,255,255));
SetClassLong(hWnd,GCL_HBRBACKGROUND,(LONG)hbrWhite );
InvalidateRect(hWnd,0,TRUE);
return 0;
}
case WM_COMMAND[img]http://proboards8.com/boardimages/sad.gif[/img]br] {
return 0;
}
case WM_CTLCOLORSTATIC[img]http://proboards8.com/boardimages/sad.gif[/img]br] {
HBRUSH hBrRed;
HBRUSH hBrWhite;
hBrRed = CreateSolidBrush(RGB(255,0,0));
hBrWhite = CreateSolidBrush(RGB(255,255,255));
HDC hdc = (HDC)wParam;
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(255,0,0));
return (ULONG)hBrWhite;
break;
}
case WM_CLOSE[img]http://proboards8.com/boardimages/sad.gif[/img]br] {
DestroyWindow(hWnd);
return 0;
}
case WM_DESTROY[img]http://proboards8.com/boardimages/sad.gif[/img]br] {
PostQuitMessage(0);
return 0;
}
default[img]http://proboards8.com/boardimages/sad.gif[/img]br] return DefWindowProc(hWnd, Msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASs** WndClass**;
WndClass**.cbSize = sizeof(WndClass**);
WndClass**.cbCls**tra = 0;
WndClass**.cbWndExtra = 0;
WndClass**.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
WndClass**.hCursor = LoadCursor(NULL, IDC_CROSS);
WndClass**.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass**.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
WndClass**.hInstance = hInstance;
WndClass**.lpfnWndProc = WndProc;
WndClass**.lpszClassName = "Window Class";
WndClass**.lpszMenuName = NULL;
WndClass**.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
if (!RegisterClass**(&WndClass**))
{
MessageBox(NULL, "Unable to register window class.", "Error", MB_ICONERROR);
return 0;
}
HWND hWnd = CreateWindowEx(NULL, "Window Class", "Win32 Hello World", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 200, 200, 300, 100, NULL, NULL, hInstance, NULL);
if (hWnd == NULL)
{
MessageBox(NULL, "Unable to create window.", "Error", MB_ICONERROR);
return 0;
}
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
Remmember, WNDCLASs** = WNDCLASS+EX
just replace the ** with ex and you will be ok.