Monday, April 19, 2010

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;}

No comments:

Post a Comment