Win32APIのダイアログを使ってダイアログボックスを作ったのですが、
ダイアログボックスの操作の仕方がわかりません。
ラジオボタンが3つ。
チェックボックスが2つ。
普通のボタンがひとつのダイアログボックスです。
コードは、
Resource.rc
1#include <windows.h> 2#include <commctrl.h> 3#include <richedit.h> 4#include "resource.h" 5 6 7 8 9// 10// Dialog resources 11// 12LANGUAGE 0, SUBLANG_NEUTRAL 13KITTY DIALOG 0, 0, 120, 101 14STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 15CAPTION "TEST" 16FONT 8, "Ms Shell Dlg" 17{ 18 LTEXT "解像度を選択してください", 0, 7, 3, 81, 9, SS_LEFT, WS_EX_LEFT 19 AUTORADIOBUTTON "640x480", 0, 6, 18, 43, 8, 0, WS_EX_LEFT 20 AUTORADIOBUTTON "960x720", 0, 6, 30, 43, 8, 0, WS_EX_LEFT 21 AUTORADIOBUTTON "1280x960(推奨)", 0, 6, 43, 67, 8, 0, WS_EX_LEFT 22 AUTOCHECKBOX "フルスクリーンで起動する", 0, 7, 57, 92, 8, 0, WS_EX_LEFT 23 AUTOCHECKBOX "起動時に毎回訊ねる", 0, 7, 68, 83, 8, 0, WS_EX_LEFT 24 PUSHBUTTON " ゲーム起動 ",IDOK, 34, 82, 52, 14, 0, WS_EX_LEFT 25} 26
Main.cpp
1 2#include<windows.h> 3#include<d3d9.h> 4#pragma comment( lib, "d3d9.lib" ) 5#pragma comment( lib, "d3dx9d.lib" ) 6#pragma comment( lib, "d3dx9.lib" ) 7#pragma comment( lib, "dxerr.lib" ) 8 9BOOL CALLBACK DialogProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { 10 switch (msg) { 11 case WM_CLOSE: 12 PostQuitMessage(0); 13 EndDialog(hwnd , IDCANCEL); 14 return TRUE; 15 case WM_COMMAND: 16 if (LOWORD(wp) == IDOK) { 17 EndDialog(hwnd , IDOK); 18 } 19 return TRUE; 20 } 21 return FALSE; 22} 23 24LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { 25 switch (msg) { 26 case WM_DESTROY: 27 PostQuitMessage(0); 28 return 0; 29 } 30 return DefWindowProc(hwnd, msg, wp, lp); 31} 32 33int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 34 PSTR lpCmdLine, int nCmdShow) { 35 HWND hwnd; 36 MSG msg; 37 WNDCLASS winc; 38 LPDIRECT3D9 m_pD3D = NULL; 39 D3DPRESENT_PARAMETERS m_D3DPP; 40 D3DDISPLAYMODE d3ddm; 41 LPDIRECT3DDEVICE9 m_pD3DDevice = NULL; 42 43 d3ddm.Width = 640; 44 d3ddm.Height = 480; 45 d3ddm.Format = D3DFMT_A8R8G8B8; 46 d3ddm.RefreshRate = 60; 47 winc.style = CS_HREDRAW | CS_VREDRAW; 48 winc.lpfnWndProc = WndProc; 49 winc.cbClsExtra = winc.cbWndExtra = 0; 50 winc.hInstance = hInstance; 51 winc.hIcon = LoadIcon(NULL, IDI_APPLICATION); 52 winc.hCursor = LoadCursor(NULL, IDC_ARROW); 53 winc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 54 winc.lpszMenuName = NULL; 55 winc.lpszClassName = TEXT("WCN"); 56 57 if (!RegisterClass(&winc)) return 0; 58 59 hwnd = CreateWindow( 60 TEXT("WCN"), TEXT("Test"), 61 WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, 62 175, 50, 640, 480, NULL, NULL, 63 hInstance, NULL 64 ); 65 66 if (hwnd == NULL) return 0; 67 BOOL isFullScreen = FALSE; 68 for (int i = 0; i < __argc; i++) { 69 if (_stricmp(__argv[i], "/f") == 0) { 70 isFullScreen = TRUE; 71 break; 72 } 73 } 74 75 76 if ((m_pD3D = ::Direct3DCreate9(D3D_SDK_VERSION)) == 0) { 77 return E_FAIL; 78 } 79 80 ZeroMemory(&m_D3DPP, sizeof(D3DPRESENT_PARAMETERS)); 81 82 m_D3DPP.BackBufferCount = 1; 83 if (isFullScreen) { 84 m_D3DPP.Windowed = FALSE; 85 m_D3DPP.BackBufferWidth = 1280; 86 m_D3DPP.BackBufferHeight = 720; 87 } 88 else { 89 m_D3DPP.Windowed = TRUE; 90 } 91 m_D3DPP.BackBufferFormat = d3ddm.Format; 92 m_D3DPP.SwapEffect = D3DSWAPEFFECT_DISCARD; 93 m_D3DPP.EnableAutoDepthStencil = TRUE; 94 m_D3DPP.AutoDepthStencilFormat = D3DFMT_D16; 95 96 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 97 D3DDEVTYPE_HAL, 98 hwnd, 99 D3DCREATE_HARDWARE_VERTEXPROCESSING, 100 &m_D3DPP, &m_pD3DDevice))) { 101 102 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 103 D3DDEVTYPE_HAL, 104 hwnd, 105 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 106 &m_D3DPP, &m_pD3DDevice))) { 107 if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, 108 D3DDEVTYPE_REF, 109 hwnd, 110 D3DCREATE_SOFTWARE_VERTEXPROCESSING, 111 &m_D3DPP, &m_pD3DDevice))) { 112 return E_FAIL; 113 } 114 } 115 } 116 117 //解像度ダイアログボックス 118 DialogBox( 119 (HINSTANCE)GetWindowLong(hwnd , GWL_HINSTANCE) , 120 TEXT("KITTY") , hwnd , DialogProc 121 ); 122 123 while (GetMessage(&msg, NULL, 0, 0)) { 124 //BeginScene 125 if (FAILED(m_pD3DDevice->BeginScene())) { 126 return 0; 127 } 128 129 if (FAILED(m_pD3DDevice->Clear(0, NULL, 130 D3DCLEAR_TARGET | 131 D3DCLEAR_ZBUFFER, 132 D3DCOLOR_XRGB(0, 0, 0), 133 1.0f, 134 0))) { 135 return 0; 136 } 137 138 m_pD3DDevice->EndScene(); 139 140 if (FAILED(m_pD3DDevice->Present(0, 0, 0, 0))) { 141 m_pD3DDevice->Reset(&m_D3DPP); 142 } 143 DispatchMessage(&msg); 144 } 145 return msg.wParam; 146}
ゲーム開始ボタンが押されたら、メインウィンドウが表示されるコードですが、
うまく機能しません。
回答1件
あなたの回答
tips
プレビュー