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