我是vc的新手,我想请教一个问题,请大家帮忙,谢谢
我建了一个标准的基于对话框的mfc工程,我想当我点
ok按纽的时候能在对话框上产生一个按纽(适当的大小,就是动态创建一个
按纽),然后按纽沿着一个圆的轨迹移动到起始位置(逆时针或
顺时针都可以),接着按纽消失(不光是不可见,要删除分配的
内存),请问怎么实现,请给出原代码实例,不够的话我还加分
我建了一个标准的基于对话框的mfc工程,我想当我点
ok按纽的时候能在对话框上产生一个按纽(适当的大小,就是动态创建一个
按纽),然后按纽沿着一个圆的轨迹移动到起始位置(逆时针或
顺时针都可以),接着按纽消失(不光是不可见,要删除分配的
内存),请问怎么实现,请给出原代码实例,不够的话我还加分
解决方案 »
- MFC程序隐藏到托盘后显示
- MFC 编辑框 数据
- RichEdit控件,变量为Cstring类型,需要字符串插入操作~
- 请问哪位有VC8的sln转换到VC6的dsw的工具?
- 我在看windows核心编程,可是里面翻译的实在有些垃圾,特来请教大家。
- 求mmc开发文档网址
- 请问如何在windows下动态改变桌面图片
- 请问大虾:如何获得AfxMessageBox()的返回值及如何使用PutCollect()函数,其中的第二个参数如何由CString类转换而来?
- 求助
- MFC的使用问题(为什么VIEW类经常无缘无故的不见了)
- 如何获得某段代码在执行时内存消耗的峰值?请指教!
- 有没有录音和放音的源程序参考一下
class CDddDlg : public CDialog
{
// Construction
public:
CDddDlg(CWnd* pParent = NULL); // standard constructor
CButton m_Button;
int angle;
int CenterX, CenterY, R;
// Dialog Data
//{{AFX_DATA(CDddDlg)
enum { IDD = IDD_DDD_DIALOG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDddDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
HICON m_hIcon; // Generated message map functions
//{{AFX_MSG(CDddDlg)
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButton1();
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//DddDlg.cpp
#include "stdafx.h"
#include "ddd.h"
#include "dddDlg.h"
#include "math.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CDddDlg dialogCDddDlg::CDddDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDddDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDddDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
angle = 0;
CenterX = 0;
CenterY = 0;
R = 50;
}void CDddDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDddDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CDddDlg, CDialog)
//{{AFX_MSG_MAP(CDddDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CDddDlg message handlersBOOL CDddDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CDddDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDddDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CDddDlg::OnButton1()
{
CRect cr, br;
GetClientRect(&cr);
CenterX = cr.Width()/2;
CenterY = cr.Height()/2;
br.SetRect(CenterX+R-5, CenterY-5, CenterX+R+5, CenterY+5);
m_Button.Create("MOVE", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, br, this, 100);
m_Button.ShowWindow(SW_SHOW);
SetTimer(1, 10, 0);
}void CDddDlg::OnTimer(UINT nIDEvent)
{
CRect br;
int x, y;
angle += 1;
if(angle == 360)
angle = 0;
x = CenterX + (int)(R*cos((double)angle*3.1415926/180));
y = CenterY + (int)(R*sin((double)angle*3.1415926/180));
br.SetRect(x-5, y-5, x+5, y+5);
m_Button.MoveWindow(&br);
CDialog::OnTimer(nIDEvent);
}