Window
Message
Windows Procedure
Painting Window
Closing Window
Events generated from the keyboard, mouse
and operating system.
Win32c Program
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE,PWSTR pCmdLine,int nCmdShow)
{
const wchar_t CLASS_NAME[] = L”Sample Window Class”; //Register the window class
WNDCLASS wc ;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
//Create the window
HWND hwnd = CreateWindowEx(0,CLASS_NAME,L”Learn to Program Windows”, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULUT,NULL,NULL,hInstance,NULL);
if(hwnd == NULL)
return 0;
ShowWindow(hwnd, nCmdShow);
//Run the message loop
MSG msg;
while(GetMessage(&msg, NULL ,0 ,0))
{
TranslateMessage(&msg);
DispatchMessage((&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd,&ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLORWINDOW+1));
EndPaint(hwnd,&ps);
}
return 0;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
MFC Application Framework Example.
--------------------------------------------------
Class CMyApp : public CWinApp
{
public :
virtual BOOL InitInstance();
};
//frame window class
class CMyFrame : public CFrameWnd
{
public:
CMyFrame()
{
}
protected:
//afx_msg next two functions are part of the MFC library message dispatch system.
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
}
MyApp.cpp Sample MFC application
-----------------------------------------------------------------------------
#include <afxwin.h>
#include <myapp.h”
CMyApp theApp; //the one and only CMyApp object
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMyFrame(); //m_pWainWnd is a public member of CWinThread
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
BEGIN_MESSAGE_MAP(CMyFrame,CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT(()
END_MESSAGE_MAP()
CMyFrame::CMyFrame()
{
Create(NULL, “MYAPP Application”);
}
void CMyFrame::OnLButton(UINT nFlags,CPoint point)
{
TRACE(“Entering CMyFrame::OnLButtonDown - %lx,%d,%d\n”,nFlags,pont.x,point.y);
}
void CMyFrame::OnPaint()
{
CPaintDC dc(this);
dc.TextOut(0,0,”Hello word”);
}
On Application ShutDown()
Events that are Fire Down
Window is Destroyed
Exit from Message Loop
Exit from WinMain
1.It has five objects that involves
CWinApp,CFrameWnd,CDocument,CView,CDocTemplateClass
2.It is based on MVC architecture. (Model,View,Controller)
3.It supports two types of document view applications
Single document Interface application
Mulitple document Interface application
Serialize Method
void CStudentDoc::Serialize(CArchive& ar)
{
CObject::Serialize(ar);
if(ar.IsStoring())
ar << StudentNo << StudentName << StudentAddr;
else
ar >> StudentNo >> StudentName >> StudentAddr;
}
What is a Root base class?
Features of Root base class
Serialization Support
Runtime class Information
Dynamic creation
Diagnostic support
Thread and synchronization
What is thread?
How do to create thread?
Various synchronization objects available in VC++.
Q&A
Thank You