| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 787 人关注过本帖
标题:c++在Windows系统下编写计算机程序
只看楼主 收藏
a948478395
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-2-23
  问题点数:0  回复次数:0   
c++在Windows系统下编写计算机程序
#include <windows.h>
LRESULT WINAPI WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);//函数声明
//主函数
RECT rect;
HDC hDC;
PAINTSTRUCT paint;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
    char *cName = "myWindow";//定义个字符指针表示窗口类的名字
    WNDCLASS wc;//定义变量
    HWND hWnd;
    MSG Msg;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);;//设置窗口背景为白色
    wc.hCursor = NULL;//窗口的光标不设置
    wc.hIcon = NULL;//窗口图标设置
    wc.hInstance = hInstance;//当前程序的句柄,hInstance是由主函数传递
    wc.lpfnWndProc = WinProc;//窗口处理过程的窗口函数。
    wc.lpszClassName =cName;//窗口类的名字。
    wc.lpszMenuName = NULL;//目录名,不设置
    wc.style = CS_HREDRAW | CS_VREDRAW; //窗口类的风格
    RegisterClass(&wc);//在系统中注册窗口
    hWnd = CreateWindow(                   //创建窗口
                cName,                 //窗口类名
                "窗口的标题",           //窗口标题
                WS_OVERLAPPEDWINDOW,       //窗口的风格
                10,             //窗口初始显示位置x
                20,             //窗口初始显示位置y:
                330,             //窗口的宽度:
                350,             //窗口的高度:
                NULL,            //父窗口:无
                NULL,            //子菜单:无
                hInstance,      //该窗口应用程序的实例句柄
                NULL            //
            ) ;
     ShowWindow(hWnd,nShowCmd);//显示窗口
    //对消息的循环处理
    while(GetMessage(&Msg,NULL,0,0))
    {
        TranslateMessage(&Msg);//翻译消息
        DispatchMessage(&Msg);//分派消息
    }
    return Msg.message;//程序结束后返回消息
}

//窗口函数
LRESULT WINAPI WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
{//处理消息过程
    static HWND btnHwnd ;
    static HWND inputHwnd ;
    switch(Msg)//对消息进行判断
    {
    case WM_PAINT:
        hDC=BeginPaint(hWnd,&paint);//获取设备上下文
        rect.left=10;
        rect.top=20;//设置矩形框的属性
        rect.right=80;
        rect.bottom=40;
        DrawText(hDC,NULL,-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
        EndPaint(hWnd,&paint);
        return 0;
    case WM_CREATE:    //响应窗口的创建事件
        //创建按钮
        btnHwnd = CreateWindow( "button", "MC",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,10, 60,    40, 30,hWnd,    (HMENU)1,(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),NULL ) ;

        btnHwnd = CreateWindow( "button", "MR",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,70, 60,    40, 30,hWnd,    (HMENU)1,(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),NULL ) ;

        btnHwnd = CreateWindow( "button", "MS",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,130,60,   40, 30,hWnd,     (HMENU)1,(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),NULL ) ;

        btnHwnd = CreateWindow( "button", "MS",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,190, 60,    40, 30,hWnd,     (HMENU)1,(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),NULL ) ;

        btnHwnd = CreateWindow( "button", "M-",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    250, 60,40, 30,    hWnd,    (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "←",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    10, 100,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "CE",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    70, 100,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "C",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    130, 100,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "±",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,190, 100,    40, 30,hWnd,    (HMENU)1,(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "√",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,250, 100,    40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "7",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    10, 140,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "8",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    70, 140,    40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "9",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,130, 140,    40, 30,hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "/",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    190, 140,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "%",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    250, 140,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "4",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    10, 180,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "5",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    70, 180,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "6",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    130, 180,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "*",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    190, 180,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "1/X",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    250, 180,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "1",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    10, 220,        40, 30,    hWnd,        (HMENU)3,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "2",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    70, 220,        40, 30,    hWnd,        (HMENU)4,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "3",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    130, 220,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "-",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    190, 220,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "=",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    250, 220,        40, 70,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "0",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    10, 260,        100, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", ".",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    130,260,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;

        btnHwnd = CreateWindow( "button", "+",    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,    190, 260,        40, 30,    hWnd,        (HMENU)1,    (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE ),    NULL ) ;
        
        //创建文本框
        inputHwnd = CreateWindow( "edit", "0",WS_CHILD | WS_VISIBLE  | WS_BORDER |ES_RIGHT | ES_MULTILINE ,10, 20, 280, 30,hWnd,(HMENU)2,((LPCREATESTRUCT) lParam) -> hInstance, NULL ) ;
        return 0 ;
    case WM_COMMAND://响应命令
      {
          switch(LOWORD(wParam))
          {
          /*这里不会*/         
            
                        }
          return 0;
      }


    case WM_DESTROY://如果是点击关闭窗口时的消息
        PostQuitMessage(0);//退出消息队列
        return 0;//返回0,结束函数
    }
    //如果是其余的消息,调用默认消息处理函数,将消息该函数处理并将返回值返回
    return DefWindowProc(hWnd,Msg,wParam,lParam);
}


求帮助
搜索更多相关主题的帖子: 计算机程序  Windows  include  
2017-02-23 09:51







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.165373 second(s), 8 queries.
Copyright©2004-2018, BCCN.NET, All Rights Reserved