Nisgrace 2017-08-31 06:45 采纳率: 100%
浏览 752
已采纳

用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条回答 默认 最新

  • 枫舞的季节 2017-09-01 01:26
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化