ReactOS  0.4.14-dev-317-g96040ec
vfdshprop.cpp
Go to the documentation of this file.
1 /*
2  vfdshprop.cpp
3 
4  Virtual Floppy Drive for Windows
5  Driver control library
6  COM shell extension class property sheet functions
7 
8  Copyright (c) 2003-2005 Ken Kato
9 */
10 
11 #define WIN32_LEAN_AND_MEAN
12 #include <windows.h>
13 #include <shellapi.h>
14 #include <shlobj.h>
15 #include <stdio.h>
16 
17 #include "vfdtypes.h"
18 #include "vfdapi.h"
19 #include "vfdlib.h"
20 #include "vfdver.h"
21 #ifndef __REACTOS__
22 #include "vfdmsg.h"
23 #else
24 #include "vfdmsg_lib.h"
25 #endif
26 #include "vfdguirc.h"
27 
28 // class header
29 #include "vfdshext.h"
30 
31 // property sheet property ID
32 
33 #define VFD_PROPERTY_ID "VFD"
34 
35 //
36 // local functions
37 //
38 #ifndef __REACTOS__
40 #else
42 #endif
43  HWND hDlg,
44  UINT uMessage,
45  WPARAM wParam,
46  LPARAM lParam);
47 
49  HWND hWnd,
50  UINT uMessage,
51  LPPROPSHEETPAGE ppsp);
52 
53 static void OnPropInit(HWND hDlg);
54 static void OnControl(HWND hDlg);
55 static void UpdateImageInfo(HWND hDlg, ULONG nDevice);
56 
57 //
58 // property sheet callback function
59 //
61  HWND hWnd,
62  UINT uMessage,
63  LPPROPSHEETPAGE ppsp)
64 {
66 
67  switch(uMessage) {
68  case PSPCB_CREATE:
69  return TRUE;
70 
71  case PSPCB_RELEASE:
72  if (ppsp->lParam) {
73  ((LPCVFDSHEXT)(ppsp->lParam))->Release();
74  }
75  return TRUE;
76  }
77  return TRUE;
78 }
79 
80 //
81 // property page dialog procedure
82 //
83 #ifndef __REACTOS__
85 #else
87 #endif
88  HWND hDlg,
89  UINT uMessage,
90  WPARAM wParam,
91  LPARAM lParam)
92 {
93  LPPROPSHEETPAGE psp;
94  LPCVFDSHEXT lpcs;
95 
96  switch (uMessage) {
97  case WM_INITDIALOG:
98 #ifndef __REACTOS__
100 #else
102 #endif
103 
104  if (lParam) {
106 
107  OnPropInit(hDlg);
108  UpdateImageInfo(hDlg, lpcs->GetDevice());
109  }
110  return TRUE;
111 
112  case WM_COMMAND:
113 #ifndef __REACTOS__
114  psp = (LPPROPSHEETPAGE)GetWindowLong(hDlg, DWL_USER);
115 #else
117 #endif
118 
119  if (!psp) {
120  break;
121  }
122 
123  lpcs = (LPCVFDSHEXT)psp->lParam;
124 
125  if (!lpcs) {
126  break;
127  }
128 
129  switch (wParam) {
130  case IDC_OPEN:
131  if (lpcs->DoVfdOpen(hDlg) == ERROR_SUCCESS) {
134  }
135  UpdateImageInfo(hDlg, lpcs->GetDevice());
136  break;
137 
138  case IDC_SAVE:
139  if (lpcs->DoVfdSave(hDlg) == ERROR_SUCCESS) {
142  }
143  UpdateImageInfo(hDlg, lpcs->GetDevice());
144  break;
145 
146  case IDC_CLOSE:
147  if (lpcs->DoVfdClose(hDlg) == ERROR_SUCCESS) {
150  }
151  UpdateImageInfo(hDlg, lpcs->GetDevice());
152  break;
153 
154  case IDC_WRITE_PROTECTED:
155  lpcs->DoVfdProtect(hDlg);
156  break;
157 
158  case IDC_FORMAT:
159  VfdGuiFormat(hDlg, lpcs->GetDevice());
160  break;
161 
162  case IDC_CONTROL:
163  OnControl(hDlg);
164  break;
165  }
166  break;
167 
168  case WM_CONTEXTMENU:
170  break;
171 
172  case WM_HELP:
173  {
175 
176  if (info->iContextType == HELPINFO_WINDOW) {
177  ShowHelpWindow(hDlg, info->iCtrlId);
178  }
179  }
180  return TRUE;
181 
182  default:
183  if (uMessage == g_nNotifyMsg) {
184 #ifndef __REACTOS__
185  psp = (LPPROPSHEETPAGE)GetWindowLong(hDlg, DWL_USER);
186 #else
188 #endif
189 
190  if (!psp) {
191  break;
192  }
193 
194  lpcs = (LPCVFDSHEXT)psp->lParam;
195 
196  if (!lpcs) {
197  break;
198  }
199 
200  UpdateImageInfo(hDlg, lpcs->GetDevice());
201  }
202  break;
203  }
204 
205  return FALSE;
206 }
207 
208 //
209 // initialize the property page
210 //
212  HWND hDlg)
213 {
214  // set up control text
215 
218 
219  SetControlText(hDlg, IDC_IMAGEFILE_LABEL, MSG_IMAGEFILE_LABEL);
220  SetControlText(hDlg, IDC_IMAGEDESC_LABEL, MSG_DESCRIPTION_LABEL);
221  SetControlText(hDlg, IDC_DISKTYPE_LABEL, MSG_DISKTYPE_LABEL);
222  SetControlText(hDlg, IDC_MEDIATYPE_LABEL, MSG_MEDIATYPE_LABEL);
223  SetControlText(hDlg, IDC_WRITE_PROTECTED, MSG_MENU_PROTECT);
224  SetControlText(hDlg, IDC_OPEN, MSG_OPEN_BUTTON);
225  SetControlText(hDlg, IDC_SAVE, MSG_SAVE_BUTTON);
226  SetControlText(hDlg, IDC_CLOSE, MSG_CLOSE_BUTTON);
227  SetControlText(hDlg, IDC_FORMAT, MSG_FORMAT_BUTTON);
228  SetControlText(hDlg, IDC_CONTROL, MSG_CONTROL_BUTTON);
229 }
230 
231 //
232 // Control Panel button is clicked
233 //
235  HWND hDlg)
236 {
237  CHAR module_path[MAX_PATH];
238  CHAR full_path[MAX_PATH];
239  PSTR file_name;
240 #ifndef __REACTOS__
241  DWORD ret;
242 #else
243  DWORD_PTR ret;
244 #endif
245 
247  g_hDllModule, module_path, sizeof(module_path));
248 
249  if (ret == 0 || ret >= sizeof(module_path)) {
250  file_name = full_path;
251  }
252  else {
254  module_path, sizeof(full_path), full_path, &file_name);
255 
256  if (ret == 0 || ret >= sizeof(full_path)) {
257  file_name = full_path;
258  }
259  }
260 
261  strcpy(file_name, "vfdwin.exe");
262 
263  VFDTRACE(0, ("Starting %s\n", full_path));
264 
265 #ifndef __REACTOS__
267  hDlg, NULL, full_path, NULL, NULL, SW_SHOW);
268 #else
270  hDlg, NULL, full_path, NULL, NULL, SW_SHOW);
271 #endif
272 
273  if (ret > 32) {
275  }
276  else {
279  }
280 }
281 
282 //
283 // Update image information on the property page
284 //
286  HWND hDlg,
287  ULONG nDevice)
288 {
289  HANDLE hDevice;
290  CHAR buf[MAX_PATH];
291  VFD_DISKTYPE disk_type;
292  VFD_MEDIA media_type;
293  VFD_FLAGS media_flags;
296  DWORD attrib;
297  ULONG ret;
298 
299  hDevice = VfdOpenDevice(nDevice);
300 
301  if (hDevice == INVALID_HANDLE_VALUE) {
302  MessageBox(hDlg,
305  return;
306  }
307 
308  // get current image information
309 
311  hDevice,
312  buf,
313  &disk_type,
314  &media_type,
315  &media_flags,
316  &file_type,
317  &image_size);
318 
319  CloseHandle(hDevice);
320 
321  if (ret != ERROR_SUCCESS) {
322  MessageBox(hDlg,
325  return;
326  }
327 
328  if (media_type == VFD_MEDIA_NONE) {
329 
330  // drive is empty
331 
336 
342 
345 
346  SetFocus(GetDlgItem(hDlg, IDC_OPEN));
347 
348  return;
349  }
350 
351  // display image file name
352 
353  if (buf[0]) {
354  attrib = GetFileAttributes(buf);
355 
356  if (attrib == INVALID_FILE_ATTRIBUTES) {
357  attrib = 0;
358  }
359  }
360  else {
361  if (disk_type != VFD_DISKTYPE_FILE) {
362  strcpy(buf, "<RAM>");
363  }
364  attrib = 0;
365  }
366 
368 
369  // display image description
370 
371  VfdMakeFileDesc(buf, sizeof(buf),
372  file_type, image_size, attrib);
373 
375 
376  // display disk type
377 
378  if (disk_type == VFD_DISKTYPE_FILE) {
379  SetDlgItemText(hDlg, IDC_DISKTYPE, "FILE");
380  }
381  else {
382  SetDlgItemText(hDlg, IDC_DISKTYPE, "RAM");
383  }
384 
385  // display media type
386 
388  VfdMediaTypeName(media_type));
389 
390  // set write protect check box
391 
392  if (media_flags & VFD_FLAG_WRITE_PROTECTED) {
394  }
395  else {
397  }
398 
404 
407 
408  SetFocus(GetDlgItem(hDlg, IDC_CLOSE));
409 }
410 
411 //
412 // CVfdShExt class members inherited from IShellPropSheetExt
413 //
414 
415 // Add property page
417  LPFNADDPROPSHEETPAGE lpfnAddPage,
418  LPARAM lParam)
419 {
420  PROPSHEETPAGE psp;
421  HPROPSHEETPAGE hpage;
422 
423  if (!m_pDataObj || m_nDevice == (ULONG)-1) {
424  // not a VFD drive
425  VFDTRACE(0, ("PropPage: Not a VFD drive\n"));
426 
427  return NOERROR;
428  }
429 
430  psp.dwSize = sizeof(psp); // no extra data.
432  psp.hInstance = g_hDllModule;
433  psp.pszTemplate = MAKEINTRESOURCE(IDD_PROPDIALOG);
434  psp.hIcon = 0;
435  psp.pszTitle = "VFD";
436  psp.pfnDlgProc = VfdPageDlgProc;
437  psp.pcRefParent = &g_cDllRefCnt;
438  psp.pfnCallback = VfdPageCallback;
439  psp.lParam = (LPARAM)this;
440 
441  AddRef();
442  hpage = CreatePropertySheetPage(&psp);
443 
444  if (hpage) {
445  if (!lpfnAddPage(hpage, lParam)) {
447  Release();
448  }
449  }
450 
451  return NOERROR;
452 }
453 
455  UINT uPageID,
456  LPFNADDPROPSHEETPAGE lpfnReplaceWith,
457  LPARAM lParam)
458 {
459  UNREFERENCED_PARAMETER(uPageID);
460  UNREFERENCED_PARAMETER(lpfnReplaceWith);
462  return E_FAIL;
463 }
#define IDD_PROPDIALOG
Definition: vfdguirc.h:5
#define MAKEINTRESOURCE
Definition: winuser.h:591
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
DWORD DoVfdClose(HWND hParent)
Definition: vfdshmenu.cpp:484
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define DWORD_PTR
Definition: treelist.c:76
UINT g_cDllRefCnt
DWORD DoVfdOpen(HWND hParent)
Definition: vfdshmenu.cpp:459
#define VFD_MSGBOX_TITLE
Definition: vfdlib.h:53
_In_ BOOLEAN Release
Definition: classpnp.h:929
UCHAR VFD_DISKTYPE
Definition: vfdtypes.h:60
#define NOERROR
Definition: winerror.h:2354
DWORD WINAPI VfdGuiFormat(HWND hParent, ULONG nDevice)
Definition: vfdguiut.c:262
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define IDC_DISKTYPE_LABEL
Definition: vfdguirc.h:20
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
Definition: propsheet.c:3144
LPDATAOBJECT m_pDataObj
Definition: vfdshext.h:25
DWORD DoVfdProtect(HWND hParent)
Definition: vfdshmenu.cpp:493
#define IDC_MEDIATYPE_LABEL
Definition: vfdguirc.h:24
char CHAR
Definition: xmlstorage.h:175
#define CALLBACK
Definition: compat.h:27
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
HWND hWnd
Definition: settings.c:17
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL(CALLBACK * LPFNADDPROPSHEETPAGE)(HPROPSHEETPAGE, LPARAM)
Definition: prsht.h:309
#define PSP_USECALLBACK
Definition: prsht.h:30
UINT_PTR WPARAM
Definition: windef.h:207
UCHAR VFD_FLAGS
Definition: vfdtypes.h:63
#define SetWindowLong
Definition: winuser.h:5754
#define MB_ICONSTOP
Definition: winuser.h:797
static BOOL CALLBACK VfdPageDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam)
Definition: vfdshprop.cpp:84
STDMETHODIMP ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
Definition: vfdshprop.cpp:454
int32_t INT_PTR
Definition: typedefs.h:62
DWORD DoVfdSave(HWND hParent)
Definition: vfdshmenu.cpp:475
#define IDC_SAVE
Definition: resource.h:16
#define E_FAIL
Definition: ddrawi.h:102
#define DWORD
Definition: nt_native.h:44
void ShowContextMenu(HWND hDlg, HWND hCtl, LPARAM lParam)
Definition: vfdguiut.c:456
void ShowHelpWindow(HWND hDlg, UINT nCtl)
Definition: vfdguiut.c:507
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
struct tagHELPINFO * LPHELPINFO
static void UpdateImageInfo(HWND hDlg, ULONG nDevice)
Definition: vfdshprop.cpp:285
CVfdShExt * LPCVFDSHEXT
Definition: vfdshext.h:101
#define DWL_USER
Definition: winuser.h:861
#define IDC_IMAGEFILE
Definition: vfdguirc.h:14
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG m_nDevice
Definition: vfdshext.h:26
#define IDC_CLOSE
Definition: resource.h:52
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
#define ShellExecute
Definition: shellapi.h:689
#define STDMETHODIMP
Definition: basetyps.h:43
ULONG Release()
#define LPPROPSHEETPAGE
Definition: prsht.h:372
static void OnPropInit(HWND hDlg)
Definition: vfdshprop.cpp:211
#define IDC_PROPERTY_TITLE
Definition: vfdguirc.h:11
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define SW_SHOW
Definition: winuser.h:769
#define PSPCB_RELEASE
Definition: prsht.h:37
#define CreatePropertySheetPage
Definition: prsht.h:381
#define PSBTN_CANCEL
Definition: prsht.h:151
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define BM_SETSTYLE
Definition: winuser.h:1906
#define IDC_MEDIATYPE
Definition: vfdguirc.h:25
PCSTR SystemMessage(DWORD nError)
Definition: vfdlib.c:147
#define MAX_PATH
Definition: compat.h:26
HINSTANCE g_hDllModule
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDC_CONTROL
Definition: vfdguirc.h:33
#define IDC_IMAGEFILE_LABEL
Definition: vfdguirc.h:13
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define GetModuleFileName
Definition: winbase.h:3655
FD_TYPE file_type(FDSC **curr, char *fixed)
Definition: file.c:221
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define SetDlgItemText
Definition: winuser.h:5750
PCSTR WINAPI VfdMediaTypeName(VFD_MEDIA nMediaType)
Definition: vfdctl.c:3280
ULONG AddRef()
ULONG GetDevice()
Definition: vfdshext.h:44
int ret
#define PSP_USEREFPARENT
Definition: prsht.h:29
#define PSPCB_CREATE
Definition: prsht.h:38
UCHAR VFD_FILETYPE
Definition: vfdtypes.h:62
#define GetWindowLong
Definition: winuser.h:5697
#define DWLP_USER
Definition: winuser.h:866
#define GetFullPathName
Definition: winbase.h:3645
#define MessageBox
Definition: winuser.h:5723
#define WM_COMMAND
Definition: winuser.h:1722
HANDLE WINAPI VfdOpenDevice(ULONG nTarget)
Definition: vfdctl.c:1215
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define PSP_USETITLE
Definition: prsht.h:26
#define BST_UNCHECKED
Definition: winuser.h:199
#define IDC_IMAGEFILE_DESC
Definition: vfdguirc.h:16
#define IDC_DISKTYPE
Definition: vfdguirc.h:21
#define GetFileAttributes
Definition: winbase.h:3639
#define BS_PUSHBUTTON
Definition: pedump.c:651
DWORD WINAPI VfdGetImageInfo(HANDLE hDevice, PSTR sFileName, PVFD_DISKTYPE pDiskType, PVFD_MEDIA pMediaType, PVFD_FLAGS pMediaFlags, PVFD_FILETYPE pFileType, PULONG pImageSize)
Definition: vfdctl.c:1839
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
HWND WINAPI GetParent(_In_ HWND)
#define IDC_OPEN
Definition: resource.h:18
#define IDC_WRITE_PROTECTED
Definition: vfdguirc.h:26
#define VFD_PRODUCT_DESC
Definition: vfdver.h:66
UINT g_nNotifyMsg
signed char * PSTR
Definition: retypes.h:7
unsigned int UINT
Definition: ndis.h:50
#define BST_CHECKED
Definition: winuser.h:197
static LPCWSTR file_name
Definition: protocol.c:146
#define SendMessage
Definition: winuser.h:5744
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
void WINAPI VfdMakeFileDesc(PSTR pBuffer, ULONG nBufSize, VFD_FILETYPE nFileType, ULONG nFileSize, DWORD nFileAttr)
Definition: vfdguiut.c:376
#define VFD_COPYRIGHT_STR
Definition: vfdver.h:69
#define GetWindowLongPtr
Definition: treelist.c:73
#define IDC_COPYRIGHT_STR
Definition: vfdguirc.h:12
STDMETHODIMP AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: vfdshprop.cpp:416
#define HELPINFO_WINDOW
Definition: winuser.h:1158
#define PropSheet_PressButton(d, i)
Definition: prsht.h:330
#define IDC_IMAGEDESC_LABEL
Definition: vfdguirc.h:15
static UINT CALLBACK VfdPageCallback(HWND hWnd, UINT uMessage, LPPROPSHEETPAGE ppsp)
Definition: vfdshprop.cpp:60
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
UCHAR VFD_MEDIA
Definition: vfdtypes.h:61
#define PROPSHEETPAGE
Definition: prsht.h:371
void SetControlText(HWND hWnd, UINT nCtrl, DWORD nMsg)
Definition: vfdguiut.c:350
static void OnControl(HWND hDlg)
Definition: vfdshprop.cpp:234
static GLint image_size(GLint width, GLint height, GLenum format, GLenum type)
Definition: mipmap.c:4856
#define IDC_FORMAT
Definition: vfdguirc.h:32