前提・実現したいこと
C++ととWinAPIで親ウィンドウに2分割で子ウィンドウを2つ配置しました。
しかし
(1)実行時は出ていないのですけどマウスでホバーすると最小化最大化終了ボタンが表示され、
(2)サイズの変更後、左の子ウィンドウの文字をクリックするとサイズ変更前の初期サイズの白い線が発生します。
どこか再描画のタイミングがおかしいのでしょうか
また(3)子ウィンドウのプロシージャのつなぎ方は親ウィンドウ同様WNDCLASSを再び使えばいいのでしょうか
発生している問題・エラーメッセージ
該当のソースコード
C++
1#define UNICODE 2#include <windows.h> 3#define ID_CHILD_1 10001 4#define ID_CHILD_2 10002 5 6LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); 7LRESULT CALLBACK ChildWindowProc1(HWND, UINT, WPARAM, LPARAM); 8LRESULT CALLBACK ChildWindowProc2(HWND, UINT, WPARAM, LPARAM); 9 10HINSTANCE hInst; 11RECT rcWindow; 12const wchar_t CLASS_NAME[] = L"Main Window"; 13 14 15int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR pCmdLine, int nCmdShow) 16{ 17 WNDCLASSEX wcMain = {}; 18 wcMain.cbSize = sizeof(WNDCLASSEX); 19 wcMain.style = CS_HREDRAW | CS_VREDRAW; 20 wcMain.lpfnWndProc = WindowProc; 21 wcMain.cbClsExtra = 0; 22 wcMain.cbWndExtra = 0; 23 wcMain.hInstance = hInstance; 24 wcMain.hIcon = NULL; 25 wcMain.hIconSm = (HCURSOR)LoadImage( 26 NULL, 27 MAKEINTRESOURCE(IDC_ARROW), 28 IMAGE_CURSOR, 29 0, 0, 30 LR_DEFAULTSIZE | LR_SHARED 31 ); 32 wcMain.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 33 wcMain.lpszMenuName = NULL; 34 wcMain.lpszClassName = CLASS_NAME; 35 wcMain.hIconSm = NULL; 36 37 RegisterClassEx(&wcMain); 38 39 HWND hMothWnd = CreateWindowEx 40 ( 41 0, 42 CLASS_NAME, 43 L"Mother Window", 44 WS_OVERLAPPEDWINDOW | WS_EX_TRANSPARENT, 45 CW_USEDEFAULT, 46 CW_USEDEFAULT, 47 CW_USEDEFAULT, 48 CW_USEDEFAULT, 49 NULL, 50 NULL, 51 hInstance, 52 NULL 53 ); 54 55 if (hMothWnd == NULL)return 0; 56 57 ShowWindow(hMothWnd, nCmdShow); 58 UpdateWindow(hMothWnd); 59 60 MSG msg = {}; 61 while (GetMessage(&msg, NULL, 0, 0)) 62 { 63 TranslateMessage(&msg); 64 DispatchMessage(&msg); 65 } 66 67 68 return 0; 69} 70 71LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 72{ 73 static HWND hChildWnd_L, hChildWnd_R; 74 switch (uMsg) 75 { 76 case WM_DESTROY: 77 PostQuitMessage(0); 78 return 0; 79 80 case WM_SIZE: 81 if (GetClientRect(hwnd, &rcWindow) == false) { 82 MessageBox(hwnd, L"Can't Get the ClientRect", L"Alert", IDOK); 83 break; 84 } 85 86 case WM_CREATE: 87 WNDCLASSEX cwlc; 88 cwlc.cbSize = sizeof(WNDCLASSEX); 89 cwlc.lpfnWndProc = ChildWindowProc1; 90 cwlc.hInstance = hInst; 91 cwlc.lpszClassName = L"Child Window 1"; 92 cwlc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 93 cwlc.style = CS_HREDRAW | CS_VREDRAW; 94 95 cwlc.lpszMenuName = NULL; 96 RegisterClassEx(&cwlc); 97 98 hChildWnd_L = CreateWindowEx 99 ( 100 0, 101 L"EDIT", 102 L"Child Window 1", 103 WS_CHILD | WS_DLGFRAME | WS_VISIBLE, 104 0, 105 0, 106 (rcWindow.right-rcWindow.left)/2, 107 rcWindow.bottom-rcWindow.top, 108 hwnd, 109 (HMENU)ID_CHILD_1, 110 hInst, 111 NULL 112 ); 113 114 WNDCLASSEX cwlc2; 115 cwlc2.cbSize = sizeof(WNDCLASSEX); 116 cwlc2.lpfnWndProc = ChildWindowProc2; 117 cwlc2.hInstance = hInst; 118 cwlc2.lpszClassName = L"Child Window 2"; 119 cwlc2.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 120 cwlc2.style = CS_HREDRAW | CS_VREDRAW; 121 122 cwlc2.lpszMenuName = NULL; 123 RegisterClassEx(&cwlc); 124 hChildWnd_R = CreateWindowEx 125 ( 126 0, 127 L"EDIT", 128 L"Child Window 2", 129 WS_CHILD | WS_THICKFRAME | WS_VISIBLE | ES_MULTILINE | 130 ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | WS_OVERLAPPEDWINDOW, 131 (rcWindow.right - rcWindow.left) / 2, 132 rcWindow.top, 133 (rcWindow.right - rcWindow.left) / 2, 134 rcWindow.bottom - rcWindow.top, 135 hwnd, 136 (HMENU)ID_CHILD_2, 137 hInst, 138 NULL 139 ); 140 break; 141 142 } 143 return DefWindowProc(hwnd, uMsg, wParam, lParam); 144} 145 146LRESULT CALLBACK ChildWindowProc1(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {return DefWindowProc(hwnd, uMsg, wParam, lParam);} 147 148LRESULT CALLBACK ChildWindowProc2(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {return DefWindowProc(hwnd, uMsg, wParam, lParam);}
コーディング上のご指摘もありがたいです。
補足情報
Windows10 Pro
VisualStudio2017Community

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/07/21 03:56
2018/07/21 05:32