什么情况下dialog会创建失败

powerhome 2004-07-19 11:51:22
调用:
CMapDlg map;
map.DoModal();
INT_PTR nRect = map.DoModal();
DWORD dw = GetLastError();

nRect等于-1,dw等于0


CMapDlg使用向导生成。

// MapDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MapDll.h"
#include "MapDlg.h"
#include ".\mapdlg.h"


// CMapDlg dialog

IMPLEMENT_DYNAMIC(CMapDlg, CDialog)
CMapDlg::CMapDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMapDlg::IDD, pParent)
{
}

CMapDlg::~CMapDlg()
{
}

void CMapDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RICHEDIT21, m_richEdit);
}


BEGIN_MESSAGE_MAP(CMapDlg, CDialog)
END_MESSAGE_MAP()


// CMapDlg message handlers

BOOL CMapDlg::OnInitDialog()
{
CDialog::OnInitDialog();

AfxMessageBox("Initial Dialog");
// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

void CMapDlg::OnOK()
{
// TODO: Add your specialized code here and/or call the base class
AfxMessageBox("on ok");
CDialog::OnOK();
}
...全文
167 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
gracezhu 2004-07-19
  • 打赏
  • 举报
回复
你的对话框上有richedit控件,要加上AfxInitRichEdit
自由的风 2004-07-19
  • 打赏
  • 举报
回复
这种问题不要拿到网络版来


自己看看头文件包了没有再说
powerhome 2004-07-19
  • 打赏
  • 举报
回复
可我在这个对话框里也没有初始化richedit,为什么就没错呢
// MapDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OutlookStyleUI.h"
#include "MapDlg.h"
#include ".\mapdlg.h"
#include <complex>


// CMapDlg dialog
const float TRANSPARENT_DEGREE = 0.3f;
const int DLGOFFSETX = 30;
const int DLGOFFSETY = 200;
IMPLEMENT_DYNAMIC(CMapDlg, CDialog)
CMapDlg::CMapDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMapDlg::IDD, pParent)
{
m_sText = "";
m_fLarger = true;
m_color = RGB(150,200,200);
m_brush.CreateSolidBrush(m_color);
m_hbrush = CreateSolidBrush(m_color);
m_nRectWidth = 250;
m_nRectHeight = 400;
for(int i=0;i<MAX_NUM_PHRASE;i++)
{
m_wndPhraseDlg[i] = NULL;
m_wndSubPhraseDlg[i] = NULL;
}

m_clrPhrse[0] = RGB(255,0,0);
m_clrPhrse[1] = RGB(0,128,0);
m_clrPhrse[2] = RGB(0,0,255);
m_clrPhrse[3] = RGB(100,0,100);
m_clrPhrse[4] = RGB(0,64,100);
}

CMapDlg::~CMapDlg()
{
for(int i=0;i<MAX_NUM_PHRASE ;i++)
{
if(m_wndPhraseDlg[i] != NULL)
{
delete m_wndPhraseDlg[i];
}
if(m_wndSubPhraseDlg[i] != NULL)
{
delete m_wndSubPhraseDlg[i];
}
}
}

void CMapDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RICHEDIT, m_richedit);
}


BEGIN_MESSAGE_MAP(CMapDlg, CDialog)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
ON_WM_NCLBUTTONDOWN()
END_MESSAGE_MAP()


// CMapDlg message handlers

BOOL CMapDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here

//initial dialog window
CRect rect;
CWnd *pWnd = this->GetDesktopWindow();
pWnd->GetWindowRect(&rect);
//30 is the width of the scroll bar
//23 is the height of the title bar
MoveWindow(rect.left + rect.Width() - m_nRectWidth - DLGOFFSETX , rect.top + DLGOFFSETY, m_nRectWidth, m_nRectHeight+23);
SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
HINSTANCE hInst = LoadLibrary("User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)fun(this->GetSafeHwnd(),0,BYTE(255*TRANSPARENT_DEGREE),LWA_ALPHA);
FreeLibrary(hInst);
}
ModifyStyle(0/*!WS_MAXIMIZEBOX*/, WS_CHILD, SWP_DRAWFRAME );

//intial static box
//SetDlgItemText(IDC_STATIC,"Mail Map");

//initial richedit box
if(m_sText=="")
{
m_sText = "No mail content!";
}
SetDlgItemText(IDC_RICHEDIT,m_sText);
m_richedit.SetBackgroundColor(FALSE,m_color);
//int nBlankLine = 0;
//int pos = m_sText.Find('\n',0);
//while(pos!=-1)
//{
// nBlankLine++;
// pos = m_sText.Find('\n',pos+1);
//}
CFont font;
//int nPixel = (m_nRectWidth*m_nRectHeight)/(m_sText.GetLength());
//m_nCharHeight = (int)sqrt((double)nPixel)/* - 3*/; //minusing const is to fit the rectangle


//UINT temp = m_nCharHeight;
//float column = m_nRectHeight/m_nCharHeight;
//column += nBlankLine;
//float height = m_nRectHeight/column;
//float offset = (m_nCharHeight-height)/3;
//m_nCharHeight = m_nCharHeight - offset;
//temp = m_nCharHeight;
//if(m_nCharHeight>15) m_nCharHeight = 15;
//temp = m_nCharHeight;

//font.CreateFont(m_nCharHeight,m_nCharHeight,0,0,m_nCharHeight*m_nCharHeight,
// FALSE,FALSE,FALSE,
// ANSI_CHARSET,OUT_DEFAULT_PRECIS,
// CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,"Times New Roman");
font.CreatePointFont(30,"Tahoma");
m_richedit.SetFont(&font);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE

}
lixiaosan 2004-07-19
  • 打赏
  • 举报
回复
把你工程传到airforcetwo@163.com

瞧瞧
gracezhu 2004-07-19
  • 打赏
  • 举报
回复
CMapDlg::CMapDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMapDlg::IDD, pParent)
{
AfxInitRichEdit();

}
powerhome 2004-07-19
  • 打赏
  • 举报
回复
根据debug发现,根本没有执行到OnInitDialog(),这是咋回事呢
Kudeet 2004-07-19
  • 打赏
  • 举报
回复
对话框不显示的原因:
1 符窗口HWND无效
2 在ONINITDIALOG里用了ENDDIALOG
3 无效的对话框资源ID
4 使用没有注册的的自定义控件
5 对话框的某些控件创建失败,如RICHEDIT,要加上AfxInitRichEdit();
lixiaosan 2004-07-19
  • 打赏
  • 举报
回复
有楼上说的这种可能性

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧