-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdDialogBoxes.cpp
204 lines (195 loc) · 5.79 KB
/
stdDialogBoxes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <windows.h>
#include <tchar.h>
#include "globalVars.h"
#include "stdDialogBoxes.h"
void createPrintDialog(void)
{
PRINTDLG printDialogStruct;
printDialogStruct.lStructSize = sizeof(PRINTDLG);
printDialogStruct.hwndOwner = hwnd;
printDialogStruct.hDevMode = (HANDLE)NULL;
printDialogStruct.hDevNames = (HANDLE)NULL;
printDialogStruct.Flags = PD_RETURNDC;
printDialogStruct.hDC = (HDC)NULL;
printDialogStruct.nFromPage = 1;
printDialogStruct.nToPage = 1;
printDialogStruct.nMinPage = 0;
printDialogStruct.nMaxPage = 1;
printDialogStruct.nCopies = 1;
printDialogStruct.hInstance = ghInstance;
printDialogStruct.lCustData = 0L;
printDialogStruct.lpfnPrintHook = (LPPRINTHOOKPROC)NULL;
printDialogStruct.lpfnSetupHook = (LPSETUPHOOKPROC)NULL;
printDialogStruct.lpPrintTemplateName = _T("Print");
printDialogStruct.lpSetupTemplateName = _T("Print");
printDialogStruct.hPrintTemplate = (HANDLE)NULL;
printDialogStruct.hSetupTemplate = (HANDLE)NULL;
PrintDlg(&printDialogStruct);
}
COLORREF initializeColorDlgBox(HWND hwnd)
{
CHOOSECOLOR cc;
COLORREF chosenColor;
static COLORREF acrCustClr[16]; // array of custom colors
// owner window
HBRUSH hbrush; // brush handle
static DWORD rgbCurrent; // initial color selection
ZeroMemory(&cc, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = hwnd;
cc.lpCustColors = (LPDWORD)acrCustClr;
cc.rgbResult = rgbCurrent;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
if (ChooseColor(&cc) == TRUE)
{
hbrush = CreateSolidBrush(cc.rgbResult);
rgbCurrent = cc.rgbResult;
}
chosenColor = cc.rgbResult;
return chosenColor;
}
CHOOSEFONT initializeFontDlgBox(HWND hwnd)
{
HDC hdc = GetDC(hwnd); // display device context of owner window
CHOOSEFONT cf; // common dialog box structure
CHOOSEFONT chosenFont;
static LOGFONT lf; // logical font structure
static DWORD rgbCurrent; // current text color
HFONT hfont, hfontPrev;
DWORD rgbPrev;
// Initialize CHOOSEFONT
ZeroMemory(&cf, sizeof(cf));
cf.lStructSize = sizeof (cf);
cf.hwndOwner = hwnd;
cf.lpLogFont = &lf;
//cf.rgbColors = rgbCurrent;
cf.Flags = CF_SCREENFONTS | CF_NOSTYLESEL;
if (ChooseFont(&cf) == TRUE)
{
hfont = CreateFontIndirect(cf.lpLogFont);
hfontPrev = (HFONT)SelectObject(hdc, hfont);
//rgbCurrent = cf.rgbColors;
//rgbPrev = SetTextColor(hdc, rgbCurrent);
}
//_tcscpy(fontFamily,cf.lpszStyle);
return cf;
}
int SearchFile(const TCHAR* find, BOOL down, BOOL ignoreCase)
{
return -1;
}
void initializeFindDlgBox(HWND hwnd)
{
static FINDREPLACE fr; // common dialog box structure
static TCHAR szFindWhat[80]; // buffer receiving string
// Initialize FINDREPLACE
ZeroMemory(&fr, sizeof(fr));
ZeroMemory(&szFindWhat,sizeof(szFindWhat));
fr.lStructSize = sizeof(fr);
fr.hwndOwner = hwnd;
fr.lpstrFindWhat = szFindWhat;
fr.wFindWhatLen = 80;
fr.Flags = FR_HIDEWHOLEWORD;
findDlg = (HWND)FindText(&fr);
try
{
if (!findDlg)
{
throw _T("Failed to create Find Dialog");
}
}
catch(TCHAR *e)
{
MessageBox(NULL, e, _T("Runtime Error"), MB_OK | MB_ICONERROR);
}
}
void initializeFindANDRplcDlgBox(HWND)
{
//to be implemented yet
}
bool findFunc(LPFINDREPLACE lpfr)
{
//handle up/down and match case
DWORD searchFlags;
if ((*lpfr).Flags & FR_DOWN)
{
searchFlags = FR_DOWN;
if ((*lpfr).Flags & FR_MATCHCASE)
{
searchFlags = FR_DOWN | FR_MATCHCASE;
}
}
bool res = false;
UINT64 richEditTextLen = GetWindowTextLength(richEditControl);
UINT64 richEditFoundSelectPos = 0;
UINT64 textToSearchLen = 0;
//TCHAR *richEditTextBuffer = NULL;
//TCHAR *richEditFoundTextPos = NULL;
INT64 richEditFoundTextPos = 0;
FINDTEXT txtToSearch;
CHARRANGE rangeToSearch;
#define rangeToHighlight rangeToSearch
txtToSearch.lpstrText = (*lpfr).lpstrFindWhat;
textToSearchLen = _tcslen((*lpfr).lpstrFindWhat);
SendMessage(richEditControl, EM_GETSEL, 0, (LPARAM)&richEditCurrOffset);
rangeToSearch.cpMin = richEditCurrOffset?richEditCurrOffset-1:0;
rangeToSearch.cpMax = -1;
txtToSearch.chrg = rangeToSearch;
richEditFoundTextPos = SendMessage(richEditControl,EM_FINDTEXT,(WPARAM)searchFlags,(LPARAM)&txtToSearch);
if (richEditFoundTextPos >= 0)
{
res = true;
rangeToHighlight.cpMin = richEditFoundTextPos;
rangeToHighlight.cpMax = richEditFoundTextPos + (textToSearchLen);
//highlighting the found text
SendMessage(richEditControl, EM_EXSETSEL, NULL, (LPARAM)&rangeToHighlight);
SendMessage(richEditControl, EM_SCROLLCARET, 0, 0);
//setting the new offset
richEditCurrOffset = rangeToHighlight.cpMax + 1;
}
#undef rangeToHighlight rangeToSearch
return res;
/*
try
{
richEditTextBuffer = new TCHAR[richEditTextLen+1];
if (!richEditTextBuffer)
{
throw _T("Unable to allocate text buffer");
}
else
{
GetWindowText(richEditControl,richEditTextBuffer,richEditTextLen+1);
SendMessage(richEditControl,EM_GETSEL,0,(LPARAM)&richEditCurrOffset);
richEditFoundTextPos = _tcsstr(richEditTextBuffer + richEditCurrOffset,(*lpfr).lpstrFindWhat);
//the string wasn't found
if (!richEditFoundTextPos)
{
res = false;
}
//the string was found -> select it and set new offset after the string
else
{
richEditFoundSelectPos = richEditFoundTextPos - richEditTextBuffer;
richEditCurrOffset = richEditFoundSelectPos + _tcslen((*lpfr).lpstrFindWhat);
CHARRANGE range;
range.cpMin = richEditFoundSelectPos;
range.cpMax = richEditCurrOffset;
SetFocus(richEditControl);
SendMessage(richEditControl,EM_EXSETSEL,NULL,(LPARAM)&range);
//SendMessage(richEditControl,EM_SETSEL,richEditFoundSelectPos,richEditCurrOffset);
SendMessage(richEditControl,EM_SCROLLCARET,0,0);
SetFocus(findDlg);
res = true;
}
}
delete richEditTextBuffer;
return res;
}
catch(TCHAR *e)
{
MessageBox(NULL,_T("Error"),e,MB_OK|MB_ICONERROR);
return false;
}
*/
}