教你如何用代码从程序里面打开 控制面板【2013.10.9 小记】

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧! 158427611



1. ShellExecute打开控制面板。。。教你如何用代码从程序里面打开 控制面板 以及其他东西


ShellExecute(NULL,"open","rundll32.exe","shell32.dll,Control_RunDLL",NULL,SW_SHOW);

还有打开控制面板里面的小项目

使用ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件、打开一个目录、打印一个文件等等),并对外部程序有一定的控制。

ShellExecute(
  hWnd: HWND; {指定父窗口句柄}
  Operation: PChar; {指定动作, 譬如: open、print}
  FileName: PChar; {指定要打开的文件或程序}
  Parameters: PChar; {给要打开的程序指定参数; 如果打开的是文件这里应该是 nil}
  Directory: PChar; {缺省目录}
  ShowCmd: Integer {打开选项}
): HINST; {执行成功会返回应用程序句柄; 如果这个值 <= 32, 表示执行错误}

//Operation 参数可选值:
	edit
Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
explore
Explores a folder specified by lpFile.
find
Initiates a search beginning in the directory specified by lpDirectory.
open
Opens the item specified by the lpFile parameter. The item can be a file or folder.
print
Prints the file specified by lpFile. If lpFile is not a document file, the function fails.

//返回值可能的错误有: = 0 {内存不足}
  ERROR_FILE_NOT_FOUND = 2; {文件名错误}
  ERROR_PATH_NOT_FOUND = 3; {路径名错误}
  ERROR_BAD_FORMAT = 11; {EXE 文件无效}
  SE_ERR_SHARE = 26; {发生共享错误}
  SE_ERR_ASSOCINCOMPLETE = 27; {文件名不完全或无效}
  SE_ERR_DDETIMEOUT = 28; {超时}
  SE_ERR_DDEFAIL = 29; {DDE 事务失败}
  SE_ERR_DDEBUSY = 30; {正在处理其他 DDE 事务而不能完成该 DDE 事务}
  SE_ERR_NOASSOC = 31; {没有相关联的应用程序}
//ShowCmd 参数可选值:SW_HIDE = 0; {隐藏}
  SW_SHOWNORMAL = 1; {用最近的大小和位置显示, 激活}
  SW_NORMAL = 1; {同 SW_SHOWNORMAL}
  SW_SHOWMINIMIZED = 2; {最小化, 激活}
  SW_SHOWMAXIMIZED = 3; {最大化, 激活}
  SW_MAXIMIZE = 3; {同 SW_SHOWMAXIMIZED}
  SW_SHOWNOACTIVATE = 4; {用最近的大小和位置显示, 不激活}
  SW_SHOW = 5; {同 SW_SHOWNORMAL}
  SW_MINIMIZE = 6; {最小化, 不激活}
  SW_SHOWMINNOACTIVE = 7; {同 SW_MINIMIZE}
  SW_SHOWNA = 8; {同 SW_SHOWNOACTIVATE}
  SW_RESTORE = 9; {同 SW_SHOWNORMAL}
  SW_SHOWDEFAULT = 10; {同 SW_SHOWNORMAL}
  SW_MAX = 10; {同 SW_SHOWNORMAL}


以上是ShellExecute函数的基本使用方法,控制面板程序是个特别的DLL外,特点是其扩展名必须为 *.cpl。
//打开 IE4 的设置窗口
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL inetcpl.cpl",NULL,SW_SHOW);
//打开 声音的设置窗口
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL mmsys.cpl @1",NULL,SW_SHOW);
//启动日期和时间设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL timedate.cpl",NULL,SW_SHOW);
//启动显示设置面板
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL desk.cpl",NULL,SW_SHOW);
//启动辅助选项
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL access.cpl",NULL,SW_SHOW);
//打开鼠标设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL main.cpl @0",NULL,SW_SHOW);
/启动键盘设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL main.cpl @1",NULL,SW_SHOW);
//打开区域设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL intl.cpl",NULL,SW_SHOW);
//启动添加软件设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL appwiz.cpl",NULL,SW_SHOW);
//启动添加硬件设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL hdwwiz.cpl",NULL,SW_SHOW);
//打开系统设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL sysdm.cpl",NULL,SW_SHOW);
//启动调制解调器设置
	::ShellExecute(NULL,"OPEN","rundll32.exe","shell32.dll Control_RunDLL modem.cpl",NULL,SW_SHOW);



详细地址

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧! 158427611 
欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧! 158427611 

你可能感兴趣的:(C++,windows,VC)