QQ登录

只需一步,快速开始

上位机MFC任意不规则按钮源代码

[ 复制链接 ]
例程是通过自己编写一个集成类CButton来实现的。
在程序初始化时对按钮实现进行了设置。
关键代码为:
  1. HRGN r;

  2.         // RECTANGULAR BUTTONS
  3.         r = CreateRectRgn(0, 0, 63, 31);
  4.         m_Btn1.Create("Btn 1", WS_CHILD | WS_VISIBLE, CPoint(15, 15), r, this, MY_BTN1, RGB(255, 255, 0));
  5.         DeleteObject(r);

  6.         // ELLIPTIC BUTTON
  7.         r = CreateEllipticRgn(0, 0, 63, 31);
  8.         m_Btn2.Create("Btn 2", WS_CHILD | WS_VISIBLE, CPoint(95, 15), r, this, MY_BTN2, 2, GetSysColor(COLOR_BTNFACE), RGB(0, 255, 0), RGB(0, 255, 0), GetSysColor(COLOR_BTNFACE));
  9.         DeleteObject(r);

  10.         // HELF_ELLIPSE: create left and right buttons splitting ellipse in half
  11.         HRGN rgnR = CreateRectRgn(0, 0, 127, 31);
  12.         HRGN rgnE = CreateEllipticRgn(0, 0, 127, 31);
  13.         OffsetRgn(rgnR, 63, 0);
  14.         CombineRgn(rgnE, rgnE, rgnR, RGN_DIFF);
  15.         m_Btn3.Create("  Btn 3", WS_CHILD | WS_VISIBLE, CPoint(175, 15), rgnE, this, MY_BTN3, 2, GetSysColor(COLOR_BTNFACE), RGB(156, 175, 194), RGB(237, 175, 71), GetSysColor(COLOR_BTNFACE));

  16.         rgnR = CreateRectRgn(0, 0, 127, 31);
  17.         rgnE = CreateEllipticRgn(0, 0, 127, 31);
  18.         OffsetRgn(rgnR, -63, 0);
  19.         CombineRgn(rgnE, rgnE, rgnR, RGN_DIFF);
  20.         OffsetRgn(rgnE, -64, 0);
  21.         m_Btn4.Create("Btn 4  ", WS_CHILD | WS_VISIBLE | WS_DISABLED, CPoint(175 + 64, 15), rgnE, this, MY_BTN4, 2, GetSysColor(COLOR_BTNFACE), RGB(156, 175, 194), RGB(237, 175, 71), GetSysColor(COLOR_BTNFACE));

  22.         DeleteObject(rgnE);
  23.         DeleteObject(rgnR);

  24.         // BUTTONS from text regions
  25.         HDC hDC = CreateCompatibleDC(GetDC() -> GetSafeHdc());
  26.         HRGN c;
  27.         LOGFONT lf;
  28.         GetFont() -> GetLogFont(&lf);
  29.         lf.lfHeight = -128;
  30.         lf.lfWeight = 1000;
  31.         HFONT hFont = CreateFontIndirect(&lf);
  32.         HFONT hOldFont = (HFONT) SelectObject(hDC, hFont);
  33.         c = CreateRectRgn(0, 0, 0, 0);

  34.         int mode = SetBkMode(hDC, TRANSPARENT);
  35.         BeginPath(hDC);
  36.         TextOut(hDC, 0, 0, "$", 1);
  37.         EndPath(hDC);
  38.         c = PathToRegion(hDC);
  39.         SetBkMode(hDC, mode);

  40.         m_Btn5.Create("", WS_CHILD | WS_VISIBLE, CPoint(15, 63), c, this, MY_BTN5, RGB(255, 255, 0));

  41.         mode = SetBkMode(hDC, TRANSPARENT);
  42.         BeginPath(hDC);
  43.         TextOut(hDC, 0, 0, "@", 1);
  44.         EndPath(hDC);
  45.         c = PathToRegion(hDC);
  46.         SetBkMode(hDC, mode);
  47.         m_Btn6.Create("", WS_CHILD | WS_VISIBLE, CPoint(15 + 64, 63), c, this, MY_BTN6, RGB(255, 0, 255));

  48.         SelectObject(hDC, hOldFont);
  49.         DeleteObject(hFont);
  50.         DeleteObject(c);

  51.         HRGN cr;

  52.         BeginPath(hDC);
  53.         MoveToEx(hDC, 0, 0, NULL);
  54.         LineTo(hDC, 64, 0);
  55.         LineTo(hDC, 64, 16);
  56.         LineTo(hDC, 48, 32);
  57.         LineTo(hDC, 0, 32);
  58.         LineTo(hDC, 0, 0);
  59.         EndPath(hDC);
  60.         cr = CreateRectRgn(0, 0, 63, 63);
  61.         cr = PathToRegion(hDC);
  62.         m_Btn7.Create("Save  ", WS_CHILD | WS_VISIBLE, CPoint(15 + 64 + 128, 63), cr, this, MY_BTN7, 1, RGB(254, 247, 211), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));

  63.         BeginPath(hDC);
  64.         MoveToEx(hDC, 64, 16, NULL);
  65.         LineTo(hDC, 64, 32);
  66.         LineTo(hDC, 48, 32);
  67.         LineTo(hDC, 64, 16);
  68.         EndPath(hDC);
  69.         cr = PathToRegion(hDC);
  70.         m_Btn8.Create("", WS_CHILD | WS_VISIBLE, CPoint(15 + 64 + 128 + 48, 63 + 16), cr, this, MY_BTN8, 1, RGB(247, 211, 254), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));

  71.        
  72.         DeleteObject(cr);


  73.         // SIMPLE POLYLINE REGION button
  74.         HRGN r1;
  75.         HRGN r2;
  76.         BeginPath(hDC);
  77.         MoveToEx(hDC, 0, 32, NULL);
  78.         LineTo(hDC, 48, 32);
  79.         LineTo(hDC, 48, 16);
  80.         LineTo(hDC, 96, 48);
  81.         LineTo(hDC, 48, 80);
  82.         LineTo(hDC, 48, 64);
  83.         LineTo(hDC, 0, 64);
  84.         LineTo(hDC, 0, 32);
  85.         EndPath(hDC);
  86.         cr = CreateRectRgn(0, 0, 63, 63);
  87.         cr = PathToRegion(hDC);
  88.         m_Btn9.Create("Btn 9", WS_CHILD | WS_VISIBLE, CPoint(32 + 64 + 96, 63 + 16 + 128), cr, this, MY_BTN9, 2, RGB(250, 207, 194), RGB(255, 0, 0), RGB(255, 0, 0), GetSysColor(COLOR_BTNFACE));

  89.         DeleteObject(cr);
  90.         DeleteObject(hDC);

  91.         // COMPLEX region
  92.         hDC = CreateCompatibleDC(GetDC() -> GetSafeHdc());
  93.         BeginPath(hDC);
  94.         MoveToEx(hDC, 31, 15, NULL);
  95.         CPoint p[7];
  96.         p[ 0] = CPoint(5, 0);
  97.         p[ 1] = CPoint(0, 55);
  98.         p[ 2] = CPoint(0, 28);
  99.         p[ 3] = CPoint(31, 64);
  100.         p[ 4] = CPoint(59, 55);
  101.         p[ 5] = CPoint(59, 0);
  102.         p[ 6] = CPoint(31, 15);

  103.         PolyBezier(hDC, &p[0], 7);
  104.         EndPath(hDC);
  105.         cr = CreateRectRgn(0, 0, 63, 63);
  106.         cr = PathToRegion(hDC);
  107.         m_Btn10.Create("Btn 10", WS_CHILD | WS_VISIBLE, CPoint(15, 63 + 16 + 64 + 64), cr, this, MY_BTN10, 2, RGB(151, 244, 219), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));

  108.         DeleteObject(cr);
  109.         DeleteObject(hDC);

  110.         // STRECHED BUTTON
  111.         c = CreateRectRgn(16, 0, 80, 31);
  112.         r1 = CreateEllipticRgn(0, 0, 32, 32);
  113.         r2 = CreateEllipticRgn(64, 0, 96, 32);
  114.         CombineRgn(c, c, r1, RGN_OR);
  115.         CombineRgn(c, c, r2, RGN_OR);
  116.         m_Btn11.Create("Btn 11", WS_CHILD | WS_VISIBLE, CPoint(15 + 64, 63 + 32 + 64 + 64), c, this, MY_BTN11, 2, GetSysColor(COLOR_BTNFACE), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  117.         DeleteObject(c);
  118.         DeleteObject(r1);
  119.         DeleteObject(r2);

  120.         // MERGED BUTTONS
  121.         c = CreateRectRgn(8, 0, 55, 31);
  122.         r1 = CreateEllipticRgn(48, 8, 15 + 48, 15 + 8);
  123.         CombineRgn(c, c, r1, RGN_OR);
  124.         m_Btn12.Create("File", WS_CHILD | WS_VISIBLE, CPoint(16, 63 + 32 + 64 + 128), c, this, MY_BTN12, 1, RGB(151, 219, 244), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  125.         r1 = CreateEllipticRgn(0, 8, 15, 15 + 8);
  126.         CombineRgn(c, c, r1, RGN_DIFF);
  127.         m_Btn13.Create("Edit", WS_CHILD | WS_VISIBLE, CPoint(16 + 48, 63 + 32 + 64 + 128), c, this, MY_BTN13, 1, RGB(151, 219, 244), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  128.         m_Btn14.Create("View", WS_CHILD | WS_VISIBLE, CPoint(16 + 48 + 48, 63 + 32 + 64 + 128), c, this, MY_BTN14, 1, RGB(151, 219, 244), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  129.         m_Btn15.Create("Insert",WS_CHILD |WS_VISIBLE, CPoint(16 + 48 + 48 + 48, 63 + 32 + 64 + 128), c, this, MY_BTN15, 1, RGB(151, 219, 244), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  130.         m_Btn16.Create("Tools", WS_CHILD |WS_VISIBLE, CPoint(16 + 48 + 48 + 48 + 48, 63 + 32 + 64 + 128), c, this, MY_BTN16, 1, RGB(151, 219, 244), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  131.         m_Btn17.Create("Help",  WS_CHILD |WS_VISIBLE, CPoint(16 + 48 + 48 + 48 + 48 + 48, 63 + 32 + 64 + 128), c, this, MY_BTN17, 1, RGB(151, 244, 219), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));
  132.         c = CreateRectRgn(8, 0, 63, 31);
  133.         r1 = CreateEllipticRgn(0, 8, 15, 15 + 8);
  134.         CombineRgn(c, c, r1, RGN_DIFF);
  135.         m_Btn18.Create("Exit",  WS_CHILD |WS_VISIBLE, CPoint(16 + 48 + 48 + 48 + 48 + 48 + 48, 63 + 32 + 64 + 128), c, this, MY_BTN18, 1, RGB(244, 151, 219), RGB(211, 247, 254), RGB(211, 247, 254), GetSysColor(COLOR_BTNFACE));

  136.         DeleteObject(c);
  137.         DeleteObject(r1);
复制代码

上位机MFC任意不规则按钮源代码

上位机MFC任意不规则按钮源代码

请点击此处下载

请先注册会员后在进行下载

已注册会员,请先登录后下载

文件名称:上位机MFC任意不规则按钮源代码.rar 
文件大小:24.81 KB  售价:1金币
下载权限: 不限 以上或 VIP会员   [购买捐助会员]   [充值积分]   有问题联系我


回复

使用道具 举报

快速回复 返回列表 客服中心 搜索