How to get pointer to CDialogBar from CView class?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to get pointer to CDialogBar from CView class?

  1. #1
    Join Date
    Nov 2013
    Posts
    5

    How to get pointer to CDialogBar from CView class?

    My program (Test) is a basic MFC AppWizard (exe) created project. I have followed the steps in the link below to create a docked dialog box (myDialog) using VC++.
    http://support.microsoft.com/default...en-us%3B185672

    The dialog box works, however, I have 2 issues that I am trying to resolve.
    1) I have added a button to the Dialog box, however, when I run the application they start as disabled (note: the Disabled option on the Button Properties is unchecked). If I add function myDialog::OnButton to the myDialog class, the button remains disabled, however, if I add the function CTestView::OnButton to the View class, the button becomes active and works. How can I make the button work from the myDialog class?

    2) I would like to be able to change an Edit box in the same dialog box when I click the button. How can I access the pointer to the myDialog from the View class?

    Thank you so much for the responses!!

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: How to get pointer to CDialogBar from CView class?

    Although it's possible, generally it's not necessary to get a pointer to dialog bar object in the view class.
    Moreover, except you really-really need a really-really customized dialogbar, it's not even needed to derive from CDialogBar.
    That's because a dialogbar (as well as other control bars like toolbar and so on) sends (command) notifications to main frame window which are further routed to view and document classes.
    So you can catch those commands in the view class. Additionally, if the button command is handled somewhere, the framework automatically enables that button.

    Let's say we have a dialogbar with a button and an edit control.
    We can handle the button clicked command, as well as notifications sent by the edit control (e.g. EN_CHANGE) in the view class, as follows:
    Code:
    // SDITestView.h
    
    class CSDITestView : public CView
    {
        // ..
        afx_msg void OnDialogbarTestButtonClicked();
        afx_msg void OnEnChangeEditText();
    };
    Code:
    // SDITestView.cpp 
    
        // ...
        ON_BN_CLICKED(IDC_BUTTON_TEST, &CSDITestView::OnDialogbarTestButtonClicked)
        ON_EN_CHANGE(IDC_EDIT_TEXT, &CSDITestView::OnEnChangeEditText)
    END_MESSAGE_MAP()
    
    
    void CSDITestView::OnDialogbarTestButtonClicked()
    {
        // Toolbar test button has been clicked. 
        // Do something cool here...
    }
    
    void CSDITestView::OnEnChangeEditText()
    {
        // Tollbar edit text has been changed. 
        // Do something even cooler...
    }
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Nov 2013
    Posts
    5

    Re: How to get pointer to CDialogBar from CView class?

    Thank you! This helps me understand the structure of MFC better.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center