首页 IP地址查询 | Alexa排名查询 | 手机归属地查询
设为首页 收藏本站
  • 网络编程网络编程
  • 软件编程软件编程
  • 数据库技术数据库技术
  • 编程学院
  • 业界资讯 业界资讯
  • 源码中心源码中心
  • 会员中心会员中心
  • 页面导航: 首页C++编程窗口&界面 → 创建以对话框为主窗口的程序

    创建以对话框为主窗口的程序

    发布:jeaye 发布日期:2009-03-15 字体:[增加 减小] 类型:原创

    其实和创建一个窗口的程序是一样的,但创建的函数不同,消息处理上有点不同.

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {

    MSG          msg ;
     WNDCLASS     wndclass ;
     
        InitCommonControls();
     
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
     wndclass.lpfnWndProc   = WndProc;
     wndclass.cbClsExtra    = 0 ;
     wndclass.cbWndExtra    = DLGWINDOWEXTRA ;
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (hInstance, szAppName);
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1) ;
     wndclass.lpszMenuName  = szAppName ;
     wndclass.lpszClassName = szAppName ;
     
     if (!RegisterClass (&wndclass))
     {
      MessageBox (NULL, TEXT ("This program requires Windows NT!"),
       szAppName, MB_ICONERROR) ;
      return 0 ;
     }
     

    //注意这里的szAppName它是对话框资源的名称,是TCHAR[]字符串数组

    //当然你还可以用函数MAKEINTRESOURCE(IDC_DIALOG)来转换成TCHAR数组


     hMainDlg = CreateDialog(hInstance,szAppName,NULL,(DLGPROC)WndProc);
     ShowWindow (hMainDlg, iCmdShow) ;
     UpdateWindow (hMainDlg) ; 

    //以下就是消息上的区别,仔细看一下和普通窗口有什么不同 

    while (GetMessage (&msg, NULL, 0, 0) )
     {
      if (!IsWindow(hMainDlg) || !IsDialogMessage(hMainDlg, &msg))
      {
       
       TranslateMessage (&msg) ;
       DispatchMessage (&msg) ;
      }
     }

     

    其它代码就和创建普通窗口一样了,原理很简单,详细请看源代码


    下载源代码
    Tags: 创建 对话框
    为配合网络严查,文章评论将关闭敬请谅解.
    同 类 文 章
    最 近 更 新
    热 点 排 行