Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Compile Errors with GLCanvas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Compile Errors with GLCanvas
#4661
Posted by: 2004-06-28 19:32:11
Hello,

I have the following files:

-------------------------------------------------
Contents of constants.h
-------------------------------------------------

#ifndef CONSTANTS_H
#define CONSTANTS_H
#include "wx/wx.h"
#endif
-------------------------------------------------
Contents of myglcanvas.h
-------------------------------------------------

#ifndef MYGLCANVAS_H
#define MYGLCANVAS_H
#include "wx/glcanvas.h"

class MyGLCanvas : public wxGLCanvas
{
public:
    MyGLCanvas(wxWindow*, const wxString& title);

    void OnSize(wxSizeEvent&);
    void OnPaint( wxPaintEvent&);
    void OnEraseBackground(wxEraseEvent&);
    void OnMouse(wxMouseEvent&);
    ~MyGLCanvas();

private:
	DECLARE_EVENT_TABLE()
};
#endif

-------------------------------------------------
Contents of myglcanvas.cpp
-------------------------------------------------

#include "MyGLCanvas.h"

BEGIN_EVENT_TABLE(MyGLCanvas, wxGLCanvas)
    EVT_SIZE(MyGLCanvas::OnSize)
    EVT_PAINT(MyGLCanvas::OnPaint)
    EVT_ERASE_BACKGROUND(MyGLCanvas::OnEraseBackground)
    EVT_MOUSE_EVENTS(MyGLCanvas::OnMouse)
END_EVENT_TABLE()

// constructor
MyGLCanvas::MyGLCanvas(wxWindow* parent, const wxString& title)
       : wxGLCanvas(parent, -1, wxDefaultPosition, wxSize(300,
	   300), wxDEFAULT_FRAME_STYLE)
{
	Centre(wxBOTH);
}
void MyGLCanvas::OnPaint( wxPaintEvent& event )
{
    wxPaintDC dc(this);
}
void MyGLCanvas::OnSize(wxSizeEvent& event)
{
}
void MyGLCanvas::OnEraseBackground(wxEraseEvent& event)
{
}
void MyGLCanvas::OnMouse( wxMouseEvent& event )
{
}
MyGLCanvas::~MyGLCanvas() {
}
-------------------------------------------------
Contents of winmain.h
-------------------------------------------------

#ifndef WINMAIN_H
#define WINMAIN_H
#include "Constants.h"
const int WIN_MAIN_WIDTH = 400;
const int WIN_MAIN_HEIGHT = 400;
class WinMain : public wxFrame
{
public:
  
    WinMain();
    WinMain(wxFrame*, const wxString& title);

private:
	
};

#endif


-------------------------------------------------
Contents of winmain.cpp
-------------------------------------------------

#include "WinMain.h"
// constructor
WinMain::WinMain(wxFrame* parent, const wxString& title)
       : wxFrame(parent, -1, title, wxDefaultPosition, wxSize(WIN_MAIN_WIDTH,
	   WIN_MAIN_HEIGHT), wxDEFAULT_FRAME_STYLE)
{
	Centre(wxBOTH);
}

-------------------------------------------------
Contents of main.cpp
-------------------------------------------------
[code]
#include "WinMain.h"
#include "MyGLCanvas.h"

class MyApp : public wxApp
{
public:
       virtual bool OnInit();
};

bool MyApp::OnInit()
{

    // create the main application window
    WinMain* myWin = new WinMain(NULL, "test");


    //SetTopWindow(myWin);
    //myWin->Show(TRUE);
    return true;
}

IMPLEMENT_APP(MyApp);
-------------------------------------------------


When I compile, I get the following errors on Windows XP using VS Studio 6, SP 5

--------------------Configuration: CDGL - Win32 Debug--------------------
Compiling...
main.cpp
main.cpp(31) : error C2065: 'myWin' : undeclared identifier
main.cpp(31) : error C2296: '*' : illegal, left operand has type 'int (__stdcall *)(struct HINSTANCE__ *,struct HINSTANCE__ *,char *,int)'
main.cpp(31) : error C2061: syntax error : identifier 'WinMain'
main.cpp(38) : error C2227: left of '->Show' must point to class/struct/union
CDGL\main.cpp(44) : error C2143: syntax error : missing ';' before '}'

The last line error C2143 repeats on about 90 times.

It's acting as if it doesn't recogonize my WinMain class.  If I comment out the line "#include "MyGLCanvas.h"" in main.cpp, it compiles fine.  Also, I can compile and run the OpenGL wxWindow examples, so it is not a matter of setting up my setup.h under wx or anything like that I can think of.  Does anyone know what I'm doing wrong?
Message2. Re: Compile Errors with GLCanvas
#4662
Posted by: 2004-06-28 21:00:19
Hmm.  I think the source of the error may be that I'm calling my class "WinMain".  Is this some sort of reserved word?
Message3. Re: Compile Errors with GLCanvas
#4663
Posted by: 2004-06-28 21:07:40
Ok, I found the error.

I changed the name of my class from "WinMain" to something else, and this solved the problem (of course properly altering main to accomdate the name change).

Anyone have any idea why the name "WinMain" for a class would have caused a problem?

Thanks,

-Tyler

Message4. Re: Compile Errors with GLCanvas
#4667
Posted by: upCASE 2004-06-29 02:52:56
Hi!
Yes. WinMain is the default entry point for windows apps. It's just like int main() but for windows. Somewhere deep inside wxWidgets (wxApp) WinMain will be used as your entry point from where everything start. Thus using it as a class name leads to trouble.
Ever tried to name a class "main" in a normal console project? :)
upCASE
-----------------------------------
If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message5. Re: Compile Errors with GLCanvas
#4682
Posted by: 2004-06-30 01:25:26
Ha.  that's funny.  i would never dream of naming a class "main", that'd be an obvious name conflict, it's just funny I happened to hit winmain right on the nose without knowing it.

thanks for the help.

-Tyler

Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥738.00 ·
 
 
¥1,480.00 ·
 
 
¥397.00 ·
 
 
¥950.00 ·
 
 
¥264.00 ·
 
 
¥1,005.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0