DlgBase
Visual C++ 2005 Express Edition
Windows Server 2003 SP1 Platform SDK
Windowsアプリケーション
リソースを使わないモーダルダイアログ
DlgBase.c
// マルチバイト文字セット #include
#define APPNAME "DlgBase" static HINSTANCE g_hInstance; static HWND g_hWndEdit; 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) { char acAppName[] = APPNAME; WNDCLASSEX wcex; HWND hWnd; MSG msg; g_hInstance = hInstance; wcex.cbSize = sizeof(WNDCLASSEX); 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 = acAppName; wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wcex); hWnd = CreateWindow( acAppName, acAppName, // WindowName WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, // x CW_USEDEFAULT, // y CW_USEDEFAULT, // Width CW_USEDEFAULT, // Height NULL, // WndParent NULL, // Menu hInstance, NULL); // Param 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) { switch (uMsg) { case WM_COMMAND: switch (LOWORD(wParam)) { case 0: SetWindowText(g_hWndEdit, "Button1"); break; case 2: SetWindowText(g_hWndEdit, "Button2"); 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("BUTTON", "Button1", WS_CHILD | WS_VISIBLE, 8, 8, 128, 32, hWnd, (HMENU)0, g_hInstance, NULL); g_hWndEdit = CreateWindow("EDIT", "Edit", WS_CHILD | WS_VISIBLE, 144, 8, 128, 32, hWnd, (HMENU)1, g_hInstance, NULL); CreateWindow("BUTTON", "Button2", WS_CHILD | WS_VISIBLE, 8, 48, 128, 32, hWnd, (HMENU)2, g_hInstance, NULL); }