2 n752796294 n752796294 于 2017.08.31 14:45 提问

用Windows API编写出来的窗口怎么才能显示另一份.cpp文件的结果

#include
#include
#include
#include
using namespace std;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
//主函数 程序入口

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
//用来保存成功创建窗口后返回的句柄
MSG msg ;
//定义消息结构体变量
WNDCLASS wndclass ;
//窗体类
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
//指定窗口风格
wndclass.lpfnWndProc = WndProc ;
////函数指针,指向处理窗口消息的函数入口
wndclass.cbClsExtra = 0 ; //结构体后附加的字节数,一般总为0
wndclass.cbWndExtra = 0 ; //窗体实例附加的字节数,一般总为0
wndclass.hInstance = hInstance ; //模块句柄
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; //图标句柄 任务栏显示的图标
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; //光标句柄
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); //背景颜色COLOR_BACKGROUND
wndclass.lpszMenuName = NULL ; //菜单名的字符串
wndclass.lpszClassName = szAppName ; //自定义类名,不要与其他类名重复
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("注册类失败!"), szAppName, MB_ICONERROR) ;
return 0 ;
}
int x =((GetSystemMetrics(SM_CXSCREEN)/2)-200); //x居中
int y =((GetSystemMetrics(SM_CYSCREEN)/2)-200); //y居中
//创建窗体api
hwnd = CreateWindow(szAppName,TEXT("NTFS文件检索"),WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,x,y,400,400,NULL,NULL,hInstance,NULL); //显示窗体的API 传入需要显示的窗体句柄和显示方式
ShowWindow(hwnd,iCmdShow); //刷新窗体的API
UpdateWindow(hwnd); //从系统的应用程序线程消息队列中取得一个消息
while(GetMessage(&msg,NULL,0,0) > 0)
{
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc; //句柄
PAINTSTRUCT ps;
RECT rect; //矩形
HINSTANCE hInstance; //窗口实例
static HWND hwndButton[10]; //按钮句柄
switch (message)
{
case WM_CREATE: //创建按钮
{
//HWND CreateWindow(LPCTSTR lpClassName,LPCTSTR lpWindowName,DWORD dwStyle,int x,int y,int nWidth,int nHeight,HWND hWndParent,HMENU hMenu,HANDLE hlnstance,LPVOID lpParam);

    hInstance = ((LPCREATESTRUCT)lParam)->hInstance; //按钮1
    hwndButton[0] = CreateWindow("BUTTON","检索盘符",  WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  10,10,100,100,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL); //按钮2
    hwndButton[1] = CreateWindow("BUTTON","查询",  WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  290,120,100,100,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    hwndButton[3] = CreateWindow("BUTTON","获取历史记录",  WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  290,260,100,100,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    hwndButton[4] = CreateWindow("LISTBOX","盘符栏",WS_VISIBLE|WS_VSCROLL|WS_CHILD,120,10,160,100,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    hwndButton[5] = CreateWindow("EDIT","输入栏",WS_VISIBLE|WS_CHILD,10,120,270,20,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    hwndButton[6] = CreateWindow("LISTBOX","结果栏",WS_VISIBLE|WS_VSCROLL|WS_CHILD,10,150,270,210,hwnd,NULL, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    return 0;
}
/*case WM_PAINT: //绘制文字
    hdc = BeginPaint(hwnd,&ps);
    TextOut(hdc,300,200,button[iFlag].szText,lstrlen(button[iFlag].szText));
    EndPaint(hwnd,&ps);
    GetClientRect(hwnd,&rect);
    DrawText(hdc,TEXT("By:Eastmount CSDN制作"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
    EndPaint(hwnd,&ps);
    return 0;*/
case WM_COMMAND: //响应按钮消息
    if((HWND)lParam == hwndButton[0])
    {
        ///MessageBox(NULL,TEXT("是否训练图片?"),TEXT("提示"),MB_YESNO|MB_ICONQUESTION);
    }
    if((HWND)lParam == hwndButton[1])
    {
        MessageBox(NULL,TEXT("是否获取图片?"),TEXT("提示"),MB_YESNO|MB_ICONQUESTION);
    }
    return 0;
case WM_CLOSE: //关闭
    if(IDYES==MessageBox(hwnd,"是否关闭程序?","提示",MB_YESNO|MB_ICONQUESTION))
    {
        DestroyWindow (hwnd);
    }
    return 0;
case WM_DESTROY: //退出程序
    PostQuitMessage (0) ;
    return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;

}

2个回答

justin_bkdrong
justin_bkdrong   2017.09.01 09:26
已采纳

使用WM_COPYDATA 就能实现从一个程序发送到另外的程序

justin_bkdrong
justin_bkdrong   2017.08.31 17:37

是两个程序通讯么?一个程序要接收另外程序的输入?

n752796294
n752796294 就是我写的这个窗口可以接收另外程序的输出
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片