ReactOS  0.4.15-dev-5488-ge316d61
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 
75  SetWindowPos(HWND_TOP, 0, 0,
76  DlgRect.right - DlgRect.left,
77  DlgRect.bottom - DlgRect.top + HeightDiff,
79 }
80 
81 unsigned int __stdcall
83 {
84  ProgressDlg *pProgressDlg = (ProgressDlg *)Param;
85 
86  pProgressDlg->m_RunOnceExInst.Exec(pProgressDlg->m_hWnd);
87  return 0;
88 }
89 
90 BOOL
92  _In_ HWND hwnd,
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.
136  HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, RunOnceExExecThread, (void *)this, 0, NULL);
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 
173  ListBox_GetText(m_hListBox, pDrawItem->itemID,
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.
216  EndDialog(lParam);
217  }
220  break;
221  }
222 
223  case WM_CTLCOLORLISTBOX:
224  {
225  lResult = (LRESULT)GetStockBrush(NULL_BRUSH);
226  break;
227  }
228 
229  case WM_DESTROY:
230  {
233  break;
234  }
235  }
236  return TRUE;
237 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
Definition: tftpd.h:59
#define CloseHandle
Definition: compat.h:739
HBITMAP m_hArrowBmp
Definition: dialog.h:26
#define _Inout_
Definition: ms_sal.h:378
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
struct tagDRAWITEMSTRUCT * PDRAWITEMSTRUCT
CSimpleArray< RunOnceExSection > m_SectionList
Definition: registry.h:98
#define _Out_
Definition: ms_sal.h:345
HDC WINAPI GetDC(_In_opt_ HWND)
#define TRUE
Definition: types.h:120
void CalcTextRect(_In_ LPCWSTR lpText, _Inout_ RECT *pRect)
Definition: dialog.cpp:40
#define NULL_BRUSH
Definition: wingdi.h:901
#define DT_WORDBREAK
Definition: winuser.h:544
static HDC
Definition: imagelist.c:92
ULONG_PTR itemData
Definition: winuser.h:3083
LONG top
Definition: windef.h:307
#define ListBox_AddString(hwndCtl, lpsz)
Definition: windowsx.h:472
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define GWL_EXSTYLE
Definition: winuser.h:845
#define HWND_TOP
Definition: winuser.h:1197
#define ITEM_LEFTPADDING
Definition: dialog.cpp:12
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
LONG left
Definition: windef.h:306
#define SWP_NOZORDER
Definition: winuser.h:1237
_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 right
Definition: windef.h:308
#define WM_CTLCOLORLISTBOX
Definition: winuser.h:1758
int GetSize() const
Definition: atlsimpcoll.h:104
int32_t INT
Definition: typedefs.h:58
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
unsigned int __stdcall RunOnceExExecThread(_In_ void *Param)
Definition: dialog.cpp:82
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1056
ProgressDlg(_In_ RunOnceExInstance &RunOnceExInst)
Definition: dialog.cpp:23
struct tagMEASUREITEMSTRUCT * PMEASUREITEMSTRUCT
BITMAP m_ArrowBmp
Definition: dialog.h:27
#define DT_CALCRECT
Definition: winuser.h:526
INT m_PointedItem
Definition: dialog.h:28
unsigned int BOOL
Definition: ntddk_ex.h:94
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define TRANSPARENT
Definition: wingdi.h:950
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
#define IDC_LB_ITEMS
Definition: resource.h:7
#define _In_
Definition: ms_sal.h:308
LONG_PTR LPARAM
Definition: windef.h:208
#define ListBox_SetItemData(hwndCtl, index, data)
Definition: windowsx.h:502
#define WM_DESTROY
Definition: winuser.h:1599
ATL::CStringW m_SectionTitle
Definition: registry.h:63
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define GetStockBrush(i)
Definition: windowsx.h:307
_In_ WDFCOLLECTION _In_ ULONG Index
BOOL RunDialogBox()
Definition: dialog.cpp:30
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
PVOID HANDLE
Definition: typedefs.h:73
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ITEM_VPADDING
Definition: dialog.cpp:11
#define WM_MEASUREITEM
Definition: winuser.h:1636
#define ListBox_GetText(hwndCtl, index, lpszBuffer)
Definition: windowsx.h:489
#define __stdcall
Definition: typedefs.h:25
#define ListBox_GetItemHeight(hwndCtl, index)
Definition: windowsx.h:484
HDC hdc
Definition: main.c:9
#define LRESULT
Definition: ole.h:14
#define ListBox_GetTextLen(hwndCtl, index)
Definition: windowsx.h:490
#define WM_SETINDEX
Definition: dialog.h:18
#define SelectFont(hdc, hfont)
Definition: windowsx.h:516
BOOL ProcessWindowMessage(_In_ HWND hwnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam, _Out_ LRESULT &lResult, _In_ DWORD dwMsgMapID)
Definition: dialog.cpp:91
bool IsEmpty() const
Definition: atlsimpstr.h:379
int WINAPI GetObjectW(_In_ HANDLE h, _In_ int c, _Out_writes_bytes_opt_(c) LPVOID pv)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define FW_BOLD
Definition: wingdi.h:378
HFONT m_hBoldFont
Definition: dialog.h:25
#define WS_EX_CLIENTEDGE
Definition: winuser.h:384
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
BOOL WINAPI DeleteDC(_In_ HDC)
#define OBM_MNARROW
Definition: winuser.h:1107
HBITMAP WINAPI LoadBitmapW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2132
void ResizeListBoxAndDialog(_In_ int NewHeight)
Definition: dialog.cpp:62
Definition: bl.h:1330
#define SRCAND
Definition: wingdi.h:330
HFONT CreateBoldFont(_In_ HFONT hOrigFont)
Definition: dialog.cpp:14
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define SelectBitmap(hdc, hbm)
Definition: windowsx.h:514
CStringW m_Title
Definition: registry.h:99
#define SWP_SHOWWINDOW
Definition: winuser.h:1238
HANDLE hThread
Definition: wizard.c:28
#define WM_DRAWITEM
Definition: winuser.h:1635
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
BOOL Exec(_In_opt_ HWND hwnd)
Definition: registry.cpp:293
LONG bottom
Definition: windef.h:309
CAtlStringW CStringW
Definition: atlstr.h:130
#define SWP_NOMOVE
Definition: winuser.h:1234
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 GetWindowLongPtr
Definition: treelist.c:73
LONG lfWeight
Definition: dimm.idl:63
LONG_PTR LRESULT
Definition: windef.h:209
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
HWND m_hListBox
Definition: dialog.h:24
RunOnceExInstance & m_RunOnceExInst
Definition: dialog.h:33
#define WM_INITDIALOG
Definition: winuser.h:1729
LPARAM lParam
Definition: combotst.c:139
static VOID NTAPI 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:49
#define DeleteFont(hfont)
Definition: windowsx.h:78
INT WINAPI DrawTextW(HDC hdc, LPCWSTR str, INT count, LPRECT rect, UINT flags)
Definition: defwnd.c:17