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

<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

//建立一个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 ; ////返回假,表示消息未被用户处理,又缺省消息处理函数去处理。
}

你可能感兴趣的:(dialog)