Sie sind auf Seite 1von 6

DialogBoxDemo>>

#include<afxwin.h>
#include<string.h>
#include "resource.h"

int ActiveStatus = 0;

class MyDialog : public CDialog


{
public:
BOOL OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

void OnCancel()
{
ActiveStatus=0;
DestroyWindow();
}

void OnOK()
{
MessageBox("OK Pressed", "Modless Dialog");
}

DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(MyDialog, CDialog)
ON_COMMAND(IDOK, OnOK)
ON_COMMAND(IDCANCEL, OnCancel)

END_MESSAGE_MAP()

MyDialog myObject;

class MyWindow : public CFrameWnd


{
public:
MyWindow()
{
Create(NULL, "Modless Dialogbox", WS_OVERLAPPEDWINDOW,
rectDefault, NULL, MAKEINTRESOURCE(IDR_MENU1));
}

void OnDialog()
{
if (ActiveStatus)
return;
else
{
ActiveStatus=1;
myObject.Create(IDD_DIALOG1, this);
myObject.ShowWindow(1);
}
}

void OnExit()
{
int msgResponse;

msgResponse = MessageBox("Quit the application?", "Exit


Confirmation", MB_YESNO);

if(msgResponse==IDYES)
SendMessage(WM_CLOSE);
}

DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(MyWindow, CFrameWnd)
ON_COMMAND(ID_MY_DIALOG1, OnDialog)
ON_COMMAND(ID_MY_EXIT1, OnExit)

END_MESSAGE_MAP()

class MyApp : public CWinApp


{
public:
BOOL InitInstance()
{
MyWindow *MyWindowObject;
MyWindowObject = new MyWindow();

m_pMainWnd = MyWindowObject;
MyWindowObject->ShowWindow(1);
MyWindowObject->UpdateWindow();
return TRUE;
}
};

MyApp MyApplicationObject;

>>>>

resource.h

>>>>
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define IDD_DIALOG1 101
#define IDR_MENU1 102
#define ID_MY_DIALOG1 40001
#define ID_MY_EXIT1 40002
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

#include<afxwin.h>
#include<string.h>
#include "resource.h"

int ActiveStatus = 0;

class MyDialog : public CDialog


{
public:
BOOL OnInitDialog()
{
CDialog::OnInitDialog();
return TRUE;
}

void OnCancel()
{
ActiveStatus=0;
DestroyWindow();
}

void OnOK()
{
MessageBox("OK Pressed", "Modless Dialog");
}

DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(MyDialog, CDialog)
ON_COMMAND(IDOK, OnOK)
ON_COMMAND(IDCANCEL, OnCancel)

END_MESSAGE_MAP()
MyDialog myObject;

class MyWindow : public CFrameWnd


{
public:

MyWindow()
{
Create(NULL, "Modless Dialogbox", WS_OVERLAPPEDWINDOW,
rectDefault, NULL, MAKEINTRESOURCE(IDR_MENU1));
}

void OnDialog()
{
if (ActiveStatus)
return;
else
{
ActiveStatus=1;
myObject.Create(IDD_DIALOG1, this);
myObject.ShowWindow(1);
myObject.DoModal();
}
}

void OnExit()
{
int msgResponse;

msgResponse = MessageBox("Quit the application?", "Exit


Confirmation", MB_YESNO);

if(msgResponse==IDYES)
SendMessage(WM_CLOSE);
}

DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(MyWindow, CFrameWnd)
ON_COMMAND(ID_MY_DIALOG1, OnDialog)
ON_COMMAND(ID_MY_EXIT1, OnExit)
END_MESSAGE_MAP()

class MyApp : public CWinApp


{
public:
BOOL InitInstance()
{
MyWindow *MyWindowObject;
MyWindowObject = new MyWindow();

m_pMainWnd = MyWindowObject;
MyWindowObject->ShowWindow(1);
MyWindowObject->UpdateWindow();
return TRUE;
}
};

MyApp MyApplicationObject;

//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define IDD_DIALOG1 101
#define IDR_MENU1 102
#define ID_MY_DIALOG1 40001
#define ID_MY_EXIT1 40002

// Next default values for new objects


//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40003
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

#include<afxwin.h>

CPoint c[20];
int i=0;
class CMainWin : public CFrameWnd
{
public :

char name[30];
int flag;

CMainWin()
{
Create(NULL,"Polygon With Mouse");
}
void OnLButtonDown(UINT f,CPoint pt)
{

CClientDC d(this);
c[i].x =pt.x;
c[i].y =pt.y;

i++;
}

void OnRButtonDown(UINT f,CPoint pt)


{

CClientDC d(this);
d.Polygon(c,i++);
i=0;
// InvalidateRect(&r,TRUE);
}

DECLARE_MESSAGE_MAP();
};

BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()

class CApp : public CWinApp


{
public : int InitInstance()
{
m_pMainWnd = new CMainWin;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

return 1;
}
};

CApp a;

Das könnte Ihnen auch gefallen