0% found this document useful (0 votes)
31 views7 pages

Experiment No. 15 (A) : To Create Pop-Up Menu in VC++

This document describes how to create a pop-up menu in Visual C++. It defines a frame window class that overrides the OnContextMenu method to display a pop-up menu when right-clicking in the client area. The pop-up menu contains menu items like "New", "Open", "Save" etc. and calls handler functions like neww(), open() etc. when these items are selected. The frame window class is instantiated and shown to test the pop-up menu functionality.

Uploaded by

Era Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views7 pages

Experiment No. 15 (A) : To Create Pop-Up Menu in VC++

This document describes how to create a pop-up menu in Visual C++. It defines a frame window class that overrides the OnContextMenu method to display a pop-up menu when right-clicking in the client area. The pop-up menu contains menu items like "New", "Open", "Save" etc. and calls handler functions like neww(), open() etc. when these items are selected. The frame window class is instantiated and shown to test the pop-up menu functionality.

Uploaded by

Era Jain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

8067

EXPERIMENT NO. 15(a)


To Create Pop-Up Menu in VC++.
#include<afxwin.h> class myframe:public CFrameWnd { public: myframe() { Create(0,"Creating Pop-Up Menu.."); } void OnContextMenu(CWnd *p, CPoint pt) { CRect r; GetClientRect(&r); ClientToScreen(&r); if(r.PtInRect(pt)) { CMenu mymenu; mymenu.CreatePopupMenu(); mymenu.AppendMenu(MF_STRING,101,"&New"); mymenu.AppendMenu(MF_STRING,102,"&Open"); mymenu.AppendMenu(MF_STRING,103,"&Save"); mymenu.AppendMenu(MF_STRING,104,"&Save As"); mymenu.AppendMenu(MF_SEPARATOR); mymenu.AppendMenu(MF_STRING,105,"&Page Setup...."); mymenu.AppendMenu(MF_STRING,106,"&Print.."); mymenu.AppendMenu(MF_SEPARATOR); mymenu.AppendMenu(MF_STRING,107,"&Exit"); mymenu.TrackPopupMenu(TPM_CENTERALIGN| TPM_RIGHTBUTTON,pt.x,pt.y,this,0); } else CFrameWnd::OnContextMenu(p,pt); } void neww() { MessageBox("To Open A New File....","New"); } void open() { MessageBox("To Open An Existing File....","Open"); }

8067 void save() { MessageBox("To Save A File....","Save"); void print() { MessageBox("To Print A New File....","Print");} void exit() { MessageBox("To Exit from Application....","Exit"); } DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(myframe,CFrameWnd) ON_WM_CONTEXTMENU() ON_COMMAND(101,neww) ON_COMMAND(102,open) ON_COMMAND(103,save) ON_COMMAND(106,print) ON_COMMAND(107,exit) END_MESSAGE_MAP() class myapp:public CWinApp { public: int InitInstance() { myframe *p; p=new myframe; p->ShowWindow(3); m_pMainWnd=p; return 1; } }; myapp a;

8067

OUTPUT:

8067

8067

8067

EXPERIMENT NO. 15(b)


To Draw Rectangles( Not More Than 20) On Mouse Left Double Click.
#include<afxwin.h> #include<afxext.h> class myframe:public CFrameWnd { public: int count; public: myframe() { Create(0,"Drawing on Mouse Double Click"); count=0; } void OnLButtonDblClk(UINT flag,CPoint pt) { CClientDC d(this); if(count<20) { d.Rectangle(pt.x,pt.y,pt.x+100,pt.y+150); count++; } else { d.TextOut(pt.x,pt.y,"No More Rectangles Can Be Drawn"); } } DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(myframe,CFrameWnd) ON_WM_LBUTTONDBLCLK() END_MESSAGE_MAP() class myapp:public CWinApp { public: int InitInstance() { myframe *p; p=new myframe; p->ShowWindow(3); m_pMainWnd=p; return 1; } }; myapp a;

8067

OUTPUT:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy