Solved

utilizing mfc class functionality

Posted on 2004-09-20
5
183 Views
Last Modified: 2013-11-20
hi all,
  Is it right that you can use the functionality of a class even though you don't instantiate that class and create an object?? For example, when you use AfxGetApp() function, it returns a pointer to a CWinApp class.  But if I never instantiated an object of that class, then what is it pointing to?

0
Comment
Question by:struggling_coder_3203
  • 2
  • 2
5 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 12107372
About specific case of AfxGetApp() function: In every MFC application generated with appWizard, a CWinApp class derived object is created. It is called 'theApp', so AfxGetApp() returns a pointer to this class.
Also, static class functions, can be used without instantiating a class. For example

CWnd::FromHandle(HWND hWnd) is a static function that returns a pointer to a window based in its handle number.

CTime::GetCurrentTime() returns an CTime object corresponding to current date/time, it is similar to time(NULL) function. You don't need a previous object to call it.
0
 

Author Comment

by:struggling_coder_3203
ID: 12107487
so an object of a class must be instantiated in order to use the functionality???
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12107507
If you plan to use non-static functions, definitively YES.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12109933
Functions can be defined as static and, by default, non-static.
Roughly a static function does not require any initialisation that would be performed in the constructor of the class.  This allows one to call a static function of a class without it being instantated.
Give it a try - create a new class yourself and do something like in the header
static int MyStaticFn() {return 2;};
now in your prog do
int x = CMyTestClass::MyStaticFn();
x now has the value 2.
0
 

Author Comment

by:struggling_coder_3203
ID: 12128732
so, are all mfc classes static in a wizard generated application????????????????????????????
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question