Вы находитесь на странице: 1из 16

PROGRAM:

#include<windows.h> int WINAPI WinMain(HINSTANCE hInt,HINSTANCE hprevInt,LPSTR lpCmdLine,int nShowCmd) { int i,j; i=MessageBox(0,"MsgBox1 displayed","MSG1",MB_OKCANCEL|MB_ICONEXCLAMATION); if(i==1) j=MessageBox(0,"OK button is Selected","MSG2",MB_OKCANCEL|MB_ICONQUESTION); else j=MessageBox(0,"CANCEL button is Selected","MSG3",MB_YESNOCANCEL|MB_DEFBUTTON2); if(j==1) j=MessageBox(0,"Option YES is Selected","MSG4",MB_ABORTRETRYIGNORE|MB_ICONASTERISK); else j=MessageBox(0,"Option CANCEL/NO is Selected","MSG5",MB_OKCANCEL|MB_ICONASTERISK); return 0; }

OUTPUT:

PROGRAM:
#include<windows.h> #include<time.h> int WINAPI WinMain(HINSTANCE hint,HINSTANCE hprev,LPSTR cmd,int ishow) { time_t t; time(&t); char *datetime=ctime(&t); MessageBox(0,datetime,"Current Date &Time ",1); return 0; }

OUTPUT:

PROGRAM:
#include<windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hint,HINSTANCE hprev,LPSTR cmdline,int cmdshow) { HWND hwnd; MSG msg; WNDCLASS wc; wc.style=CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc=WndProc; wc.hInstance=hint; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH); wc.lpszClassName="MyClass"; wc.lpszMenuName=NULL; if(!RegisterClass(&wc)) { MessageBox(0,"MyClass is not registered!!","Registry",MB_OK); return 0;} hwnd=CreateWindow("MyClass","MyWindow",WS_OVERLAPPEDWINDOW,CW_U SEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL, NULL,hint,NULL); ShowWindow(hwnd,cmdshow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)){ TranslateMessage(&msg); DispatchMessage(&msg);} return 0;} LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){ switch(msg){ case WM_CREATE: MessageBox(hwnd,"Window Created","MyBox1",MB_OK); break; case WM_DESTROY: MessageBox(hwnd,"Window Destroyed","MyBox2",MB_OK); PostQuitMessage(0); break; default: return DefWindowProc(hwnd,msg,wparam,lparam); }}

OUTPUT:

PROGRAM:
#include<windows.h> LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hint,HINSTANCE hprev,LPSTR cmdline,int cmdshow) { HWND hwnd; MSG msg; WNDCLASS wc; wc.style=CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc=WndProc; wc.hInstance=hint; wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH); wc.lpszClassName="MyClass"; wc.lpszMenuName=NULL; if(!RegisterClass(&wc)){ MessageBox(0,"MyClass is not registered!!","Registry",MB_OK); return 0;} hwnd=CreateWindow("MyClass","MyWindow",WS_OVERLAPPEDWINDOW,100,20 0,500,500,NULL,NULL,hint,NULL); ShowWindow(hwnd,cmdshow); UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0)){ TranslateMessage(&msg); DispatchMessage(&msg);} return 0;} LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){ switch(msg){ case WM_LBUTTONDOWN: char *p; p=GetCommandLine(); MessageBox(hwnd,p,"MyBox1",MB_OKCANCEL|MB_DEFBUTTON1); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,msg,wparam,lparam); }}

OUTPUT:

PROGRAM:
#include "stdafx.h" #include "App2.h" #include "App2Doc.h" #include "App2View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CApp2View IMPLEMENT_DYNCREATE(CApp2View, CView) BEGIN_MESSAGE_MAP(CApp2View, CView) //{{AFX_MSG_MAP(CApp2View) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CApp2View construction/destruction CApp2View::CApp2View() { // TODO: add construction code here } CApp2View::~CApp2View() { } BOOL CApp2View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); }

///////////////////////////////////////////////////////////////////////////// // CApp2View drawing void CApp2View::OnDraw(CDC* pDC) { CApp2Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here CBrush myBrush; for(int i=0;i<pDoc->GetCoinCount();i++) { int y=200-10*i; myBrush.CreateSolidBrush(RGB(150,y,200)); pDC->SelectObject(myBrush); pDC->Ellipse(40,y,100,y-30); pDC->Ellipse(40,y-10,100,y-35); } } ///////////////////////////////////////////////////////////////////////////// // CApp2View diagnostics #ifdef _DEBUG void CApp2View::AssertValid() const { CView::AssertValid(); } void CApp2View::Dump(CDumpContext& dc) const { CView::Dump(dc); } CApp2Doc* CApp2View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CApp2Doc))); return (CApp2Doc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CApp2View message handlers APP2DOC.CPP

#include "stdafx.h" #include "App2.h" #include "App2Doc.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CApp2Doc IMPLEMENT_DYNCREATE(CApp2Doc, CDocument) BEGIN_MESSAGE_MAP(CApp2Doc, CDocument) //{{AFX_MSG_MAP(CApp2Doc) ON_COMMAND(ID_EDIT_ADDCOIN, OnEditAddcoin) ON_COMMAND(ID_EDIT_REMOVECOIN, OnEditRemovecoin) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CApp2Doc construction/destruction CApp2Doc::CApp2Doc() { // TODO: add one-time construction code here } CApp2Doc::~CApp2Doc() { } BOOL CApp2Doc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; // TODO: add reinitialization code here // (SDI documents will reuse this document) return TRUE; }

///////////////////////////////////////////////////////////////////////////// // CApp2Doc serialization void CApp2Doc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CApp2Doc diagnostics #ifdef _DEBUG void CApp2Doc::AssertValid() const { CDocument::AssertValid(); } void CApp2Doc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CApp2Doc commands int CApp2Doc::GetCoinCount() { return m_nCoins; } void CApp2Doc::DeleteContents() { // TODO: Add your specialized code here and/or call the base class m_nCoins=1; CDocument::DeleteContents();

} void CApp2Doc::OnEditAddcoin() { // TODO: Add your command handler code here m_nCoins++; UpdateAllViews(NULL); } void CApp2Doc::OnEditRemovecoin() { // TODO: Add your command handler code here if(m_nCoins>0) m_nCoins--; UpdateAllViews(NULL); }

OUTPUT:

Вам также может понравиться