xref: /aosp_15_r20/external/lzma/CPP/Windows/Control/Window2.cpp (revision f6dc9357d832569d4d1f5d24eacdb3935a1ae8e6)
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 
WindowProcedure(HWND aHWND,UINT message,WPARAM wParam,LPARAM lParam)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 && message == MY_START_WM_CREATE)
36     window->Attach(aHWND);
37   if (!window)
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 
CreateEx(DWORD exStyle,LPCTSTR className,LPCTSTR windowName,DWORD style,int x,int y,int width,int height,HWND parentWindow,HMENU idOrHMenu,HINSTANCE instance)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 
CreateEx(DWORD exStyle,LPCWSTR className,LPCWSTR windowName,DWORD style,int x,int y,int width,int height,HWND parentWindow,HMENU idOrHMenu,HINSTANCE instance)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 
DefProc(UINT message,WPARAM wParam,LPARAM lParam)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 
OnMessage(UINT message,WPARAM wParam,LPARAM lParam)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(HIWORD(wParam), LOWORD(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 /*
164 bool CWindow2::OnCommand2(WPARAM wParam, LPARAM lParam, LRESULT &result)
165 {
166   return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam, result);
167 }
168 */
169 
OnCommand(unsigned,unsigned,LPARAM,LRESULT &)170 bool CWindow2::OnCommand(unsigned /* code */, unsigned /* itemID */, LPARAM /* lParam */, LRESULT & /* result */)
171 {
172   return false;
173   // return DefProc(message, wParam, lParam);
174   /*
175   if (code == BN_CLICKED)
176     return OnButtonClicked(itemID, (HWND)lParam);
177   */
178 }
179 
180 /*
181 bool CDialog::OnButtonClicked(unsigned buttonID, HWND buttonHWND)
182 {
183   switch (buttonID)
184   {
185     case IDOK:
186       OnOK();
187       break;
188     case IDCANCEL:
189       OnCancel();
190       break;
191     case IDHELP:
192       OnHelp();
193       break;
194     default:
195       return false;
196   }
197   return true;
198 }
199 
200 */
201 
202 }}
203