Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
29Activity
0 of .
Results for:
No results containing your search query
P. 1
Yashwant Kanitker - VC++, COM and Beyond

Yashwant Kanitker - VC++, COM and Beyond

Ratings:

4.5

(2)
|Views: 1,918 |Likes:
Published by api-3708828

More info:

Published by: api-3708828 on Oct 14, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

V
C++ programs are either generated through AppWizard and ClassWizard or are hand coded
by the programmer. It is often found that programmers are able to build reasonably

complicated applications without a clear understanding of how the program works. Similarly, many programmers are able to tackle various Windows messages using the message maps. However, when it comes to knowing how a message gets transformed into a call to a message handler there is utter confusion. We think that it is imperative to understand the working of the VC++ program and the message maps before we can venture into advanced VC++ topics. Towards this end we would write a simple program that displays a message in a window. Then we would examine in detail the working of this program. Here is the program\u2026

Program 1
myapp.h
class myapp : public CWinApp
{
public :
1
How
VC++
Programs
Work
2
VC++, COM and Beyond
BOOL InitInstance( ) ;
};
myapp.cpp

#include <afxwin.h>
#include "myframe.h"
#include "myapp.h"

myapp a ;
BOOL myapp::InitInstance( )

{
myframe *p ;
p = new myframe ;
m_pMainWnd = p ;

p -> ShowWindow ( SW_SHOWNORMAL ) ;
return TRUE ;
}myframe.h
class myframe : public CFrameWnd
{
public :
myframe( ) ;
void OnPaint( ) ;
DECLARE_MESSAGE_MAP( )
};
myframe.cpp
#include <afxwin.h>
#include "myframe.h"
BEGIN_MESSAGE_MAP ( myframe, CFrameWnd )
ON_WM_PAINT( )
END_MESSAGE_MAP( )
myframe::myframe( )
{
Create ( 0, "Draw" ) ;
Chapter 1: How VC++ Programs Work
3
}void myframe::OnPaint( )

{
CPaintDC d ( this ) ;
d.TextOut ( 50, 50, "Hello", 5 ) ;

}
Is it necessary to keep different classes in separate
files?

We are not bound by any rule to do so. However, we are bound by tradition. Among C++ programmers it is a tradition to write the class declarations in.h files and class implementations in.cpp files. We too would follow this strategy throughout this book. For small programs this might appear to be an overkill. But in large programs containing numerous classes it is worthwhile to give each class its own.h and.cpp files. The same convention has been followed while storing the files on the CD accompanying this book.

Once we create the.h and.cpp files we must include the
.cpp files in the current project using the \u2018Project | Add
to Project | Files\u2019 menu option.
On execution of this program the window shown in Figure 1-1 gets displayed.
Figure 1-1.A window with a message.
This program has two principal components:
Important Stuff

Activity (29)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
sudhansukanungo liked this
varunpandeyengg liked this
avis123 liked this
liya_lion liked this
sreelalrama liked this
manjunathp079030 liked this
nitinlomte07 liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->