Skip to content

Commit 3331011

Browse files
committed
Added FabFormatDialog
1 parent cc99f2e commit 3331011

File tree

2 files changed

+237
-0
lines changed

2 files changed

+237
-0
lines changed

FabTools/FabTools/FabTools.xsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<Compile Include="Error.prg" />
140140
<Compile Include="FabOpenDialogEx.prg" />
141141
<Compile Include="FileBin.prg" />
142+
<Compile Include="Format Dialog.prg" />
142143
<Compile Include="IniFile.prg" />
143144
<Compile Include="InputDlg.prg">
144145
<SubType>Form</SubType>
Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
#region DEFINES
2+
DEFINE SHFMT_CANCEL := 0xFFFFFFFEL // Last format wascanceled
3+
DEFINE SHFMT_ERROR := 0xFFFFFFFFL // Error on last format,
4+
// drive may be formatable
5+
DEFINE SHFMT_ID_DEFAULT := 0xFFFF
6+
DEFINE SHFMT_NOFORMAT := 0xFFFFFFFDL // Drive is not formatable
7+
DEFINE SHFMT_OPT_FULL := 0x0001
8+
DEFINE SHFMT_OPT_QUICK := 0x0000
9+
DEFINE SHFMT_OPT_SYSONLY := 0x0002
10+
#endregion
11+
12+
CLASS FabFormatDialog
13+
//g Drives,Drives related Classes/Functions
14+
//l Access to Drive Format Dialog
15+
//d This class provide a way to access the standard Shell Drive-Format Dialog from within your application.
16+
17+
// Handle of Owner
18+
PROTECT hWnd AS PTR
19+
// Last Return Code
20+
PROTECT dwRet AS DWORD
21+
//s
22+
// Drive Letter
23+
EXPORT Drive AS STRING
24+
// Quick Format
25+
EXPORT QuickFormat AS LOGIC
26+
// Add System Files
27+
EXPORT System AS LOGIC
28+
29+
30+
31+
32+
METHOD Init( oOwner, cDrive )
33+
//d Create a FabFormatDialog Object.\line
34+
//d You must pass a Owner, or the method will try to determine what is the current active window, and set it as Owner.
35+
//a <oOwner> is a Window that owns the FormatDialog.
36+
//a <cDrive> is a string, indicating what drive to format
37+
//a You can specify "A", "A:", "A:\", ...
38+
//
39+
IF Empty( oOwner )
40+
SELF:hWnd := GetActiveWindow()
41+
ELSE
42+
IF IsMethod( oOwner, #Handle )
43+
SELF:hWnd := Send( oOwner, #Handle )
44+
ELSE
45+
SELF:hWnd := GetActiveWindow()
46+
ENDIF
47+
ENDIF
48+
//
49+
IF IsString( cDrive )
50+
SELF:Drive := cDrive
51+
ELSE
52+
// Floppy per default
53+
SELF:Drive := "A" // You can specify "A", "A:", "A:\", ...
54+
ENDIF
55+
//
56+
57+
58+
RETURN self
59+
60+
61+
ACCESS LastReturnCode
62+
//r The Last Return Code
63+
RETURN SELF:dwRet
64+
65+
66+
67+
68+
METHOD Show()
69+
//p Show the Format Dialog.
70+
//r A Logical indicating if the last format as been successfull
71+
LOCAL aDrives AS ARRAY
72+
LOCAL aDrv AS ARRAY
73+
LOCAL cDrv AS STRING
74+
LOCAL wCpt AS WORD
75+
LOCAL lResult AS LOGIC
76+
LOCAL liAction AS LONGINT
77+
//
78+
aDrives := FabGetlogicalDrivesArray( )
79+
cDrv := Upper( Left( SELF:Drive, 1 ) )
80+
//
81+
IF Empty( cDrv )
82+
RETURN FALSE
83+
ENDIF
84+
// Cannot format
85+
lResult := FALSE
86+
FOR wCpt := 1 TO ALen( aDrives )
87+
//
88+
aDrv := aDrives[ wCpt ]
89+
//
90+
IF ( Upper( Left( aDrv[ 1 ], 1 ) ) == cDrv )
91+
// Check Drive type
92+
IF ( aDrv[ 2 ] == DRIVE_REMOVABLE ) .or. ;
93+
( aDrv[ 2 ] == DRIVE_FIXED )
94+
// Can be formatted
95+
lResult := TRUE
96+
EXIT
97+
ENDIF
98+
ENDIF
99+
NEXT
100+
// Cannot format or not found
101+
IF !lResult
102+
RETURN FALSE
103+
ENDIF
104+
// Default Action : Normal Formatting
105+
liAction := SHFMT_OPT_FULL
106+
// Action code
107+
IF SELF:QuickFormat
108+
liAction := SHFMT_OPT_QUICK
109+
ELSE
110+
IF SELF:System
111+
liAction := SHFMT_OPT_SYSONLY
112+
ENDIF
113+
ENDIF
114+
//
115+
self:dwRet := SHFormatDrive( self:hWnd, longint( Asc( cDrv ) - Asc( "A" ) ), 0, liAction )
116+
//
117+
RETURN SELF:Success
118+
119+
120+
121+
122+
ACCESS Success
123+
//r A logical value indicating if the last Format has been successfull
124+
LOCAL lSuccess AS LOGIC
125+
//
126+
lSuccess := ( SELF:dwRet != DWORD(_CAST, SHFMT_ERROR ) ) .and. ;
127+
( SELF:dwRet != DWORD(_CAST, SHFMT_CANCEL ) ) .and. ;
128+
( SELF:dwRet != DWORD(_CAST, SHFMT_NOFORMAT ) )
129+
IF lSuccess
130+
// Check for HiWord of dwRet
131+
lSuccess := ( HiWord( SELF:dwRet ) == 0 )
132+
ENDIF
133+
RETURN lSuccess
134+
135+
136+
137+
END CLASS
138+
139+
140+
_DLL FUNCTION SHFormatDrive ( hwnd AS PTR, drive AS LONGINT, size AS DWORD, action AS LONGINT ) AS DWORD PASCAL:SHELL32.SHFormatDrive
141+
//
142+
// hwnd : the handle of the owner-window for the format-dialog
143+
// drive : 0=a, 1=b ...
144+
// size : ? seems not to be implemented
145+
// action :
146+
// 0 : quick - format (destroys only the fat)
147+
// 1 : normal formatting
148+
// 2 : "sys x:"
149+
// result : the result should be 0 if the function was successfull, but it seems that
150+
// error # 6 (= error_invalid_handle) is returned on success
151+
152+
153+
/*
154+
The SHFormatDrive API provides access to the Shell's format
155+
dialog box. This allows applications that want to format disks to bring
156+
up the same dialog box that the Shell uses for disk formatting.
157+
158+
PARAMETERS
159+
hwnd = The window handle of the window that will own the
160+
dialog. NOTE that hwnd == NULL does not cause this
161+
dialog to come up as a "top level application"
162+
window. This parameter should always be non-null,
163+
this dialog box is only designed to be the child of
164+
another window, not a stand-alone application.
165+
166+
drive = The 0 based (A: == 0) drive number of the drive
167+
to format.
168+
169+
fmtID = Currently must be set to SHFMT_ID_DEFAULT.
170+
171+
options = There are currently only two option bits defined.
172+
173+
SHFMT_OPT_FULL
174+
SHFMT_OPT_SYSONLY
175+
176+
SHFMT_OPT_FULL specifies that the "Quick Format"
177+
setting should be cleared by default. If the user
178+
leaves the "Quick Format" setting cleared, then a
179+
full format will be applied (this is useful for
180+
users that detect "unformatted" disks and want
181+
to bring up the format dialog box).
182+
183+
If options is set to zero (0), then the "Quick
184+
Format" setting will be set by default. In addition,
185+
if the user leaves it set, a quick format will be
186+
performed.
187+
188+
The SHFMT_OPT_SYSONLY initializes the dialog to
189+
default to just sys the disk.
190+
191+
All other bits are reserved for future expansion
192+
and must be 0.
193+
194+
Please note that this is a bit field and not a
195+
value, treat it accordingly.
196+
197+
RETURN
198+
The return is either one of the SHFMT_* values, or if
199+
the returned DWORD value is not == to one of these
200+
values, then the return is the physical format ID of the
201+
last successful format. The LOWORD of this value can be
202+
passed on subsequent calls as the fmtID parameter to
203+
"format the same type you did last time".
204+
205+
DWORD WINAPI SHFormatDrive(HWND hwnd,
206+
UINT drive,
207+
UINT fmtID,
208+
UINT options);
209+
210+
//
211+
// Special value of fmtID which means "use the defaultformat"
212+
//
213+
214+
#DEFINE SHFMT_ID_DEFAULT 0xFFFF
215+
216+
//
217+
// Option bits for options parameter
218+
//
219+
220+
#DEFINE SHFMT_OPT_FULL 0x0001
221+
#DEFINE SHFMT_OPT_SYSONLY 0x0002
222+
223+
//
224+
// Special return values. PLEASE NOTE that these are DWORD values.
225+
//
226+
227+
#DEFINE SHFMT_ERROR 0xFFFFFFFFL // Error on last format,
228+
// drive may be formatable
229+
#DEFINE SHFMT_CANCEL 0xFFFFFFFEL // Last format wascanceled
230+
#DEFINE SHFMT_NOFORMAT 0xFFFFFFFDL // Drive is not formatable
231+
232+
*/
233+
234+
235+
236+

0 commit comments

Comments
 (0)