Vector that creates new windows doesn't work (MFC)

This is a discussion on Vector that creates new windows doesn't work (MFC) within the Windows Programming forums, part of the Platform Specific Boards category; For some reason I am getting a lot of errors in what I thought would be a fairly simple application ...

  1. #1
    Shadow12345
    Guest

    Vector that creates new windows doesn't work (MFC)

    For some reason I am getting a lot of errors in what I thought would be a fairly simple application
    Code:
    #include <afxwin.h>
    #include <vector>
    
    
    
    class COurApp : public CWinApp {
    public:
    	virtual BOOL InitInstance();
    
    };
    
    class COurWnd: public CFrameWnd {
    public:
    	COurWnd() {
    		Create(0, "Charles is god");
    	}
    };
    
    BOOL COurApp::InitInstance() {
    	m_pMainWnd = new COurWnd;
    	m_pMainWnd->ShowWindow(m_nCmdShow);
    	return true;
    }
     
    std::vector<COurApp*> ApplicationVector;
    
    
    for(int NumOfWindows = 0; NumOfWindows < 5; NumOfWindows++) {
    ApplicationVector.push_back(new COurApp);
    }
    Here are the errors that I am getting (there are 12 of them and it is really stupid):
    --------------------Configuration: simplewindow - Win32 Debug--------------------
    Compiling...
    smpwnd1.cpp
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ';' before 'for'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ')' before ';'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ';' before '<'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2501: 'NumOfWindows' : missing storage-class or type specifiers
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ';' before '<'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ';' before '++'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2501: 'NumOfWindows' : missing storage-class or type specifiers
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2086: 'NumOfWindows' : redefinition
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ';' before '++'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2059: syntax error : ')'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2143: syntax error : missing ';' before '{'
    C:\Documents and Settings\04thibaultc\Desktop\simplewindow\simplewi ndow\smpwnd1.cpp(26) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.

    simplewindow.exe - 12 error(s), 0 warning(s)

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    this section of code
    Code:
    std::vector<COurApp*> ApplicationVector;
    
    for(int NumOfWindows = 0; NumOfWindows < 5; NumOfWindows++) {
    ApplicationVector.push_back(new COurApp);
    }
    is not inside a function.

    Your initinstance() closes after the return true.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Shadow12345
    Guest
    Oh I didn't know you can't do that at global space...so i just add some function?Like main()?

  4. #4
    Shadow12345
    Guest
    I really don't know how to change that program to do what i wanted...with mfc winmain is 'taken care of behind the scenes'

    should i just make a function that is a member of the COurApp class?

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    honestly I don't remember how that's handled in MFC. I would assume a member of the "CApp" class is where you create the window. But what the heck to I know. I'm a Win32API guy.

    all I can say is you can't execute code outside of any function.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Shadow12345
    Guest
    I'm going to make a class wiht COurApp as a member

    It'll work eventually

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I did a little research. InitInstance is apparently where you need to do the stuff that would have been in WinMain().
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 03:58 AM
  2. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 06:58 PM
  3. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 01:33 AM
  4. Getting Layered Windows to Work
    By Si in forum Windows Programming
    Replies: 3
    Last Post: 01-22-2002, 06:21 PM
  5. Replies: 6
    Last Post: 01-07-2002, 02:46 AM

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