有多个重载函数“to

您所在的位置:网站首页 有多个重载函数实例 有多个重载函数“to

有多个重载函数“to

2022-05-24 02:05| 来源: 网络整理| 查看: 265

#include "stdafx.h" #include "XZPKS.h" #include "XZPKSDlg.h" #include "afxdialogex.h"

#ifdef _DEBUG #define new DEBUG_NEW #endif

int index1 = -1, z= -1; int p = 0; int q = 0; int t = 0; // 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx { public:     CAboutDlg();

// 对话框数据     enum { IDD = IDD_ABOUTBOX };

    protected:     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现 protected:     DECLARE_MESSAGE_MAP() };

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) { }

void CAboutDlg::DoDataExchange(CDataExchange* pDX) {     CDialogEx::DoDataExchange(pDX); }

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP()

// CXZPKSDlg 对话框

CXZPKSDlg::CXZPKSDlg(CWnd* pParent /*=NULL*/)     : CDialogEx(CXZPKSDlg::IDD, pParent) {     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }

void CXZPKSDlg::DoDataExchange(CDataExchange* pDX) {     CDialogEx::DoDataExchange(pDX);     DDX_Control(pDX, IDC_EDIT1, m_edit); }

BEGIN_MESSAGE_MAP(CXZPKSDlg, CDialogEx)     ON_WM_SYSCOMMAND()     ON_WM_PAINT()     ON_WM_QUERYDRAGICON()     ON_BN_CLICKED(IDC_BUTTON2, &CXZPKSDlg::OnBnClickedButton2)     ON_WM_TIMER()     ON_BN_CLICKED(IDC_BUTTON3, &CXZPKSDlg::OnBnClickedButton3)     ON_BN_CLICKED(IDC_BUTTON4, &CXZPKSDlg::OnBnClickedButton4) END_MESSAGE_MAP()

// CXZPKSDlg 消息处理程序

BOOL CXZPKSDlg::OnInitDialog() {     CDialogEx::OnInitDialog();

    // 将“关于...”菜单项添加到系统菜单中。

    // IDM_ABOUTBOX 必须在系统命令范围内。     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);     ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);     if (pSysMenu != NULL)     {         BOOL bNameValid;         CString strAboutMenu;         bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);         ASSERT(bNameValid);         if (!strAboutMenu.IsEmpty())         {             pSysMenu->AppendMenu(MF_SEPARATOR);             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);         }     }

    // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动     //  执行此操作     SetIcon(m_hIcon, TRUE);            // 设置大图标     SetIcon(m_hIcon, FALSE);        // 设置小图标

    // TODO: 在此添加额外的初始化代码     playflag = false;     CRect rect;     GetDlgItem(IDC_STATIC)->GetWindowRect(&rect); // 检索窗口尺寸     ScreenToClient(rect);     startRect = rect;     SetTimer(1, 1000, NULL);     return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE }

void CXZPKSDlg::OnSysCommand(UINT nID, LPARAM lParam) {     if ((nID & 0xFFF0) == IDM_ABOUTBOX)     {         CAboutDlg dlgAbout;         dlgAbout.DoModal();     }     else     {         CDialogEx::OnSysCommand(nID, lParam);     } }

// 如果向对话框添加最小化按钮,则需要下面的代码 //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, //  这将由框架自动完成。

void CXZPKSDlg::OnPaint() {     if (IsIconic())     {         CPaintDC dc(this); // 用于绘制的设备上下文

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);

        // 使图标在工作区矩形中居中         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;

        // 绘制图标         dc.DrawIcon(x, y, m_hIcon);     }     else     {         CDialogEx::OnPaint();     } }

//当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CXZPKSDlg::OnQueryDragIcon() {     return static_cast(m_hIcon); }

void CXZPKSDlg::DrawLinkHead() {     CWnd* pWnd = GetDlgItem(IDC_STATIC);     CDC* pDC = pWnd->GetDC();     Graphics myGraphics(pDC->GetSafeHdc());     // 提高绘制质量     myGraphics.SetSmoothingMode(SmoothingModeAntiAlias);     myGraphics.SetCompositingQuality(CompositingQualityHighQuality);     myGraphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);     // 定义笔刷     SolidBrush mybrush(Color(90, 90, 225, 255)); // 天蓝色     SolidBrush mybrush2(Color(255, 255, 225, 0)); // 黄色笔刷     SolidBrush mybrush3(Color(255, 0, 225, 255)); // 天蓝色笔刷     Pen Pen(Color(0, 0, 0), 2); // 黑色笔

    // 定义字体     FontFamily fontfamily(L"宋体");       Gdiplus::Font font(&fontfamily, 25, FontStyleRegular, UnitPixel);

    int start_x = 20, start_y = 60;     int width = 50, height = 50;     int span = 30; // 定义偏移量     file.append( to_string( long long(abs( (int)floor(lng) ) )) );

    CRect* rectNode1 = new CRect[list_len];     CRect* rectNode2 = new CRect[list_len];

    for (int i = 0; i < list_len; i++)     {         rectNode1[i].left = start_x + span * i + width * i;         rectNode1[i].top = start_y;

        rectNode2[i].left = start_x + span * i + width * i + 1;         rectNode2[i].top = start_y + 1;     }

    

    // 画矩形     myGraphics.DrawRectangle(&Pen, rectNode1[list_len - index1 % (list_len + 1) - 1].left, rectNode1[list_len - index1 % (list_len + 1) - 1].top, width, height);     if (list_len - index1 % (list_len + 1) - 1 != list_len - 1)     {         // 画线条         myGraphics.DrawLine(&Pen, rectNode1[list_len - index1 % (list_len + 1) - 1].left + width, rectNode1[list_len - index1 % (list_len + 1) - 1].top + height / 2, rectNode1[list_len - index1 % (list_len + 1) - 1].left + width + span, rectNode1[list_len - index1 % (list_len + 1) - 1].top + height / 2);     }     // 画数据     PointF pointf(rectNode1[list_len - index1 % (list_len + 1) - 1].left + 10, rectNode1[list_len - index1 % (list_len + 1) - 1].top - 30);     myGraphics.DrawString(to_wstring(copy[list_len - index1 % (list_len + 1) - 1]).c_str(), -1, &font, pointf, &mybrush3);     // 画边框     myGraphics.FillRectangle(&mybrush2, rectNode2[list_len - index1 % (list_len + 1) - 1].left, rectNode2[list_len - index1 % (list_len + 1) - 1].top, width - 1, height - 1); // 画实心     p++;

}

void CXZPKSDlg::DrawLinkTail() {     CWnd* pWnd = GetDlgItem(IDC_STATIC);     CDC* pDC = pWnd->GetDC();     Graphics myGraphics(pDC->GetSafeHdc());     // 提高绘制质量     myGraphics.SetSmoothingMode(SmoothingModeAntiAlias);     myGraphics.SetCompositingQuality(CompositingQualityHighQuality);     myGraphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);     // 定义笔刷     SolidBrush mybrush(Color(90, 90, 225, 255)); // 天蓝色     SolidBrush mybrush2(Color(255, 255, 225, 0)); // 黄色笔刷     SolidBrush mybrush3(Color(255, 0, 225, 255)); // 天蓝色笔刷     Pen Pen(Color(0, 0, 0), 2); // 黑色笔

    // 定义字体     FontFamily fontfamily(L"宋体");     Gdiplus::Font font(&fontfamily, 25, FontStyleRegular, UnitPixel);

    int start_x = 20, start_y = 60;     int width = 50, height = 50;     int span = 30; // 定义偏移量

    CRect* rectNode1 = new CRect[list_len];     CRect* rectNode2 = new CRect[list_len];

    for (int i = 0; i < list_len; i++)     {         rectNode1[i].left = start_x + span * i + width * i;         rectNode1[i].top = start_y;

        rectNode2[i].left = start_x + span * i + width * i + 1;         rectNode2[i].top = start_y + 1;     }

    // 画矩形     myGraphics.DrawRectangle(&Pen, rectNode1[index1 % (list_len + 1)].left, rectNode1[index1 % (list_len + 1)].top, width, height);     if (index1 % ((list_len + 1)) != (list_len - 1))     {         // 画线条         myGraphics.DrawLine(&Pen, rectNode1[index1 % (list_len + 1)].left + width, rectNode1[index1 % (list_len + 1)].top + height / 2, rectNode1[index1 % (list_len + 1)].left + width + span, rectNode1[index1 % (list_len + 1)].top + height / 2);     }     // 画数据     PointF pointf(rectNode1[index1 % (list_len + 1)].left + 10, rectNode1[index1 % (list_len + 1)].top - 30);     myGraphics.DrawString(to_wstring(copy[(index1 % (list_len + 1))]).c_str(), -1, &font, pointf, &mybrush3);     // 画边框     myGraphics.FillRectangle(&mybrush2, rectNode2[index1 % (list_len + 1)].left, rectNode2[index1 % (list_len + 1)].top, width - 1, height - 1); // 画实心     q++; }

void CXZPKSDlg::OnBnClickedButton2() {     // TODO: 在此添加控件通知处理程序代码     t = 1;     playflag = !playflag;     CreatListTail(); }

void CXZPKSDlg::OnTimer(UINT_PTR nIDEvent) {     // TODO: 在此添加消息处理程序代码和/或调用默认值     if (p == list_len - 1)     {         KillTimer(1);     }

    if (nIDEvent == 1 && playflag)     {         if (t == 0)         {             index1++;             DrawLinkHead();         }         else if (t == 1)         {             index1++;             DrawLinkTail();         }     }     CDialogEx::OnTimer(nIDEvent); } void CXZPKSDlg::CreateListHead() {     CString s;     m_edit.GetWindowTextA(s);

    CString t;     m_edit.GetWindowTextA(t);

    int initdata[100];     stringstream ss(t.GetBuffer(0));     int num;     int k = 0;     while (ss >> num)     {         initdata[k++] = num;     }

    for (int i = 0; i < k / 2; i++) swap(initdata[i], initdata[k - i - 1]);

    LinkList L, p;     L = (LinkList)malloc(sizeof(LNode)); // 创建头节点     L->next = NULL;     for (int i = 0; i < k; i++)     {         p = (LinkList)malloc(sizeof(LNode));         p->data = initdata[i];         p->next = L->next;         L->next = p;         copy.push_back(initdata[i]);     }     m_linklist = L;     list_len = k; }

void CXZPKSDlg::CreatListTail() {     CString s;     m_edit.GetWindowTextA(s);

    CString t;     m_edit.GetWindowTextA(t);

    int initdata[100];     stringstream ss(t.GetBuffer(0));     int num;     int k = 0;     while (ss >> num)     {         initdata[k++] = num;     }

    LinkList L, tail, p;     L = (LinkList)malloc(sizeof(LNode));     tail = L;     for (int i = 0; i < k; i++)     {         p = (LinkList)malloc(sizeof(LNode));         p->data = initdata[i];         tail->next = p;         tail = p;         copy.push_back(initdata[i]);     }     tail->next = NULL;

    m_linklist = L;     list_len = k; }

void CXZPKSDlg::DelList(int n) {     int k = 0;     LinkList p = NULL, L, q;     L = m_linklist->next;     while (L)     {         if (k == n)         {             p = L;             break;         }         L = L->next;         k++;     }     if (p != NULL)     {         q = p->next;         p->next = q->next;         free(q);     }     list_len -= 1;

    copy.clear();     L = m_linklist->next;     while (L)     {         copy.push_back(L->data);         L = L->next;     } }

void CXZPKSDlg::OnBnClickedButton3() {     // TODO: 在此添加控件通知处理程序代码     CString t;     m_edit2.GetWindowTextA(t);     int pos = atoi(t);     DelList(pos - 1);

    CWnd* pWnd = GetDlgItem(IDC_pic1);     CDC* pDC = pWnd->GetDC();     Graphics myGraphics(pDC->GetSafeHdc());     // 提高绘制质量     myGraphics.SetSmoothingMode(SmoothingModeAntiAlias);     myGraphics.SetCompositingQuality(CompositingQualityHighQuality);     myGraphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);     // 定义笔刷     SolidBrush mybrush(Color(90, 90, 225, 255)); // 天蓝色     SolidBrush mybrush2(Color(255, 255, 225, 0)); // 黄色笔刷     SolidBrush mybrush3(Color(255, 0, 225, 255)); // 天蓝色笔刷     Pen Pen(Color(0, 0, 0), 2); // 黑色笔

    // 定义字体     FontFamily fontfamily(L"宋体");     Gdiplus::Font font(&fontfamily, 25, FontStyleRegular, UnitPixel);

    int start_x = 20, start_y = 60;     int width = 50, height = 50;     int span = 30; // 定义偏移量

    CRect* rectNode1 = new CRect[list_len];     CRect* rectNode2 = new CRect[list_len];

    for (int i = 0; i < list_len; i++)     {         rectNode1[i].left = start_x + span * i + width * i;         rectNode1[i].top = start_y;

        rectNode2[i].left = start_x + span * i + width * i + 1;         rectNode2[i].top = start_y + 1;     }

    // 画矩形     for (int i = 0; i < list_len; i++)     {

        myGraphics.DrawRectangle(&Pen, rectNode1[i].left, rectNode1[i].top, width, height);         if (i != list_len - 1)         {             // 画线条             myGraphics.DrawLine(&Pen, rectNode1[i].left + width, rectNode1[i].top + height / 2, rectNode1[i].left + width + span, rectNode1[i].top + height / 2);         }         // 画数据         PointF pointf(rectNode1[i].left + 10, rectNode1[i].top - 30);         myGraphics.DrawString(to_wstring(copy[i]).c_str(), -1, &font, pointf, &mybrush3);         // 画边框         myGraphics.FillRectangle(&mybrush2, rectNode2[i].left, rectNode2[i].top, width - 1, height - 1); // 画实心     } }

void CXZPKSDlg::OnBnClickedButton4() {     // TODO: 在此添加控件通知处理程序代码     Invalidate(true); }  

头文件 

#pragma once #include "afxwin.h"

// CXZPKSDlg 对话框 class CXZPKSDlg : public CDialogEx { // 构造 public:     CXZPKSDlg(CWnd* pParent = NULL);    // 标准构造函数     CRect startRect;     bool playflag;     typedef struct LNode     {         int data;         struct LNode* next;     }LNode, * LinkList;     LinkList m_linklist;

    int list_len; // 链表长度     vector copy;

// 对话框数据     enum { IDD = IDD_XZPKS_DIALOG };

    protected:     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现 protected:     HICON m_hIcon;

    // 生成的消息映射函数     virtual BOOL OnInitDialog();     afx_msg void OnSysCommand(UINT nID, LPARAM lParam);     afx_msg void OnPaint();     afx_msg HCURSOR OnQueryDragIcon();     DECLARE_MESSAGE_MAP()

    public:     void DrawLinkHead();     void DrawLinkTail();     void CreateListHead();     void CreatListTail();     void DelList(int);     afx_msg void OnBnClickedButton2();     afx_msg void OnTimer(UINT_PTR nIDEvent);     CEdit m_edit;     afx_msg void OnBnClickedButton3();     afx_msg void OnBnClickedButton4();     CEdit m_edit2; };

 

 

请问怎么解决这个问题?

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3