Just for the heck of it, I translated my PowerBASIC code to C++. Here's the whole program (which contains the fnWndProc_OnPaint() handler which paints the screen red and prints "Hello, World!" in a gigantic font). Its a compilable program...
//WinTypes.h
#ifndef WINTYPES_H
#define WINTYPES_H
#define dim(x) (sizeof(x) / sizeof(x[0]))
typedef struct WindowsEventArguments
{
HWND hWnd;
WPARAM wParam;
LPARAM lParam;
HINSTANCE hIns;
}WndEventArgs, *lpWndEventArgs;
long fnWndProc_OnPaint (lpWndEventArgs Wea);
long fnWndProc_OnClose (lpWndEventArgs Wea);
struct EVENTHANDLER
{
unsigned int Code;
long (*fnPtr)(lpWndEventArgs);
};
const EVENTHANDLER EventHandler[]=
{
{WM_PAINT, fnWndProc_OnPaint},
{WM_CLOSE, fnWndProc_OnClose}
};
#endif
//Main.cpp
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <tchar.h>
#include "WinTypes.h"
long fnWndProc_OnPaint(lpWndEventArgs Wea)
{
TCHAR szBuffer[]=_T("Hello, World!");
HFONT hFont,hTmpFnt;
HBRUSH hBrush,hTmpBr;
PAINTSTRUCT ps;
RECT rc;
HDC hDC;
hDC=BeginPaint(Wea->hWnd,&ps);
hBrush=CreateSolidBrush(0x000000FF);
hTmpBr=(HBRUSH)SelectObject(hDC,hBrush);
GetClientRect(Wea->hWnd,&rc);
FillRect(hDC,&rc,hBrush);
DeleteObject(SelectObject(hDC,hTmpBr));
SetTextColor(hDC,0x00FFFFFF);
hFont=CreateFont(80,0,0,0,FW_BOLD,0,0,0,0,0,0,2,0,_T("SYSTEM_FIXED_FONT"));
hTmpFnt=(HFONT)SelectObject(hDC,hFont);
SetBkMode(hDC,TRANSPARENT);
DrawText(hDC,szBuffer,13,&rc,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
DeleteObject(SelectObject(hDC,hTmpFnt));
EndPaint(Wea->hWnd,&ps);
return 0;
}
long fnWndProc_OnClose(lpWndEventArgs Wea)
{
DestroyWindow(Wea->hWnd);
PostQuitMessage(0);
return 0;
}
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
WndEventArgs Wea;
for(unsigned int i=0; i<dim(EventHandler); i++)
{
if(EventHandler[i].Code==msg)
{
Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
return (*EventHandler[i].fnPtr)(&Wea);
}
}
return (DefWindowProc(hwnd,msg,wParam,lParam));
}
int WINAPI WinMain(HINSTANCE hIns,HINSTANCE hPrevIns,LPSTR lpszArgument,int iShow)
{
TCHAR szClassName[]=_T("Hello");
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName; wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX); wc.style=CS_VREDRAW|CS_HREDRAW;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=hIns;
wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wc.cbWndExtra=12;
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindow(szClassName,szClassName,WS_OVERLAPPEDWINDOW,150,150,500,450,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
UpdateWindow(hWnd);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}