簡體   English   中英

在編寫將工具欄添加到基於對話框的MFC的代碼后,該對話框無法運行

[英]after writing the code to add a toolbar to a dialog-based mfc the dialog doesn't run

是我用來在對話框上創建工具欄的代碼,而在本教程的早期階段,我只是將這些代碼添加到了程序中:

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
}  

添加此部分以添加工具欄:

    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 );  

在此階段,當我運行代碼時,沒有錯誤,但沒有顯示對話框窗口。 將豐富的編輯框添加到對話框時,我遇到了類似的問題,但在網上搜索工具欄的情況沒有結果!
您能幫我什么問題,我應該怎么辦?

MSDN中的DLGCBR32示例顯示了如何向MFC對話框添加工具欄:

http://msdn.microsoft.com/zh-CN/library/ccstww6w(v=VS.80).aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM