Document Class and Dialog Windows :: MFC

This is a discussion on Document Class and Dialog Windows :: MFC within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I am working on a project that contains a formview class with multiple dialog windows visible. As the user ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Document Class and Dialog Windows :: MFC

    Hi.

    I am working on a project that contains a formview class with multiple dialog windows visible. As the user make changes to each dialog box, I want to update the document class. I implemente a message solution. The dialog boxes update send messages to the view class. The view class update the document class.

    In general, the solution above is adequate. However, in this particular project, the dialog windows are visible in the formview. I would like to know is there other more elegant solutions?

    For example, is it possible to implement a GetDocument() function that returns a pointer to the document class inside the dialog boxes? As another example, how about passing the dialog boxes pointers to the document class? I do not want to implement these solution unless messages fail. Thus these solutions should be last resorts.

    Thanks,
    Kuphryn

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,701
    This is hardly elegant, but one way to store a pointer. The basic idea is to have a static pointer set to NULL within the dialog callback, make a "dummy" call from within the constructor (or another function) of the object to initialize it, and finally set it to NULL when we're done so that another object can safely reuse the pointer. Yes, it's an ugly hack, but Windows doesn't give us many options, true ?

    Code:
    Propsheetpage::Propsheetpage(){
    dialog_callback(0, this, 0);
    }
    
    friend UINT CALLBACK dialog_callback( HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp){
    static Propsheetpage * p = NULL;
    if(!p){
     p = (Propsheetpage *)uMsg;
     return 0;
    }
    switch(uMsg){
      case PSPCB_CREATE: return p->OnCreate(); break;
      case PSPCB_RELEASE: return p->OnDestroy(); p = NULL; break;
     }
     return 0;
    }
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Interesting. Thanks.

    Kuphryn

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,701
    Noticed a bug in my code though, I was returning before I could set the pointer back to NULL. So obviously:

    case PSPCB_RELEASE:
    return p->OnDestroy();
    p = NULL;
    break;

    should be something like:

    case PSPCB_RELEASE:
    int value = p->OnDestroy();
    p = NULL;
    return value;
    break;
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I change the class of a dialog ?
    By Frandy in forum Windows Programming
    Replies: 0
    Last Post: 02-28-2005, 02:37 AM
  2. Replies: 6
    Last Post: 04-27-2004, 08:02 PM
  3. Replies: 3
    Last Post: 05-03-2003, 12:04 PM
  4. MFC Assertion Failure
    By maxthecat in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 09:58 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21