void CModallessDialog::OnOK() //非模态对话框按钮函数
{
// TODO: Add extra validation here
if(m_pView!=NULL)
{
UpdateData(TRUE);
//向父窗口发送消息
m_pView->PostMessage(WM_DLGOK,IDOK);
}
CDialog::OnOK();}
CTestDialogView::CTestDialogView()
{
CModallessDialog* m_pModallessDialog;//指向非模态对话框的指针
//单击“应用”按钮的消息处理函数
LRESULT CTestDialogView::OnDialogApply(WPARAM wParam,LPARAM lParam)
{
//获取画线颜色
if(m_pModallessDialog->m_linecolor=="红色")
linecolor=RGB(255,0,0);
else
if(m_pModallessDialog->m_linecolor=="绿色")
linecolor=RGB(0,255,0);
else
linecolor=RGB(0,0,255);
//获取画线粗细
if(m_pModallessDialog->m_linewidth==0)
linewidth=3;
else
if(m_pModallessDialog->m_linewidth==1)
linewidth=6;
else
linewidth=9;
//获取图形添充颜色
fillcolor=m_pModallessDialog->m_fillcolor;
//获取显示图形
rectangle=m_pModallessDialog->m_rectangel;
ellipse=m_pModallessDialog->m_ellipse;
//更新视窗
Invalidate();
return 0L;
}
为什么我无法响应对话框!!!!!!!
告诉我怎么回事
或者怎么做!
zhn
{
// TODO: Add extra validation here
if(m_pView!=NULL)
{
UpdateData(TRUE);
//向父窗口发送消息
m_pView->PostMessage(WM_DLGOK,IDOK);
}
CDialog::OnOK();}
CTestDialogView::CTestDialogView()
{
CModallessDialog* m_pModallessDialog;//指向非模态对话框的指针
//单击“应用”按钮的消息处理函数
LRESULT CTestDialogView::OnDialogApply(WPARAM wParam,LPARAM lParam)
{
//获取画线颜色
if(m_pModallessDialog->m_linecolor=="红色")
linecolor=RGB(255,0,0);
else
if(m_pModallessDialog->m_linecolor=="绿色")
linecolor=RGB(0,255,0);
else
linecolor=RGB(0,0,255);
//获取画线粗细
if(m_pModallessDialog->m_linewidth==0)
linewidth=3;
else
if(m_pModallessDialog->m_linewidth==1)
linewidth=6;
else
linewidth=9;
//获取图形添充颜色
fillcolor=m_pModallessDialog->m_fillcolor;
//获取显示图形
rectangle=m_pModallessDialog->m_rectangel;
ellipse=m_pModallessDialog->m_ellipse;
//更新视窗
Invalidate();
return 0L;
}
为什么我无法响应对话框!!!!!!!
告诉我怎么回事
或者怎么做!
zhn
在什么时候串的?
还有,为什么要用非模态对话框呢
按照你程序,似乎用摸态比较合适
#if !defined(AFX_MODALLESSDIALOG_H__2258860E_09E3_49AE_BE08_551CEDFE8E25__INCLUDED_)
#define AFX_MODALLESSDIALOG_H__2258860E_09E3_49AE_BE08_551CEDFE8E25__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ModallessDialog.h : header file
///////////////////////////////////////////////////////////////////////////////
// CModallessDialog dialog//以下为三个自定义消息
#define WM_DLGAPPLY WM_USER+1
#define WM_DLGOK WM_USER+2
#define WM_DLGCANCEL WM_USER+3class CModallessDialog : public CDialog
{
// Construction
public:
CModallessDialog::CModallessDialog(CView* pView);//自定义的非模式对话框构造函数
CModallessDialog(CWnd* pParent = NULL); // standard constructor// Dialog Data
//{{AFX_DATA(CModallessDialog)
enum { IDD = IDD_MODALLESS_DIALOG };
//以下为用户通过classwizard添加的成员函数变量
CComboBox m_linecolorctrl;
CSpinButtonCtrl m_colorspin;
BOOL m_ellipse;
long m_fillcolor;
CString m_linecolor;
BOOL m_rectangel;
int m_linewidth;
WPARAM wParam;
LPARAM lParam ;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CModallessDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
//public:
// virtual BOOL OnInitDialog();protected: // Generated message map functions
//{{AFX_MSG(CModallessDialog)
afx_msg void OnApply();
virtual void OnCancel();
virtual void OnOK();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CView* m_pView;
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MODALLESSDIALOG_H__2258860E_09E3_49AE_BE08_551CEDFE8E25__INCLUDED_)
对话框cpp文件
// ModallessDialog.cpp : implementation file
//#include "stdafx.h"
#include "TestDialog.h"
#include "ModallessDialog.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CModallessDialog dialogCModallessDialog::CModallessDialog(CView* pView)//自定义的非模式对话框构造函数
{
m_pView=pView;//使得m_Pview指向调用该非模态对话框的视图
}
CModallessDialog::CModallessDialog(CWnd* pParent /*=NULL*/)
: CDialog(CModallessDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CModallessDialog)
m_ellipse = FALSE;
m_fillcolor = 0;
m_linecolor = _T("");
m_rectangel = FALSE;
m_linewidth = -1;
//}}AFX_DATA_INIT
}
void CModallessDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CModallessDialog)
DDX_Control(pDX, IDC_LINECOLOR, m_linecolorctrl);
DDX_Control(pDX, IDC_SPIN1, m_colorspin);
DDX_Check(pDX, IDC_ELLIPSE, m_ellipse);
DDX_Text(pDX, IDC_FILLCOLOR, m_fillcolor);
DDX_CBString(pDX, IDC_LINECOLOR, m_linecolor);
DDX_Check(pDX, IDC_RECTANGEL, m_rectangel);
DDX_Radio(pDX, IDC_THIN, m_linewidth);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CModallessDialog, CDialog)
//{{AFX_MSG_MAP(CModallessDialog)
ON_BN_CLICKED(IDAPPLY, OnApply)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CModallessDialog message handlersvoid CModallessDialog::OnApply()
{
// TODO: Add your control notification handler code here
if(m_pView!=NULL)
{
UpdateData(TRUE);
//向父窗口发送消息
m_pView->PostMessage(WM_DLGAPPLY,IDAPPLY);
}}void CModallessDialog::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();}void CModallessDialog::OnOK()
{
// TODO: Add extra validation here
if(m_pView!=NULL)
{
UpdateData(TRUE);
//向父窗口发送消息
m_pView->PostMessage(WM_DLGOK,IDOK);
}
CDialog::OnOK();}BOOL CModallessDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_colorspin.SetRange(1,9999);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// TestDialogView.h : interface of the CTestDialogView class
//
/////////////////////////////////////////////////////////////////////////////
#include "ModallessDialog.h"
#if !defined(AFX_TESTDIALOGVIEW_H__A3AD4159_0C8D_443E_88D8_3F8E315B2662__INCLUDED_)
#define AFX_TESTDIALOGVIEW_H__A3AD4159_0C8D_443E_88D8_3F8E315B2662__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CTestDialogView : public CView
{
protected: // create from serialization only
CTestDialogView();
DECLARE_DYNCREATE(CTestDialogView)// Attributes
public:
CTestDialogDoc* GetDocument();// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestDialogView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC,CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC,CPrintInfo* pInfo); //}}AFX_VIRTUAL// Implementation
public:
int linewidth;//线的宽度
long fillcolor;//添充颜色
COLORREF linecolor;//画线颜色
BOOL ellipse;//是否画椭圆
BOOL rectangle;//是否画矩形
CModallessDialog* m_pModallessDialog;//指向非模态对话框的指针
virtual ~CTestDialogView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected:
//{{AFX_MSG(CTestDialogView)
afx_msg LRESULT OnDialogApply(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnDialogOk(WPARAM wParam,LPARAM lParam);
afx_msg LRESULT OnDialogCancel(WPARAM wParam,LPARAM lParam);
afx_msg void OnSelectGraph();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};#ifndef _DEBUG // debug version in TestDialogView.cpp
inline CTestDialogDoc* CTestDialogView::GetDocument()
{ return (CTestDialogDoc*)m_pDocument; }
#endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_TESTDIALOGVIEW_H__A3AD4159_0C8D_443E_88D8_3F8E315B2662__INCLUDED_)
试图cpp文件*/
// TestDialogView.cpp : implementation of the CTestDialogView class
//#include "stdafx.h"
#include "TestDialog.h"#include "TestDialogDoc.h"
#include "TestDialogView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CTestDialogViewIMPLEMENT_DYNCREATE(CTestDialogView, CView)BEGIN_MESSAGE_MAP(CTestDialogView, CView)
//{{AFX_MSG_MAP(CTestDialogView)
ON_COMMAND(ID_SELECT_GRAPH, OnSelectGraph)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CTestDialogView construction/destructionCTestDialogView::CTestDialogView()
{
// TODO: add construction code here
m_pModallessDialog=NULL;
//初始化显示风格
linewidth=3;//图形线的宽度
fillcolor=::GetSysColor(COLOR_WINDOWTEXT);//添充颜色
linecolor=RGB(255,0,0);//画线的颜色
ellipse=TRUE;//是否画椭圆
rectangle=TRUE;//是否画矩形
}CTestDialogView::~CTestDialogView()
{
}BOOL CTestDialogView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CTestDialogView drawingvoid CTestDialogView::OnDraw(CDC* pDC)
{
CTestDialogDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rect,RectangleRange,EllipseRange;
GetClientRect(rect);
CPen MyPen,*OldPen;
CBrush MyBrush,*OldBrush;
//创建画刷与画笔
MyPen.CreatePen(PS_DASH,linewidth,linecolor);
MyBrush.CreateSolidBrush(fillcolor);
OldPen=pDC->SelectObject(&MyPen);
OldBrush=pDC->SelectObject(&MyBrush);
//如果选择矩形与椭圆
if(rectangle&&ellipse)
{
RectangleRange.top=rect.top+10;
RectangleRange.left=rect.left+10;
RectangleRange.bottom=rect.bottom-10;
RectangleRange.right=rect.Width()/2-10;
pDC->Rectangle(RectangleRange);
EllipseRange.top=rect.top+10;
EllipseRange.left=rect.Width()/2+10;
EllipseRange.bottom=rect.bottom-10;
EllipseRange.right=rect.right-10;
pDC->Ellipse(EllipseRange);
}
//如果仅选择矩形
if((rectangle)&&(!ellipse))
{
RectangleRange.top=rect.top+10;
RectangleRange.left=rect.left+10;
RectangleRange.bottom=rect.bottom-10;
RectangleRange.right=rect.Width()-10;
pDC->Rectangle(RectangleRange);
}
//如果仅选择椭圆
if((!rectangle)&&(ellipse))
{
pDC->Ellipse(rect);
}
if((!rectangle)&&(!ellipse))
{
pDC->TextOut(1,1,"对不起您没选择任何图形");
}
}/////////////////////////////////////////////////////////////////////////////
// CTestDialogView diagnostics#ifdef _DEBUG
void CTestDialogView::AssertValid() const
{
CView::AssertValid();
}void CTestDialogView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CTestDialogDoc* CTestDialogView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDialogDoc)));
return (CTestDialogDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CTestDialogView message handlers
//单击“应用”按钮的消息处理函数
LRESULT CTestDialogView::OnDialogApply(WPARAM wParam,LPARAM lParam)
{
//获取画线颜色
if(m_pModallessDialog->m_linecolor=="红色")
linecolor=RGB(255,0,0);
else
if(m_pModallessDialog->m_linecolor=="绿色")
linecolor=RGB(0,255,0);
else
linecolor=RGB(0,0,255);
//获取画线粗细
if(m_pModallessDialog->m_linewidth==0)
linewidth=3;
else
if(m_pModallessDialog->m_linewidth==1)
linewidth=6;
else
linewidth=9;
//获取图形添充颜色
fillcolor=m_pModallessDialog->m_fillcolor;
//获取显示图形
rectangle=m_pModallessDialog->m_rectangel;
ellipse=m_pModallessDialog->m_ellipse;
//更新视窗
Invalidate();
return 0L;
}
//单击“确定”按钮的消息处理函数
LRESULT CTestDialogView::OnDialogOk(WPARAM wParam,LPARAM lParam)
{
//获取画线颜色
if(m_pModallessDialog->m_linecolor=="红色")
linecolor=RGB(255,0,0);
else
if(m_pModallessDialog->m_linecolor=="绿色")
linecolor=RGB(0,255,0);
else
linecolor=RGB(0,0,255);
//获取画线粗细
if(m_pModallessDialog->m_linewidth==0)
linewidth=3;
else
if(m_pModallessDialog->m_linewidth==1)
linewidth=6;
else
linewidth=9;
//获取图形添充颜色
fillcolor=m_pModallessDialog->m_fillcolor;
//获取显示图形
rectangle=m_pModallessDialog->m_rectangel;
ellipse=m_pModallessDialog->m_ellipse;
//更新视窗
Invalidate();
return 0L;
}
//单击“取消”按钮的消息处理函数
LRESULT CTestDialogView::OnDialogCancel(WPARAM wParam,LPARAM lParam)
{
m_pModallessDialog->ShowWindow(SW_HIDE);
return 0L;
}void CTestDialogView::OnSelectGraph()
{
// TODO: Add your command handler code here
//若非模式对话框还没创建,则动态创建它
if(m_pModallessDialog==NULL)
{
m_pModallessDialog=new CModallessDialog(this);
m_pModallessDialog->Create(CModallessDialog::IDD,this);
//m_pModallessDialog->OnInitDialog();
} //1.
if(linecolor==RGB(255,0,0))
{
m_pModallessDialog->m_linecolor="红色";
}
else
if(linecolor==RGB(0,255,0))
m_pModallessDialog->m_linecolor="绿色";
else
m_pModallessDialog->m_linecolor="兰色";
//2.
if(linewidth==3)
{
m_pModallessDialog->m_linewidth=0;
}
else
if(linewidth==6)
m_pModallessDialog->m_linewidth=1;
else
m_pModallessDialog->m_linewidth=2;
//3.
m_pModallessDialog->m_fillcolor=::GetSysColor(COLOR_WINDOWTEXT);
//4.
m_pModallessDialog->m_rectangel=rectangle;
m_pModallessDialog->m_ellipse=ellipse;
//显示非模式对话框
m_pModallessDialog->UpdateData(FALSE);
m_pModallessDialog->ShowWindow(SW_SHOWNA);
}
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
BOOL CTestDialogView::OnPreparePrinting( CPrintInfo *pInfo )
{
return DoPreparePrinting( pInfo );
}
void CTestDialogView::OnBeginPrinting(CDC* pDC,CPrintInfo* pInfo)
{}
void CTestDialogView::OnEndPrinting(CDC* pDC,CPrintInfo* pInfo)
{}