资源简介
父进程创建子进程并通信
代码片段和文件信息
#include
#include “resource.h“
wchar_t data[1000];
HWND faHwnd;
HANDLE hmap = NULL;
LPVOID lpdata = NULL;
HWND win = NULL;
LRESULT CALLBACK WinMainProc(HWND hwnd UINT msg WPARAM wParam LPARAM LParam);
INT_PTR CALLBACK DlgProc(HWND hdlg UINT msg WPARAM wParam LPARAM lParam);
HINSTANCE hgapp; //当前应用程序句柄
int WINAPI WinMain(HINSTANCE hThisApp HINSTANCE hPrevApp LPSTR lpCmd int nShow)
{
LPCWSTR title = L“Child_Process“;
WNDCLASS wc = { sizeof(WNDCLASS) };
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hInstance = hThisApp;
wc.lpfnWndProc = WinMainProc;
wc.lpszClassName = title;
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
HWND hwnd = CreateWindow(title L“Child_Process“ WS_OVERLAPPEDWINDOW50 100 50 240 NULL NULL hThisApp NULL);
if (!hwnd)
return 0;
hgapp = hThisApp;
ShowWindow(hwnd nShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg NULL 0 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinMainProc(HWND hwnd UINT msg WPARAM wParam LPARAM LParam)
{
HWND hdlg = NULL;
switch (msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CREATE:
hdlg = CreateDialog(hgapp MAKEINTRESOURCE(WIN) hwnd (DLGPROC)DlgProc);
if (hdlg)
{
win = hdlg;
ShowWindow(hdlg SW_NORMAL);
}
return 0;
case LB_ADDSTRING:
{
SendMessage(GetDlgItem(win SHOWCHAT) msg wParam LParam);
return 0;
}
case WM_SETTEXT:
{
hmap = OpenFileMappingA(FILE_MAP_READ FALSE “share“);
lpdata = MapViewOfFile(hmap FILE_MAP_READ 0 0 0);
SendMessage(GetDlgItem(win SHOWFILE) msg NULL (LPARAM)lpdata);
UnmapViewOfFile(lpdata);
CloseHandle(hmap);
return 0;
}
default:
return DefWindowProc(hwnd msg wParam LParam);
}
return 0;
}
// 处理对话框中的数据
INT_PTR CALLBACK DlgProc(HWND hdlg UINT msg WPARAM wParam LPARAM lParam)
{
int dwLen = 0;
int nwLen = 0;
LPWSTR lpszPath = NULL;
switch (msg)
{
case WM_SYSCOMMAND:
if (wParam == SC_CLOSE)
{
DestroyWindow(hdlg);
}
return 0;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case COM_CHAT:
faHwnd = FindWindow(L“Father_Process“ L“Father_Process“);
SendMessage(GetDlgItem(win CHATBOX) WM_GETTEXT 1000 (LPARAM)data);
SendMessage(faHwnd LB_ADDSTRING NULL (LPARAM)data);
break;
case FIND_FILE:
OPENFILENAME opfn;
WCHAR strFilename[MAX_PATH];
ZeroMemory(&opfn sizeof(OPENFILENAME));
opfn.lStructSize = sizeof(OPENFILENAME);
opfn.lpstrFilter = L“*.*\0*.*\0*.txt\0*.txt\0“;
opfn.nFilterIndex = 1;
opfn.lpstrFile = strFilename;
opfn.lpstrFile[0] = ‘\0‘;
opfn.nMaxFile = sizeof(strFilename);
opfn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
if (GetOpenFileName(&opfn))
{
SendMessage(GetDlgItem(hdlg FILE) WM_SETTEXT NULL (LPARAM)strFilename);
}
HANDLE hFile;
hFile = Create
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-10-28 09:29 .vs\
目录 0 2016-10-28 09:29 .vs\fatherprocess\
目录 0 2016-10-28 09:29 .vs\fatherprocess\v14\
文件 34816 2016-11-06 15:31 .vs\fatherprocess\v14\.suo
目录 0 2016-10-28 13:41 childprocess\
文件 2728 2016-10-28 13:15 childprocess\childprocess.aps
文件 5220 2016-10-28 13:15 childprocess\childprocess.rc
文件 7401 2016-10-28 13:18 childprocess\childprocess.vcxproj
文件 1205 2016-10-28 13:18 childprocess\childprocess.vcxproj.filters
文件 4044 2016-10-28 13:41 childprocess\cp.cpp
目录 0 2016-10-28 13:41 childprocess\Debug\
文件 96 2016-10-28 13:41 childprocess\Debug\childprocess.log
文件 496 2016-10-28 13:18 childprocess\Debug\childprocess.res
目录 0 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\
文件 199 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\childprocess.lastbuildstate
文件 644 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\CL.command.1.tlog
文件 20642 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\CL.read.1.tlog
文件 484 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\CL.write.1.tlog
文件 1336 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\li
文件 2998 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\li
文件 604 2016-10-28 13:41 childprocess\Debug\childprocess.tlog\li
文件 400 2016-10-28 13:18 childprocess\Debug\childprocess.tlog\rc.command.1.tlog
文件 2224 2016-10-28 13:18 childprocess\Debug\childprocess.tlog\rc.read.1.tlog
文件 270 2016-10-28 13:18 childprocess\Debug\childprocess.tlog\rc.write.1.tlog
文件 31813 2016-10-28 13:41 childprocess\Debug\cp.obj
文件 535552 2016-10-28 13:41 childprocess\Debug\vc140.idb
文件 167936 2016-10-28 13:41 childprocess\Debug\vc140.pdb
文件 911 2016-10-28 13:18 childprocess\resource.h
目录 0 2016-10-28 13:36 Debug\
文件 44544 2016-10-28 13:41 Debug\childprocess.exe
文件 377244 2016-10-28 13:41 Debug\childprocess.ilk
............此处省略30个文件信息
评论
共有 条评论