Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can';为什么不能创建同一类的多个窗口?_C++_Mfc - Fatal编程技术网

C++ Can';为什么不能创建同一类的多个窗口?

C++ Can';为什么不能创建同一类的多个窗口?,c++,mfc,C++,Mfc,我是MFC的新手,所以这个问题可能很愚蠢,但我自己似乎找不到答案,所以我来回答 我有一个从CWnd派生的自定义窗口控件。当我在对话框中只使用该控件的一个实例时,一切正常。现在,我尝试创建以下几个实例: for (int i = 0; i < 10; i++) { control[i] = new CMyControl; control[i]->CreateEx(exStyle, name, "", style, CRect(i * 10, 0, 10, 10),

我是MFC的新手,所以这个问题可能很愚蠢,但我自己似乎找不到答案,所以我来回答

我有一个从CWnd派生的自定义窗口控件。当我在对话框中只使用该控件的一个实例时,一切正常。现在,我尝试创建以下几个实例:

for (int i = 0; i < 10; i++)
{
    control[i] = new CMyControl;
    control[i]->CreateEx(exStyle, name, "", style, CRect(i * 10, 0, 10, 10), 
                         this, IDC_FIRST + i, 0);
}
class CMyControl : public CWnd
{
public: 
    CMyControl()
    {
        m_ClassName = AfxRegisterWndClass(
                    CS_VREDRAW | CS_HREDRAW,
                    ::LoadCursor(NULL, IDC_ARROW),
                    (HBRUSH) ::GetStockObject(WHITE_BRUSH),
                    ::LoadIcon(NULL, IDI_APPLICATION));
    } 

    LPCTSTR GetClassName() const {return m_ClassName;}

protected:    

    afx_msg int OnCreate(LPCREATESTRUCT) {return 0;}
    afx_msg void OnPaint() {}

DECLARE_MESSAGE_MAP()

private:   
    LPCTSTR m_ClassName;
};

BEGIN_MESSAGE_MAP(CMyControl, CWnd)
    ON_WM_CREATE()
    ON_WM_PAINT()    
END_MESSAGE_MAP()

//then, in my main dialog's OnInitDialog,

BOOL CMyDialog::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    CMyControl* controls[10];

    for (unsigned int i = 0; i < 10; i++)
    {
        controls[i] = new CMyControl;
        controls[i]->CreateEx(WS_EX_CLIENTEDGE, controls[i]->GetClassName(), L"", 
        WS_CHILD | WS_VISIBLE, CRect(i*10, 0, 10, 10), this, 1006 + i, 0);
    }
    return TRUE;
}
参数是左/右/上/下,而不是左/右/宽/高


很抱歉。

如果您添加了一个完整的(可编译但最少的)示例程序来演示您的问题,那么回答这个问题就会容易得多。@Mankarse:我添加了一些代码,希望能有所帮助。@obamator,您可以回答自己的问题并接受它。这比把它编辑成问题更清楚。
CRect(i * 10, 0, 10, 10)