寻求SHFormatDrive(格式化硬盘api函数的用法)?

tryibest 2001-07-31 03:51:18
...全文
493 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
snlee 2001-10-21
  • 打赏
  • 举报
回复
gz
prog_st 2001-10-21
  • 打赏
  • 举报
回复
#if !defined(SHFMT_OPT_FULL)

#if defined (__cplusplus)
extern "C" {
#endif

/*****************************************************************
The SHFormatDrive API provides access to the Shell's format
dialog box. This allows applications that want to format disks to bring
up the same dialog box that the Shell uses for disk formatting.

PARAMETERS
hwnd = The window handle of the window that will own the
dialog. NOTE that hwnd == NULL does not cause this
dialog to come up as a "top level application"
window. This parameter should always be non-null,
this dialog box is only designed to be the child of
another window, not a stand-alone application.

drive = The 0 based (A: == 0) drive number of the drive
to format.

fmtID = Currently must be set to SHFMT_ID_DEFAULT.

options = There are currently only two option bits defined.

SHFMT_OPT_FULL
SHFMT_OPT_SYSONLY

SHFMT_OPT_FULL specifies that the "Quick Format"
setting should be cleared by default. If the user
leaves the "Quick Format" setting cleared, then a
full format will be applied (this is useful for
users that detect "unformatted" disks and want
to bring up the format dialog box).

If options is set to zero (0), then the "Quick Format"
setting is set by default. In addition, if the user leaves
it set, a quick format is performed. Under Windows NT 4.0,
this flag is ignored and the "Quick Format" box is always
checked when the dialog box first appears. The user can
still change it. This is by design.

The SHFMT_OPT_SYSONLY initializes the dialog to
default to just sys the disk.

All other bits are reserved for future expansion
and must be 0.

Please note that this is a bit field and not a
value, treat it accordingly.

RETURN
The return is either one of the SHFMT_* values, or if
the returned DWORD value is not == to one of these
values, then the return is the physical format ID of the
last successful format. The LOWORD of this value can be
passed on subsequent calls as the fmtID parameter to
"format the same type you did last time".

*****************************************************************/
DWORD WINAPI SHFormatDrive(HWND hwnd,
UINT drive,
UINT fmtID,
UINT options);

//
// Special value of fmtID which means "use the defaultformat"
//

#define SHFMT_ID_DEFAULT 0xFFFF

//
// Option bits for options parameter
//

#define SHFMT_OPT_FULL 0x0001
#define SHFMT_OPT_SYSONLY 0x0002

//
// Special return values. PLEASE NOTE that these are DWORD values.
//

#define SHFMT_ERROR 0xFFFFFFFFL // Error on last format,
// drive may be formatable
#define SHFMT_CANCEL 0xFFFFFFFEL // Last format wascanceled
#define SHFMT_NOFORMAT 0xFFFFFFFDL // Drive is not formatable

#if defined (__cplusplus)
}
#endif
#endif

//
void CFormatDriveDlg::OnFormat()
{
UINT OldMode = SetErrorMode(0); // Get the current Error Mode settings.
SetErrorMode(OldMode & !SEM_FAILCRITICALERRORS); // Force O/S to handle
//critical errors.
// Call SHFormatDrive here.
SHFormatDrive (this->m_hWnd, 0 /* A: */, SHFMT_ID_DEFAULT, 0);

SetErrorMode(OldMode); // Put it back the way it was.
}
chinaLinCT 2001-10-20
  • 打赏
  • 举报
回复
在头部加入以下代码
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#if !defined(SHFMT_OPT_FULL)

#if defined (__cplusplus)
extern "C" {
#endif

DWORD WINAPI SHFormatDrive(HWND hwnd,
UINT drive,
UINT fmtID,
UINT options);

#define SHFMT_ID_DEFAULT 0xFFFF

//
// Option bits for options parameter
//

#define SHFMT_OPT_FULL 0x0001
#define SHFMT_OPT_SYSONLY 0x0002

//
// Special return values. PLEASE NOTE that these are DWORD values.
//

#define SHFMT_ERROR 0xFFFFFFFFL // Error on last format,
// drive may be formatable
#define SHFMT_CANCEL 0xFFFFFFFEL // Last format wascanceled
#define SHFMT_NOFORMAT 0xFFFFFFFDL // Drive is not formatable

#if defined (__cplusplus)
}
#endif
#endif
ExitWindows 2001-07-31
  • 打赏
  • 举报
回复
up
tryibest 2001-07-31
  • 打赏
  • 举报
回复
怎么没有人来呀,很难吗?
tryibest 2001-07-31
  • 打赏
  • 举报
回复
接上
#include <windows.h>
//#include <shellapi.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{

SHFormatDrive (NULL, 0, SHFMT_ID_DEFAULT, 0);

return 0;
}

已上是我的代码, 可是编译不能能过,我已经包含了shell32.lib,
请教怎么才能调用成功shformatdrive函数,希望能贴出编译成功,能够格式化硬盘的代码 ,谢谢!!!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧