after writing the code to add a toolbar to a dialog-based mfc the dialog doesn#39;t run(编写代码以将工具栏添加到基于对话框的 mfc 后,对话框不运行)
问题描述
这里是代码我曾经在我的对话框上创建一个工具栏,我正处于教程的早期阶段,刚刚将这些代码添加到我的程序中:
here's the code that I have used to create a toolbar on my dialog and I am in the early stages of the tutorial just added these codes to my program:
InitialJobProject2Dlg.h
CToolBar m_FirstToolBar;  
InitialJobProject2.cpp
BOOL CInitialJobProject2Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
    BOOL bNameValid;
    CString strAboutMenu;
    bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
    ASSERT(bNameValid);
    if (!strAboutMenu.IsEmpty())
    {
        pSysMenu->AppendMenu(MF_SEPARATOR);
        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
}
// Set the icon for this dialog.  The framework does this automatically
//  when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);         // Set big icon
SetIcon(m_hIcon, FALSE);        // Set small icon
// TODO: Add extra initialization here
GDALAllRegister();
bool bAnchored = false;
bAnchored = m_resizer.Hook(this);
assert(bAnchored);
bAnchored = m_resizer.SetAnchor(IDC_TXTDataFile,ANCHOR_LEFT | ANCHOR_TOP);
assert(bAnchored);
bAnchored = m_resizer.SetAnchor(IDC_EDTDataPath,ANCHOR_LEFT | ANCHOR_TOP);
assert(bAnchored);
bAnchored = m_resizer.SetAnchor(IDC_BTNBrowse,ANCHOR_LEFT | ANCHOR_TOP);
assert(bAnchored);
bAnchored = m_resizer.SetAnchor(IDC_RICHEDTHeader,ANCHOR_HORIZONTALLY);
assert(bAnchored);
bAnchored = m_resizer.SetAnchor(IDC_OPENGL,ANCHOR_ALL);
assert(bAnchored);
bAnchored = m_resizer.InvokeOnResized();
assert(bAnchored);
if(!m_FirstToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | 
    WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | 
    CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
    !m_FirstToolBar.LoadToolBar(IDR_TOOLBAR1))
{
    EndDialog(IDCANCEL);
}
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0);
m_FirstToolBar.MoveWindow( 50, 0,100, 100, 1 );
m_oglWindow = new COpenGLControl();
CRect rect;
// Get size and position of the picture control
GetDlgItem(IDC_OPENGL)->GetWindowRect(rect);
// Convert screen coordinates to client coordinates
ScreenToClient(rect);
// Create OpenGL Control window
m_oglWindow -> oglCreate(rect, this);
// Setup the OpenGL Window's timer to render
//m_oglWindow -> m_unpTimer = m_oglWindow -> SetTimer(1, 1, 0);
return TRUE;  // return TRUE  unless you set the focus to a control
}  
表示这部分是添加工具栏:
that this part is added to add a toolbar:
    if(!m_FirstToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | 
        WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | 
        CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || 
        !m_FirstToolBar.LoadToolBar(IDR_TOOLBAR1))
    {
        EndDialog(IDCANCEL);
    }
    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0);
    m_FirstToolBar.MoveWindow( 50, 0,100, 100, 1 );  
在我运行代码的这个阶段,没有错误但没有显示对话框窗口.我有 将富编辑框添加到我的对话框时出现类似问题,但在网上搜索工具栏案例没有结果!
您能帮我解决问题吗?我该怎么办?
at this stage when I run the code, there's no error but the dialog window isn't shown. I had a similar problem when adding rich edit box to my dialog but searching the web for the toolbar case had no result!
Could you help me what's the problem and what should I do?
推荐答案
MSDN 中的 DLGCBR32 示例展示了如何向 MFC 对话框添加工具栏:
The DLGCBR32 sample in MSDN shows how to add a toolbar to an MFC dialog:
http://msdn.microsoft.com/en-us/library/ccstww6w(v=VS.80).aspx
这篇关于编写代码以将工具栏添加到基于对话框的 mfc 后,对话框不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:编写代码以将工具栏添加到基于对话框的 mfc 后,对话框不运行
				
        
 
            
        基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
 - 如何通过C程序打开命令提示符Cmd 2022-12-09
 - 如何在 C++ 中初始化静态常量成员? 2022-01-01
 - 这个宏可以转换成函数吗? 2022-01-01
 - 我有静态或动态 boost 库吗? 2021-01-01
 - C++结构和函数声明。为什么它不能编译? 2022-11-07
 - 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
 - 在 C++ 中计算滚动/移动平均值 2021-01-01
 - 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
 - 常量变量在标题中不起作用 2021-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				