// マルチバイト文字セット
#include <stdio.h>
#include <string.h>
#include <Windows.h>
#define IDC_STATIC -1
#define IDC_EDIT 100
static HINSTANCE g_hInstance;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void OnCreate(HWND hWnd);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
const char acClassName[] = "DlgFrame";
WNDCLASSEX wcex;
HWND hWnd;
MSG msg;
g_hInstance = hInstance;
// ウィンドウクラスの登録
wcex.cbSize = sizeof wcex;
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = acClassName;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (RegisterClassEx(&wcex) == 0) {
return 0;
}
// ウィンドウの作成
hWnd = CreateWindow(
acClassName, // ClassName
"Dialog Frame", // WindowName
WS_OVERLAPPEDWINDOW, // Style
CW_USEDEFAULT, // x
0, // y
CW_USEDEFAULT, // Width
0, // Height
NULL, // WndParent
NULL, // Menu
hInstance,
NULL);
if (hWnd == NULL) {
return 0;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND hWndEdit;
switch (uMsg) {
case WM_COMMAND:
hWndEdit = GetDlgItem(hWnd, IDC_EDIT);
switch (LOWORD(wParam)) {
case IDOK:
SetWindowText(hWndEdit, "OK");
break;
case IDCANCEL:
SetWindowText(hWndEdit, "Cancel");
break;
}
break;
case WM_CREATE:
OnCreate(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
void OnCreate(HWND hWnd)
{
CreateWindow("STATIC", "Push button",
WS_CHILD | WS_VISIBLE,
8, 8, 123, 32, hWnd, (HMENU)IDC_STATIC, g_hInstance, NULL);
CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "Edit",
WS_CHILD | WS_VISIBLE,
144, 8, 123, 32, hWnd, (HMENU)IDC_EDIT, g_hInstance, NULL);
CreateWindow("BUTTON", "OK",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
8, 48, 128, 32, hWnd, (HMENU)IDOK, g_hInstance, NULL);
CreateWindow("BUTTON", "Cancel",
WS_CHILD | WS_VISIBLE,
144, 48, 128, 32, hWnd, (HMENU)IDCANCEL, g_hInstance, NULL);
}