Sign in to follow this  
Renegadeandy

C++ MFC GUI Issues!

Recommended Posts

HI! Using VC 2005 to program some C++ stuff. Now, am dipping my toes into the world of MFC, and am trying to make this code segment work : #include <afxwin.h> class MFC_Tutorial_Window :public CFrameWnd { public: MFC_Tutorial_Window() { Create(NULL,"MFC Tutorial Part 1 CoderSource Window"); } }; class MyApp :public CWinApp { MFC_Tutorial_Window *wnd; public: BOOL InitInstance() { wnd = new MFC_Tutorial_Window(); m_pMainWnd = wnd; m_pMainWnd->ShowWindow(1); return 1; } }; MyApp theApp; However - what it reports is the following error: WINVER not defined. Defaulting to 0x0502 (Windows Server 2003) c:\documents and settings\andy\my documents\visual studio 2005\projects\upsetpc\upsetpc\main.cpp(8) : error C2664: 'CFrameWnd::Create' : cannot convert parameter 2 from 'const char [39]' to 'LPCTSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Could anybody offer any insight into this error? Thanks very much Andy

Share this post


Link to post
Share on other sites
Looks like the project is setup to use Unicode.

Use the TEXT macro:

Create( NULL, TEXT( "MFC Tutorial Part 1 CoderSource Window" ) );


This will tell the compiler that the text literal should be inserted as Unicode if the project requires it.

Share this post


Link to post
Share on other sites
On a side note, don't Create the window in the class constructor - as you don't have much control on the return value of Create() - if an error occurs, it just goes unnoticed (of course, you can throw an exception to handle the problem).

Construtors should only be used to initialize class members.

Your best bet if to explicitely call Create() in the InitInstance() method - that's how it's done generally.

Best regards, and good luck with the MFC [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by Renegadeandy
Hi! Thanks verry much - Sure it will go ok.

Cannot find any decent tutorials however. Can you suggest any?


Code Project has a very decent MFC article collection - filled with tutorials and code. I used it very often.

Best regards,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this