uLib  User mode C/C++ extended API library for Win32 programmers.
StdDlg.h
Go to the documentation of this file.
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // Project: uLib - User mode utility library.
3 // Module: Standard dialog wrapper classes.
4 // Author: Copyright (c) Love Nystrom
5 // License: NNOSL (BSD descendant, see NNOSL.txt in the base directory).
6 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 
8 #ifndef __StdDlg_h_incl__
9 #define __StdDlg_h_incl__
10 
11 #include <uLib/Common.h>
12 
20 
21 #define DLGHOOKPROC UINT_PTR CALLBACK
22 
23 typedef class FileDialog* PFileDialog;
24 typedef class DirDialog* PDirDialog;
25 typedef class FindDialog* PFindDialog;
26 typedef class FontDialog* PFontDialog;
27 typedef class ColorDialog* PColorDialog;
28 
30 
31 ACSTR CDErrorMsg( DWORD Err DEF_(0) );
32 
33 // Common dialog box registered window messages
34 
35 extern UINT WM_CommonHelp;
36 extern UINT WM_FileOk;
37 extern UINT WM_SelChange;
38 extern UINT WM_ShareViolation;
39 extern UINT WM_FindReplace;
40 extern UINT WM_ColorOk;
41 extern UINT WM_SetRGB;
42 
43 #define REGISTER_CommonHelp() \
44  if (!WM_CommonHelp) WM_CommonHelp = RegisterWindowMessage( HELPMSGSTRING )
45 
46 #define REGISTER_FileOk() \
47  if (!WM_FileOk) WM_FileOk = RegisterWindowMessage( FILEOKSTRING )
48 
49 #define REGISTER_SelChange() \
50  if (!WM_SelChange) WM_SelChange = RegisterWindowMessage( LBSELCHSTRING )
51 
52 #define REGISTER_ShareViolation() \
53  if (!WM_ShareViolation) WM_ShareViolation = RegisterWindowMessage( SHAREVISTRING )
54 
55 #define REGISTER_FindReplace() \
56  if (!WM_FindReplace) WM_FindReplace = RegisterWindowMessage( FINDMSGSTRING )
57 
58 #define REGISTER_ColorOk() \
59  if (!WM_ColorOk) WM_ColorOk = RegisterWindowMessage( COLOROKSTRING )
60 
61 #define REGISTER_SetRGB() \
62  if (!WM_SetRGB) WM_SetRGB = RegisterWindowMessage( SETRGBSTRING )
63 
64 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65 // FileDialog
66 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67 
69 #define FDLG_USEINITDIR 1 // Build option: Support lpstrInitialDir.
70 
72 extern const CSTR ALLFILE_FILTER;
73 
78 
79 typedef bool (CALLBACK *FDLG_ItemProc)( CSTR FileName, PVOID UserData );
80 
90 
91 class FileDialog : public OPENFILENAME {
92  // The inherited OPENFILENAME fields are used for Execute calls.
93  // DWORD lStructSize;
94  // HWND hwndOwner;
95  // HINSTANCE hInstance;
96  // LPCTSTR lpstrFilter;
97  // LPTSTR lpstrCustomFilter;
98  // DWORD nMaxCustFilter;
99  // DWORD nFilterIndex;
100  // LPTSTR lpstrFile;
101  // DWORD nMaxFile;
102  // LPTSTR lpstrFileTitle;
103  // DWORD nMaxFileTitle;
104  // LPCTSTR lpstrInitialDir;
105  // LPCTSTR lpstrTitle;
106  // DWORD Flags;
107  // WORD nFileOffset;
108  // WORD nFileExtension;
109  // LPCTSTR lpstrDefExt;
110  // LPARAM lCustData;
111  // LPOFNHOOKPROC lpfnHook;
112  // LPCTSTR lpTemplateName;
113 public:
114  TCHAR FullName[ MAX_PATH ];
115  #if FDLG_USEINITDIR
116  TCHAR InitDir[ MAX_PATH ];
117  #endif
118 
119  FileDialog( HWND owner = NULL );
120  void SetOwner( HWND owner, HINSTANCE hInst = NULL );
121  ~FileDialog();
122 
125 
126  bool Execute( UINT mode );
127  #define FDLG_OPEN 1
128  #define FDLG_SAVE 2
129 
130  CSTR Name();
131  CSTR Ext();
132 
135 
136  bool ForEach( FDLG_ItemProc Action, PVOID UserData );
137 
140 
141  CSTR PickFile( HWND owner, CSTR caption, CSTR filter );
142 
145 
146  CSTR SetFilename( CSTR PathName );
147 
148 protected:
150  void _updateOffsets(); // Scan FullName and update nFileOffset/nFileExtension
152 };
153 
154 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155 // FindDialog
156 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157 
158 #ifndef FR_ACTIONMASK // (wCore and WCL defines this too)
159  #define FRX_FINDALL 0x00100000 // Use an undefined Flags bit as 'Find All'
160  #define FR_ACTIONMASK (FR_FINDNEXT| FR_REPLACE |FR_REPLACEALL| FR_DIALOGTERM| FRX_FINDALL)
161  #define FR_OPTIONMASK (FR_DOWN| FR_MATCHCASE| FR_WHOLEWORD)
162 #endif
163 
172 
173 class FindDialog : public FINDREPLACE {
174  // The inherited FINDREPLACE fields are used for Execute calls.
175  // DWORD lStructSize;
176  // HWND hwndOwner;
177  // HINSTANCE hInstance;
178  // DWORD Flags;
179  // LPTSTR lpstrFindWhat;
180  // LPTSTR lpstrReplaceWith;
181  // WORD wFindWhatLen;
182  // WORD wReplaceWithLen;
183  // LPARAM lCustData;
184  // LPFRHOOKPROC lpfnHook;
185  // LPCTSTR lpTemplateName;
186 public:
187  HWND hWnd;
188  TCHAR What[256];
189  TCHAR With[256];
190 
191  FindDialog( HWND Owner = NULL );
192  void SetOwner( HWND Owner, HINSTANCE hInst = NULL );
193  ~FindDialog();
194 
197 
198  bool Execute( UINT Mode );
199 
200  #define FD_FIND 1
201  #define FD_REPLACE 2
202  #define FD_CLOSE 3
203 
204  void SendFindNext();
205 };
206 
207 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208 // FontDialog
209 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210 
217 
218 class FontDialog : public CHOOSEFONT {
219  // DWORD lStructSize;
220  // HWND hwndOwner; // Caller's window handle
221  // HDC hDC; // Printer DC/IC or NULL
222  // LPLOGFONTA lpLogFont; // Pointer to a LOGFONT struct
223  // INT iPointSize; // 10 * size in points of selected font
224  // DWORD Flags; // enum. type flags
225  // COLORREF rgbColors; // Returned text color
226  // LPARAM lCustData; // Data passed to hook fn.
227  // LPCFHOOKPROC lpfnHook; // Ptr. to hook function
228  // LPCSTR lpTemplateName; // Custom template name
229  // HINSTANCE hInstance; // Instance that contains cust template
230  // LPSTR lpszStyle; // Return style field (>= LF_FACESIZE)
231  // WORD nFontType; // Same as reported to the EnumFonts with FONTTYPE_
232  // WORD ___MISSING_ALIGNMENT__;
233  // INT nSizeMin; // Minimum pt size allowed &
234  // INT nSizeMax; // Max pt size allowed if CF_LIMITSIZE is used
235 public:
236  LOGFONT LogFont;
237 
238  FontDialog();
239  void SetOwner( HWND Owner, HINSTANCE hInst = NULL );
240 
242 
243  bool Execute() { return bool_cast( ChooseFont( this )); }
244 
246 
247  HFONT CreateFont() { return CreateFontIndirect( &LogFont ); }
248 
249  void SetFaceName( CSTR Face );
250  void SetTypeface( CSTR Face, WORD Points, WORD Weight, BYTE ChrSet = ANSI_CHARSET );
251 
254 
255  bool GetLogFontFromDC( HDC hDC );
256 };
257 
258 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 // ColorDialog
260 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261 
269 
270 class ColorDialog : public CHOOSECOLOR {
271  // DWORD lStructSize;
272  // HWND hwndOwner;
273  // HWND hInstance;
274  // COLORREF rgbResult;
275  // COLORREF* lpCustColors;
276  // DWORD Flags;
277  // LPARAM lCustData;
278  // LPCCHOOKPROC lpfnHook;
279  // LPCSTR lpTemplateName;
280 public:
281  COLORREF Colors[16];
282 
283  ColorDialog();
284  void SetOwner( HWND Owner, HINSTANCE hInst = NULL );
285 
288 
289  bool Execute() { return bool_cast( ChooseColor( this )); }
290 };
291 
292 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
293 // DirDialog
294 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
295 
296 #ifndef BIF_DEFAULT // Also defined by wCore (commercial lib)
297  #define BIF_DEFAULT (BIF_RETURNONLYFSDIRS| BIF_NEWDIALOGSTYLE| BIF_EDITBOX)
298 #endif
299 
310 
311 class DirDialog : public BROWSEINFO {
312  // HWND hwndOwner;
313  // PCIDLIST_ABSOLUTE pidlRoot;
314  // LPTSTR pszDisplayName;
315  // LPCTSTR lpszTitle;
316  // UINT ulFlags;
317  // BFFCALLBACK lpfn;
318  // LPARAM lParam; // RESERVED (for DirDialog::_Hook)
319  // int iImage;
320 public:
321  LPITEMIDLIST pIdl;
322  TCHAR Folder[ MAX_PATH ];
323  PVOID pData;
324 
326  static IFolderFilter* FolderFilter;
327 
328  DirDialog( HWND Owner = NULL, UINT Flags = BIF_DEFAULT );
329  void SetOwner( HWND Owner );
330  void Done();
331  ~DirDialog();
332 
333  bool SetInitialDir( CSTR Dir );
334 
335  void SetRoot( LPITEMIDLIST pidl );
336  bool SetRootCsid( int csId );
337  bool SetRootDir( CSTR Dir );
338 
342 
343  bool Execute();
344 
345 protected:
346  IFolderFilterSite* pFilterSite; // Used to install FolderFilter, if any.
352  static DLGHOOKPROC _Hook( HWND hwnd, UINT msg, LPARAM lp, LPARAM data );
353 };
354 
356 #endif//ndef __StdDlg_h_incl__
357 // EOF
unsigned long DWORD
Definition: Common.h:414
static CCSTR DefaultTitle
Definition: StdDlg.h:325
const CSTR ALLFILE_FILTER
Definition: StdDlg.cpp:83
FindDialog(HWND Owner=NULL)
Definition: StdDlg.cpp:252
bool ForEach(FDLG_ItemProc Action, PVOID UserData)
Definition: StdDlg.cpp:209
UINT WM_ShareViolation
Definition: StdDlg.cpp:16
#define BIF_DEFAULT
Definition: StdDlg.h:297
UINT WM_FileOk
Definition: StdDlg.cpp:14
LPITEMIDLIST pIdl
Definition: StdDlg.h:321
const char * ACSTR
Definition: Common.h:345
CSTR Name()
Definition: StdDlg.cpp:167
TCHAR FullName[MAX_PATH]
Definition: StdDlg.h:114
TCHAR Folder[MAX_PATH]
Definition: StdDlg.h:322
#define CSTR
Definition: Common.h:329
unsigned short WORD
Definition: Common.h:413
void SetFaceName(CSTR Face)
Definition: StdDlg.cpp:344
bool SetRootCsid(int csId)
Definition: StdDlg.cpp:485
bool Execute(UINT mode)
Definition: StdDlg.cpp:119
bool GetLogFontFromDC(HDC hDC)
Definition: StdDlg.cpp:357
DirDialog(HWND Owner=NULL, UINT Flags=(BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE|BIF_EDITBOX))
Definition: StdDlg.cpp:406
void SendFindNext()
Definition: StdDlg.cpp:309
class FontDialog * PFontDialog
Definition: StdDlg.h:26
~FindDialog()
Definition: StdDlg.cpp:279
CSTR Ext()
Definition: StdDlg.cpp:172
IFolderFilterSite * pFilterSite
Definition: StdDlg.h:346
void SetTypeface(CSTR Face, WORD Points, WORD Weight, BYTE ChrSet=ANSI_CHARSET)
Definition: StdDlg.cpp:349
bool SetInitialDir(CSTR Dir)
Definition: StdDlg.cpp:467
class FindDialog * PFindDialog
Definition: StdDlg.h:25
COLORREF Colors[16]
Definition: StdDlg.h:281
CSTR PickFile(HWND owner, CSTR caption, CSTR filter)
Definition: StdDlg.cpp:141
FontDialog()
Definition: StdDlg.cpp:320
ACSTR CDErrorMsg(DWORD Err=0)
Definition: StdDlg.cpp:23
void SetOwner(HWND owner, HINSTANCE hInst=NULL)
Definition: StdDlg.cpp:109
static UINT_PTR CALLBACK _Hook(HWND hwnd, UINT msg, LPARAM lp, LPARAM data)
Definition: StdDlg.cpp:520
LOGFONT LogFont
Definition: StdDlg.h:236
FileDialog(HWND owner=NULL)
Definition: StdDlg.cpp:85
CSTR SetFilename(CSTR PathName)
Definition: StdDlg.cpp:177
UINT WM_SelChange
Definition: StdDlg.cpp:15
const LPCTSTR CCSTR
Definition: Common.h:335
bool Execute()
Definition: StdDlg.h:243
bool Execute(UINT Mode)
Definition: StdDlg.cpp:284
UINT WM_ColorOk
Definition: StdDlg.cpp:18
TCHAR With[256]
Definition: StdDlg.h:189
#define DLGHOOKPROC
Definition: StdDlg.h:21
~DirDialog()
Definition: StdDlg.cpp:433
void Done()
Definition: StdDlg.cpp:438
bool Execute()
Definition: StdDlg.h:289
void SetOwner(HWND Owner, HINSTANCE hInst=NULL)
Definition: StdDlg.cpp:337
bool __forceinline bool_cast(BOOL B52)
Definition: Common.h:767
HWND hWnd
Definition: StdDlg.h:187
UINT WM_FindReplace
Definition: StdDlg.cpp:17
static IFolderFilter * FolderFilter
Definition: StdDlg.h:326
~FileDialog()
Definition: StdDlg.cpp:116
void SetOwner(HWND Owner, HINSTANCE hInst=NULL)
Definition: StdDlg.cpp:272
UINT WM_SetRGB
Definition: StdDlg.cpp:19
void SetOwner(HWND Owner)
Definition: StdDlg.cpp:462
bool(CALLBACK * FDLG_ItemProc)(CSTR FileName, PVOID UserData)
Definition: StdDlg.h:79
PVOID pData
Definition: StdDlg.h:323
bool Execute()
Definition: StdDlg.cpp:503
#define DEF_(x)
Definition: Common.h:240
bool SetRootDir(CSTR Dir)
Definition: StdDlg.cpp:495
HFONT CreateFont()
Definition: StdDlg.h:247
Common include; Added types, small "ubiquitous" utilities, et c.
class FileDialog * PFileDialog
Definition: StdDlg.h:23
void SetOwner(HWND Owner, HINSTANCE hInst=NULL)
Definition: StdDlg.cpp:382
class ColorDialog * PColorDialog
Definition: StdDlg.h:27
class DirDialog * PDirDialog
Definition: StdDlg.h:24
TCHAR What[256]
Definition: StdDlg.h:188
TCHAR InitDir[MAX_PATH]
Definition: StdDlg.h:116
UINT WM_CommonHelp
Definition: StdDlg.cpp:13
unsigned char BYTE
Definition: Common.h:412
void SetRoot(LPITEMIDLIST pidl)
Definition: StdDlg.cpp:479