GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Sep-2007, 02:18
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Simple Window Application Using MFC


Hello everyone, i truly new to window programming.

My code as below:

CPP / C++ / C Code:
#pragma once

#include<afxwin.h>

// All application derived from the CWinApp
// Our application name CExerciseApp
class CExerciseApp : public CWinApp  // Class-For-A-Windows-Application
{
public:
	bool InitInstance();  
    /* To check the application has 
	   successful created
	*/
};

/* We need to display our application.
   Therefore, we need a frame in windows
   which is CFrameWnd
*/

// The main frame of the application 

class CMainFrame : public CFrameWnd 
{
public:
	CMainFrame();
};

// Global variable of our application.
// Define global because it can be used by others
CExerciseApp theapp;




CPP / C++ / C Code:
#include<afxwin.h>
#include "Window.h"



int main(int argc, char *argv[])
{
	return 0;
}
// -----------------------------------------

// CExerciseApp Section

bool CExerciseApp::InitInstance()
{
	m_pMainWnd = new CMainFrame; 
    
	/* In order to provide a window to an application, 
	   you must create thread which is m_pMainWnd. 

	   Assign our CMainFrame to m_pMainWnd;
	*/
	
	m_pMainWnd->ShowWindow(SW_NORMAL);
	 m_pMainWnd->UpdateWindow();
	 
	 /* 
	    Display the CMainFrame as normal
	 */

	 /* CMainFrame *Frame = new CMainFrame();
		m_pMainWnd = Frame;

		Frame->ShowWindow(SW_NORMAL);
	 */ 
	return true;
}
// -----------------------------------------

// CMainFrame Section

CMainFrame::CMainFrame()
{
	LPCTSTR AppTitle = "MFC Fundametals";
	Create(0, AppTitle);
	// Class Name:0, Window Name:MFC Fundametals
}
/* BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
       DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault,
       CWnd* pParentWnd = NULL, LPCTSTR lpszMenuName = NULL, DWORD dwExStyle = 0,
       CCreateContext* pContext = NULL );
*/
// -------------------------------------------



/* CWinThread - m_pMainWnd(Global ptr)
       |
    CWinApp

*/

Error Message as below:

Quote:
Error 1 error C2555: 'CExerciseApp::InitInstance': overriding virtual function return type differs and is not covariant from 'CWinApp::InitInstance' d:\c++\window\window\window.h 14
Error 2 error C2440: 'initializing' : cannot convert from 'const char [16]' to 'LPCTSTR' d:\c++\window\window\window.cpp 44



Thanks for oyur help.

I really need your help.

Your help is greatly appreciated by me and others.
Last edited by LuciWiz : 09-Sep-2007 at 03:17. Reason: One of the code snipets didn't use [cpp] tags...
  #2  
Old 10-Sep-2007, 08:31
dlp dlp is offline
Member
 
Join Date: May 2006
Posts: 157
dlp has a spectacular aura about

Re: Simple Window Application Using MFC


1.
I believe what it's saying is your overload of InitInstance has a different return type which it can't have. What's the original return type of InitInstance from your base, CWinApp?

2.
LPCTSTR;
L Pointer to Const TCHAR string. It means it should be cast (I doubt I'm using that word right) to UNICODE, whereas right now, it's an ANSI string. Try this:
CPP / C++ / C Code:
LPCTSTR AppTitle = L"MFC Fundametals";
  #3  
Old 21-Sep-2007, 21:12
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Simple Window Application Using MFC


2 is solved by me but the first one. I still cannot solved it.


Thanks for your help.
  #4  
Old 23-Sep-2007, 00:20
coder1985 coder1985 is offline
New Member
 
Join Date: Sep 2007
Posts: 2
coder1985 is on a distinguished road

Re: Simple Window Application Using MFC


Quote:
Originally Posted by Peter_APIIT
Hello everyone, i truly new to window programming.

My code as below:

CPP / C++ / C Code:
#pragma once

#include<afxwin.h>

// All application derived from the CWinApp
// Our application name CExerciseApp
class CExerciseApp : public CWinApp  // Class-For-A-Windows-Application
{
public:
	bool InitInstance();  
    /* To check the application has 
	   successful created
	*/
};

/* We need to display our application.
   Therefore, we need a frame in windows
   which is CFrameWnd
*/

// The main frame of the application 

class CMainFrame : public CFrameWnd 
{
public:
	CMainFrame();
};

// Global variable of our application.
// Define global because it can be used by others
CExerciseApp theapp;




CPP / C++ / C Code:
#include<afxwin.h>
#include "Window.h"



int main(int argc, char *argv[])
{
	return 0;
}
// -----------------------------------------

// CExerciseApp Section

bool CExerciseApp::InitInstance()
{
	m_pMainWnd = new CMainFrame; 
    
	/* In order to provide a window to an application, 
	   you must create thread which is m_pMainWnd. 

	   Assign our CMainFrame to m_pMainWnd;
	*/
	
	m_pMainWnd->ShowWindow(SW_NORMAL);
	 m_pMainWnd->UpdateWindow();
	 
	 /* 
	    Display the CMainFrame as normal
	 */

	 /* CMainFrame *Frame = new CMainFrame();
		m_pMainWnd = Frame;

		Frame->ShowWindow(SW_NORMAL);
	 */ 
	return true;
}
// -----------------------------------------

// CMainFrame Section

CMainFrame::CMainFrame()
{
	LPCTSTR AppTitle = "MFC Fundametals";
	Create(0, AppTitle);
	// Class Name:0, Window Name:MFC Fundametals
}
/* BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
       DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault,
       CWnd* pParentWnd = NULL, LPCTSTR lpszMenuName = NULL, DWORD dwExStyle = 0,
       CCreateContext* pContext = NULL );
*/
// -------------------------------------------



/* CWinThread - m_pMainWnd(Global ptr)
       |
    CWinApp

*/

Error Message as below:



Thanks for oyur help.

I really need your help.

Your help is greatly appreciated by me and others.
I think that the function - bool InitInstance(); -
should be writen like this BOOL InitInstance();
and return type return TRUE;
  #5  
Old 24-Sep-2007, 06:20
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Simple Window Application Using MFC


The problem solved. The title should display this LPCTSTR AppTitle = "MFC Fundametals"; How come the title display in the bar is not what i wroted ?
  #6  
Old 28-Sep-2007, 02:34
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Simple Window Application Using MFC


The title bar display some unknown character such as [][[][]][][][][]][]. How to solve this ?
  #7  
Old 28-Sep-2007, 02:38
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: Simple Window Application Using MFC


As you all know the application frame us create calling the create method inside the constructor but how come we still need to send a message to the operating system and create the application frame.

CPP / C++ / C Code:
#pragma once

// Library of MFC
#include<afxwin.h>

// All application derived from the CWinApp
// Our application name CExerciseApp
class CExerciseApp : public CWinApp  // Class-For-A-Windows-Application
{
public:
	 BOOL InitInstance();  
    /* To check the application has 
	   successful created
	*/
};

/* We need to display our application.
   Therefore, we need a frame in windows
   which is CFrameWnd
*/

// The main frame of the application 
// All frame derived from CFrameWnd
class CMainFrame : public CFrameWnd 
{
public:
	CMainFrame();

protected:


// Messages event should declare above 
// this definition
	
	afx_msg int OnCreate(LPCREATESTRUCT lpcreatestruct);

// Place it at the end of the class definition
	DECLARE_MESSAGE_MAP()
};

// Global variable of our application.
// Define global because it can be used by others
CExerciseApp theapp;


CPP / C++ / C Code:
#include<afxwin.h>
#include<ctime>
#include<iostream>
#include "Window.h"

using std::cout;
using std::cin;

int main(int argc, char *argv[])
{
	return 0;
}
// -----------------------------------------

// CExerciseApp Section

BOOL CExerciseApp::InitInstance()
{
	m_pMainWnd = new CMainFrame; 
    
	/* In order to provide a window to an application, 
	   you must create thread(Small process) 
	   which is m_pMainWnd. 

	   Assign our CMainFrame to m_pMainWnd;
	*/
	
	m_pMainWnd->ShowWindow(SW_NORMAL);
	m_pMainWnd->UpdateWindow();
	m_pMainWnd->FlashWindow(1); // Flash the applicaiton in the Start Bar
	m_pMainWnd->BringWindowToTop();
	
	time_t current_t = time(0);
	
//  After 5 minutes destroy window
//	m_pMainWnd->DestroyWindow();
	
	 /* 
	    Display the CMainFrame as normal
	 */

	 /* CMainFrame *Frame = new CMainFrame();
		m_pMainWnd = Frame;

		Frame->ShowWindow(SW_NORMAL);
	 */ 
	return true;
}
// -----------------------------------------

// CMainFrame Section

CMainFrame::CMainFrame()
{
	LPCTSTR AppTitle = (LPCTSTR)"MFC Fundametals";
	
	Create(0, AppTitle);
	// Class Name:0, Window Name:MFC Fundametals
}
/* BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
       DWORD dwStyle = WS_OVERLAPPEDWINDOW, const RECT& rect = rectDefault,
       CWnd* pParentWnd = NULL, LPCTSTR lpszMenuName = NULL, DWORD dwExStyle = 0,
       CCreateContext* pContext = NULL );
*/
/* CWinThread - m_pMainWnd(Global ptr)
       |
    CWinApp

*/

// -------------------------------------------
int CMainFrame::OnCreate(LPCREATESTRUCT lpcreatestruct)
{
	// Called the base class to create the window
	if (CFrameWnd::OnCreate(lpcreatestruct) == 0)
	{
		LPCTSTR message = (LPCTSTR)"The Window was successfully created";
		MessageBox(message);
		return 0;
	}
	
	return -1;
	
}
// -------------------------------------------
/*  To implement messages(OOP)Parameter(Procedures),
    Starts with BEGIN_MESSAGE_MAP and end
	with END_MESSAGE_MAP
*/	
	BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)

		ON_WM_CREATE()
// This message called the CMainFrame create method
	
	END_MESSAGE_MAP()
// -------------------------------------------


I don't understand the window message handling techniques.


Thanks for your explanation and help.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Child window creation from a dialog based application CyberFriend MS Visual C++ / MFC Forum 0 06-Nov-2006 06:51
need help with a console menu system BullBuchanan C++ Forum 6 20-Aug-2006 14:46
help rajusb MS Visual C++ / MFC Forum 24 28-Nov-2005 22:35
Simple Calculator Application MOHAMMEDALI1989 Java Forum 1 06-Oct-2005 17:00
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 03:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:16.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.