MFC simple question

This is a discussion on MFC simple question within the Windows Programming forums, part of the Platform Specific Boards category; Hi there Iím interested in building a MFC application which generates 5 or 10 windows when I press on a ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    2

    MFC simple question

    Hi there

    Iím interested in building a MFC application which generates 5 or 10 windows when I press on a button. The windows must have a certain name and position.

    I know some C and C++ but I don't know any windows GUI programming. I need this in order to modify a MFC application.

    Who can help me?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    What does certain name mean?
    Position can be set with CWnd::SetWindowPos.
    To show and create windows, you just need to create an instance of the appropriate class and call the member function CDialog:oModal.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    SetWindowText to set the title in the top of the window frame if that's what you mean
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    2
    Many thx Fib and Elysia. This is what I've did. I've 'duplicate' aboutbox resource and Ive build a class as this.

    Code:
    class CSecondWindow : public CDialog
    {
    public:
    	CSecondWindow();
    
    // Dialog Data
    	//{{AFX_DATA(CAboutDlg)
    	enum { IDD = IDD_ABOUTBOX1 };
    	//}}AFX_DATA
    
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CAboutDlg)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    	//}}AFX_VIRTUAL
    
    // Implementation
    protected:
    	//{{AFX_MSG(CAboutDlg)
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    public:
    //	afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
    public:
    	afx_msg void OnChildActivate();
    };
    #endif
    In the main class of my application I have:
    Code:
     CSecondWindow m_new_window1, m_new_window2....m_new_window5;
    and on a button click I have
    Code:
    m_new_window1.Create(IDD_ABOUTBOX1, this);
    m_new_window1.SetWindowTextA("one");
    ....
    m_new_window5.Create(IDD_ABOUTBOX1, this);
    m_new_window5.SetWindowTextA("five");
    Scenario:
    When a user use alt+shift or click in order to chose between one of the generated windows, how can I know which window has the focus?
    Last edited by dole.doug; 09-23-2008 at 09:22 AM.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Windows sends a message when a window receives focus. WM_SETFOCUS or something I think.
    When you receive it, store information is some global variable or something which tells which window currently has focus.
    I also believe there's a function IsFocus, but I can't be sure.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Add an OnKillFocus() handler (depends on which version of MSCV) and use GetParent() to find your main window.

    Then find the window getting focus (from the pNewWnd) in the m_new_window(s)

    PS:
    I would use an array for the windows.

    Code:
    //declare a constant size (in header)
    //so we can change the number of windows easily
    #define NUM_WNDS       5//number of new windows
    
    //declare array (in header)
    CSecondWindow m_NewWindows[NUM_WNDS];
    
    //use in a loop
    for(int i = 0; i < NUM_WNDS; i++)
    {
          m_NewWindow[i].CreateWindow(....);
          m_NewWindow[i].SetWindowText(....);
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC Question
    By sunbie in forum C++ Programming
    Replies: 0
    Last Post: 03-30-2005, 08:01 AM
  2. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  3. MFC CFileDialog question
    By VirtualAce in forum Windows Programming
    Replies: 3
    Last Post: 01-30-2005, 01:56 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Question about document/view app in MFC
    By hpy_gilmore8 in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2004, 07:51 PM

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