您的位置:程序门 -> vc/mfc -> 界面



winmain里用dialogbox直接创建dialog窗口,这样做有什么缺点?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


winmain里用dialogbox直接创建dialog窗口,这样做有什么缺点?[已结贴,结贴人:aj3423]
发表于:2008-02-03 16:14:05 楼主
以前一直用的书上的代码,今天试了下winmain里直接dialogbox也行。省去了那些retister   class什么的,代码如下:
c/c++ code
#include <windows.h> #include "resource.h" lresult callback wndproc(hwnd, uint, wparam, lparam) ; int winapi winmain(hinstance hinstance, hinstance hprevinstance, pstr szcmdline, int icmdshow) { dialogbox( hinstance, ( lpctstr ) idd_dialog1, null, ( dlgproc ) wndproc ); return 0; } lresult callback wndproc(hwnd hdlg, uint umsg, wparam wparam, lparam lparam) { switch(umsg){ case wm_initdialog: { } break; case wm_command: switch(loword( wparam )) { case idok: { enddialog( hdlg, 0 ); } break; }; break; case wm_close: enddialog( hdlg, 0 ); break; }; return 0; }

比起先register   class,createwindow,然后getmessage,translatemessage,dispatchmessage   ,   直接把所有工作交给dialogbox不是更方便?请问这样做有什么缺点?
发表于:2008-02-03 16:18:001楼 得分:4
没什么缺点。
模态对话框有自己的消息循环。
发表于:2008-02-03 16:32:292楼 得分:0
这样写小程序比较快的.
发表于:2008-02-03 16:35:133楼 得分:4
其实对话框和普通窗口都差不多.只不过普通窗口程序需要自己定义窗口过程,而对话框系统负责,但是修改rc文件,可以把默认的窗口过程替换成用户自己的,有点忘记了,大概这样.对话框只是一个特殊的窗口.
发表于:2008-02-03 18:47:324楼 得分:4
没什么缺点。这样写比自己注册类简单一点,比用mfc麻烦。主要看个人爱好。
发表于:2008-02-03 22:11:045楼 得分:0
缺点就是自由度不够。但凡省事的,总有缺失的。
发表于:2008-02-03 22:50:026楼 得分:0
好用就好,管那么多优点缺点干嘛
发表于:2008-02-04 10:11:017楼 得分:8
int   winapi   winmain(hinstance   hinstance,   hinstance   hprevinstance,   pstr   szcmdline,   int   icmdshow)   {
        dialogbox(   hinstance,   (   lpctstr   )   idd_dialog1,   null,   (   dlgproc   )   wndproc   );

        return   0;
}
=================================================================================================
windows   uses   its   own   internal   window   procedure   to   process   messages   to   a   dialog   box   window.   windows   then   passes   these   messages   to   a   dialog   box   procedure   within   the   program   that   creates   the   dialog   box.  

so   application   cannot   catch   such   as   wm_keyup,wm_keydown   messages   in   its   own   dialogproc.
(   try   to   catch   them)


快速检索

最新资讯
热门点击