diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
| commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
| tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /CPP/Windows/Control/Window2.cpp | |
| parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
| download | 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.gz 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.tar.bz2 7zip-f19f813537c7aea1c20749c914e756b54a9c3cf5.zip | |
'21.07'21.07
Diffstat (limited to 'CPP/Windows/Control/Window2.cpp')
| -rw-r--r-- | CPP/Windows/Control/Window2.cpp | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/CPP/Windows/Control/Window2.cpp b/CPP/Windows/Control/Window2.cpp new file mode 100644 index 0000000..994d96e --- /dev/null +++ b/CPP/Windows/Control/Window2.cpp | |||
| @@ -0,0 +1,200 @@ | |||
| 1 | // Windows/Control/Window2.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #ifndef _UNICODE | ||
| 6 | #include "../../Common/StringConvert.h" | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include "Window2.h" | ||
| 10 | |||
| 11 | #ifndef _UNICODE | ||
| 12 | extern bool g_IsNT; | ||
| 13 | #endif | ||
| 14 | |||
| 15 | namespace NWindows { | ||
| 16 | |||
| 17 | #ifndef _UNICODE | ||
| 18 | ATOM MyRegisterClass(CONST WNDCLASSW *wndClass); | ||
| 19 | #endif | ||
| 20 | |||
| 21 | namespace NControl { | ||
| 22 | |||
| 23 | #ifdef UNDER_CE | ||
| 24 | #define MY_START_WM_CREATE WM_CREATE | ||
| 25 | #else | ||
| 26 | #define MY_START_WM_CREATE WM_NCCREATE | ||
| 27 | #endif | ||
| 28 | |||
| 29 | static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 30 | { | ||
| 31 | CWindow tempWindow(aHWND); | ||
| 32 | if (message == MY_START_WM_CREATE) | ||
| 33 | tempWindow.SetUserDataLongPtr((LONG_PTR)(((LPCREATESTRUCT)lParam)->lpCreateParams)); | ||
| 34 | CWindow2 *window = (CWindow2 *)(tempWindow.GetUserDataLongPtr()); | ||
| 35 | if (window != NULL && message == MY_START_WM_CREATE) | ||
| 36 | window->Attach(aHWND); | ||
| 37 | if (window == 0) | ||
| 38 | { | ||
| 39 | #ifndef _UNICODE | ||
| 40 | if (g_IsNT) | ||
| 41 | return DefWindowProcW(aHWND, message, wParam, lParam); | ||
| 42 | else | ||
| 43 | #endif | ||
| 44 | return DefWindowProc(aHWND, message, wParam, lParam); | ||
| 45 | } | ||
| 46 | return window->OnMessage(message, wParam, lParam); | ||
| 47 | } | ||
| 48 | |||
| 49 | bool CWindow2::CreateEx(DWORD exStyle, LPCTSTR className, LPCTSTR windowName, | ||
| 50 | DWORD style, int x, int y, int width, int height, | ||
| 51 | HWND parentWindow, HMENU idOrHMenu, HINSTANCE instance) | ||
| 52 | { | ||
| 53 | WNDCLASS wc; | ||
| 54 | if (!::GetClassInfo(instance, className, &wc)) | ||
| 55 | { | ||
| 56 | // wc.style = CS_HREDRAW | CS_VREDRAW; | ||
| 57 | wc.style = 0; | ||
| 58 | wc.lpfnWndProc = WindowProcedure; | ||
| 59 | wc.cbClsExtra = 0; | ||
| 60 | wc.cbWndExtra = 0; | ||
| 61 | wc.hInstance = instance; | ||
| 62 | wc.hIcon = NULL; | ||
| 63 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); | ||
| 64 | wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | ||
| 65 | wc.lpszMenuName = NULL; | ||
| 66 | wc.lpszClassName = className; | ||
| 67 | if (::RegisterClass(&wc) == 0) | ||
| 68 | return false; | ||
| 69 | } | ||
| 70 | return CWindow::CreateEx(exStyle, className, windowName, style, | ||
| 71 | x, y, width, height, parentWindow, idOrHMenu, instance, this); | ||
| 72 | } | ||
| 73 | |||
| 74 | #ifndef _UNICODE | ||
| 75 | |||
| 76 | bool CWindow2::CreateEx(DWORD exStyle, LPCWSTR className, LPCWSTR windowName, | ||
| 77 | DWORD style, int x, int y, int width, int height, | ||
| 78 | HWND parentWindow, HMENU idOrHMenu, HINSTANCE instance) | ||
| 79 | { | ||
| 80 | bool needRegister; | ||
| 81 | if (g_IsNT) | ||
| 82 | { | ||
| 83 | WNDCLASSW wc; | ||
| 84 | needRegister = ::GetClassInfoW(instance, className, &wc) == 0; | ||
| 85 | } | ||
| 86 | else | ||
| 87 | { | ||
| 88 | WNDCLASSA windowClassA; | ||
| 89 | AString classNameA; | ||
| 90 | LPCSTR classNameP; | ||
| 91 | if (IS_INTRESOURCE(className)) | ||
| 92 | classNameP = (LPCSTR)className; | ||
| 93 | else | ||
| 94 | { | ||
| 95 | classNameA = GetSystemString(className); | ||
| 96 | classNameP = classNameA; | ||
| 97 | } | ||
| 98 | needRegister = ::GetClassInfoA(instance, classNameP, &windowClassA) == 0; | ||
| 99 | } | ||
| 100 | if (needRegister) | ||
| 101 | { | ||
| 102 | WNDCLASSW wc; | ||
| 103 | // wc.style = CS_HREDRAW | CS_VREDRAW; | ||
| 104 | wc.style = 0; | ||
| 105 | wc.lpfnWndProc = WindowProcedure; | ||
| 106 | wc.cbClsExtra = 0; | ||
| 107 | wc.cbWndExtra = 0; | ||
| 108 | wc.hInstance = instance; | ||
| 109 | wc.hIcon = NULL; | ||
| 110 | wc.hCursor = LoadCursor(NULL, IDC_ARROW); | ||
| 111 | wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | ||
| 112 | wc.lpszMenuName = NULL; | ||
| 113 | wc.lpszClassName = className; | ||
| 114 | if (MyRegisterClass(&wc) == 0) | ||
| 115 | return false; | ||
| 116 | } | ||
| 117 | return CWindow::CreateEx(exStyle, className, windowName, style, | ||
| 118 | x, y, width, height, parentWindow, idOrHMenu, instance, this); | ||
| 119 | } | ||
| 120 | |||
| 121 | #endif | ||
| 122 | |||
| 123 | LRESULT CWindow2::DefProc(UINT message, WPARAM wParam, LPARAM lParam) | ||
| 124 | { | ||
| 125 | #ifndef _UNICODE | ||
| 126 | if (g_IsNT) | ||
| 127 | return DefWindowProcW(_window, message, wParam, lParam); | ||
| 128 | else | ||
| 129 | #endif | ||
| 130 | return DefWindowProc(_window, message, wParam, lParam); | ||
| 131 | } | ||
| 132 | |||
| 133 | LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | ||
| 134 | { | ||
| 135 | LRESULT result; | ||
| 136 | switch (message) | ||
| 137 | { | ||
| 138 | case WM_CREATE: | ||
| 139 | if (!OnCreate((CREATESTRUCT *)lParam)) | ||
| 140 | return -1; | ||
| 141 | break; | ||
| 142 | case WM_COMMAND: | ||
| 143 | if (OnCommand(wParam, lParam, result)) | ||
| 144 | return result; | ||
| 145 | break; | ||
| 146 | case WM_NOTIFY: | ||
| 147 | if (OnNotify((UINT)wParam, (LPNMHDR) lParam, result)) | ||
| 148 | return result; | ||
| 149 | break; | ||
| 150 | case WM_DESTROY: | ||
| 151 | OnDestroy(); | ||
| 152 | break; | ||
| 153 | case WM_CLOSE: | ||
| 154 | OnClose(); | ||
| 155 | return 0; | ||
| 156 | case WM_SIZE: | ||
| 157 | if (OnSize(wParam, LOWORD(lParam), HIWORD(lParam))) | ||
| 158 | return 0; | ||
| 159 | } | ||
| 160 | return DefProc(message, wParam, lParam); | ||
| 161 | } | ||
| 162 | |||
| 163 | bool CWindow2::OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result) | ||
| 164 | { | ||
| 165 | return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result); | ||
| 166 | } | ||
| 167 | |||
| 168 | bool CWindow2::OnCommand(int /* code */, int /* itemID */, LPARAM /* lParam */, LRESULT & /* result */) | ||
| 169 | { | ||
| 170 | return false; | ||
| 171 | // return DefProc(message, wParam, lParam); | ||
| 172 | /* | ||
| 173 | if (code == BN_CLICKED) | ||
| 174 | return OnButtonClicked(itemID, (HWND)lParam); | ||
| 175 | */ | ||
| 176 | } | ||
| 177 | |||
| 178 | /* | ||
| 179 | bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) | ||
| 180 | { | ||
| 181 | switch (buttonID) | ||
| 182 | { | ||
| 183 | case IDOK: | ||
| 184 | OnOK(); | ||
| 185 | break; | ||
| 186 | case IDCANCEL: | ||
| 187 | OnCancel(); | ||
| 188 | break; | ||
| 189 | case IDHELP: | ||
| 190 | OnHelp(); | ||
| 191 | break; | ||
| 192 | default: | ||
| 193 | return false; | ||
| 194 | } | ||
| 195 | return true; | ||
| 196 | } | ||
| 197 | |||
| 198 | */ | ||
| 199 | |||
| 200 | }} | ||
