我设计了一个电子时钟的程序,但是题目要求用户可以自己定制钟表的颜色,指针的颜色,以及个人喜欢的属性,请教各位大牛应该在哪里加入菜单函数?加什么呢?谢谢!大一新生的程序设计作业,很急!

解决方案 »

  1.   

    (1)单文档程序不是有菜单栏嘛?你创建一个菜单资源,然后在菜单栏load菜单资源的时候换成你的菜单资源的ID就可以了;
    (2)你可以已右键菜单的方式来实现:CXXXXView::OnRightButtonDown()
    {
    CPoint point;
    CMenu menu;
    menu.LoadMenu(IDR_RBUTTON_MENU);
    CMenu *pMenu = menu.GetSubMenu(1);
    ASSERT(pMenu != NULL);
    GetCursorPos(&point);
    pMenu->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
    }
      

  2.   

    直接在资源Menu中添加菜单项,然后响应WM_COMMAND命令消息
      

  3.   

    好吧,我可能描述能力有限,我再详细说一下,现在我已经在菜单项处增加了ONCOMMAND命令,现在需要写这个命令消息,我想完成的功能是:在这个消息中可以做到调用ONDRAW函数,使其中图形的颜色按命令改变,那应该如何写这个调用ONDRAW的函数呢?我是个初学者,希望大家可以帮帮我~~~谢谢了
    这个是我的view.cpp文件的代码:
    MyClockView.cpp
    // MyClockView.cpp : implementation of the CMyClockView class
    //#include "stdafx.h"
    #include "MyClock.h"#include "MyClockDoc.h"
    #include "MyClockView.h"
    #include "Math.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMyClockViewIMPLEMENT_DYNCREATE(CMyClockView, CView)BEGIN_MESSAGE_MAP(CMyClockView, CView)
    //{{AFX_MSG_MAP(CMyClockView)
    ON_WM_CREATE()
    ON_WM_TIMER()
    //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMyClockView construction/destructionCMyClockView::CMyClockView()
    {
    // TODO: add construction code here}CMyClockView::~CMyClockView()
    {
    }BOOL CMyClockView::PreCreateWindow(CREATESTRUCT& cs)
    {
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
    }/////////////////////////////////////////////////////////////////////////////
    // CMyClockView drawingvoid CMyClockView::OnDraw(CDC* pDC)
    {
    CMyClockDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    RECT Rect;
    GetClientRect(&Rect);
    int CenterX = Rect.right/2;
    int CenterY = Rect.bottom/2;
    CTime Time = CTime::GetCurrentTime();//取当前时间
    CString str;
    int i,x,y;
    CSize size;
    CPen Pen(PS_SOLID,5,RGB(0,200,200));
    CPen *OldPen = pDC->SelectObject(&Pen); pDC->Rectangle(20,20,Rect.right-20,Rect.bottom-20);//绘制钟面矩形 double Radians;
    pDC->SetTextColor(RGB(255,0,255));//设置字体颜色
    for(i = 1;i <= 12;i++)
    {
    str.Format("%d",i);
    size = pDC->GetTextExtent(str,str.GetLength()); Radians = (double)i*6.28/12.0;

    x = CenterX - (size.cx/2) + (int)((double)(CenterX - 30)*
    sin(Radians));
    y = CenterY - (size.cy/2) - (int)((double)(CenterY - 30)*
    cos(Radians)); pDC->TextOut(x,y,str);
    }
    //计算时钟时针指针的夹角
    Radians = (double)Time.GetHour() + (double)Time.GetMinute()/60.0 +
    (double)Time.GetSecond()/3600.0;
    Radians *= 6.28/12.0;
    //创建时钟时针指针画笔
    CPen HourPen(PS_SOLID,5,RGB(0,255,0));
    pDC->SelectObject(&HourPen);
    //绘制时钟时针指针
    pDC->MoveTo(CenterX,CenterY);
    pDC->LineTo(CenterX + (int)((double)(CenterX/3)*sin(Radians)),
    CenterY - (int)((double)(CenterY/3)*cos(Radians)));
    //计算时钟分针指针的夹角
    Radians = (double)Time.GetMinute()+(double)Time.GetSecond()/60.0;
    Radians *= 6.28/60.0;
    //创建分针指针画笔
    CPen MinutePen(PS_SOLID,3,RGB(0,0,255));
    pDC->SelectObject(&MinutePen);
    //绘制分针指针
    pDC->MoveTo(CenterX,CenterY);
    pDC->LineTo(CenterX + (int)((double)(CenterX*2)/3)*sin(Radians),
    CenterY - (int)((double)(CenterY*2/3)*cos(Radians)));
    //计算时钟秒针指针的夹角
    Radians = (double)Time.GetSecond();
    Radians *= 6.28/60.0;
    //创建秒针指针画笔
    CPen SecondPen(PS_SOLID,1,RGB(0,255,255));
    pDC->SelectObject(&SecondPen);
    //绘制秒针指针
    pDC->MoveTo(CenterX,CenterY);
    pDC->LineTo(CenterX + (int)((double)(CenterX*4)/5)*sin(Radians),
    CenterY - (int)((double)(CenterY*4)/5*cos(Radians)));
    pDC->SelectObject(OldPen);
    }/////////////////////////////////////////////////////////////////////////////
    // CMyClockView printingBOOL CMyClockView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    // default preparation
    return DoPreparePrinting(pInfo);
    }void CMyClockView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add extra initialization before printing
    }void CMyClockView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add cleanup after printing
    }/////////////////////////////////////////////////////////////////////////////
    // CMyClockView diagnostics#ifdef _DEBUG
    void CMyClockView::AssertValid() const
    {
    CView::AssertValid();
    }void CMyClockView::Dump(CDumpContext& dc) const
    {
    CView::Dump(dc);
    }CMyClockDoc* CMyClockView::GetDocument() // non-debug version is inline
    {
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyClockDoc)));
    return (CMyClockDoc*)m_pDocument;
    }
    #endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
    // CMyClockView message handlers
    int CMyClockView::OnCreate(LPCREATESTRUCT lpCreateStruct) /* oncreate 消息响应函数,是用来"表示一个窗口正在生成"。*/
    {
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here
    SetTimer(1,1000,NULL);
    return 0;
    }void CMyClockView::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default
    InvalidateRect(NULL,true);
    UpdateWindow();
    CView::OnTimer(nIDEvent); 
    }希望哪位高手可以根据我的题目要求在其中增加可以使用户改变钟表形状及颜色的代码~万分感谢
      

  4.   

    你定义几个COLORREF变量,比如:COLORREF clrLine,clrText,clrHour,clrMin,clrSec;然后在构造函数中初始化,在你的OnDraw函数中用各自的变量替代实际的RGB()值然后在你菜单的响应函数中修改这些变量的值就可以了
      

  5.   

    改变钟表形状,设置个int变量,在右键弹出菜单中改变,在OnDraw里判断,比如说是1就画矩形,是2就画圆