Thread: Some MFC questions

  1. #1
    Registered User
    Join Date
    Sep 2001

    Some MFC questions

    I'm fairly familiar with the API, but I'm starting my first big MFC project (I'd use API but it's an MDI database frontend, MFC will save me about a decade). From learning API, I thought all programs had to have a WinMain function, and then RegisterClass or RegisterClassEx, but I cant find them in my AppWizard generated app. What I need for several functions is the address of the parent class, how do I get this?

    One more question that might be related. I'm creating a dialog from a menu call in the parent window, and it works fine using sheet.DoModal();, but using sheet.Create(); for a modeless dialog it flashes up and then instantly disappears.


  2. #2
    sorry this is only a half-arsed reply

    WinMain is there - it's just buried so deep it's almost impossible to get at it - but you can if you use the debugger to step through the program. I don't think it is advisable to play around with WinMain within MFC, though as it will probably seriously affect the mfc app's initialisation.

    As for the address of the parent class isn't there a CWnd::GetParent() fn? Presumably your wnd isderived from CWnd?

    The 'flashing' dialog is a chicken & egg problem. You have to be cautious with modal dialogs created wihin any c++ class because if the class goes out of scope the box dies. I can't remember the exact sequence of events but I remember reading &| discovering this....somewhere|sometime or other. Anyway make your dialog wnd obj a class local variable rather than a fn local variable and see if that works.

    I'd be curious to find out if any of this helps...?

  3. #3
    Registered User
    Join Date
    Aug 2001

    modeless dialog

    That is correct in your class declaration declare the dialog as a member...
    then create it in your ::OnCreate message handler...
    after creating it you must make a call to m_myModeles.ShowWindow( SW_SHOW );

    just remember to hide it and show it as needed ..
    and when you are done with it call its Destroy(...) method..ahem.. member function.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Thanks for the help.

    One more question; in an appwizard generated MDI the form names are MyProjectName, followed by a number, this number isnt really relevant in the program I am producing, so how do I remove it? If I take out the form name completely under the string table it calls my documents Untitled, without a number, but any valid character adds the number too. So I really have two questions.

    Where does the number after the document name come from, and how can I remove it?

    Where does Untitled come from, and how can I change it?

    Thanks again

  5. #5
    Registered User
    Join Date
    Sep 2001

    Another question

    I have an MDI with a form, which has some tab controls and property sheets on it. From a menu command how do I create a new form which opens automatically at a tab I define, so from a menu command I could click page 2 and a new form would open at page 2? This is zMan's code/method which I am using for tab controls:

    void  CTykeView::CreateTabControl()
    pSheet = new CPropertySheet( "My Tab", this, 0); 
    pSheet->AddPage( &m_Page1 ); 
    pSheet->AddPage( &m_Page2 ); 
    pSheet->AddPage( &m_Page3 ); 
    pSheet->Create( this, WS_CHILD | WS_VISIBLE ); 
    //** Create a static text with the resource editor where you 
    //** would like to position your control and bind a CStatic 
    //** member to it... you must change the default idd from 
    //** IDC_STATIC to IDC_STATIC1 or something more meaningfull 
    CRect r; 
    m_staticPlaceHolder.GetWindowRect( &r ); 
    ScreenToClient( &r ); 
    //** reposition the window where you want it..... 
    pSheet->SetWindowPos( pSheet,, r.left, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); 

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows Forms and/or MFC [But definately not win32!] questions
    By Robert_Sitter in forum Windows Programming
    Replies: 2
    Last Post: 12-03-2005, 09:28 PM
  2. MFC: CStrings & binary files question(s)
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-24-2004, 05:41 PM
  3. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  4. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  5. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 06:58 PM