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



wm_initdialog消息创建控件失败


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


wm_initdialog消息创建控件失败[已结贴,结贴人:yangxingkuan]
发表于:2007-08-22 16:08:13 楼主
api对话框:
case   wm_initdialog:
                  hedit   =   createwindow   (text   ( "edit "),   text   ( "bianji "),
                                                                    ws_child   ¦   ws_visible   ,
                                                                          110,   50,   50,   30,
                                                                        hdlgmodeless,   (hmenu)   id_new_edit,   hins,   null)   ;

return   true;
没有控件出来,
窗体在
  case   wm_create   :可以创建控件,对话框不在wm_initdialog中创建吗??
应该在哪个消息??
发表于:2007-08-22 16:16:011楼 得分:4
wm_initdialog对话框已经创建好了,此消息做初始化。
创建对话框是在wm_create下做的
发表于:2007-08-22 17:11:392楼 得分:4
应该可以。
判断返回句柄hedit是否为空。如果不为空,说明创建成功,然后movewindow到可视位置。
发表于:2007-08-22 17:17:223楼 得分:0
showwindow也没有~???
发表于:2007-08-22 17:30:144楼 得分:2
你创建的是基于对话框的吗?不是的话没有wm_initdialog.
在wm_initdialog是可以创建对话框的子控件.

如果不是的话要在wm_create中建.
发表于:2007-08-22 18:32:315楼 得分:0
对话框已经创建好了。
对于窗体有
wm_create消息。
而对话框没有wm_create消息
特有消息
wm_initdialog
初始化,没有错吧。
switch(message)
{
case   wm_initdialog:

            hedit   =   createwindow   (text   ( "edit "),   text   ( "bianji "),
                                                                        ws_child   ¦   ws_visible   ,
                                                                          110,   50,   50,   30,
                                                                        hdlgmodeless,   (hmenu)   id_new_edit,hh,   null)   ;
return   true;
发表于:2007-08-22 20:28:586楼 得分:0
你最好发全一点的代码
  不然谁知道你是基于什么建的!
把前面的也发出来
发表于:2007-08-23 09:02:567楼 得分:0
//   dlg.cpp   :   defines   the   entry   point   for   the   application.
//

#include   "stdafx.h "
#include   "resource.h "

bool   callback   dlgfunc(hwnd,   uint,   wparam,   lparam);
lresult   callback   buttonproc(hwnd,uint,wparam,lparam);
lresult   callback   editproc(hwnd,uint,wparam,lparam);
hwnd   hdlgmodeless;
hinstance   hins;  
wndproc   oldbutton,oldedit   ;
int   winapi   winmain(hinstance   hinstance,
                                          hinstance   hprevinstance,
                                          lpstr           lpcmdline,
                                          int               ncmdshow)
{
 
hdlgmodeless=createdialog(hinstance,makeintresource(idd_dialog1),null,dlgfunc);
showwindow   (hdlgmodeless,   sw_show)   ;

hins=hinstance;
msg   msg;
while(getmessage(&msg,null,0,0))
{
if(hdlgmodeless==0 ¦ ¦!isdialogmessage(hdlgmodeless,&msg))
{
translatemessage(&msg);
dispatchmessage(&msg);

}
}

return   msg.wparam;
}

bool   callback   dlgfunc(hwnd   hwnd,   uint   message   ,   wparam   wparam,   lparam   lparam)
{
  static   hwnd             hwndsmaller,   hwndlarger   ;
  static   hwnd             hedit;
     
        static     hinstance     hh;
switch(message)
{
case   wm_initdialog:

    hh   =   (hinstance)   getwindowlong   (hwnd,   gwl_hinstance)   ;
    hedit   =   createwindow   (text   ( "edit "),   text   ( "bianji "),
                                                                          ws_child   ¦   ws_visible   ,
                                                                          110,   50,   50,   30,
                                                                        hdlgmodeless,   (hmenu)   id_new_edit,hh,   null)   ;
return   true;
case   wm_command:
switch(loword(wparam))
{
case   idcancel:
hwndsmaller   =   createwindow   (text   ( "button "),   text   ( "pp "),
                                                                          ws_child   ¦   ws_visible   ,
                                                                            50,   50,   50,   30,
                                                                          hdlgmodeless,   (hmenu)   id_smaller,   hins,   null)   ;

oldbutton=(wndproc)   setwindowlong(hwndsmaller,gwl_wndproc,(long)buttonproc);

hedit   =   createwindow   (text   ( "edit "),   text   ( "bianji "),
                                                                          ws_child   ¦   ws_visible   ,
                                                                          110,   50,   50,   30,
                                                                        hdlgmodeless,   (hmenu)   id_new_edit,   hins,   null)   ;

oldedit=(wndproc)   setwindowlong(hedit,gwl_wndproc,(long)editproc);
return   true;
case   idok:
destroywindow(hdlgmodeless);
hdlgmodeless=0;
::postquitmessage(0);
return   true;
}

}
return   false;


}

lresult   callback   buttonproc(hwnd   hwnd,uint   message,wparam   wparam,lparam   lparam)
{
      //   int   id   =   getwindowlong   (hwnd,   gwl_id)   ;
                   
          switch   (message)
          {
          case   wm_lbuttondown   :
                    break   ;
                             
          case   wm_rbuttondown   :
                    messagebox(hdlgmodeless, "右键按下 ", "鼠标右键 ",1);
                    break   ;
          }

          return   callwindowproc   (oldbutton,   hwnd,   message,   wparam,   lparam)   ;
//   return   1;

}

lresult   callback   editproc(hwnd   hwnd,uint   message,wparam   wparam,lparam   lparam)
{
   
                   
          switch   (message)
          {
          case   wm_lbuttondown   :
                    break   ;
                             
          case   wm_rbuttondown   :
                    messagebox(hdlgmodeless, "右键按下 ", "鼠标右键 ",1);
                    break   ;
          }

          return   callwindowproc   (oldedit,   hwnd,   message,   wparam,   lparam)   ;
//   return   1;

}

都在了,有什么不对的地方请指出??
发表于:2007-08-23 10:52:518楼 得分:10
问题找到了.
你在wm_initdialog中hedit   =   createwindow   (text   ( "edit "),   text   ( "bianji "),
                                                                          ws_child   ¦   ws_visible   ,
                                                                          110,   50,   50,   30,
                                                                        hdlgmodeless,   (hmenu)   id_new_edit,hh,   null)   ;
因为是基于模板的,所以那时侯dlgmodeless=createdialog()还没有返回,因而是0,会产生1046错误.
正确的做法是在hdlgmodeless=createdialog()返回后再hedit   =   createwindow();
  hdlgmodeless=createdialog(hinstance,makeintresource(idd_dialog1),null,dlgfunc);    
hedit   =   createwindow   (text   ( "edit "),   text   ( "bianji "),
                                                                          ws_child   ¦   ws_visible   ,
                                                                        110,   50,   50,   30,
                                                                        hdlgmodeless,   (hmenu)   id_new_edit,hh,   null)   ;
发表于:2007-08-23 12:07:209楼 得分:0
谢谢楼上,但是楼上方法在对话框过程外,我如果想在对话框过程中创建,产生如同模板加载的按钮,可以对那些消息处理。
发表于:2007-08-23 13:52:5510楼 得分:0
照着你的idcancel处理就ok了,我还以为你已经知道了.
上面的是动态方法.
静态的你可以直接在模板上放置控件,大小什么的都更容易控制


快速检索

最新资讯
热门点击