ReactOS 0.4.15-dev-7918-g2a2556c
dialog.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS system libraries
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Classes for displaying progress dialog.
5 * COPYRIGHT: Copyright 2021 He Yang <1160386205@qq.com>
6 */
7
8#include "iernonce.h"
9#include <process.h>
10
11#define ITEM_VPADDING 3
12#define ITEM_LEFTPADDING 22
13
15{
16 LOGFONTW fontAttributes = { 0 };
17 GetObjectW(hOrigFont, sizeof(fontAttributes), &fontAttributes);
18 fontAttributes.lfWeight = FW_BOLD;
19
20 return CreateFontIndirectW(&fontAttributes);
21}
22
24 m_hListBox(NULL),
25 m_hBoldFont(NULL),
26 m_PointedItem(0),
27 m_RunOnceExInst(RunOnceExInst)
28{ ; }
29
31{
32 // Show the dialog and run the items only when the list is not empty.
34 {
35 return (DoModal() == 1);
36 }
37 return TRUE;
38}
39
41 _In_ LPCWSTR lpText,
42 _Inout_ PRECT pRect)
43{
46
47 pRect->bottom = pRect->top;
48 pRect->left += ITEM_LEFTPADDING;
49
50 HFONT OldFont = SelectFont(hdc, GetFont());
51 DrawTextW(hdc, lpText, -1, pRect, DT_CALCRECT | DT_WORDBREAK);
54
55 pRect->bottom -= pRect->top;
56 pRect->bottom += ITEM_VPADDING * 2;
57 pRect->top = 0;
58 pRect->right -= pRect->left;
59 pRect->left = 0;
60}
61
63{
64 RECT ListBoxRect;
65 RECT DlgRect;
66 ::GetWindowRect(m_hListBox, &ListBoxRect);
67 GetWindowRect(&DlgRect);
68
69 int HeightDiff = NewHeight - (ListBoxRect.bottom - ListBoxRect.top);
70
72 ListBoxRect.right - ListBoxRect.left, NewHeight,
74
76 DlgRect.right - DlgRect.left,
77 DlgRect.bottom - DlgRect.top + HeightDiff,
79}
80
81unsigned int __stdcall
83{
84 ProgressDlg *pProgressDlg = (ProgressDlg *)Param;
85
86 pProgressDlg->m_RunOnceExInst.Exec(pProgressDlg->m_hWnd);
87 return 0;
88}
89
90BOOL
96 _Out_ LRESULT& lResult,
97 _In_ DWORD dwMsgMapID)
98{
99 lResult = 0;
100 switch (message)
101 {
102 case WM_INITDIALOG:
103 {
104 if (!m_RunOnceExInst.m_Title.IsEmpty())
105 {
107 }
108
110
111 m_hBoldFont = CreateBoldFont(GetFont());
112
115
116 // Add all sections with non-empty title into listbox
117 int TotalHeight = 0;
118 for (int i = 0; i < m_RunOnceExInst.m_SectionList.GetSize(); i++)
119 {
121
122 if (!Section.m_SectionTitle.IsEmpty())
123 {
125 TotalHeight += ListBox_GetItemHeight(m_hListBox, Index);
127 }
128 }
129
130 // Remove the sunken-edged border from the listbox.
132
133 ResizeListBoxAndDialog(TotalHeight);
134
135 // Launch a thread to execute tasks.
138 {
139 EndDialog(0);
140 return TRUE;
141 }
143
144 lResult = TRUE; // set keyboard focus to the dialog box control.
145 break;
146 }
147
148 case WM_MEASUREITEM:
149 {
151 RECT TextRect = { 0 };
152
153 CStringW ItemText;
154 ListBox_GetText(m_hListBox, pMeasureItem->itemID,
155 ItemText.GetBuffer(ListBox_GetTextLen(m_hListBox,
156 pMeasureItem->itemID) + 1));
157
158 CalcTextRect(ItemText, &TextRect);
159
160 ItemText.ReleaseBuffer();
161
162 pMeasureItem->itemHeight = TextRect.bottom - TextRect.top;
163 pMeasureItem->itemWidth = TextRect.right - TextRect.left;
164
165 break;
166 }
167
168 case WM_DRAWITEM:
169 {
171 CStringW ItemText;
172
174 ItemText.GetBuffer(ListBox_GetTextLen(m_hListBox,
175 pDrawItem->itemID) + 1));
176
177 SetBkMode(pDrawItem->hDC, TRANSPARENT);
178
179 HFONT hOldFont = NULL;
180 if (m_PointedItem == (INT)pDrawItem->itemData)
181 {
182 HDC hCompDC = CreateCompatibleDC(pDrawItem->hDC);
183
184 SelectBitmap(hCompDC, m_hArrowBmp);
185
186 int IconLeftPadding = (ITEM_LEFTPADDING - m_ArrowBmp.bmWidth) / 2;
187 int IconTopPadding = (pDrawItem->rcItem.bottom - pDrawItem->rcItem.top - m_ArrowBmp.bmHeight) / 2;
188
189 BitBlt(pDrawItem->hDC, IconLeftPadding, pDrawItem->rcItem.top + IconTopPadding,
190 m_ArrowBmp.bmWidth, m_ArrowBmp.bmHeight, hCompDC, 0, 0, SRCAND);
191
192 DeleteDC(hCompDC);
193
194 hOldFont = SelectFont(pDrawItem->hDC, m_hBoldFont);
195 }
196
197 pDrawItem->rcItem.left += ITEM_LEFTPADDING;
198 pDrawItem->rcItem.top += ITEM_VPADDING;
199 DrawTextW(pDrawItem->hDC, ItemText, -1,
200 &(pDrawItem->rcItem), DT_WORDBREAK);
201
202 if (hOldFont)
203 {
204 SelectFont(pDrawItem->hDC, hOldFont);
205 }
206 ItemText.ReleaseBuffer();
207
208 break;
209 }
210
211 case WM_SETINDEX:
212 {
214 {
215 // All sections are handled, lParam is bSuccess.
217 }
220 break;
221 }
222
224 {
225 lResult = (LRESULT)GetStockBrush(NULL_BRUSH);
226 break;
227 }
228
229 case WM_DESTROY:
230 {
233 break;
234 }
235 }
236 return TRUE;
237}
int GetSize() const
Definition: atlsimpcoll.h:104
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
HWND m_hListBox
Definition: dialog.h:24
BITMAP m_ArrowBmp
Definition: dialog.h:27
ProgressDlg(_In_ RunOnceExInstance &RunOnceExInst)
Definition: dialog.cpp:23
HFONT m_hBoldFont
Definition: dialog.h:25
BOOL RunDialogBox()
Definition: dialog.cpp:30
HBITMAP m_hArrowBmp
Definition: dialog.h:26
BOOL ProcessWindowMessage(_In_ HWND hwnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam, _Out_ LRESULT &lResult, _In_ DWORD dwMsgMapID)
Definition: dialog.cpp:91
void CalcTextRect(_In_ LPCWSTR lpText, _Inout_ RECT *pRect)
Definition: dialog.cpp:40
RunOnceExInstance & m_RunOnceExInst
Definition: dialog.h:33
void ResizeListBoxAndDialog(_In_ int NewHeight)
Definition: dialog.cpp:62
INT m_PointedItem
Definition: dialog.h:28
BOOL Exec(_In_opt_ HWND hwnd)
Definition: registry.cpp:293
CStringW m_Title
Definition: registry.h:99
CSimpleArray< RunOnceExSection > m_SectionList
Definition: registry.h:98
ATL::CStringW m_SectionTitle
Definition: registry.h:63
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define ITEM_VPADDING
Definition: dialog.cpp:11
unsigned int __stdcall RunOnceExExecThread(_In_ void *Param)
Definition: dialog.cpp:82
HFONT CreateBoldFont(_In_ HFONT hOrigFont)
Definition: dialog.cpp:14
#define ITEM_LEFTPADDING
Definition: dialog.cpp:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define WM_SETINDEX
Definition: dialog.h:18
#define IDC_LB_ITEMS
Definition: resource.h:7
static VOID BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:57
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
unsigned int UINT
Definition: ndis.h:50
HANDLE hThread
Definition: wizard.c:28
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:16
#define LRESULT
Definition: ole.h:14
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
LONG lfWeight
Definition: dimm.idl:63
Definition: bl.h:1331
Definition: tftpd.h:60
ULONG_PTR itemData
Definition: winuser.h:3093
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
PVOID HANDLE
Definition: typedefs.h:73
int32_t INT
Definition: typedefs.h:58
#define __stdcall
Definition: typedefs.h:25
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define GetStockBrush(i)
Definition: windowsx.h:307
#define ListBox_GetTextLen(hwndCtl, index)
Definition: windowsx.h:490
#define DeleteFont(hfont)
Definition: windowsx.h:78
#define ListBox_GetItemHeight(hwndCtl, index)
Definition: windowsx.h:484
#define SelectFont(hdc, hfont)
Definition: windowsx.h:516
#define ListBox_GetText(hwndCtl, index, lpszBuffer)
Definition: windowsx.h:489
#define SelectBitmap(hdc, hbm)
Definition: windowsx.h:514
#define ListBox_SetItemData(hwndCtl, index, data)
Definition: windowsx.h:502
#define ListBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:472
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
#define FW_BOLD
Definition: wingdi.h:378
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define TRANSPARENT
Definition: wingdi.h:950
#define NULL_BRUSH
Definition: wingdi.h:901
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
BOOL WINAPI DeleteDC(_In_ HDC)
#define SRCAND
Definition: wingdi.h:330
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define SWP_NOMOVE
Definition: winuser.h:1244
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define WM_DRAWITEM
Definition: winuser.h:1645
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define HWND_TOP
Definition: winuser.h:1207
#define DT_WORDBREAK
Definition: winuser.h:544
#define SWP_SHOWWINDOW
Definition: winuser.h:1248
HDC WINAPI GetDC(_In_opt_ HWND)
#define WM_MEASUREITEM
Definition: winuser.h:1646
struct tagMEASUREITEMSTRUCT * PMEASUREITEMSTRUCT
struct tagDRAWITEMSTRUCT * PDRAWITEMSTRUCT
#define WM_CTLCOLORLISTBOX
Definition: winuser.h:1768
#define WM_DESTROY
Definition: winuser.h:1609
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
HBITMAP WINAPI LoadBitmapW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2163
#define SWP_NOZORDER
Definition: winuser.h:1247
#define DT_CALCRECT
Definition: winuser.h:526
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define GWL_EXSTYLE
Definition: winuser.h:851
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185