Et meget hurtigt eksempel:
#include <windows.h>
#include <commctrl.h>
#include <sstream>
#include <string>
#include <iomanip>
enum WindowsId
{
FirstEditId = 256,
ButtonId,
};
HINSTANCE InstanceHandle;
int NumPush = 0;
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
CreateWindowEx(WS_EX_CLIENTEDGE,
"EDIT",
"",
WS_CHILD | WS_VISIBLE | ES_NUMBER | WS_TABSTOP | WS_GROUP,
5, 5, 380, 20,
hwndDlg,
(HMENU)(FirstEditId),
InstanceHandle,
0);
CreateWindow("BUTTON",
"Push Me",
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
10, 105, 75, 25,
hwndDlg,
(HMENU )ButtonId,
InstanceHandle,
0);
break;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == ButtonId)
{
std::stringstream SS;
double d = 5.0/3.0;
SS << "Lets play with numbers: ";
SS << std::setprecision(5) << d;
std::string T = SS.str();
SetDlgItemText(hwndDlg, FirstEditId, T.c_str());
}
break;
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, INT nCmdShow)
{
InstanceHandle = hInstance;
InitCommonControls();
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",
"Calc", // Caption text
WS_MINIMIZEBOX | WS_VISIBLE | WS_MAXIMIZEBOX |
WS_CAPTION | WS_BORDER | WS_SYSMENU,
100, 100, 400, 240, // Position
NULL,
NULL,
InstanceHandle,
0);
MSG Msg;
while(GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
{
if(!IsDialogMessage(WindowHandle, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}