win32应用程序模板(DialogBox模式)--用来创建一个进程的

本文展示了一个简单的Windows应用程序示例,通过对话框选择并运行指定的.exe文件。该程序利用了DialogBox和CreateProcess等API函数实现。

//建立一个dialog资源,名字叫IDD_MainDLG,将其中的static命名为IDC_SN_STATIC,用来显示要运行程序的名字。
// MemKey.cpp : Defines the entry point for the application.
//

#include "stdafx.h"

BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);


int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
DialogBox(hInstance, MAKEINTRESOURCE (IDD_MainDLG),NULL,DialogProc);
return 0;
}


BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG :
return TRUE ;//返回真,表示消息被处理了。

case WM_COMMAND :
switch (LOWORD (wParam))
{
case IDOK :
OPENFILENAME lpfilename;
char szFile[256]; // buffer for file name
STARTUPINFO stStartup;
PROCESS_INFORMATION proinfo;
ZeroMemory(&stStartup,sizeof(STARTUPINFO));
ZeroMemory(&proinfo,sizeof(PROCESS_INFORMATION));
ZeroMemory(&lpfilename, sizeof(lpfilename));
ZeroMemory(szFile,sizeof(szFile));
lpfilename.lStructSize = sizeof(OPENFILENAME);
lpfilename.lpstrFile=szFile;
lpfilename.nMaxFile = sizeof(szFile);
lpfilename.lpstrFilter="Exe/0*.EXE/0All/0*.*/0";
lpfilename.hwndOwner=hwndDlg;
lpfilename.Flags=OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetOpenFileName(&lpfilename))
{
SetDlgItemText(hwndDlg,IDC_SN_STATIC,lpfilename.lpstrFile );
BOOL proret=CreateProcess(lpfilename.lpstrFile,"",NULL,NULL,FALSE,DEBUG_PROCESS,NULL,NULL,&stStartup,&proinfo);
//BOOL proret=CreateProcess(lpfilename.lpstrFile,"",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&stStartup,&proinfo);
if(proret==FALSE)
MessageBox(hwndDlg,"创建进程失败!","警告",NULL);
}else
{
MessageBox(hwndDlg,"打开文件失败!","警告",NULL);
}
break;
case IDCANCEL :
EndDialog (hwndDlg, 0) ;//使用EndDialog关闭对话框
return TRUE ; //返回真,表示消息被处理了。
}
default:
break ;
}
return FALSE ; ////返回假,表示消息未被用户处理,又缺省消息处理函数去处理。
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

uz-UZ-Latn api-ms-win-core-localization-l1-2-1 Failed to resolve full path to executable %ls. sr-BA-Latn div-MV LOADER: length of teporary directory path exceeds maximum path length! Wednesday advapi32 sma-se ext-ms-win-ntuser-windowstation-l1-1-0 Friday Tuesday zh-cht api-ms-win-core-fibers-l1-1-1 HH:mm:ss Failed to get address for %hs PyInstaller Onefile Hidden Window MM/dd/yy smj-no D:(A;;FA;;;%s)(A;;FA;;;%s) WARNING CreateDirectory uz-uz-cyrl Failed to load Python DLL '%ls'. api-ms-win-core-fibers-l1-1-2 api-ms-win-core-sysinfo-l1-2-1 quz-ec GetModuleFileNameW zh-CHS Failed to execute script '%ls' due to unhandled exception: %ls kok-IN Needs to remove its temporary files. sr-BA-Cyrl api-ms-win-rtcore-ntuser-window-l1-1-0 LOADER: failed to create runtime-tmpdir path %ls! mscoree.dll Failed to convert executable path to UTF-8. sr-sp-cyrl S-1-3-4 az-AZ-Cyrl #+3;CScs az-AZ-Latn sma-NO LOADER: failed to obtain the absolute path of the runtime-tmpdir. January GetProcAddress quz-EC February api-ms-win-core-file-l2-1-4 api-ms-win-core-localization-obsolete-l1-2-0 sms-fi smn-FI az-az-latn smn-fi October Security descriptor string length exceeds PYI_PATH_MAX! div-mv api-ms-win-security-systemfunctions-l1-1-0 sr-SP-Cyrl ext-ms- smj-se bs-ba-latn api-ms-win-core-file-l1-2-2 Unhandled exception in script quz-pe VCRUNTIME140.dll Saturday ext-ms-win-ntuser-dialogbox-l1-1-0 LOADER: failed to expand environment variables in the runtime-tmpdir. [PYI-%d:ERROR] api-ms-win-core-synch-l1-2-0 kok-in LOADER: failed to set the TMP environment variable. api-ms-win-core-processthreads-l1-1-2 api-ms-win-core-xstate-l2-1-0 Failed to obtain/convert traceback! LoadLibrary sr-SP-Latn smj-NO Failed to obtain executable path. ((((( H api-ms-win-core-file-l1-2-4 sma-no quz-BO STATIC <FormatMessageW failed.> api-ms-win-core-string-l1-1-0 [PYI-%d:%ls] sma-SE quz-PE user32 VCRUNTIME140_1.dll Failed to create child process! api-ms-win-appmodel-runtime-l1-1-2 November api-ms-win-core-datetime-l1-1-1 api-ms-win-core-winrt-l1-1-0 CreateProcessW August zh-CHT kernelbase PyInstallerOnefileHiddenWindow Thursday D:(A;;FA;;;%s) (null) CONOUT$ LOADER: failed to convert runtime-tmpdir to a wide string. az-az-cyrl December September Monday LOADER: runtime-tmpdir points to non-existent drive %ls (type: %d)! smj-SE uz-uz-latn BUTTON ]Warning UTF-16LEUNICODE kernel32 sr-ba-latn syr-sy Sunday sr-sp-latn uz-UZ-Cyrl api-ms- bs-BA-Latn dddd, MMMM dd, yyyy zh-chs sr-ba-cyrl sms-FI syr-SY _MEI%d ( quz-bo / P6pL /-P?pR ,/KPip 判断是否是木马字符。
05-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值