MODELESS
1)Run application wizard and choose single document
2)Create a dialog resource,IDP_DIALOG,Dialog class projdialog
a)Create a pointer to view window in construction
b)Define function create( ) then call base class create( ) function.
c)Define ON-OK,ON-CANCEL functions and post the message GOODBYE.
3)View class:
a)Create a pointer to dialog window with constructor.
b)Onleft mouse button class call create( ) of dialog class.
c)Define on goodbye function that destroy window.
d)Build and execute program.
CODE:
Projdialog.h
#define WM_GOODBYE WM_USER+5
private:
CView* m_pView;
public:
ProjDialog(CView* pView);
BOOL Create();
Projdialog.cpp:
Projdialog::Projdialog(CView* pView)
{
m_pview=pView;
}
BOOL Projdialog::Create()
{
Return CDialog::Create(Projdialog::IDD);
}
void Projdialog::OnOK()
{
if(m_pView!=NULL)
{
UpdateData(TRUE);
m_pView->PostMessage(WM_GOODBYE,IDOK);
}
else
CDialog::OnOK();
}
void Projdialog::OnCancel( )
{
if(m_pView!=NULL)
{
m_pView->PostMessage(WM_GOODBYE,IDCANCEL);
}
else
CDialog::OnCancel();
}
Projview.h
//Add this at the begning
Class Projdialog;
Private:
Projdialog *m_pDlg;
Protected:
//add this line after AFX_MSG and before DECLARE MESSAGE MAP
Afx_msg LRESULT OnGoodbye(WPARAM wparam,LPARAM lparam);
Projview.cpp
//Add after Begin_Message_Map but inside AFX_MSG_MAP
ON_MESSAGE(WM_GOODBYE,OnGoodbye);
#include “Projview.h”
#include “Projdialog.h”
Projview::Projview()
{
m_pDlg=new Projdialog(this);
}
Projview::~Projview()
{
delete m_pDlg;
}
void Projview::OnLButtonDown(UINT nFlags,CPoint point)
{
if(m_pDlg->Get SafeHwnd( )==0)
{
m_pDlg->Create( );
}
CView::OnLButtonDown(nFlags,point);
}
LRESULT Projview::OnGoodbye(WPARAM wparam,LPARAM lparam)
{
m_pDlg->DestroyWindow( );
Return 0;
}
Monday, April 19, 2010
modal
Modal
1)Run application wizard(exe)->SDI->Project name and location.
2)Create dialog resource IDD_DIALOG1 and dialog class projdialog
3)Define OnLButtonDown->click view.cpp
4)Define InitDialog
5)Execute.
CODE:
Modaldialogview.cpp
#include “resource.h”
#include "projdialog.h"
void CModView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Moddialog dlg;
dlg.DoModal();
CView::OnLButtonDown(nFlags, point);
}
projdialog.cpp
#include “resource.h”
#include "projdialog.h"
BOOL projdialog::OnInitDialog()
{
CListBox *plb=(CListBox*)GetDlgItem(IDC_LIST1);
plb->InsertString(-1,"ece");
plb->InsertString(-1,"it");
plb->InsertString(-1,"eee");
plb->InsertString(-1,"cse");
return TRUE;
}
1)Run application wizard(exe)->SDI->Project name and location.
2)Create dialog resource IDD_DIALOG1 and dialog class projdialog
3)Define OnLButtonDown->click view.cpp
4)Define InitDialog
5)Execute.
CODE:
Modaldialogview.cpp
#include “resource.h”
#include "projdialog.h"
void CModView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Moddialog dlg;
dlg.DoModal();
CView::OnLButtonDown(nFlags, point);
}
projdialog.cpp
#include “resource.h”
#include "projdialog.h"
BOOL projdialog::OnInitDialog()
{
CListBox *plb=(CListBox*)GetDlgItem(IDC_LIST1);
plb->InsertString(-1,"ece");
plb->InsertString(-1,"it");
plb->InsertString(-1,"eee");
plb->InsertString(-1,"cse");
return TRUE;
}
menu
menu
6.Window Procedure:
a)WM_PAINT:
i)Get the device context handle and coordinates of client area.
ii)Draw the text at the center of client area.
b)WM_COMMAND:
i)When the child window control is pressed,corresponding message is
sent to window procedure.
c)WM_LBUTTONDOWN:
Set the flag value to ‘1’
d)WM_MOUSEMOVE:
1.if the flag is set to ‘1’,get the device context handle
2.set the pixel value
e)WM_LBUTTONUP:
set the flag value to ‘0’
f)WM_DESTROY:
i)Post quit message that generates WM_DESTROY
g)Default:
Other messages are handled by default window procedure
HEADER FILES:
#define ID_FILE_NEW 9000
#define ID_FILE_OPEN 9001
#define ID_FILE_SAVE 9002
#define ID_FILE_EXIT 9003
#define ID_EDIT_CUT 8000
#define ID_EDIT_COPY 8001
#define ID_EDIT_PASTE 8002
#define ID_EDIT_CLEAR 8003
#define ID_DRAW_RECT 7000
#define ID_DRAW_ELLIPSE 7001
#define ID_DRAW_POLYGON 7002
SOURCE FILE:
#include"nn.h"
#include"windows.h"
WNDCLASS a;
int id;
static RECT rect;
static POINT apt[6];
static int flag=0,f=0,x1,y1,x2,y2,i=0;
LRESULT CALLBACK wndproc(HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
HDC hdc;
switch(x)
{
case WM_CREATE:
{
HMENU hmenu,hsubmenu;
hmenu=CreateMenu();
hsubmenu=CreatePopupMenu();
AppendMenu(hsubmenu,MF_STRING,ID_FILE_NEW,"&new");
AppendMenu(hsubmenu,MF_STRING,ID_FILE_OPEN,"&open");
AppendMenu(hsubmenu,MF_STRING,ID_FILE_SAVE,"&save");
AppendMenu(hsubmenu,MF_STRING,ID_FILE_EXIT,"&exit");
AppendMenu(hmenu,MF_STRING|MF_POPUP,(UINT) hsubmenu,"&file");
hsubmenu=CreatePopupMenu();
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_CUT,"&cut");
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_COPY,"©");
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_PASTE,"&paste");
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_CLEAR,"&clear");
AppendMenu(hmenu,MF_STRING|MF_POPUP,(UINT) hsubmenu,"&edit");
hsubmenu=CreatePopupMenu();
AppendMenu(hsubmenu,MF_STRING,ID_DRAW_RECT,"&rectangle");
AppendMenu(hsubmenu,MF_STRING,ID_DRAW_ELLIPSE,"&ellipse");
AppendMenu(hsubmenu,MF_STRING,ID_DRAW_POLYGON,"&polygon");
AppendMenu(hmenu,MF_STRING|MF_POPUP,(UINT) hsubmenu,"&draw");
SetMenu(hwnd,hmenu);}break;
case WM_LBUTTONDOWN:
x1=LOWORD(l);
y1=HIWORD(l);
if(flag==3)
{
apt[i].x=x1;
apt[i].y=y1;
hdc=GetDC(hwnd);
SetPixel(hdc,x1,y1,RGB(255,0,255));
ReleaseDC(hwnd,hdc);
if(i==5)
{
hdc=GetDC(hwnd);
Polygon(hdc,apt,6);
i=0;
ReleaseDC(hwnd,hdc);
return 0;
}
else
i++;
}
else
f=1;
return 0;
case WM_MOUSEMOVE:
x2=LOWORD(l);
y2=HIWORD(l);
if(f==1)
{
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
switch(flag)
{
case 1:
Rectangle(hdc,x1,y1,x2,y2);
break;
case 2:
Ellipse(hdc,x1,y1,x2,y2);
break;
}
SetRect(&rect,x1,y1,x2,y2);
ReleaseDC(hwnd,hdc);
}
return 0;
case WM_LBUTTONUP:
f=0;
SetRect(&rect,0,0,0,0);
return 0;
case WM_COMMAND:
switch(LOWORD(w))
{
case ID_FILE_NEW:
case ID_FILE_OPEN:
case ID_FILE_SAVE:
MessageBeep(0);
return 0;
case ID_FILE_EXIT:
id=MessageBox(hwnd,"do u want to exit","exiting",MB_OKCANCEL);
if(id==0)
PostQuitMessage(0);
break;
case ID_EDIT_CUT:
case ID_EDIT_COPY:
case ID_EDIT_PASTE:
case ID_EDIT_CLEAR:
case ID_DRAW_RECT:
flag=1;
return 0;
case ID_DRAW_ELLIPSE:
flag=2;
break;
case ID_DRAW_POLYGON:
flag=3;
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);break;
default:
return DefWindowProc(hwnd,x,w,l);
}return 0;}
6.Window Procedure:
a)WM_PAINT:
i)Get the device context handle and coordinates of client area.
ii)Draw the text at the center of client area.
b)WM_COMMAND:
i)When the child window control is pressed,corresponding message is
sent to window procedure.
c)WM_LBUTTONDOWN:
Set the flag value to ‘1’
d)WM_MOUSEMOVE:
1.if the flag is set to ‘1’,get the device context handle
2.set the pixel value
e)WM_LBUTTONUP:
set the flag value to ‘0’
f)WM_DESTROY:
i)Post quit message that generates WM_DESTROY
g)Default:
Other messages are handled by default window procedure
HEADER FILES:
#define ID_FILE_NEW 9000
#define ID_FILE_OPEN 9001
#define ID_FILE_SAVE 9002
#define ID_FILE_EXIT 9003
#define ID_EDIT_CUT 8000
#define ID_EDIT_COPY 8001
#define ID_EDIT_PASTE 8002
#define ID_EDIT_CLEAR 8003
#define ID_DRAW_RECT 7000
#define ID_DRAW_ELLIPSE 7001
#define ID_DRAW_POLYGON 7002
SOURCE FILE:
#include"nn.h"
#include"windows.h"
WNDCLASS a;
int id;
static RECT rect;
static POINT apt[6];
static int flag=0,f=0,x1,y1,x2,y2,i=0;
LRESULT CALLBACK wndproc(HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
HDC hdc;
switch(x)
{
case WM_CREATE:
{
HMENU hmenu,hsubmenu;
hmenu=CreateMenu();
hsubmenu=CreatePopupMenu();
AppendMenu(hsubmenu,MF_STRING,ID_FILE_NEW,"&new");
AppendMenu(hsubmenu,MF_STRING,ID_FILE_OPEN,"&open");
AppendMenu(hsubmenu,MF_STRING,ID_FILE_SAVE,"&save");
AppendMenu(hsubmenu,MF_STRING,ID_FILE_EXIT,"&exit");
AppendMenu(hmenu,MF_STRING|MF_POPUP,(UINT) hsubmenu,"&file");
hsubmenu=CreatePopupMenu();
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_CUT,"&cut");
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_COPY,"©");
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_PASTE,"&paste");
AppendMenu(hsubmenu,MF_STRING,ID_EDIT_CLEAR,"&clear");
AppendMenu(hmenu,MF_STRING|MF_POPUP,(UINT) hsubmenu,"&edit");
hsubmenu=CreatePopupMenu();
AppendMenu(hsubmenu,MF_STRING,ID_DRAW_RECT,"&rectangle");
AppendMenu(hsubmenu,MF_STRING,ID_DRAW_ELLIPSE,"&ellipse");
AppendMenu(hsubmenu,MF_STRING,ID_DRAW_POLYGON,"&polygon");
AppendMenu(hmenu,MF_STRING|MF_POPUP,(UINT) hsubmenu,"&draw");
SetMenu(hwnd,hmenu);}break;
case WM_LBUTTONDOWN:
x1=LOWORD(l);
y1=HIWORD(l);
if(flag==3)
{
apt[i].x=x1;
apt[i].y=y1;
hdc=GetDC(hwnd);
SetPixel(hdc,x1,y1,RGB(255,0,255));
ReleaseDC(hwnd,hdc);
if(i==5)
{
hdc=GetDC(hwnd);
Polygon(hdc,apt,6);
i=0;
ReleaseDC(hwnd,hdc);
return 0;
}
else
i++;
}
else
f=1;
return 0;
case WM_MOUSEMOVE:
x2=LOWORD(l);
y2=HIWORD(l);
if(f==1)
{
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
switch(flag)
{
case 1:
Rectangle(hdc,x1,y1,x2,y2);
break;
case 2:
Ellipse(hdc,x1,y1,x2,y2);
break;
}
SetRect(&rect,x1,y1,x2,y2);
ReleaseDC(hwnd,hdc);
}
return 0;
case WM_LBUTTONUP:
f=0;
SetRect(&rect,0,0,0,0);
return 0;
case WM_COMMAND:
switch(LOWORD(w))
{
case ID_FILE_NEW:
case ID_FILE_OPEN:
case ID_FILE_SAVE:
MessageBeep(0);
return 0;
case ID_FILE_EXIT:
id=MessageBox(hwnd,"do u want to exit","exiting",MB_OKCANCEL);
if(id==0)
PostQuitMessage(0);
break;
case ID_EDIT_CUT:
case ID_EDIT_COPY:
case ID_EDIT_PASTE:
case ID_EDIT_CLEAR:
case ID_DRAW_RECT:
flag=1;
return 0;
case ID_DRAW_ELLIPSE:
flag=2;
break;
case ID_DRAW_POLYGON:
flag=3;
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CLOSE:
DestroyWindow(hwnd);break;
default:
return DefWindowProc(hwnd,x,w,l);
}return 0;}
Button
Button
6.Window Procedure:
a)WM_PAINT:
i)Get the device context handle and coordinates of client area.
ii)Draw the text at the center of client area.
b)WM_COMMAND:
i)When the child window control is pressed,corresponding message is
sent to window procedure.
c)WM_LBUTTONDOWN:
Set the flag value to ‘1’
d)WM_MOUSEMOVE:
1.if the flag is set to ‘1’,get the device context handle
2.set the pixel value
e)WM_LBUTTONUP:
set the flag value to ‘0’
f)WM_DESTROY:
i)Post quit message that generates WM_DESTROY
g)Default:
Other messages are handled by default window procedure.
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM lp)
{
HDC hdc;
HWND h1,h2,h3;
static RECT rect;
switch(x)
{
case WM_CREATE:
h1=CreateWindow("button","rect",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,80,60,60,hwnd,(HMENU)1,hinst,0);
h2=CreateWindow("button","ellipse",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,10,60,60,hwnd,(HMENU)2,hinst,0);
h3=CreateWindow("button","poly",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,200,60,60,hwnd,(HMENU)3,hinst,0);
return 0;
case WM_COMMAND:
if(LOWORD(w)==1 && HIWORD(w)==0)
f=1;
else if(LOWORD(w)==2 && HIWORD(w)==0)
f=2;
else if(LOWORD(w)==3 && HIWORD(w)==0)
f=3;
break;
case WM_LBUTTONDOWN:
x1=LOWORD(lp);
y1=HIWORD(lp);
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
if(f==3)
{
c[i].x=x1;
c[i].y=y1;
i++;
SetPixel(hdc,x1,y1,RGB(255,0,0));
}
if(i==6)
{
Polygon(hdc,c,6);
i=0;
}
flag=1;
ReleaseDC(hwnd,hdc);
break;
case WM_MOUSEMOVE:
if(flag==1)
{
x2=LOWORD(lp);
y2=HIWORD(lp);
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
rect.left=x1;
rect.bottom=y2;
rect.top=y1;
rect.right=x2;
if(f==1)
Rectangle(hdc,x1,y1,x2,y2);
else if(f==2)
Ellipse(hdc,x1,y1,x2,y2);
ReleaseDC(hwnd,hdc);
}
break;
case WM_LBUTTONUP:
flag=0;
SetRect(&rect,0,0,0,0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,lp);
}
}
6.Window Procedure:
a)WM_PAINT:
i)Get the device context handle and coordinates of client area.
ii)Draw the text at the center of client area.
b)WM_COMMAND:
i)When the child window control is pressed,corresponding message is
sent to window procedure.
c)WM_LBUTTONDOWN:
Set the flag value to ‘1’
d)WM_MOUSEMOVE:
1.if the flag is set to ‘1’,get the device context handle
2.set the pixel value
e)WM_LBUTTONUP:
set the flag value to ‘0’
f)WM_DESTROY:
i)Post quit message that generates WM_DESTROY
g)Default:
Other messages are handled by default window procedure.
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM lp)
{
HDC hdc;
HWND h1,h2,h3;
static RECT rect;
switch(x)
{
case WM_CREATE:
h1=CreateWindow("button","rect",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,80,60,60,hwnd,(HMENU)1,hinst,0);
h2=CreateWindow("button","ellipse",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,10,60,60,hwnd,(HMENU)2,hinst,0);
h3=CreateWindow("button","poly",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,20,200,60,60,hwnd,(HMENU)3,hinst,0);
return 0;
case WM_COMMAND:
if(LOWORD(w)==1 && HIWORD(w)==0)
f=1;
else if(LOWORD(w)==2 && HIWORD(w)==0)
f=2;
else if(LOWORD(w)==3 && HIWORD(w)==0)
f=3;
break;
case WM_LBUTTONDOWN:
x1=LOWORD(lp);
y1=HIWORD(lp);
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
if(f==3)
{
c[i].x=x1;
c[i].y=y1;
i++;
SetPixel(hdc,x1,y1,RGB(255,0,0));
}
if(i==6)
{
Polygon(hdc,c,6);
i=0;
}
flag=1;
ReleaseDC(hwnd,hdc);
break;
case WM_MOUSEMOVE:
if(flag==1)
{
x2=LOWORD(lp);
y2=HIWORD(lp);
hdc=GetDC(hwnd);
InvalidateRect(hwnd,&rect,TRUE);
GetUpdateRect(hwnd,&rect,TRUE);
ValidateRect(hwnd,&rect);
rect.left=x1;
rect.bottom=y2;
rect.top=y1;
rect.right=x2;
if(f==1)
Rectangle(hdc,x1,y1,x2,y2);
else if(f==2)
Ellipse(hdc,x1,y1,x2,y2);
ReleaseDC(hwnd,hdc);
}
break;
case WM_LBUTTONUP:
flag=0;
SetRect(&rect,0,0,0,0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,lp);
}
}
Stroke
Stroke
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM l);
{
HDC hdc;
char buffer[100];
TCHAR szkeyname[30];
switch(x)
{
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
hdc=GetDC(hwnd);
InvalidateRect(hwnd,NULL,TRUE);
GetUpdateRect(hwnd,NULL,TRUE);
ValidateRect(hwnd,NULL);
GetKeyNameText(l,szkeyname,sizeof(szkeyname)/sizeof(TCHAR));
TextOut(hdc,0,0,"keypressed",12);
TextOut(hdc,120,0,szkeyname,strlen(szkeyname));
sprintf(buffer,"keypressed=%d",w);
TextOut(hdc,0,50,buffer,strlen(buffer));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM l);
{
HDC hdc;
char buffer[100];
TCHAR szkeyname[30];
switch(x)
{
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
hdc=GetDC(hwnd);
InvalidateRect(hwnd,NULL,TRUE);
GetUpdateRect(hwnd,NULL,TRUE);
ValidateRect(hwnd,NULL);
GetKeyNameText(l,szkeyname,sizeof(szkeyname)/sizeof(TCHAR));
TextOut(hdc,0,0,"keypressed",12);
TextOut(hdc,120,0,szkeyname,strlen(szkeyname));
sprintf(buffer,"keypressed=%d",w);
TextOut(hdc,0,50,buffer,strlen(buffer));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;
Free hand I and II
FREE HAND DRAWING-1&II
6.Window Procedure(I&II)
a) WM_LBUTTONDOWN:
i)Set a flag value
b) WM_MOUSEMOVE:
i)Set the pixel if flag is true
ii)Print the pixel
c) WM_LBUTTONUP:
i)Reset the flag value
d)WM_DESTROY
Post quit Message that generates WM_QUIT
e) Default:
Other messages are handled by the default window procedure.
I
Int flag=0;
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
switch(x)
{
case WM_LBUTTONDOWN:
flag=1;break;
case WM_MOUSEMOVE:
if(flag==1)
{
hdc=GetDC(hwnd);
SetPixel(hdc,LOWRD(l),HIWORD(l),RGB(255,255.255));
ReleaseDC(hwnd,hdc);
}
Break;
case WM_LBUTTONUP:
flag=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;}
II
Int flag=0;
Int x1,y1,x2,y2;
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
switch(x)
{
case WM_LBUTTONDOWN:
if(flag==0)
{
x1=LOWORD(l);
y1=HIWORD(l);
flag=1;
}
break;
case WM_MOUSEMOVE:
if(flag==1)
{
x2=LOWORD(l);
y2=HIWORD(l);
hdc = GetDC(hwnd);
MOVETOEX(hdc,x1,y1,0);
LineTo(hdc,x2,y2);
ReleaseDC(hwnd,hdc);
x1=x2;
y1=y2;
}
break;
case WM_LBUTTONUP:
flag=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}return 0;}
KEYBOARD EVENTS-PROCESSING CHARACTER MESSAGES
6.window procedure
a)WM_CHAR: -It is used to handle character keys.
b)InvalidateRect is used for making variable invalid.
c)GetUpdateRect is used for returning co-ordinate value of client area and validate client area.
d)GetKeyNameText is used to get keys name.
e)WM_DESTROY:
Post Quit Message that generates WM_QUIT.
f)default:
Other messages are handled by the default window procedure.
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
HDC hdc;char buffer[100];
TCHAR szkeyname[30];
switch(x)
{
case WM_CHAR:
hdc=GetDC(hwnd);
InvalidateRect(hwnd,NULL,TRUE);
GetUpdateRect(hwnd,NULL,TRUE);
ValidateRect(hwnd,NULL);
GetKeyNameText(1,szkeyname,sizeof(szkeyname)/sizeof(TCHAR));
wsprintf(buffer,"keypressed=%c",w);
TextOut(hdc,0,20,buffer,strlen(buffer));
TextOut(hdc,120,0,szkeyname,strlen(szkeyname));
wsprintf(buffer,"keypressed=%d",w);
TextOut(hdc,0,50,buffer,strlen(buffer));
break;
case WM_DESTROY:
PostQuitMessage(0);break;
default:return DefWindowProc(hwnd,x,w,l);
}return 0;}
6.Window Procedure(I&II)
a) WM_LBUTTONDOWN:
i)Set a flag value
b) WM_MOUSEMOVE:
i)Set the pixel if flag is true
ii)Print the pixel
c) WM_LBUTTONUP:
i)Reset the flag value
d)WM_DESTROY
Post quit Message that generates WM_QUIT
e) Default:
Other messages are handled by the default window procedure.
I
Int flag=0;
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
switch(x)
{
case WM_LBUTTONDOWN:
flag=1;break;
case WM_MOUSEMOVE:
if(flag==1)
{
hdc=GetDC(hwnd);
SetPixel(hdc,LOWRD(l),HIWORD(l),RGB(255,255.255));
ReleaseDC(hwnd,hdc);
}
Break;
case WM_LBUTTONUP:
flag=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;}
II
Int flag=0;
Int x1,y1,x2,y2;
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
switch(x)
{
case WM_LBUTTONDOWN:
if(flag==0)
{
x1=LOWORD(l);
y1=HIWORD(l);
flag=1;
}
break;
case WM_MOUSEMOVE:
if(flag==1)
{
x2=LOWORD(l);
y2=HIWORD(l);
hdc = GetDC(hwnd);
MOVETOEX(hdc,x1,y1,0);
LineTo(hdc,x2,y2);
ReleaseDC(hwnd,hdc);
x1=x2;
y1=y2;
}
break;
case WM_LBUTTONUP:
flag=0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}return 0;}
KEYBOARD EVENTS-PROCESSING CHARACTER MESSAGES
6.window procedure
a)WM_CHAR: -It is used to handle character keys.
b)InvalidateRect is used for making variable invalid.
c)GetUpdateRect is used for returning co-ordinate value of client area and validate client area.
d)GetKeyNameText is used to get keys name.
e)WM_DESTROY:
Post Quit Message that generates WM_QUIT.
f)default:
Other messages are handled by the default window procedure.
long _stdcall wproc(HWND hwnd,UINT x,WPARAM w,LPARAM l)
{
HDC hdc;char buffer[100];
TCHAR szkeyname[30];
switch(x)
{
case WM_CHAR:
hdc=GetDC(hwnd);
InvalidateRect(hwnd,NULL,TRUE);
GetUpdateRect(hwnd,NULL,TRUE);
ValidateRect(hwnd,NULL);
GetKeyNameText(1,szkeyname,sizeof(szkeyname)/sizeof(TCHAR));
wsprintf(buffer,"keypressed=%c",w);
TextOut(hdc,0,20,buffer,strlen(buffer));
TextOut(hdc,120,0,szkeyname,strlen(szkeyname));
wsprintf(buffer,"keypressed=%d",w);
TextOut(hdc,0,50,buffer,strlen(buffer));
break;
case WM_DESTROY:
PostQuitMessage(0);break;
default:return DefWindowProc(hwnd,x,w,l);
}return 0;}
left mouse button
DISPLAYING TEXT ON LEFT MOUSE BUTTON CLICK
Step6:Window Procedure
a) WM_LBUTTONDOWN:
i)Get the Device context handle and the coordinates of the client area whenever left mouse
button is clicked.
ii)Draw the text in the client area.
b)WM_DESTROY
Post quit Message that generates WM_QUIT
c) Default:
Other messages are handled by the default window procedure.
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM z)
{
int xi,yi;
HDC d;
switch(x)
{
case WM_LBUTTONDOWN:
x1=LOWORD(z);
y1=HIWORD(z);
d=GetDC(hwnd);
TextOut(d,x1,y1,”HELLO”,5);
ReleaseDC(hwnd,d);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;
}
Step6:Window Procedure
a) WM_LBUTTONDOWN:
i)Get the Device context handle and the coordinates of the client area whenever left mouse
button is clicked.
ii)Draw the text in the client area.
b)WM_DESTROY
Post quit Message that generates WM_QUIT
c) Default:
Other messages are handled by the default window procedure.
long _stdcall WProc (HWND hwnd,UINT x,WPARAM w,LPARAM z)
{
int xi,yi;
HDC d;
switch(x)
{
case WM_LBUTTONDOWN:
x1=LOWORD(z);
y1=HIWORD(z);
d=GetDC(hwnd);
TextOut(d,x1,y1,”HELLO”,5);
ReleaseDC(hwnd,d);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,x,w,l);
}
return 0;
}
Subscribe to:
Posts (Atom)
