-
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?
-
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::DoModal.
-
SetWindowText to set the title in the top of the window frame if that's what you mean
-
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?
-
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.
-
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(....);
}