2 * Copyright (c) 2001, Gary R. Van Sickle.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
16 // This is the implementation of the PropSheet class. This class encapsulates
17 // a Windows property sheet / wizard and interfaces with the PropertyPage class.
18 // It's named PropSheet instead of PropertySheet because the latter conflicts with
19 // the Windows function of the same name.
21 #include "propsheet.h"
24 //#include <shlwapi.h>
25 // ...but since there is no shlwapi.h in mingw yet:
26 typedef struct _DllVersionInfo
35 typedef HRESULT
CALLBACK (*DLLGETVERSIONPROC
) (DLLVERSIONINFO
* pdvi
);
36 #define PROPSHEETHEADER_V1_SIZE 40
38 // Sort of a "hidden" Windows structure. Used in the PropSheetCallback.
40 typedef struct DLGTEMPLATEEX
53 DLGTEMPLATEEX
, *LPDLGTEMPLATEEX
;
56 PropSheet::PropSheet ()
61 PropSheet::~PropSheet ()
66 PropSheet::CreatePages ()
68 HPROPSHEETPAGE
*retarray
;
70 // Create the return array
71 retarray
= new HPROPSHEETPAGE
[NumPropPages
];
73 // Create the pages with CreatePropertySheetPage().
74 // We do it here rather than in the PropertyPages themselves
75 // because, for reasons known only to Microsoft, these handles will be
76 // destroyed by the property sheet before the PropertySheet() call returns,
77 // at least if it's modal (don't know about modeless).
79 for (i
= 0; i
< NumPropPages
; i
++)
82 CreatePropertySheetPage (PropertyPages
[i
]->GetPROPSHEETPAGEPtr ());
87 PropertyPages
[i
]->YouAreFirst ();
89 else if (i
== NumPropPages
- 1)
91 PropertyPages
[i
]->YouAreLast ();
95 PropertyPages
[i
]->YouAreMiddle ();
103 PropSheetProc (HWND hwndDlg
, UINT uMsg
, LPARAM lParam
)
109 // Add a minimize box to the sheet/wizard.
110 if (((LPDLGTEMPLATEEX
) lParam
)->signature
== 0xFFFF)
112 ((LPDLGTEMPLATEEX
) lParam
)->style
|= WS_MINIMIZEBOX
;
116 ((LPDLGTEMPLATE
) lParam
)->style
|= WS_MINIMIZEBOX
;
125 GetPROPSHEETHEADERSize ()
127 // For compatibility with all versions of comctl32.dll, we have to do this.
131 DLLGETVERSIONPROC DllGetVersion
;
135 // This 'isn't safe' in a DLL, according to MSDN
136 mod
= LoadLibrary ("comctl32.dll");
138 DllGetVersion
= (DLLGETVERSIONPROC
) GetProcAddress (mod
, "DllGetVersion");
139 if (DllGetVersion
== NULL
)
141 // Something's wildly broken, punt.
142 retval
= PROPSHEETHEADER_V1_SIZE
;
146 vi
.cbSize
= sizeof (DLLVERSIONINFO
);
149 if ((vi
.dwMajorVersion
< 4) ||
150 ((vi
.dwMajorVersion
== 4) && (vi
.dwMinorVersion
< 71)))
153 retval
= sizeof (PROPSHEETHEADER
);
157 // Old (== Win95/NT4 w/o IE 4 or better)
158 retval
= PROPSHEETHEADER_V1_SIZE
;
168 PropSheet::Create (const Window
* Parent
, DWORD Style
)
172 PageHandles
= CreatePages ();
174 p
.dwSize
= GetPROPSHEETHEADERSize ();
176 PSH_NOAPPLYNOW
| PSH_WIZARD
| PSH_USECALLBACK
/*| PSH_MODELESS */ ;
179 p
.hwndParent
= Parent
->GetHWND ();
185 p
.hInstance
= GetInstance ();
186 p
.nPages
= NumPropPages
;
188 p
.phpage
= PageHandles
;
189 p
.pfnCallback
= PropSheetProc
;
192 // The winmain event loop actually resides in here.
195 // Do a modeless property sheet...
196 //SetHWND((HWND)PropertySheet(&p));
197 /*Show(SW_SHOWNORMAL);
199 // ...but pretend it's modal
201 MessageBox(NULL, "DONE", NULL, MB_OK);
203 // FIXME: Enable the parent before destroying this window to prevent another window
204 // from becoming the foreground window
205 // ala: EnableWindow(<parent_hwnd>, TRUE);
206 //DestroyWindow(WindowHandle);
215 PropSheet::SetHWNDFromPage (HWND h
)
217 // If we're a modal dialog, there's no way for us to know our window handle unless
218 // one of our pages tells us through this function.
223 PropSheet::AddPage (PropertyPage
* p
)
225 // Add a page to the property sheet.
226 p
->YouAreBeingAddedToASheet (this);
227 PropertyPages
[NumPropPages
] = p
;
232 PropSheet::SetActivePage (int i
)
234 // Posts a message to the message queue, so this won't block
235 return static_cast < bool > (::PropSheet_SetCurSel (GetHWND (), NULL
, i
));
239 PropSheet::SetActivePageByID (int resource_id
)
241 // Posts a message to the message queue, so this won't block
242 return static_cast < bool >
243 (::PropSheet_SetCurSelByID (GetHWND (), resource_id
));
247 PropSheet::SetButtons (DWORD flags
)
249 // Posts a message to the message queue, so this won't block
250 ::PropSheet_SetWizButtons (GetHWND (), flags
);
254 PropSheet::PressButton (int button
)
256 ::PropSheet_PressButton (GetHWND (), button
);