Re: How to format disk by application
- From: "Volodymyr Shcherbyna" <v_scherbina@xxxxxxxxxxxxxxx>
- Date: Thu, 10 Jan 2008 08:55:17 +0100
This, I believe, is a clone of originally posted by
Nish(http://www.voidnish.com/) solution which is written in C++:
http://www.codeproject.com/KB/dialog/cformatdrivedialog.aspx
--
Volodymyr
NG tips:
http://msmvps.com/blogs/v_scherbina/pages/microsoft-newsgroups-tips.aspx
"Christian Kaiser" <chk@xxxxxxxxx> wrote in message
news:478533b8$0$25372$9b4e6d93@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
T.Masuda wrote:
I want to format disk from my application. Does anyone know how to do
that? Thanks in advance.
Takashi Masuda
Here's some Delphi code I use. Basically it uses the shell function
SHFormatDrive, but uses a CBT hook to fill out the dialog with the volume
name and disable 'quick format' in the dialog that pops up.
By removing the comment of SendMessage(...BN_CLICKED...), you can start
formatting automatically. But it still requires the user to "close" the
dialog.
Christian
--------------------------
function SHFormatDrive (hWnd : HWND;
Drive,
FmtID,
Options : word) : LongInt; stdcall;
external 'Shell32.dll';
//////////////////////////////////////////////////////////////////////////////
var
hCBTHook: HHOOK;
ThisForm: TFrmDiskCreation;
function WndEnumProc(hWnd: HWND; lParam: LPARAM): boolean; stdcall;
begin
// pass on to dialog: TFrmDiskCreation.EnumProc()
Result := ThisForm.EnumProc(hWnd);
end;
function CBTProc(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT;
stdcall;
begin
// pass on to dialog: call TFrmDiskCreation.CBT()
Result := ThisForm.CBT(nCode,wParam,lParam);
end;
function TFrmDiskCreation.EnumProc(hWnd: HWND): boolean;
var
szClass: array[0..30] of char;
szText: array[0..30] of char;
begin
GetClassName(hWnd,szClass,sizeof(szClass));
if stricomp(szClass,'edit') = 0 then
SetWindowText(hWnd,pchar(EdtName.Text));
GetWindowText(hWnd,szText,sizeof(szText));
if (stricomp(szClass,'button') = 0) and
(((GetWindowLong(hWnd,GWL_STYLE) and $0000000f) = BS_CHECKBOX) or
((GetWindowLong(hWnd,GWL_STYLE) and $0000000f) = BS_AUTOCHECKBOX)) and
(strpos(szText,'Quick') <> NIL) then
SendMessage(hWnd,BM_SETCHECK,0,0);
Result := true;
end;
function TFrmDiskCreation.CBT(nCode: integer; wParam: WPARAM; lParam:
LPARAM): LRESULT;
begin
case nCode of
HCBT_ACTIVATE:
begin
EnumChildWindows(HWND(wParam),@WndEnumProc,0);
UnhookWindowsHookEx(hCBTHook);
// SendMessage(HWND(wParam), WM_COMMAND, MAKELONG(1,BN_CLICKED),
hWndStart);
end;
end;
Result := 0;
end;
function TFrmDiskCreation.FormatDisk(hWndParent: HWND): integer;
begin
ThisForm := self;
hCBTHook := SetWindowsHookEx(WH_CBT,@CBTProc,0,GetCurrentThreadId);
Result := SHFormatDrive(hWndParent,
ord(Config._sDataDrive[1]) - ord('A'),
0,
1);
ThisForm := NIL;
end;
.
- Follow-Ups:
- Re: How to format disk by application
- From: Christian Kaiser
- Re: How to format disk by application
- References:
- Re: How to format disk by application
- From: Christian Kaiser
- Re: How to format disk by application
- Prev by Date: Re: working set, virtual bytes and private bytes
- Next by Date: working set is larger than virtual bytes?
- Previous by thread: Re: How to format disk by application
- Next by thread: Re: How to format disk by application
- Index(es):
Relevant Pages
|