diff options
Diffstat (limited to '')
| -rw-r--r-- | CPP/Windows/Control/ComboBox.cpp | 66 | ||||
| -rw-r--r-- | CPP/Windows/Control/ComboBox.h | 77 | ||||
| -rw-r--r-- | CPP/Windows/Control/CommandBar.h | 52 | ||||
| -rw-r--r-- | CPP/Windows/Control/Dialog.cpp | 414 | ||||
| -rw-r--r-- | CPP/Windows/Control/Dialog.h | 190 | ||||
| -rw-r--r-- | CPP/Windows/Control/Edit.h | 19 | ||||
| -rw-r--r-- | CPP/Windows/Control/ImageList.cpp | 10 | ||||
| -rw-r--r-- | CPP/Windows/Control/ImageList.h | 87 | ||||
| -rw-r--r-- | CPP/Windows/Control/ListView.cpp | 155 | ||||
| -rw-r--r-- | CPP/Windows/Control/ListView.h | 147 | ||||
| -rw-r--r-- | CPP/Windows/Control/ProgressBar.h | 35 | ||||
| -rw-r--r-- | CPP/Windows/Control/PropertyPage.cpp | 143 | ||||
| -rw-r--r-- | CPP/Windows/Control/PropertyPage.h | 50 | ||||
| -rw-r--r-- | CPP/Windows/Control/ReBar.h | 34 | ||||
| -rw-r--r-- | CPP/Windows/Control/Static.h | 28 | ||||
| -rw-r--r-- | CPP/Windows/Control/StatusBar.h | 42 | ||||
| -rw-r--r-- | CPP/Windows/Control/StdAfx.h | 8 | ||||
| -rw-r--r-- | CPP/Windows/Control/ToolBar.h | 43 | ||||
| -rw-r--r-- | CPP/Windows/Control/Trackbar.h | 27 | ||||
| -rw-r--r-- | CPP/Windows/Control/Window2.cpp | 200 | ||||
| -rw-r--r-- | CPP/Windows/Control/Window2.h | 51 |
21 files changed, 1878 insertions, 0 deletions
diff --git a/CPP/Windows/Control/ComboBox.cpp b/CPP/Windows/Control/ComboBox.cpp new file mode 100644 index 0000000..f6ed8d3 --- /dev/null +++ b/CPP/Windows/Control/ComboBox.cpp | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | // Windows/Control/ComboBox.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #ifndef _UNICODE | ||
| 6 | #include "../../Common/StringConvert.h" | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include "ComboBox.h" | ||
| 10 | |||
| 11 | #ifndef _UNICODE | ||
| 12 | extern bool g_IsNT; | ||
| 13 | #endif | ||
| 14 | |||
| 15 | namespace NWindows { | ||
| 16 | namespace NControl { | ||
| 17 | |||
| 18 | LRESULT CComboBox::GetLBText(int index, CSysString &s) | ||
| 19 | { | ||
| 20 | s.Empty(); | ||
| 21 | LRESULT len = GetLBTextLen(index); // length, excluding the terminating null character | ||
| 22 | if (len == CB_ERR) | ||
| 23 | return len; | ||
| 24 | LRESULT len2 = GetLBText(index, s.GetBuf((unsigned)len)); | ||
| 25 | if (len2 == CB_ERR) | ||
| 26 | return len; | ||
| 27 | if (len > len2) | ||
| 28 | len = len2; | ||
| 29 | s.ReleaseBuf_CalcLen((unsigned)len); | ||
| 30 | return len; | ||
| 31 | } | ||
| 32 | |||
| 33 | #ifndef _UNICODE | ||
| 34 | LRESULT CComboBox::AddString(LPCWSTR s) | ||
| 35 | { | ||
| 36 | if (g_IsNT) | ||
| 37 | return SendMsgW(CB_ADDSTRING, 0, (LPARAM)s); | ||
| 38 | return AddString(GetSystemString(s)); | ||
| 39 | } | ||
| 40 | |||
| 41 | LRESULT CComboBox::GetLBText(int index, UString &s) | ||
| 42 | { | ||
| 43 | s.Empty(); | ||
| 44 | if (g_IsNT) | ||
| 45 | { | ||
| 46 | LRESULT len = SendMsgW(CB_GETLBTEXTLEN, MY__int_TO_WPARAM(index), 0); | ||
| 47 | if (len == CB_ERR) | ||
| 48 | return len; | ||
| 49 | LRESULT len2 = SendMsgW(CB_GETLBTEXT, MY__int_TO_WPARAM(index), (LPARAM)s.GetBuf((unsigned)len)); | ||
| 50 | if (len2 == CB_ERR) | ||
| 51 | return len; | ||
| 52 | if (len > len2) | ||
| 53 | len = len2; | ||
| 54 | s.ReleaseBuf_CalcLen((unsigned)len); | ||
| 55 | return len; | ||
| 56 | } | ||
| 57 | AString sa; | ||
| 58 | LRESULT len = GetLBText(index, sa); | ||
| 59 | if (len == CB_ERR) | ||
| 60 | return len; | ||
| 61 | s = GetUnicodeString(sa); | ||
| 62 | return s.Len(); | ||
| 63 | } | ||
| 64 | #endif | ||
| 65 | |||
| 66 | }} | ||
diff --git a/CPP/Windows/Control/ComboBox.h b/CPP/Windows/Control/ComboBox.h new file mode 100644 index 0000000..f08b1f7 --- /dev/null +++ b/CPP/Windows/Control/ComboBox.h | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // Windows/Control/ComboBox.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_COMBOBOX_H | ||
| 4 | #define __WINDOWS_CONTROL_COMBOBOX_H | ||
| 5 | |||
| 6 | #include "../../Common/MyWindows.h" | ||
| 7 | |||
| 8 | #include <CommCtrl.h> | ||
| 9 | |||
| 10 | #include "../Window.h" | ||
| 11 | |||
| 12 | namespace NWindows { | ||
| 13 | namespace NControl { | ||
| 14 | |||
| 15 | #define MY__int_TO_WPARAM(i) ((WPARAM)(INT_PTR)(i)) | ||
| 16 | |||
| 17 | class CComboBox: public CWindow | ||
| 18 | { | ||
| 19 | public: | ||
| 20 | void ResetContent() { SendMsg(CB_RESETCONTENT, 0, 0); } | ||
| 21 | LRESULT AddString(LPCTSTR s) { return SendMsg(CB_ADDSTRING, 0, (LPARAM)s); } | ||
| 22 | #ifndef _UNICODE | ||
| 23 | LRESULT AddString(LPCWSTR s); | ||
| 24 | #endif | ||
| 25 | |||
| 26 | /* If this parameter is -1, any current selection in the list is removed and the edit control is cleared.*/ | ||
| 27 | LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, MY__int_TO_WPARAM(index), 0); } | ||
| 28 | |||
| 29 | /* If no item is selected, it returns CB_ERR (-1) */ | ||
| 30 | int GetCurSel() { return (int)SendMsg(CB_GETCURSEL, 0, 0); } | ||
| 31 | |||
| 32 | /* If an error occurs, it is CB_ERR (-1) */ | ||
| 33 | int GetCount() { return (int)SendMsg(CB_GETCOUNT, 0, 0); } | ||
| 34 | |||
| 35 | LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, MY__int_TO_WPARAM(index), 0); } | ||
| 36 | LRESULT GetLBText(int index, LPTSTR s) { return SendMsg(CB_GETLBTEXT, MY__int_TO_WPARAM(index), (LPARAM)s); } | ||
| 37 | LRESULT GetLBText(int index, CSysString &s); | ||
| 38 | #ifndef _UNICODE | ||
| 39 | LRESULT GetLBText(int index, UString &s); | ||
| 40 | #endif | ||
| 41 | |||
| 42 | LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, MY__int_TO_WPARAM(index), lParam); } | ||
| 43 | LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, MY__int_TO_WPARAM(index), 0); } | ||
| 44 | |||
| 45 | LRESULT GetItemData_of_CurSel() { return GetItemData(GetCurSel()); } | ||
| 46 | |||
| 47 | void ShowDropDown(bool show = true) { SendMsg(CB_SHOWDROPDOWN, show ? TRUE : FALSE, 0); } | ||
| 48 | }; | ||
| 49 | |||
| 50 | #ifndef UNDER_CE | ||
| 51 | |||
| 52 | class CComboBoxEx: public CComboBox | ||
| 53 | { | ||
| 54 | public: | ||
| 55 | bool SetUnicodeFormat(bool fUnicode) { return LRESULTToBool(SendMsg(CBEM_SETUNICODEFORMAT, BOOLToBool(fUnicode), 0)); } | ||
| 56 | |||
| 57 | /* Returns: | ||
| 58 | an INT value that represents the number of items remaining in the control. | ||
| 59 | If (index) is invalid, the message returns CB_ERR. */ | ||
| 60 | LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, MY__int_TO_WPARAM(index), 0); } | ||
| 61 | |||
| 62 | LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_INSERTITEM, 0, (LPARAM)item); } | ||
| 63 | #ifndef _UNICODE | ||
| 64 | LRESULT InsertItem(COMBOBOXEXITEMW *item) { return SendMsg(CBEM_INSERTITEMW, 0, (LPARAM)item); } | ||
| 65 | #endif | ||
| 66 | |||
| 67 | LRESULT SetItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_SETITEM, 0, (LPARAM)item); } | ||
| 68 | DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, exStyle); } | ||
| 69 | HWND GetEditControl() { return (HWND)SendMsg(CBEM_GETEDITCONTROL, 0, 0); } | ||
| 70 | HIMAGELIST SetImageList(HIMAGELIST imageList) { return (HIMAGELIST)SendMsg(CBEM_SETIMAGELIST, 0, (LPARAM)imageList); } | ||
| 71 | }; | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
| 75 | }} | ||
| 76 | |||
| 77 | #endif | ||
diff --git a/CPP/Windows/Control/CommandBar.h b/CPP/Windows/Control/CommandBar.h new file mode 100644 index 0000000..a619744 --- /dev/null +++ b/CPP/Windows/Control/CommandBar.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | // Windows/Control/CommandBar.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_COMMANDBAR_H | ||
| 4 | #define __WINDOWS_CONTROL_COMMANDBAR_H | ||
| 5 | |||
| 6 | #ifdef UNDER_CE | ||
| 7 | |||
| 8 | #include "../../Common/MyWindows.h" | ||
| 9 | |||
| 10 | #include <commctrl.h> | ||
| 11 | |||
| 12 | #include "../Window.h" | ||
| 13 | |||
| 14 | namespace NWindows { | ||
| 15 | namespace NControl { | ||
| 16 | |||
| 17 | class CCommandBar: public NWindows::CWindow | ||
| 18 | { | ||
| 19 | public: | ||
| 20 | bool Create(HINSTANCE hInst, HWND hwndParent, int idCmdBar) | ||
| 21 | { | ||
| 22 | _window = ::CommandBar_Create(hInst, hwndParent, idCmdBar); | ||
| 23 | return (_window != NULL); | ||
| 24 | } | ||
| 25 | |||
| 26 | // Macros | ||
| 27 | // void Destroy() { CommandBar_Destroy(_window); } | ||
| 28 | // bool AddButtons(UINT numButtons, LPTBBUTTON buttons) { return BOOLToBool(SendMsg(TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)buttons)); } | ||
| 29 | bool InsertButton(int iButton, LPTBBUTTON button) { return BOOLToBool(SendMsg(TB_INSERTBUTTON, (WPARAM)iButton, (LPARAM)button)); } | ||
| 30 | BOOL AddToolTips(UINT numToolTips, LPTSTR toolTips) { return BOOLToBool(SendMsg(TB_SETTOOLTIPS, (WPARAM)numToolTips, (LPARAM)toolTips)); } | ||
| 31 | void AutoSize() { SendMsg(TB_AUTOSIZE, 0, 0); } | ||
| 32 | |||
| 33 | bool AddAdornments(DWORD dwFlags) { return BOOLToBool(::CommandBar_AddAdornments(_window, dwFlags, 0)); } | ||
| 34 | int AddBitmap(HINSTANCE hInst, int idBitmap, int iNumImages, int iImageWidth, int iImageHeight) { return ::CommandBar_AddBitmap(_window, hInst, idBitmap, iNumImages, iImageWidth, iImageHeight); } | ||
| 35 | bool DrawMenuBar(WORD iButton) { return BOOLToBool(::CommandBar_DrawMenuBar(_window, iButton)); } | ||
| 36 | HMENU GetMenu(WORD iButton) { return ::CommandBar_GetMenu(_window, iButton); } | ||
| 37 | int Height() { return CommandBar_Height(_window); } | ||
| 38 | HWND InsertComboBox(HINSTANCE hInst, int iWidth, UINT dwStyle, WORD idComboBox, WORD iButton) { return ::CommandBar_InsertComboBox(_window, hInst, iWidth, dwStyle, idComboBox, iButton); } | ||
| 39 | bool InsertMenubar(HINSTANCE hInst, WORD idMenu, WORD iButton) { return BOOLToBool(::CommandBar_InsertMenubar(_window, hInst, idMenu, iButton)); } | ||
| 40 | bool InsertMenubarEx(HINSTANCE hInst, LPTSTR pszMenu, WORD iButton) { return BOOLToBool(::CommandBar_InsertMenubarEx(_window, hInst, pszMenu, iButton)); } | ||
| 41 | bool Show(bool cmdShow) { return BOOLToBool(::CommandBar_Show(_window, BoolToBOOL(cmdShow))); } | ||
| 42 | |||
| 43 | |||
| 44 | // CE 4.0 | ||
| 45 | void AlignAdornments() { CommandBar_AlignAdornments(_window); } | ||
| 46 | }; | ||
| 47 | |||
| 48 | }} | ||
| 49 | |||
| 50 | #endif | ||
| 51 | |||
| 52 | #endif | ||
diff --git a/CPP/Windows/Control/Dialog.cpp b/CPP/Windows/Control/Dialog.cpp new file mode 100644 index 0000000..9ddd234 --- /dev/null +++ b/CPP/Windows/Control/Dialog.cpp | |||
| @@ -0,0 +1,414 @@ | |||
| 1 | // Windows/Control/Dialog.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | // #include "../../Windows/DLL.h" | ||
| 6 | |||
| 7 | #ifndef _UNICODE | ||
| 8 | #include "../../Common/StringConvert.h" | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #include "Dialog.h" | ||
| 12 | |||
| 13 | extern HINSTANCE g_hInstance; | ||
| 14 | #ifndef _UNICODE | ||
| 15 | extern bool g_IsNT; | ||
| 16 | #endif | ||
| 17 | |||
| 18 | namespace NWindows { | ||
| 19 | namespace NControl { | ||
| 20 | |||
| 21 | static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 22 | { | ||
| 23 | CWindow tempDialog(dialogHWND); | ||
| 24 | if (message == WM_INITDIALOG) | ||
| 25 | tempDialog.SetUserDataLongPtr(lParam); | ||
| 26 | CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr()); | ||
| 27 | if (dialog == NULL) | ||
| 28 | return FALSE; | ||
| 29 | if (message == WM_INITDIALOG) | ||
| 30 | dialog->Attach(dialogHWND); | ||
| 31 | |||
| 32 | /* MSDN: The dialog box procedure should return | ||
| 33 | TRUE - if it processed the message | ||
| 34 | FALSE - if it did not process the message | ||
| 35 | If the dialog box procedure returns FALSE, | ||
| 36 | the dialog manager performs the default dialog operation in response to the message. | ||
| 37 | */ | ||
| 38 | |||
| 39 | try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); } | ||
| 40 | catch(...) { return TRUE; } | ||
| 41 | } | ||
| 42 | |||
| 43 | bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | ||
| 44 | { | ||
| 45 | switch (message) | ||
| 46 | { | ||
| 47 | case WM_INITDIALOG: return OnInit(); | ||
| 48 | case WM_COMMAND: return OnCommand(wParam, lParam); | ||
| 49 | case WM_NOTIFY: return OnNotify((UINT)wParam, (LPNMHDR) lParam); | ||
| 50 | case WM_TIMER: return OnTimer(wParam, lParam); | ||
| 51 | case WM_SIZE: return OnSize(wParam, LOWORD(lParam), HIWORD(lParam)); | ||
| 52 | case WM_DESTROY: return OnDestroy(); | ||
| 53 | case WM_HELP: OnHelp(); return true; | ||
| 54 | /* | ||
| 55 | OnHelp( | ||
| 56 | #ifdef UNDER_CE | ||
| 57 | (void *) | ||
| 58 | #else | ||
| 59 | (LPHELPINFO) | ||
| 60 | #endif | ||
| 61 | lParam); | ||
| 62 | return true; | ||
| 63 | */ | ||
| 64 | default: return false; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam) | ||
| 69 | { | ||
| 70 | return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); | ||
| 71 | } | ||
| 72 | |||
| 73 | bool CDialog::OnCommand(int code, int itemID, LPARAM lParam) | ||
| 74 | { | ||
| 75 | if (code == BN_CLICKED) | ||
| 76 | return OnButtonClicked(itemID, (HWND)lParam); | ||
| 77 | return false; | ||
| 78 | } | ||
| 79 | |||
| 80 | bool CDialog::OnButtonClicked(int buttonID, HWND /* buttonHWND */) | ||
| 81 | { | ||
| 82 | switch (buttonID) | ||
| 83 | { | ||
| 84 | case IDOK: OnOK(); break; | ||
| 85 | case IDCANCEL: OnCancel(); break; | ||
| 86 | case IDCLOSE: OnClose(); break; | ||
| 87 | case IDHELP: OnHelp(); break; | ||
| 88 | default: return false; | ||
| 89 | } | ||
| 90 | return true; | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | static bool GetWorkAreaRect(RECT *rect, HWND hwnd) | ||
| 95 | { | ||
| 96 | if (hwnd) | ||
| 97 | { | ||
| 98 | #ifndef UNDER_CE | ||
| 99 | /* MonitorFromWindow() is supported in Win2000+ | ||
| 100 | MonitorFromWindow() : retrieves a handle to the display monitor that has the | ||
| 101 | largest area of intersection with the bounding rectangle of a specified window. | ||
| 102 | dwFlags: Determines the function's return value if the window does not intersect any display monitor. | ||
| 103 | MONITOR_DEFAULTTONEAREST : Returns display that is nearest to the window. | ||
| 104 | MONITOR_DEFAULTTONULL : Returns NULL. | ||
| 105 | MONITOR_DEFAULTTOPRIMARY : Returns the primary display monitor. | ||
| 106 | */ | ||
| 107 | const HMONITOR hmon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); | ||
| 108 | if (hmon) | ||
| 109 | { | ||
| 110 | MONITORINFO mi; | ||
| 111 | memset(&mi, 0, sizeof(mi)); | ||
| 112 | mi.cbSize = sizeof(mi); | ||
| 113 | if (GetMonitorInfoA(hmon, &mi)) | ||
| 114 | { | ||
| 115 | *rect = mi.rcWork; | ||
| 116 | return true; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | #endif | ||
| 120 | } | ||
| 121 | |||
| 122 | /* Retrieves the size of the work area on the primary display monitor. | ||
| 123 | The work area is the portion of the screen not obscured | ||
| 124 | by the system taskbar or by application desktop toolbars. | ||
| 125 | Any DPI virtualization mode of the caller has no effect on this output. */ | ||
| 126 | |||
| 127 | return BOOLToBool(::SystemParametersInfo(SPI_GETWORKAREA, 0, rect, 0)); | ||
| 128 | } | ||
| 129 | |||
| 130 | |||
| 131 | bool IsDialogSizeOK(int xSize, int ySize, HWND hwnd) | ||
| 132 | { | ||
| 133 | // it returns for system font. Real font uses another values | ||
| 134 | const LONG v = GetDialogBaseUnits(); | ||
| 135 | const int x = LOWORD(v); | ||
| 136 | const int y = HIWORD(v); | ||
| 137 | |||
| 138 | RECT rect; | ||
| 139 | GetWorkAreaRect(&rect, hwnd); | ||
| 140 | const int wx = RECT_SIZE_X(rect); | ||
| 141 | const int wy = RECT_SIZE_Y(rect); | ||
| 142 | return | ||
| 143 | xSize / 4 * x <= wx && | ||
| 144 | ySize / 8 * y <= wy; | ||
| 145 | } | ||
| 146 | |||
| 147 | bool CDialog::GetMargins(int margin, int &x, int &y) | ||
| 148 | { | ||
| 149 | x = margin; | ||
| 150 | y = margin; | ||
| 151 | RECT rect; | ||
| 152 | rect.left = 0; | ||
| 153 | rect.top = 0; | ||
| 154 | rect.right = margin; | ||
| 155 | rect.bottom = margin; | ||
| 156 | if (!MapRect(&rect)) | ||
| 157 | return false; | ||
| 158 | x = rect.right - rect.left; | ||
| 159 | y = rect.bottom - rect.top; | ||
| 160 | return true; | ||
| 161 | } | ||
| 162 | |||
| 163 | int CDialog::Units_To_Pixels_X(int units) | ||
| 164 | { | ||
| 165 | RECT rect; | ||
| 166 | rect.left = 0; | ||
| 167 | rect.top = 0; | ||
| 168 | rect.right = units; | ||
| 169 | rect.bottom = units; | ||
| 170 | if (!MapRect(&rect)) | ||
| 171 | return units * 3 / 2; | ||
| 172 | return rect.right - rect.left; | ||
| 173 | } | ||
| 174 | |||
| 175 | bool CDialog::GetItemSizes(int id, int &x, int &y) | ||
| 176 | { | ||
| 177 | RECT rect; | ||
| 178 | if (!::GetWindowRect(GetItem(id), &rect)) | ||
| 179 | return false; | ||
| 180 | x = RECT_SIZE_X(rect); | ||
| 181 | y = RECT_SIZE_Y(rect); | ||
| 182 | return true; | ||
| 183 | } | ||
| 184 | |||
| 185 | void CDialog::GetClientRectOfItem(int id, RECT &rect) | ||
| 186 | { | ||
| 187 | ::GetWindowRect(GetItem(id), &rect); | ||
| 188 | ScreenToClient(&rect); | ||
| 189 | } | ||
| 190 | |||
| 191 | bool CDialog::MoveItem(int id, int x, int y, int width, int height, bool repaint) | ||
| 192 | { | ||
| 193 | return BOOLToBool(::MoveWindow(GetItem(id), x, y, width, height, BoolToBOOL(repaint))); | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | /* | ||
| 198 | typedef BOOL (WINAPI * Func_DwmGetWindowAttribute)( | ||
| 199 | HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute); | ||
| 200 | |||
| 201 | static bool GetWindowsRect_DWM(HWND hwnd, RECT *rect) | ||
| 202 | { | ||
| 203 | // dll load and free is too slow : 300 calls in second. | ||
| 204 | NDLL::CLibrary dll; | ||
| 205 | if (!dll.Load(FTEXT("dwmapi.dll"))) | ||
| 206 | return false; | ||
| 207 | Func_DwmGetWindowAttribute f = (Func_DwmGetWindowAttribute)dll.GetProc("DwmGetWindowAttribute" ); | ||
| 208 | if (f) | ||
| 209 | { | ||
| 210 | #define MY__DWMWA_EXTENDED_FRAME_BOUNDS 9 | ||
| 211 | // 30000 per second | ||
| 212 | RECT r; | ||
| 213 | if (f(hwnd, MY__DWMWA_EXTENDED_FRAME_BOUNDS, &r, sizeof(RECT)) == S_OK) | ||
| 214 | { | ||
| 215 | *rect = r; | ||
| 216 | return true; | ||
| 217 | } | ||
| 218 | } | ||
| 219 | return false; | ||
| 220 | } | ||
| 221 | */ | ||
| 222 | |||
| 223 | |||
| 224 | static bool IsRect_Small_Inside_Big(const RECT &sm, const RECT &big) | ||
| 225 | { | ||
| 226 | return sm.left >= big.left | ||
| 227 | && sm.right <= big.right | ||
| 228 | && sm.top >= big.top | ||
| 229 | && sm.bottom <= big.bottom; | ||
| 230 | } | ||
| 231 | |||
| 232 | |||
| 233 | static bool AreRectsOverlapped(const RECT &r1, const RECT &r2) | ||
| 234 | { | ||
| 235 | return r1.left < r2.right | ||
| 236 | && r1.right > r2.left | ||
| 237 | && r1.top < r2.bottom | ||
| 238 | && r1.bottom > r2.top; | ||
| 239 | } | ||
| 240 | |||
| 241 | |||
| 242 | static bool AreRectsEqual(const RECT &r1, const RECT &r2) | ||
| 243 | { | ||
| 244 | return r1.left == r2.left | ||
| 245 | && r1.right == r2.right | ||
| 246 | && r1.top == r2.top | ||
| 247 | && r1.bottom == r2.bottom; | ||
| 248 | } | ||
| 249 | |||
| 250 | |||
| 251 | void CDialog::NormalizeSize(bool fullNormalize) | ||
| 252 | { | ||
| 253 | RECT workRect; | ||
| 254 | if (!GetWorkAreaRect(&workRect, *this)) | ||
| 255 | return; | ||
| 256 | RECT rect; | ||
| 257 | if (!GetWindowRect(&rect)) | ||
| 258 | return; | ||
| 259 | int xs = RECT_SIZE_X(rect); | ||
| 260 | int ys = RECT_SIZE_Y(rect); | ||
| 261 | |||
| 262 | // we don't want to change size using workRect, if window is outside of WorkArea | ||
| 263 | if (!AreRectsOverlapped(rect, workRect)) | ||
| 264 | return; | ||
| 265 | |||
| 266 | /* here rect and workRect are overlapped, but it can be false | ||
| 267 | overlapping of small shadow when window in another display. */ | ||
| 268 | |||
| 269 | const int xsW = RECT_SIZE_X(workRect); | ||
| 270 | const int ysW = RECT_SIZE_Y(workRect); | ||
| 271 | if (xs <= xsW && ys <= ysW) | ||
| 272 | return; // size of window is OK | ||
| 273 | if (fullNormalize) | ||
| 274 | { | ||
| 275 | Show(SW_SHOWMAXIMIZED); | ||
| 276 | return; | ||
| 277 | } | ||
| 278 | int x = workRect.left; | ||
| 279 | int y = workRect.top; | ||
| 280 | if (xs < xsW) x += (xsW - xs) / 2; else xs = xsW; | ||
| 281 | if (ys < ysW) y += (ysW - ys) / 2; else ys = ysW; | ||
| 282 | Move(x, y, xs, ys, true); | ||
| 283 | } | ||
| 284 | |||
| 285 | |||
| 286 | void CDialog::NormalizePosition() | ||
| 287 | { | ||
| 288 | RECT workRect; | ||
| 289 | if (!GetWorkAreaRect(&workRect, *this)) | ||
| 290 | return; | ||
| 291 | |||
| 292 | RECT rect2 = workRect; | ||
| 293 | bool useWorkArea = true; | ||
| 294 | const HWND parentHWND = GetParent(); | ||
| 295 | |||
| 296 | if (parentHWND) | ||
| 297 | { | ||
| 298 | RECT workRectParent; | ||
| 299 | if (!GetWorkAreaRect(&workRectParent, parentHWND)) | ||
| 300 | return; | ||
| 301 | |||
| 302 | // if windows are in different monitors, we use only workArea of current window | ||
| 303 | |||
| 304 | if (AreRectsEqual(workRectParent, workRect)) | ||
| 305 | { | ||
| 306 | // RECT rect3; if (GetWindowsRect_DWM(parentHWND, &rect3)) {} | ||
| 307 | CWindow wnd(parentHWND); | ||
| 308 | if (wnd.GetWindowRect(&rect2)) | ||
| 309 | { | ||
| 310 | // it's same monitor. So we try to use parentHWND rect. | ||
| 311 | /* we don't want to change position, if parent window is not inside work area. | ||
| 312 | In Win10 : parent window rect is 8 pixels larger for each corner than window size for shadow. | ||
| 313 | In maximize mode : window is outside of workRect. | ||
| 314 | if parent window is inside workRect, we will use parent window instead of workRect */ | ||
| 315 | if (IsRect_Small_Inside_Big(rect2, workRect)) | ||
| 316 | useWorkArea = false; | ||
| 317 | } | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | RECT rect; | ||
| 322 | if (!GetWindowRect(&rect)) | ||
| 323 | return; | ||
| 324 | |||
| 325 | if (useWorkArea) | ||
| 326 | { | ||
| 327 | // we don't want to move window, if it's already inside. | ||
| 328 | if (IsRect_Small_Inside_Big(rect, workRect)) | ||
| 329 | return; | ||
| 330 | // we don't want to move window, if it's outside of workArea | ||
| 331 | if (!AreRectsOverlapped(rect, workRect)) | ||
| 332 | return; | ||
| 333 | rect2 = workRect; | ||
| 334 | } | ||
| 335 | |||
| 336 | { | ||
| 337 | const int xs = RECT_SIZE_X(rect); | ||
| 338 | const int ys = RECT_SIZE_Y(rect); | ||
| 339 | const int xs2 = RECT_SIZE_X(rect2); | ||
| 340 | const int ys2 = RECT_SIZE_Y(rect2); | ||
| 341 | // we don't want to change position if parent is smaller. | ||
| 342 | if (xs <= xs2 && ys <= ys2) | ||
| 343 | { | ||
| 344 | const int x = rect2.left + (xs2 - xs) / 2; | ||
| 345 | const int y = rect2.top + (ys2 - ys) / 2; | ||
| 346 | |||
| 347 | if (x != rect.left || y != rect.top) | ||
| 348 | Move(x, y, xs, ys, true); | ||
| 349 | // SetWindowPos(*this, HWND_TOP, x, y, 0, 0, SWP_NOSIZE); | ||
| 350 | return; | ||
| 351 | } | ||
| 352 | } | ||
| 353 | } | ||
| 354 | |||
| 355 | |||
| 356 | |||
| 357 | bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow) | ||
| 358 | { | ||
| 359 | HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); | ||
| 360 | if (aHWND == 0) | ||
| 361 | return false; | ||
| 362 | Attach(aHWND); | ||
| 363 | return true; | ||
| 364 | } | ||
| 365 | |||
| 366 | INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow) | ||
| 367 | { | ||
| 368 | return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); | ||
| 369 | } | ||
| 370 | |||
| 371 | #ifndef _UNICODE | ||
| 372 | |||
| 373 | bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow) | ||
| 374 | { | ||
| 375 | HWND aHWND; | ||
| 376 | if (g_IsNT) | ||
| 377 | aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); | ||
| 378 | else | ||
| 379 | { | ||
| 380 | AString name; | ||
| 381 | LPCSTR templateNameA; | ||
| 382 | if (IS_INTRESOURCE(templateName)) | ||
| 383 | templateNameA = (LPCSTR)templateName; | ||
| 384 | else | ||
| 385 | { | ||
| 386 | name = GetSystemString(templateName); | ||
| 387 | templateNameA = name; | ||
| 388 | } | ||
| 389 | aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); | ||
| 390 | } | ||
| 391 | if (aHWND == 0) | ||
| 392 | return false; | ||
| 393 | Attach(aHWND); | ||
| 394 | return true; | ||
| 395 | } | ||
| 396 | |||
| 397 | INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow) | ||
| 398 | { | ||
| 399 | if (g_IsNT) | ||
| 400 | return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); | ||
| 401 | AString name; | ||
| 402 | LPCSTR templateNameA; | ||
| 403 | if (IS_INTRESOURCE(templateName)) | ||
| 404 | templateNameA = (LPCSTR)templateName; | ||
| 405 | else | ||
| 406 | { | ||
| 407 | name = GetSystemString(templateName); | ||
| 408 | templateNameA = name; | ||
| 409 | } | ||
| 410 | return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); | ||
| 411 | } | ||
| 412 | #endif | ||
| 413 | |||
| 414 | }} | ||
diff --git a/CPP/Windows/Control/Dialog.h b/CPP/Windows/Control/Dialog.h new file mode 100644 index 0000000..8a39e99 --- /dev/null +++ b/CPP/Windows/Control/Dialog.h | |||
| @@ -0,0 +1,190 @@ | |||
| 1 | // Windows/Control/Dialog.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_DIALOG_H | ||
| 4 | #define __WINDOWS_CONTROL_DIALOG_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CDialog: public CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | CDialog(HWND wnd = NULL): CWindow(wnd){}; | ||
| 15 | virtual ~CDialog() {}; | ||
| 16 | |||
| 17 | HWND GetItem(int itemID) const | ||
| 18 | { return GetDlgItem(_window, itemID); } | ||
| 19 | |||
| 20 | bool EnableItem(int itemID, bool enable) const | ||
| 21 | { return BOOLToBool(::EnableWindow(GetItem(itemID), BoolToBOOL(enable))); } | ||
| 22 | |||
| 23 | bool ShowItem(int itemID, int cmdShow) const | ||
| 24 | { return BOOLToBool(::ShowWindow(GetItem(itemID), cmdShow)); } | ||
| 25 | |||
| 26 | bool ShowItem_Bool(int itemID, bool show) const | ||
| 27 | { return ShowItem(itemID, show ? SW_SHOW: SW_HIDE); } | ||
| 28 | |||
| 29 | bool HideItem(int itemID) const { return ShowItem(itemID, SW_HIDE); } | ||
| 30 | |||
| 31 | bool SetItemText(int itemID, LPCTSTR s) | ||
| 32 | { return BOOLToBool(SetDlgItemText(_window, itemID, s)); } | ||
| 33 | |||
| 34 | bool SetItemTextA(int itemID, LPCSTR s) | ||
| 35 | { return BOOLToBool(SetDlgItemTextA(_window, itemID, s)); } | ||
| 36 | |||
| 37 | bool SetItemText_Empty(int itemID) | ||
| 38 | { return SetItemText(itemID, TEXT("")); } | ||
| 39 | |||
| 40 | #ifndef _UNICODE | ||
| 41 | bool SetItemText(int itemID, LPCWSTR s) | ||
| 42 | { | ||
| 43 | CWindow window(GetItem(itemID)); | ||
| 44 | return window.SetText(s); | ||
| 45 | } | ||
| 46 | #endif | ||
| 47 | |||
| 48 | UINT GetItemText(int itemID, LPTSTR string, int maxCount) | ||
| 49 | { return GetDlgItemText(_window, itemID, string, maxCount); } | ||
| 50 | #ifndef _UNICODE | ||
| 51 | /* | ||
| 52 | bool GetItemText(int itemID, LPWSTR string, int maxCount) | ||
| 53 | { | ||
| 54 | CWindow window(GetItem(itemID)); | ||
| 55 | return window.GetText(string, maxCount); | ||
| 56 | } | ||
| 57 | */ | ||
| 58 | #endif | ||
| 59 | |||
| 60 | bool GetItemText(int itemID, UString &s) | ||
| 61 | { | ||
| 62 | CWindow window(GetItem(itemID)); | ||
| 63 | return window.GetText(s); | ||
| 64 | } | ||
| 65 | |||
| 66 | bool SetItemInt(int itemID, UINT value, bool isSigned) | ||
| 67 | { return BOOLToBool(SetDlgItemInt(_window, itemID, value, BoolToBOOL(isSigned))); } | ||
| 68 | bool GetItemInt(int itemID, bool isSigned, UINT &value) | ||
| 69 | { | ||
| 70 | BOOL result; | ||
| 71 | value = GetDlgItemInt(_window, itemID, &result, BoolToBOOL(isSigned)); | ||
| 72 | return BOOLToBool(result); | ||
| 73 | } | ||
| 74 | |||
| 75 | HWND GetNextGroupItem(HWND control, bool previous) | ||
| 76 | { return GetNextDlgGroupItem(_window, control, BoolToBOOL(previous)); } | ||
| 77 | HWND GetNextTabItem(HWND control, bool previous) | ||
| 78 | { return GetNextDlgTabItem(_window, control, BoolToBOOL(previous)); } | ||
| 79 | |||
| 80 | LRESULT SendMsg_NextDlgCtl(WPARAM wParam, LPARAM lParam) | ||
| 81 | { return SendMsg(WM_NEXTDLGCTL, wParam, lParam); } | ||
| 82 | LRESULT SendMsg_NextDlgCtl_HWND(HWND hwnd) { return SendMsg_NextDlgCtl((WPARAM)hwnd, TRUE); } | ||
| 83 | LRESULT SendMsg_NextDlgCtl_CtlId(int id) { return SendMsg_NextDlgCtl_HWND(GetItem(id)); } | ||
| 84 | LRESULT SendMsg_NextDlgCtl_Next() { return SendMsg_NextDlgCtl(0, FALSE); } | ||
| 85 | LRESULT SendMsg_NextDlgCtl_Prev() { return SendMsg_NextDlgCtl(1, FALSE); } | ||
| 86 | |||
| 87 | bool MapRect(LPRECT rect) | ||
| 88 | { return BOOLToBool(MapDialogRect(_window, rect)); } | ||
| 89 | |||
| 90 | bool IsMessage(LPMSG message) | ||
| 91 | { return BOOLToBool(IsDialogMessage(_window, message)); } | ||
| 92 | |||
| 93 | LRESULT SendItemMessage(int itemID, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 94 | { return SendDlgItemMessage(_window, itemID, message, wParam, lParam); } | ||
| 95 | |||
| 96 | bool CheckButton(int buttonID, UINT checkState) | ||
| 97 | { return BOOLToBool(CheckDlgButton(_window, buttonID, checkState)); } | ||
| 98 | bool CheckButton(int buttonID, bool checkState) | ||
| 99 | { return CheckButton(buttonID, UINT(checkState ? BST_CHECKED : BST_UNCHECKED)); } | ||
| 100 | |||
| 101 | UINT IsButtonChecked(int buttonID) const | ||
| 102 | { return IsDlgButtonChecked(_window, buttonID); } | ||
| 103 | bool IsButtonCheckedBool(int buttonID) const | ||
| 104 | { return (IsButtonChecked(buttonID) == BST_CHECKED); } | ||
| 105 | |||
| 106 | bool CheckRadioButton(int firstButtonID, int lastButtonID, int checkButtonID) | ||
| 107 | { return BOOLToBool(::CheckRadioButton(_window, firstButtonID, lastButtonID, checkButtonID)); } | ||
| 108 | |||
| 109 | virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | ||
| 110 | virtual bool OnInit() { return true; } | ||
| 111 | virtual bool OnCommand(WPARAM wParam, LPARAM lParam); | ||
| 112 | virtual bool OnCommand(int code, int itemID, LPARAM lParam); | ||
| 113 | virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } | ||
| 114 | virtual bool OnDestroy() { return false; } | ||
| 115 | |||
| 116 | /* | ||
| 117 | #ifdef UNDER_CE | ||
| 118 | virtual void OnHelp(void *) { OnHelp(); } | ||
| 119 | #else | ||
| 120 | virtual void OnHelp(LPHELPINFO) { OnHelp(); } | ||
| 121 | #endif | ||
| 122 | */ | ||
| 123 | virtual void OnHelp() {}; | ||
| 124 | |||
| 125 | virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); | ||
| 126 | virtual void OnOK() {}; | ||
| 127 | virtual void OnCancel() {}; | ||
| 128 | virtual void OnClose() {} | ||
| 129 | virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */) { return false; } | ||
| 130 | virtual bool OnTimer(WPARAM /* timerID */, LPARAM /* callback */) { return false; } | ||
| 131 | |||
| 132 | LONG_PTR SetMsgResult(LONG_PTR newLongPtr ) | ||
| 133 | { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); } | ||
| 134 | LONG_PTR GetMsgResult() const | ||
| 135 | { return GetLongPtr(DWLP_MSGRESULT); } | ||
| 136 | |||
| 137 | bool GetMargins(int margin, int &x, int &y); | ||
| 138 | int Units_To_Pixels_X(int units); | ||
| 139 | bool GetItemSizes(int id, int &x, int &y); | ||
| 140 | void GetClientRectOfItem(int id, RECT &rect); | ||
| 141 | bool MoveItem(int id, int x, int y, int width, int height, bool repaint = true); | ||
| 142 | |||
| 143 | void NormalizeSize(bool fullNormalize = false); | ||
| 144 | void NormalizePosition(); | ||
| 145 | }; | ||
| 146 | |||
| 147 | class CModelessDialog: public CDialog | ||
| 148 | { | ||
| 149 | public: | ||
| 150 | bool Create(LPCTSTR templateName, HWND parentWindow); | ||
| 151 | bool Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); } | ||
| 152 | #ifndef _UNICODE | ||
| 153 | bool Create(LPCWSTR templateName, HWND parentWindow); | ||
| 154 | #endif | ||
| 155 | virtual void OnOK() { Destroy(); } | ||
| 156 | virtual void OnCancel() { Destroy(); } | ||
| 157 | virtual void OnClose() { Destroy(); } | ||
| 158 | }; | ||
| 159 | |||
| 160 | class CModalDialog: public CDialog | ||
| 161 | { | ||
| 162 | public: | ||
| 163 | INT_PTR Create(LPCTSTR templateName, HWND parentWindow); | ||
| 164 | INT_PTR Create(UINT resID, HWND parentWindow) { return Create(MAKEINTRESOURCEW(resID), parentWindow); } | ||
| 165 | #ifndef _UNICODE | ||
| 166 | INT_PTR Create(LPCWSTR templateName, HWND parentWindow); | ||
| 167 | #endif | ||
| 168 | |||
| 169 | bool End(INT_PTR result) { return BOOLToBool(::EndDialog(_window, result)); } | ||
| 170 | virtual void OnOK() { End(IDOK); } | ||
| 171 | virtual void OnCancel() { End(IDCANCEL); } | ||
| 172 | virtual void OnClose() { End(IDCLOSE); } | ||
| 173 | }; | ||
| 174 | |||
| 175 | class CDialogChildControl: public NWindows::CWindow | ||
| 176 | { | ||
| 177 | int m_ID; | ||
| 178 | public: | ||
| 179 | void Init(const NWindows::NControl::CDialog &parentDialog, int id) | ||
| 180 | { | ||
| 181 | m_ID = id; | ||
| 182 | Attach(parentDialog.GetItem(id)); | ||
| 183 | } | ||
| 184 | }; | ||
| 185 | |||
| 186 | bool IsDialogSizeOK(int xSize, int ySize, HWND hwnd = NULL); | ||
| 187 | |||
| 188 | }} | ||
| 189 | |||
| 190 | #endif | ||
diff --git a/CPP/Windows/Control/Edit.h b/CPP/Windows/Control/Edit.h new file mode 100644 index 0000000..51a22c5 --- /dev/null +++ b/CPP/Windows/Control/Edit.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | // Windows/Control/Edit.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_EDIT_H | ||
| 4 | #define __WINDOWS_CONTROL_EDIT_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CEdit: public CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | void SetPasswordChar(WPARAM c) { SendMsg(EM_SETPASSWORDCHAR, c); } | ||
| 15 | }; | ||
| 16 | |||
| 17 | }} | ||
| 18 | |||
| 19 | #endif | ||
diff --git a/CPP/Windows/Control/ImageList.cpp b/CPP/Windows/Control/ImageList.cpp new file mode 100644 index 0000000..3e22b95 --- /dev/null +++ b/CPP/Windows/Control/ImageList.cpp | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | // Windows/Control/ImageList.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #include "ImageList.h" | ||
| 6 | |||
| 7 | namespace NWindows { | ||
| 8 | namespace NControl { | ||
| 9 | |||
| 10 | }} | ||
diff --git a/CPP/Windows/Control/ImageList.h b/CPP/Windows/Control/ImageList.h new file mode 100644 index 0000000..19feb11 --- /dev/null +++ b/CPP/Windows/Control/ImageList.h | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | // Windows/Control/ImageList.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_IMAGE_LIST_H | ||
| 4 | #define __WINDOWS_CONTROL_IMAGE_LIST_H | ||
| 5 | |||
| 6 | #include <CommCtrl.h> | ||
| 7 | |||
| 8 | #include "../Defs.h" | ||
| 9 | |||
| 10 | namespace NWindows { | ||
| 11 | namespace NControl { | ||
| 12 | |||
| 13 | class CImageList | ||
| 14 | { | ||
| 15 | HIMAGELIST m_Object; | ||
| 16 | public: | ||
| 17 | operator HIMAGELIST() const {return m_Object; } | ||
| 18 | CImageList(): m_Object(NULL) {} | ||
| 19 | bool Attach(HIMAGELIST imageList) | ||
| 20 | { | ||
| 21 | if (imageList == NULL) | ||
| 22 | return false; | ||
| 23 | m_Object = imageList; | ||
| 24 | return true; | ||
| 25 | } | ||
| 26 | |||
| 27 | HIMAGELIST Detach() | ||
| 28 | { | ||
| 29 | HIMAGELIST imageList = m_Object; | ||
| 30 | m_Object = NULL; | ||
| 31 | return imageList; | ||
| 32 | } | ||
| 33 | |||
| 34 | bool Create(int width, int height, UINT flags, int initialNumber, int grow) | ||
| 35 | { | ||
| 36 | HIMAGELIST a = ImageList_Create(width, height, flags, | ||
| 37 | initialNumber, grow); | ||
| 38 | if (a == NULL) | ||
| 39 | return false; | ||
| 40 | return Attach(a); | ||
| 41 | } | ||
| 42 | |||
| 43 | bool Destroy() // DeleteImageList() in MFC | ||
| 44 | { | ||
| 45 | if (m_Object == NULL) | ||
| 46 | return false; | ||
| 47 | return BOOLToBool(ImageList_Destroy(Detach())); | ||
| 48 | } | ||
| 49 | |||
| 50 | ~CImageList() | ||
| 51 | { Destroy(); } | ||
| 52 | |||
| 53 | int GetImageCount() const | ||
| 54 | { return ImageList_GetImageCount(m_Object); } | ||
| 55 | |||
| 56 | bool GetImageInfo(int index, IMAGEINFO* imageInfo) const | ||
| 57 | { return BOOLToBool(ImageList_GetImageInfo(m_Object, index, imageInfo)); } | ||
| 58 | |||
| 59 | int Add(HBITMAP hbmImage, HBITMAP hbmMask = 0) | ||
| 60 | { return ImageList_Add(m_Object, hbmImage, hbmMask); } | ||
| 61 | int AddMasked(HBITMAP hbmImage, COLORREF mask) | ||
| 62 | { return ImageList_AddMasked(m_Object, hbmImage, mask); } | ||
| 63 | int AddIcon(HICON icon) | ||
| 64 | { return ImageList_AddIcon(m_Object, icon); } | ||
| 65 | int Replace(int index, HICON icon) | ||
| 66 | { return ImageList_ReplaceIcon(m_Object, index, icon); } | ||
| 67 | |||
| 68 | // If index is -1, the function removes all images. | ||
| 69 | bool Remove(int index) | ||
| 70 | { return BOOLToBool(ImageList_Remove(m_Object, index)); } | ||
| 71 | bool RemoveAll() | ||
| 72 | { return BOOLToBool(ImageList_RemoveAll(m_Object)); } | ||
| 73 | |||
| 74 | HICON ExtractIcon(int index) | ||
| 75 | { return ImageList_ExtractIcon(NULL, m_Object, index); } | ||
| 76 | HICON GetIcon(int index, UINT flags) | ||
| 77 | { return ImageList_GetIcon(m_Object, index, flags); } | ||
| 78 | |||
| 79 | bool GetIconSize(int &width, int &height) const | ||
| 80 | { return BOOLToBool(ImageList_GetIconSize(m_Object, &width, &height)); } | ||
| 81 | bool SetIconSize(int width, int height) | ||
| 82 | { return BOOLToBool(ImageList_SetIconSize(m_Object, width, height)); } | ||
| 83 | }; | ||
| 84 | |||
| 85 | }} | ||
| 86 | |||
| 87 | #endif | ||
diff --git a/CPP/Windows/Control/ListView.cpp b/CPP/Windows/Control/ListView.cpp new file mode 100644 index 0000000..16cfd39 --- /dev/null +++ b/CPP/Windows/Control/ListView.cpp | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | // Windows/Control/ListView.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #include "ListView.h" | ||
| 6 | |||
| 7 | #ifndef _UNICODE | ||
| 8 | extern bool g_IsNT; | ||
| 9 | #endif | ||
| 10 | |||
| 11 | namespace NWindows { | ||
| 12 | namespace NControl { | ||
| 13 | |||
| 14 | bool CListView::CreateEx(DWORD exStyle, DWORD style, | ||
| 15 | int x, int y, int width, int height, | ||
| 16 | HWND parentWindow, HMENU idOrHMenu, | ||
| 17 | HINSTANCE instance, LPVOID createParam) | ||
| 18 | { | ||
| 19 | return CWindow::CreateEx(exStyle, WC_LISTVIEW, TEXT(""), style, x, y, width, | ||
| 20 | height, parentWindow, idOrHMenu, instance, createParam); | ||
| 21 | } | ||
| 22 | |||
| 23 | bool CListView::GetItemParam(int index, LPARAM ¶m) const | ||
| 24 | { | ||
| 25 | LVITEM item; | ||
| 26 | item.iItem = index; | ||
| 27 | item.iSubItem = 0; | ||
| 28 | item.mask = LVIF_PARAM; | ||
| 29 | bool aResult = GetItem(&item); | ||
| 30 | param = item.lParam; | ||
| 31 | return aResult; | ||
| 32 | } | ||
| 33 | |||
| 34 | int CListView::InsertColumn(int columnIndex, LPCTSTR text, int width) | ||
| 35 | { | ||
| 36 | LVCOLUMN ci; | ||
| 37 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | ||
| 38 | ci.pszText = (LPTSTR)(void *)text; | ||
| 39 | ci.iSubItem = columnIndex; | ||
| 40 | ci.cx = width; | ||
| 41 | return InsertColumn(columnIndex, &ci); | ||
| 42 | } | ||
| 43 | |||
| 44 | int CListView::InsertItem(int index, LPCTSTR text) | ||
| 45 | { | ||
| 46 | LVITEM item; | ||
| 47 | item.mask = LVIF_TEXT | LVIF_PARAM; | ||
| 48 | item.iItem = index; | ||
| 49 | item.lParam = index; | ||
| 50 | item.pszText = (LPTSTR)(void *)text; | ||
| 51 | item.iSubItem = 0; | ||
| 52 | return InsertItem(&item); | ||
| 53 | } | ||
| 54 | |||
| 55 | int CListView::SetSubItem(int index, int subIndex, LPCTSTR text) | ||
| 56 | { | ||
| 57 | LVITEM item; | ||
| 58 | item.mask = LVIF_TEXT; | ||
| 59 | item.iItem = index; | ||
| 60 | item.pszText = (LPTSTR)(void *)text; | ||
| 61 | item.iSubItem = subIndex; | ||
| 62 | return SetItem(&item); | ||
| 63 | } | ||
| 64 | |||
| 65 | #ifndef _UNICODE | ||
| 66 | |||
| 67 | int CListView::InsertColumn(int columnIndex, LPCWSTR text, int width) | ||
| 68 | { | ||
| 69 | LVCOLUMNW ci; | ||
| 70 | ci.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; | ||
| 71 | ci.pszText = (LPWSTR)(void *)text; | ||
| 72 | ci.iSubItem = columnIndex; | ||
| 73 | ci.cx = width; | ||
| 74 | return InsertColumn(columnIndex, &ci); | ||
| 75 | } | ||
| 76 | |||
| 77 | int CListView::InsertItem(int index, LPCWSTR text) | ||
| 78 | { | ||
| 79 | LVITEMW item; | ||
| 80 | item.mask = LVIF_TEXT | LVIF_PARAM; | ||
| 81 | item.iItem = index; | ||
| 82 | item.lParam = index; | ||
| 83 | item.pszText = (LPWSTR)(void *)text; | ||
| 84 | item.iSubItem = 0; | ||
| 85 | return InsertItem(&item); | ||
| 86 | } | ||
| 87 | |||
| 88 | int CListView::SetSubItem(int index, int subIndex, LPCWSTR text) | ||
| 89 | { | ||
| 90 | LVITEMW item; | ||
| 91 | item.mask = LVIF_TEXT; | ||
| 92 | item.iItem = index; | ||
| 93 | item.pszText = (LPWSTR)(void *)text; | ||
| 94 | item.iSubItem = subIndex; | ||
| 95 | return SetItem(&item); | ||
| 96 | } | ||
| 97 | |||
| 98 | #endif | ||
| 99 | |||
| 100 | static LRESULT APIENTRY ListViewSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 101 | { | ||
| 102 | CWindow window(hwnd); | ||
| 103 | CListView2 *w = (CListView2 *)(window.GetUserDataLongPtr()); | ||
| 104 | if (w == NULL) | ||
| 105 | return 0; | ||
| 106 | return w->OnMessage(message, wParam, lParam); | ||
| 107 | } | ||
| 108 | |||
| 109 | LRESULT CListView2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | ||
| 110 | { | ||
| 111 | #ifndef _UNICODE | ||
| 112 | if (g_IsNT) | ||
| 113 | return CallWindowProcW(_origWindowProc, *this, message, wParam, lParam); | ||
| 114 | else | ||
| 115 | #endif | ||
| 116 | return CallWindowProc(_origWindowProc, *this, message, wParam, lParam); | ||
| 117 | } | ||
| 118 | |||
| 119 | void CListView2::SetWindowProc() | ||
| 120 | { | ||
| 121 | SetUserDataLongPtr((LONG_PTR)this); | ||
| 122 | #ifndef _UNICODE | ||
| 123 | if (g_IsNT) | ||
| 124 | _origWindowProc = (WNDPROC)SetLongPtrW(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc); | ||
| 125 | else | ||
| 126 | #endif | ||
| 127 | _origWindowProc = (WNDPROC)SetLongPtr(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc); | ||
| 128 | } | ||
| 129 | |||
| 130 | /* | ||
| 131 | LRESULT CListView3::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) | ||
| 132 | { | ||
| 133 | LRESULT res = CListView2::OnMessage(message, wParam, lParam); | ||
| 134 | if (message == WM_GETDLGCODE) | ||
| 135 | { | ||
| 136 | // when user presses RETURN, windows sends default (first) button command to parent dialog. | ||
| 137 | // we disable this: | ||
| 138 | MSG *msg = (MSG *)lParam; | ||
| 139 | WPARAM key = wParam; | ||
| 140 | bool change = false; | ||
| 141 | if (msg) | ||
| 142 | { | ||
| 143 | if (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN) | ||
| 144 | change = true; | ||
| 145 | } | ||
| 146 | else if (wParam == VK_RETURN) | ||
| 147 | change = true; | ||
| 148 | if (change) | ||
| 149 | res |= DLGC_WANTALLKEYS; | ||
| 150 | } | ||
| 151 | return res; | ||
| 152 | } | ||
| 153 | */ | ||
| 154 | |||
| 155 | }} | ||
diff --git a/CPP/Windows/Control/ListView.h b/CPP/Windows/Control/ListView.h new file mode 100644 index 0000000..a13b104 --- /dev/null +++ b/CPP/Windows/Control/ListView.h | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | // Windows/Control/ListView.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_LISTVIEW_H | ||
| 4 | #define __WINDOWS_CONTROL_LISTVIEW_H | ||
| 5 | |||
| 6 | #include "../../Common/MyWindows.h" | ||
| 7 | |||
| 8 | #include <CommCtrl.h> | ||
| 9 | |||
| 10 | #include "../Window.h" | ||
| 11 | |||
| 12 | namespace NWindows { | ||
| 13 | namespace NControl { | ||
| 14 | |||
| 15 | class CListView: public NWindows::CWindow | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | bool CreateEx(DWORD exStyle, DWORD style, | ||
| 19 | int x, int y, int width, int height, | ||
| 20 | HWND parentWindow, HMENU idOrHMenu, | ||
| 21 | HINSTANCE instance, LPVOID createParam); | ||
| 22 | |||
| 23 | void SetUnicodeFormat() | ||
| 24 | { | ||
| 25 | #ifndef UNDER_CE | ||
| 26 | ListView_SetUnicodeFormat(_window, TRUE); | ||
| 27 | #endif | ||
| 28 | } | ||
| 29 | |||
| 30 | bool DeleteAllItems() { return BOOLToBool(ListView_DeleteAllItems(_window)); } | ||
| 31 | bool DeleteColumn(int columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); } | ||
| 32 | |||
| 33 | int InsertColumn(int columnIndex, const LVCOLUMN *columnInfo) { return ListView_InsertColumn(_window, columnIndex, columnInfo); } | ||
| 34 | int InsertColumn(int columnIndex, LPCTSTR text, int width); | ||
| 35 | bool SetColumnOrderArray(int count, const int *columns) | ||
| 36 | { return BOOLToBool(ListView_SetColumnOrderArray(_window, count, (int *)(void *)columns)); } | ||
| 37 | |||
| 38 | /* | ||
| 39 | int GetNumColumns() | ||
| 40 | { | ||
| 41 | HWND header = ListView_GetHeader(_window); | ||
| 42 | if (!header) | ||
| 43 | return -1; | ||
| 44 | return Header_GetItemCount(header); | ||
| 45 | } | ||
| 46 | */ | ||
| 47 | |||
| 48 | int InsertItem(const LVITEM* item) { return ListView_InsertItem(_window, item); } | ||
| 49 | int InsertItem(int index, LPCTSTR text); | ||
| 50 | bool SetItem(const LVITEM* item) { return BOOLToBool(ListView_SetItem(_window, item)); } | ||
| 51 | int SetSubItem(int index, int subIndex, LPCTSTR text); | ||
| 52 | |||
| 53 | #ifndef _UNICODE | ||
| 54 | |||
| 55 | int InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo) { return (int)SendMsg(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); } | ||
| 56 | int InsertColumn(int columnIndex, LPCWSTR text, int width); | ||
| 57 | int InsertItem(const LV_ITEMW* item) { return (int)SendMsg(LVM_INSERTITEMW, 0, (LPARAM)item); } | ||
| 58 | int InsertItem(int index, LPCWSTR text); | ||
| 59 | bool SetItem(const LV_ITEMW* item) { return BOOLToBool((BOOL)SendMsg(LVM_SETITEMW, 0, (LPARAM)item)); } | ||
| 60 | int SetSubItem(int index, int subIndex, LPCWSTR text); | ||
| 61 | |||
| 62 | #endif | ||
| 63 | |||
| 64 | bool DeleteItem(int itemIndex) { return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); } | ||
| 65 | |||
| 66 | UINT GetSelectedCount() const { return ListView_GetSelectedCount(_window); } | ||
| 67 | int GetItemCount() const { return ListView_GetItemCount(_window); } | ||
| 68 | |||
| 69 | INT GetSelectionMark() const { return ListView_GetSelectionMark(_window); } | ||
| 70 | |||
| 71 | void SetItemCount(int numItems) { ListView_SetItemCount(_window, numItems); } | ||
| 72 | void SetItemCountEx(int numItems, DWORD flags) { ListView_SetItemCountEx(_window, numItems, flags); } | ||
| 73 | |||
| 74 | int GetNextItem(int startIndex, UINT flags) const { return ListView_GetNextItem(_window, startIndex, flags); } | ||
| 75 | int GetNextSelectedItem(int startIndex) const { return GetNextItem(startIndex, LVNI_SELECTED); } | ||
| 76 | int GetFocusedItem() const { return GetNextItem(-1, LVNI_FOCUSED); } | ||
| 77 | |||
| 78 | bool GetItem(LVITEM* item) const { return BOOLToBool(ListView_GetItem(_window, item)); } | ||
| 79 | bool GetItemParam(int itemIndex, LPARAM ¶m) const; | ||
| 80 | void GetItemText(int itemIndex, int subItemIndex, LPTSTR text, int textSizeMax) const | ||
| 81 | { ListView_GetItemText(_window, itemIndex, subItemIndex, text, textSizeMax); } | ||
| 82 | bool SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam) | ||
| 83 | { return BOOLToBool(ListView_SortItems(_window, compareFunction, dataParam)); } | ||
| 84 | |||
| 85 | void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask); } | ||
| 86 | void SetItemState_Selected(int index, bool select) { SetItemState(index, select ? LVIS_SELECTED : 0, LVIS_SELECTED); } | ||
| 87 | void SetItemState_Selected(int index) { SetItemState(index, LVIS_SELECTED, LVIS_SELECTED); } | ||
| 88 | void SelectAll() { SetItemState_Selected(-1); } | ||
| 89 | void SetItemState_FocusedSelected(int index) { SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); } | ||
| 90 | UINT GetItemState(int index, UINT mask) const { return ListView_GetItemState(_window, index, mask); } | ||
| 91 | bool IsItemSelected(int index) const { return GetItemState(index, LVIS_SELECTED) == LVIS_SELECTED; } | ||
| 92 | |||
| 93 | bool GetColumn(int columnIndex, LVCOLUMN* columnInfo) const | ||
| 94 | { return BOOLToBool(ListView_GetColumn(_window, columnIndex, columnInfo)); } | ||
| 95 | |||
| 96 | HIMAGELIST SetImageList(HIMAGELIST imageList, int imageListType) | ||
| 97 | { return ListView_SetImageList(_window, imageList, imageListType); } | ||
| 98 | |||
| 99 | // version 4.70: NT5 | (NT4 + ie3) | w98 | (w95 + ie3) | ||
| 100 | DWORD GetExtendedListViewStyle() { return ListView_GetExtendedListViewStyle(_window); } | ||
| 101 | void SetExtendedListViewStyle(DWORD exStyle) { ListView_SetExtendedListViewStyle(_window, exStyle); } | ||
| 102 | void SetExtendedListViewStyle(DWORD exMask, DWORD exStyle) { ListView_SetExtendedListViewStyleEx(_window, exMask, exStyle); } | ||
| 103 | |||
| 104 | void SetCheckState(UINT index, bool checkState) { ListView_SetCheckState(_window, index, BoolToBOOL(checkState)); } | ||
| 105 | bool GetCheckState(UINT index) { return BOOLToBool(ListView_GetCheckState(_window, index)); } | ||
| 106 | |||
| 107 | bool EnsureVisible(int index, bool partialOK) { return BOOLToBool(ListView_EnsureVisible(_window, index, BoolToBOOL(partialOK))); } | ||
| 108 | |||
| 109 | bool GetItemRect(int index, RECT *rect, int code) { return BOOLToBool(ListView_GetItemRect(_window, index, rect, code)); } | ||
| 110 | |||
| 111 | HWND GetEditControl() { return ListView_GetEditControl(_window) ; } | ||
| 112 | HWND EditLabel(int itemIndex) { return ListView_EditLabel(_window, itemIndex) ; } | ||
| 113 | |||
| 114 | bool RedrawItems(int firstIndex, int lastIndex) { return BOOLToBool(ListView_RedrawItems(_window, firstIndex, lastIndex)); } | ||
| 115 | bool RedrawAllItems() | ||
| 116 | { | ||
| 117 | if (GetItemCount() > 0) | ||
| 118 | return RedrawItems(0, GetItemCount() - 1); | ||
| 119 | return true; | ||
| 120 | } | ||
| 121 | bool RedrawItem(int index) { return RedrawItems(index, index); } | ||
| 122 | |||
| 123 | int HitTest(LPLVHITTESTINFO info) { return ListView_HitTest(_window, info); } | ||
| 124 | COLORREF GetBkColor() { return ListView_GetBkColor(_window); } | ||
| 125 | bool SetColumnWidth(int iCol, int cx) { return BOOLToBool(ListView_SetColumnWidth(_window, iCol, cx)); } | ||
| 126 | bool SetColumnWidthAuto(int iCol) { return SetColumnWidth(iCol, LVSCW_AUTOSIZE); } | ||
| 127 | }; | ||
| 128 | |||
| 129 | class CListView2: public CListView | ||
| 130 | { | ||
| 131 | WNDPROC _origWindowProc; | ||
| 132 | public: | ||
| 133 | void SetWindowProc(); | ||
| 134 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | ||
| 135 | }; | ||
| 136 | |||
| 137 | /* | ||
| 138 | class CListView3: public CListView2 | ||
| 139 | { | ||
| 140 | public: | ||
| 141 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | ||
| 142 | }; | ||
| 143 | */ | ||
| 144 | |||
| 145 | }} | ||
| 146 | |||
| 147 | #endif | ||
diff --git a/CPP/Windows/Control/ProgressBar.h b/CPP/Windows/Control/ProgressBar.h new file mode 100644 index 0000000..0374306 --- /dev/null +++ b/CPP/Windows/Control/ProgressBar.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // Windows/Control/ProgressBar.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_PROGRESSBAR_H | ||
| 4 | #define __WINDOWS_CONTROL_PROGRESSBAR_H | ||
| 5 | |||
| 6 | #include "../../Common/MyWindows.h" | ||
| 7 | |||
| 8 | #include <CommCtrl.h> | ||
| 9 | |||
| 10 | #include "../Window.h" | ||
| 11 | |||
| 12 | namespace NWindows { | ||
| 13 | namespace NControl { | ||
| 14 | |||
| 15 | class CProgressBar: public CWindow | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | LRESULT SetPos(int pos) { return SendMsg(PBM_SETPOS, pos, 0); } | ||
| 19 | LRESULT DeltaPos(int increment) { return SendMsg(PBM_DELTAPOS, increment, 0); } | ||
| 20 | UINT GetPos() { return (UINT)SendMsg(PBM_GETPOS, 0, 0); } | ||
| 21 | LRESULT SetRange(unsigned short minValue, unsigned short maxValue) { return SendMsg(PBM_SETRANGE, 0, MAKELPARAM(minValue, maxValue)); } | ||
| 22 | DWORD SetRange32(int minValue, int maxValue) { return (DWORD)SendMsg(PBM_SETRANGE32, minValue, maxValue); } | ||
| 23 | int SetStep(int step) { return (int)SendMsg(PBM_SETSTEP, step, 0); } | ||
| 24 | LRESULT StepIt() { return SendMsg(PBM_STEPIT, 0, 0); } | ||
| 25 | INT GetRange(bool minValue, PPBRANGE range) { return (INT)SendMsg(PBM_GETRANGE, BoolToBOOL(minValue), (LPARAM)range); } | ||
| 26 | |||
| 27 | #ifndef UNDER_CE | ||
| 28 | COLORREF SetBarColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBARCOLOR, 0, color); } | ||
| 29 | COLORREF SetBackgroundColor(COLORREF color) { return (COLORREF)SendMsg(PBM_SETBKCOLOR, 0, color); } | ||
| 30 | #endif | ||
| 31 | }; | ||
| 32 | |||
| 33 | }} | ||
| 34 | |||
| 35 | #endif | ||
diff --git a/CPP/Windows/Control/PropertyPage.cpp b/CPP/Windows/Control/PropertyPage.cpp new file mode 100644 index 0000000..ce8696d --- /dev/null +++ b/CPP/Windows/Control/PropertyPage.cpp | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | // Windows/Control/PropertyPage.cpp | ||
| 2 | |||
| 3 | #include "StdAfx.h" | ||
| 4 | |||
| 5 | #ifndef _UNICODE | ||
| 6 | #include "../../Common/StringConvert.h" | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include "PropertyPage.h" | ||
| 10 | |||
| 11 | extern HINSTANCE g_hInstance; | ||
| 12 | #ifndef _UNICODE | ||
| 13 | extern bool g_IsNT; | ||
| 14 | #endif | ||
| 15 | |||
| 16 | namespace NWindows { | ||
| 17 | namespace NControl { | ||
| 18 | |||
| 19 | static INT_PTR APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam) | ||
| 20 | { | ||
| 21 | CWindow tempDialog(dialogHWND); | ||
| 22 | if (message == WM_INITDIALOG) | ||
| 23 | tempDialog.SetUserDataLongPtr(((PROPSHEETPAGE *)lParam)->lParam); | ||
| 24 | CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr()); | ||
| 25 | if (dialog == NULL) | ||
| 26 | return FALSE; | ||
| 27 | if (message == WM_INITDIALOG) | ||
| 28 | dialog->Attach(dialogHWND); | ||
| 29 | try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); } | ||
| 30 | catch(...) { return TRUE; } | ||
| 31 | } | ||
| 32 | |||
| 33 | bool CPropertyPage::OnNotify(UINT /* controlID */, LPNMHDR lParam) | ||
| 34 | { | ||
| 35 | switch (lParam->code) | ||
| 36 | { | ||
| 37 | case PSN_APPLY: SetMsgResult(OnApply(LPPSHNOTIFY(lParam))); break; | ||
| 38 | case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive(LPPSHNOTIFY(lParam)))); break; | ||
| 39 | case PSN_SETACTIVE: SetMsgResult(OnSetActive(LPPSHNOTIFY(lParam))); break; | ||
| 40 | case PSN_RESET: OnReset(LPPSHNOTIFY(lParam)); break; | ||
| 41 | case PSN_HELP: OnNotifyHelp(LPPSHNOTIFY(lParam)); break; | ||
| 42 | default: return false; | ||
| 43 | } | ||
| 44 | return true; | ||
| 45 | } | ||
| 46 | |||
| 47 | INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title) | ||
| 48 | { | ||
| 49 | #ifndef _UNICODE | ||
| 50 | AStringVector titles; | ||
| 51 | #endif | ||
| 52 | #ifndef _UNICODE | ||
| 53 | CRecordVector<PROPSHEETPAGEA> pagesA; | ||
| 54 | #endif | ||
| 55 | CRecordVector<PROPSHEETPAGEW> pagesW; | ||
| 56 | |||
| 57 | unsigned i; | ||
| 58 | #ifndef _UNICODE | ||
| 59 | for (i = 0; i < pagesInfo.Size(); i++) | ||
| 60 | titles.Add(GetSystemString(pagesInfo[i].Title)); | ||
| 61 | #endif | ||
| 62 | |||
| 63 | for (i = 0; i < pagesInfo.Size(); i++) | ||
| 64 | { | ||
| 65 | const CPageInfo &pageInfo = pagesInfo[i]; | ||
| 66 | #ifndef _UNICODE | ||
| 67 | { | ||
| 68 | PROPSHEETPAGE page; | ||
| 69 | page.dwSize = sizeof(page); | ||
| 70 | page.dwFlags = PSP_HASHELP; | ||
| 71 | page.hInstance = g_hInstance; | ||
| 72 | page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID); | ||
| 73 | page.pszIcon = NULL; | ||
| 74 | page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; | ||
| 75 | |||
| 76 | if (titles[i].IsEmpty()) | ||
| 77 | page.pszTitle = NULL; | ||
| 78 | else | ||
| 79 | { | ||
| 80 | page.dwFlags |= PSP_USETITLE; | ||
| 81 | page.pszTitle = titles[i]; | ||
| 82 | } | ||
| 83 | page.lParam = (LPARAM)pageInfo.Page; | ||
| 84 | page.pfnCallback = NULL; | ||
| 85 | pagesA.Add(page); | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | { | ||
| 89 | PROPSHEETPAGEW page; | ||
| 90 | page.dwSize = sizeof(page); | ||
| 91 | page.dwFlags = PSP_HASHELP; | ||
| 92 | page.hInstance = g_hInstance; | ||
| 93 | page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID); | ||
| 94 | page.pszIcon = NULL; | ||
| 95 | page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure; | ||
| 96 | |||
| 97 | if (pageInfo.Title.IsEmpty()) | ||
| 98 | page.pszTitle = NULL; | ||
| 99 | else | ||
| 100 | { | ||
| 101 | page.dwFlags |= PSP_USETITLE; | ||
| 102 | page.pszTitle = pageInfo.Title; | ||
| 103 | } | ||
| 104 | page.lParam = (LPARAM)pageInfo.Page; | ||
| 105 | page.pfnCallback = NULL; | ||
| 106 | pagesW.Add(page); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | #ifndef _UNICODE | ||
| 111 | if (!g_IsNT) | ||
| 112 | { | ||
| 113 | PROPSHEETHEADER sheet; | ||
| 114 | sheet.dwSize = sizeof(sheet); | ||
| 115 | sheet.dwFlags = PSH_PROPSHEETPAGE; | ||
| 116 | sheet.hwndParent = hwndParent; | ||
| 117 | sheet.hInstance = g_hInstance; | ||
| 118 | AString titleA (GetSystemString(title)); | ||
| 119 | sheet.pszCaption = titleA; | ||
| 120 | sheet.nPages = pagesInfo.Size(); | ||
| 121 | sheet.nStartPage = 0; | ||
| 122 | sheet.ppsp = &pagesA.Front(); | ||
| 123 | sheet.pfnCallback = NULL; | ||
| 124 | return ::PropertySheetA(&sheet); | ||
| 125 | } | ||
| 126 | else | ||
| 127 | #endif | ||
| 128 | { | ||
| 129 | PROPSHEETHEADERW sheet; | ||
| 130 | sheet.dwSize = sizeof(sheet); | ||
| 131 | sheet.dwFlags = PSH_PROPSHEETPAGE; | ||
| 132 | sheet.hwndParent = hwndParent; | ||
| 133 | sheet.hInstance = g_hInstance; | ||
| 134 | sheet.pszCaption = title; | ||
| 135 | sheet.nPages = pagesInfo.Size(); | ||
| 136 | sheet.nStartPage = 0; | ||
| 137 | sheet.ppsp = &pagesW.Front(); | ||
| 138 | sheet.pfnCallback = NULL; | ||
| 139 | return ::PropertySheetW(&sheet); | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | }} | ||
diff --git a/CPP/Windows/Control/PropertyPage.h b/CPP/Windows/Control/PropertyPage.h new file mode 100644 index 0000000..b68fd8f --- /dev/null +++ b/CPP/Windows/Control/PropertyPage.h | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // Windows/Control/PropertyPage.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_PROPERTYPAGE_H | ||
| 4 | #define __WINDOWS_CONTROL_PROPERTYPAGE_H | ||
| 5 | |||
| 6 | #include "../../Common/MyWindows.h" | ||
| 7 | |||
| 8 | #include <PrSht.h> | ||
| 9 | |||
| 10 | #include "Dialog.h" | ||
| 11 | |||
| 12 | namespace NWindows { | ||
| 13 | namespace NControl { | ||
| 14 | |||
| 15 | INT_PTR APIENTRY ProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam); | ||
| 16 | |||
| 17 | class CPropertyPage: public CDialog | ||
| 18 | { | ||
| 19 | public: | ||
| 20 | CPropertyPage(HWND window = NULL): CDialog(window){}; | ||
| 21 | |||
| 22 | void Changed() { PropSheet_Changed(GetParent(), (HWND)*this); } | ||
| 23 | void UnChanged() { PropSheet_UnChanged(GetParent(), (HWND)*this); } | ||
| 24 | |||
| 25 | virtual bool OnNotify(UINT controlID, LPNMHDR lParam); | ||
| 26 | |||
| 27 | virtual bool OnKillActive() { return false; } // false = OK | ||
| 28 | virtual bool OnKillActive(const PSHNOTIFY *) { return OnKillActive(); } | ||
| 29 | virtual LONG OnSetActive() { return false; } // false = OK | ||
| 30 | virtual LONG OnSetActive(const PSHNOTIFY *) { return OnSetActive(); } | ||
| 31 | virtual LONG OnApply() { return PSNRET_NOERROR; } | ||
| 32 | virtual LONG OnApply(const PSHNOTIFY *) { return OnApply(); } | ||
| 33 | virtual void OnNotifyHelp() {} | ||
| 34 | virtual void OnNotifyHelp(const PSHNOTIFY *) { OnNotifyHelp(); } | ||
| 35 | virtual void OnReset() {} | ||
| 36 | virtual void OnReset(const PSHNOTIFY *) { OnReset(); } | ||
| 37 | }; | ||
| 38 | |||
| 39 | struct CPageInfo | ||
| 40 | { | ||
| 41 | CPropertyPage *Page; | ||
| 42 | UString Title; | ||
| 43 | UINT ID; | ||
| 44 | }; | ||
| 45 | |||
| 46 | INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title); | ||
| 47 | |||
| 48 | }} | ||
| 49 | |||
| 50 | #endif | ||
diff --git a/CPP/Windows/Control/ReBar.h b/CPP/Windows/Control/ReBar.h new file mode 100644 index 0000000..c2d58db --- /dev/null +++ b/CPP/Windows/Control/ReBar.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // Windows/Control/ReBar.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_REBAR_H | ||
| 4 | #define __WINDOWS_CONTROL_REBAR_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CReBar: public NWindows::CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | bool SetBarInfo(LPREBARINFO barInfo) | ||
| 15 | { return LRESULTToBool(SendMsg(RB_SETBARINFO, 0, (LPARAM)barInfo)); } | ||
| 16 | bool InsertBand(int index, LPREBARBANDINFO bandInfo) | ||
| 17 | { return LRESULTToBool(SendMsg(RB_INSERTBAND, index, (LPARAM)bandInfo)); } | ||
| 18 | bool SetBandInfo(unsigned index, LPREBARBANDINFO bandInfo) | ||
| 19 | { return LRESULTToBool(SendMsg(RB_SETBANDINFO, index, (LPARAM)bandInfo)); } | ||
| 20 | void MaximizeBand(unsigned index, bool ideal) | ||
| 21 | { SendMsg(RB_MAXIMIZEBAND, index, BoolToBOOL(ideal)); } | ||
| 22 | bool SizeToRect(LPRECT rect) | ||
| 23 | { return LRESULTToBool(SendMsg(RB_SIZETORECT, 0, (LPARAM)rect)); } | ||
| 24 | UINT GetHeight() | ||
| 25 | { return (UINT)SendMsg(RB_GETBARHEIGHT); } | ||
| 26 | UINT GetBandCount() | ||
| 27 | { return (UINT)SendMsg(RB_GETBANDCOUNT); } | ||
| 28 | bool DeleteBand(UINT index) | ||
| 29 | { return LRESULTToBool(SendMsg(RB_DELETEBAND, index)); } | ||
| 30 | }; | ||
| 31 | |||
| 32 | }} | ||
| 33 | |||
| 34 | #endif | ||
diff --git a/CPP/Windows/Control/Static.h b/CPP/Windows/Control/Static.h new file mode 100644 index 0000000..5523b2e --- /dev/null +++ b/CPP/Windows/Control/Static.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | // Windows/Control/Static.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_STATIC_H | ||
| 4 | #define __WINDOWS_CONTROL_STATIC_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CStatic: public CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | HANDLE SetImage(WPARAM imageType, HANDLE handle) { return (HANDLE)SendMsg(STM_SETIMAGE, imageType, (LPARAM)handle); } | ||
| 15 | HANDLE GetImage(WPARAM imageType) { return (HANDLE)SendMsg(STM_GETIMAGE, imageType, 0); } | ||
| 16 | |||
| 17 | #ifdef UNDER_CE | ||
| 18 | HICON SetIcon(HICON icon) { return (HICON)SetImage(IMAGE_ICON, icon); } | ||
| 19 | HICON GetIcon() { return (HICON)GetImage(IMAGE_ICON); } | ||
| 20 | #else | ||
| 21 | HICON SetIcon(HICON icon) { return (HICON)SendMsg(STM_SETICON, (WPARAM)icon, 0); } | ||
| 22 | HICON GetIcon() { return (HICON)SendMsg(STM_GETICON, 0, 0); } | ||
| 23 | #endif | ||
| 24 | }; | ||
| 25 | |||
| 26 | }} | ||
| 27 | |||
| 28 | #endif | ||
diff --git a/CPP/Windows/Control/StatusBar.h b/CPP/Windows/Control/StatusBar.h new file mode 100644 index 0000000..988b847 --- /dev/null +++ b/CPP/Windows/Control/StatusBar.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | // Windows/Control/StatusBar.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_STATUSBAR_H | ||
| 4 | #define __WINDOWS_CONTROL_STATUSBAR_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CStatusBar: public NWindows::CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | bool Create(LONG style, LPCTSTR text, HWND hwndParent, UINT id) | ||
| 15 | { return (_window = ::CreateStatusWindow(style, text, hwndParent, id)) != 0; } | ||
| 16 | bool SetText(LPCTSTR text) | ||
| 17 | { return CWindow::SetText(text); } | ||
| 18 | bool SetText(unsigned index, LPCTSTR text, UINT type) | ||
| 19 | { return LRESULTToBool(SendMsg(SB_SETTEXT, index | type, (LPARAM)text)); } | ||
| 20 | bool SetText(unsigned index, LPCTSTR text) | ||
| 21 | { return SetText(index, text, 0); } | ||
| 22 | |||
| 23 | #ifndef _UNICODE | ||
| 24 | bool Create(LONG style, LPCWSTR text, HWND hwndParent, UINT id) | ||
| 25 | { return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != 0; } | ||
| 26 | bool SetText(LPCWSTR text) | ||
| 27 | { return CWindow::SetText(text); } | ||
| 28 | bool SetText(unsigned index, LPCWSTR text, UINT type) | ||
| 29 | { return LRESULTToBool(SendMsg(SB_SETTEXTW, index | type, (LPARAM)text)); } | ||
| 30 | bool SetText(unsigned index, LPCWSTR text) | ||
| 31 | { return SetText(index, text, 0); } | ||
| 32 | #endif | ||
| 33 | |||
| 34 | bool SetParts(unsigned numParts, const int *edgePostions) | ||
| 35 | { return LRESULTToBool(SendMsg(SB_SETPARTS, numParts, (LPARAM)edgePostions)); } | ||
| 36 | void Simple(bool simple) | ||
| 37 | { SendMsg(SB_SIMPLE, BoolToBOOL(simple), 0); } | ||
| 38 | }; | ||
| 39 | |||
| 40 | }} | ||
| 41 | |||
| 42 | #endif | ||
diff --git a/CPP/Windows/Control/StdAfx.h b/CPP/Windows/Control/StdAfx.h new file mode 100644 index 0000000..1cbd7fe --- /dev/null +++ b/CPP/Windows/Control/StdAfx.h | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | // StdAfx.h | ||
| 2 | |||
| 3 | #ifndef __STDAFX_H | ||
| 4 | #define __STDAFX_H | ||
| 5 | |||
| 6 | #include "../../Common/Common.h" | ||
| 7 | |||
| 8 | #endif | ||
diff --git a/CPP/Windows/Control/ToolBar.h b/CPP/Windows/Control/ToolBar.h new file mode 100644 index 0000000..7bc93a2 --- /dev/null +++ b/CPP/Windows/Control/ToolBar.h | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | // Windows/Control/ToolBar.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_TOOLBAR_H | ||
| 4 | #define __WINDOWS_CONTROL_TOOLBAR_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CToolBar: public NWindows::CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | void AutoSize() { SendMsg(TB_AUTOSIZE, 0, 0); } | ||
| 15 | DWORD GetButtonSize() { return (DWORD)SendMsg(TB_GETBUTTONSIZE, 0, 0); } | ||
| 16 | |||
| 17 | bool GetMaxSize(LPSIZE size) | ||
| 18 | #ifdef UNDER_CE | ||
| 19 | { | ||
| 20 | // maybe it must be fixed for more than 1 buttons | ||
| 21 | DWORD val = GetButtonSize(); | ||
| 22 | size->cx = LOWORD(val); | ||
| 23 | size->cy = HIWORD(val); | ||
| 24 | return true; | ||
| 25 | } | ||
| 26 | #else | ||
| 27 | { | ||
| 28 | return LRESULTToBool(SendMsg(TB_GETMAXSIZE, 0, (LPARAM)size)); | ||
| 29 | } | ||
| 30 | #endif | ||
| 31 | |||
| 32 | bool EnableButton(UINT buttonID, bool enable) { return LRESULTToBool(SendMsg(TB_ENABLEBUTTON, buttonID, MAKELONG(BoolToBOOL(enable), 0))); } | ||
| 33 | void ButtonStructSize() { SendMsg(TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON)); } | ||
| 34 | HIMAGELIST SetImageList(UINT listIndex, HIMAGELIST imageList) { return HIMAGELIST(SendMsg(TB_SETIMAGELIST, listIndex, (LPARAM)imageList)); } | ||
| 35 | bool AddButton(UINT numButtons, LPTBBUTTON buttons) { return LRESULTToBool(SendMsg(TB_ADDBUTTONS, numButtons, (LPARAM)buttons)); } | ||
| 36 | #ifndef _UNICODE | ||
| 37 | bool AddButtonW(UINT numButtons, LPTBBUTTON buttons) { return LRESULTToBool(SendMsg(TB_ADDBUTTONSW, numButtons, (LPARAM)buttons)); } | ||
| 38 | #endif | ||
| 39 | }; | ||
| 40 | |||
| 41 | }} | ||
| 42 | |||
| 43 | #endif | ||
diff --git a/CPP/Windows/Control/Trackbar.h b/CPP/Windows/Control/Trackbar.h new file mode 100644 index 0000000..313e0c8 --- /dev/null +++ b/CPP/Windows/Control/Trackbar.h | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | // Windows/Control/Trackbar.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_TRACKBAR_H | ||
| 4 | #define __WINDOWS_CONTROL_TRACKBAR_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CTrackbar: public CWindow | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | void SetRange(int minimum, int maximum, bool redraw = true) | ||
| 15 | { SendMsg(TBM_SETRANGE, BoolToBOOL(redraw), MAKELONG(minimum, maximum)); } | ||
| 16 | void SetPos(int pos, bool redraw = true) | ||
| 17 | { SendMsg(TBM_SETPOS, BoolToBOOL(redraw), pos); } | ||
| 18 | void SetTicFreq(int freq) | ||
| 19 | { SendMsg(TBM_SETTICFREQ, freq); } | ||
| 20 | |||
| 21 | int GetPos() | ||
| 22 | { return (int)SendMsg(TBM_GETPOS); } | ||
| 23 | }; | ||
| 24 | |||
| 25 | }} | ||
| 26 | |||
| 27 | #endif | ||
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 | }} | ||
diff --git a/CPP/Windows/Control/Window2.h b/CPP/Windows/Control/Window2.h new file mode 100644 index 0000000..7ac580c --- /dev/null +++ b/CPP/Windows/Control/Window2.h | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | // Windows/Control/Window2.h | ||
| 2 | |||
| 3 | #ifndef __WINDOWS_CONTROL_WINDOW2_H | ||
| 4 | #define __WINDOWS_CONTROL_WINDOW2_H | ||
| 5 | |||
| 6 | #include "../Window.h" | ||
| 7 | |||
| 8 | namespace NWindows { | ||
| 9 | namespace NControl { | ||
| 10 | |||
| 11 | class CWindow2: public CWindow | ||
| 12 | { | ||
| 13 | LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam); | ||
| 14 | public: | ||
| 15 | CWindow2(HWND newWindow = NULL): CWindow(newWindow){}; | ||
| 16 | virtual ~CWindow2() {}; | ||
| 17 | |||
| 18 | bool CreateEx(DWORD exStyle, LPCTSTR className, LPCTSTR windowName, | ||
| 19 | DWORD style, int x, int y, int width, int height, | ||
| 20 | HWND parentWindow, HMENU idOrHMenu, HINSTANCE instance); | ||
| 21 | |||
| 22 | #ifndef _UNICODE | ||
| 23 | bool CreateEx(DWORD exStyle, LPCWSTR className, LPCWSTR windowName, | ||
| 24 | DWORD style, int x, int y, int width, int height, | ||
| 25 | HWND parentWindow, HMENU idOrHMenu, HINSTANCE instance); | ||
| 26 | #endif | ||
| 27 | |||
| 28 | virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam); | ||
| 29 | virtual bool OnCreate(CREATESTRUCT * /* createStruct */) { return true; } | ||
| 30 | // virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam); | ||
| 31 | virtual bool OnCommand(WPARAM wParam, LPARAM lParam, LRESULT &result); | ||
| 32 | virtual bool OnCommand(int code, int itemID, LPARAM lParam, LRESULT &result); | ||
| 33 | virtual bool OnSize(WPARAM /* wParam */, int /* xSize */, int /* ySize */) { return false; } | ||
| 34 | virtual bool OnNotify(UINT /* controlID */, LPNMHDR /* lParam */, LRESULT & /* result */) { return false; } | ||
| 35 | virtual void OnDestroy() { PostQuitMessage(0); } | ||
| 36 | virtual void OnClose() { Destroy(); } | ||
| 37 | /* | ||
| 38 | virtual LRESULT OnHelp(LPHELPINFO helpInfo) { OnHelp(); } | ||
| 39 | virtual LRESULT OnHelp() {}; | ||
| 40 | virtual bool OnButtonClicked(int buttonID, HWND buttonHWND); | ||
| 41 | virtual void OnOK() {}; | ||
| 42 | virtual void OnCancel() {}; | ||
| 43 | */ | ||
| 44 | |||
| 45 | LONG_PTR SetMsgResult(LONG_PTR newLongPtr) { return SetLongPtr(DWLP_MSGRESULT, newLongPtr); } | ||
| 46 | LONG_PTR GetMsgResult() const { return GetLongPtr(DWLP_MSGRESULT); } | ||
| 47 | }; | ||
| 48 | |||
| 49 | }} | ||
| 50 | |||
| 51 | #endif | ||
