Code:
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
char szClassName[] = "WindowsApp";
HINSTANCE g_hInst;
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
g_hInst = hThisInstance;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProc;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wincl)) return 0;
hwnd = CreateWindowEx(0,szClassName, "Windows App",
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT, HWND_DESKTOP,NULL,
hThisInstance,NULL );
ShowWindow(hwnd, nFunsterStil);
UpdateWindow(hwnd);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc; //handle to device context
static enum {RED = 0,GREEN,BLUE};//enumerate possible colours
static int nCol = 0;//Active colour
COLORREF col;//RGB colour to use
PAINTSTRUCT ps;//Paint structure
switch (message)
{
case WM_COMMAND:
switch(LOWORD(wParam)){//What col was selected in menu
case ID_COLOUR_GREEN:
nCol = GREEN;
break;
case ID_COLOUR_BLUE:
nCol = BLUE;
break;
case ID_COLOUR_RED:
nCol = RED;
break;
}
InvalidateRect(hwnd,NULL,TRUE);//Make window repaint itself
break;
case WM_PAINT:
switch(nCol){//What is the active colour
case BLUE:
col = RGB(0,0,255);
break;
case GREEN:
col = RGB(0,255,0);
break;
case RED:
col = RGB(255,0,0);
break;
}
hdc = BeginPaint(hwnd, &ps);//Get DC and remove paint message
SetTextColor(hdc,col);//Set the colour of test
TextOut(hdc,100,100,"Hello World - in colour",23);//Some text to write
EndPaint(hwnd,&ps);//Clear DC
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
Here's an app that paints some txt on its window.....you click down the menu and you can change the colour