Et meget hurtigt eksempel:
#include <windows.h>
#define IDC_BUTTON1 1200
HINSTANCE InstanceHandle;
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
CreateWindow("BUTTON",
"",
WS_CHILD | WS_VISIBLE | BS_BITMAP,
5, 5, 40, 40,
hwndDlg,
(HMENU)(IDC_BUTTON1),
InstanceHandle,
0);
HBITMAP ButtonBitmap = (HBITMAP )LoadImage(0, "button.bmp", IMAGE_BITMAP, 32, 32, LR_LOADFROMFILE);
SendDlgItemMessage(hwndDlg, IDC_BUTTON1, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM )ButtonBitmap);
}
break;
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, INT nCmdShow)
{
InstanceHandle = hInstance;
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = DialogProc;
wc.hInstance = InstanceHandle;
wc.hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1);
wc.lpszClassName = "WhateverClass";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if(!RegisterClass(&wc))
return FALSE;
HWND WindowHandle = CreateWindow("WhateverClass",
"Whatever", // Caption text
WS_MINIMIZEBOX | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_CAPTION | WS_BORDER | WS_SYSMENU,
100, 100, 150, 100, // Position
NULL,
NULL,
InstanceHandle,
0);
MSG Msg;
while(GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
{
if(!IsDialogMessage(WindowHandle, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}
Det loader et billede kaldet button.bmp, som forventes at ligge i samme mappe som programmet.