Unit1.cpp
上传用户:jjjzlw
上传日期:2022-05-15
资源大小:695k
文件大小:13k
源码类别:

按钮控件

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. int w;
  10. void *OldProc;  // 保存旧的消息处理函数地址入口
  11. int flag1=0;
  12. int flag2=0;
  13. int SetF =0;
  14. //---------------------------------------------------------------------------
  15. __fastcall TForm1::TForm1(TComponent* Owner)
  16.         : TForm(Owner)
  17. {
  18.         this->DoubleBuffered=true;
  19. }
  20. //---------------------------------------------------------------------------
  21. void __fastcall TForm1::FormCreate(TObject *Sender)
  22. {
  23.         HRGN rgn;
  24.         rgn=CreateRoundRectRgn(0,0,75,25,4,4);
  25.         SetWindowRgn(Button5->Handle,rgn,TRUE);
  26.         TCanvas *can = new TCanvas();
  27.         HDC ae = GetDC(Button5->Handle);
  28.         can->Handle = ae;
  29.         can->Brush->Style = bsClear;
  30.         can->Brush->Color = clBackground;
  31.         can->Pen->Color = clBackground;
  32.         can->Pen->Width = 1;
  33.         can->RoundRect(0,0,75,25,5,5);
  34.         can->Font->Color = clBlack;
  35.         can->Brush->Style = bsClear;
  36.         ReleaseDC(Button5->Handle,ae);
  37.         delete can;
  38.         Button5->WindowProc = NewProc3;
  39. }
  40. void __fastcall TForm1::NewProc3(TMessage &msg)
  41. {
  42.     TCanvas *can = new TCanvas();
  43.     TRect r;
  44.     HDC ae = GetDC(Button5->Handle);
  45.     switch (msg.Msg)
  46.     {
  47.         case WM_PAINT:
  48.                 Button5->Dispatch(&msg);
  49.                 can->Handle = ae;
  50.                 /////////////////加底色,刷屏幕
  51.                 can->Brush->Style = bsClear;
  52.                 can->Brush->Color = clBackground;
  53.                 can->Pen->Color = clBackground;
  54.                 can->Pen->Width = 1;
  55.                 can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  56.                 /////////////////重画新的边框,并重填按钮色彩
  57.                 can->Brush->Style = bsClear;
  58.                 can->Brush->Color = TColor(0xEEF5FF);
  59.                 can->Pen->Color = TColor(0xEBCE87);
  60.                 can->RoundRect(1,1,73,23,5,5);
  61.                 can->Font->Color = clBlack;
  62.                 can->Brush->Style = bsClear;
  63.                 can->TextOut(18, 5, "下一条");
  64.                 ReleaseDC(Button5->Handle,ae);
  65.                 delete can;
  66.                 break;
  67.          case WM_SETFOCUS:
  68.                 Button5->Dispatch(&msg);
  69.                 can->Handle = ae;
  70.                 /////////////////加底色,刷屏幕
  71.                 can->Brush->Style = bsClear;
  72.                 can->Brush->Color = clBackground;
  73.                 can->Pen->Color = clBackground;
  74.                 can->Pen->Width = 1;
  75.                 can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  76.                 /////////////////重画新的边框,并重填按钮色彩
  77.                 can->Brush->Style = bsClear;
  78.                 can->Brush->Color = TColor(0xEEF5FF);
  79.                 can->Pen->Color = TColor(0x25C1FF);  //黄色
  80.                 can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  81.                 can->Font->Color = clBlack;
  82.                 can->Brush->Style = bsClear;
  83.                 can->TextOut(18, 5, "下一条");
  84.                 ReleaseDC(Button5->Handle,ae);
  85.                 delete can;
  86.                 SetF=1;
  87.                 break;
  88.          case WM_KILLFOCUS:
  89.                 SetF=0;
  90.                 Button5->Dispatch(&msg);
  91.                 can->Handle = ae;
  92.                 /////////////////加底色,刷屏幕
  93.                 can->Brush->Style = bsClear;
  94.                 can->Brush->Color = clBackground;
  95.                 can->Pen->Color = clBackground;
  96.                 can->Pen->Width = 1;
  97.                 can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  98.                 /////////////////重画新的边框,并重填按钮色彩
  99.                 can->Brush->Style = bsClear;
  100.                 can->Brush->Color = TColor(0xEEF5FF);
  101.                 can->Pen->Color = TColor(0xEBCE87);
  102.                 can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  103.                 can->Font->Color = clBlack;
  104.                 can->Brush->Style = bsClear;
  105.                 can->TextOut(18, 5, "下一条");
  106.                 ReleaseDC(Button5->Handle,ae);
  107.                 delete can;
  108.                 break;
  109.         case WM_LBUTTONDOWN:
  110.                 if(SetF==0){
  111.                 Button5->Dispatch(&msg);
  112.                 can->Handle = ae;
  113.                 /////////////////加底色,刷屏幕
  114.                 can->Brush->Style = bsClear;
  115.                 can->Brush->Color = clBackground;
  116.                 can->Pen->Color = clBackground;
  117.                 can->Pen->Width = 1;
  118.                 can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  119.                 /////////////////重画新的边框,并重填按钮色彩
  120.                 can->Brush->Style = bsClear;
  121.                 can->Brush->Color = TColor(0xEEF5FF);
  122.                 can->Pen->Color = TColor(0x25C1FF);  //黄色
  123.                 can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  124.                 can->Font->Color = clBlack;
  125.                 can->Brush->Style = bsClear;
  126.                 can->TextOut(18, 5, "下一条");
  127.                 ReleaseDC(Button5->Handle,ae);
  128.                 delete can;
  129.                 SetF=1;
  130.                 }
  131.                 break;
  132.         default:
  133.                 Button5->Dispatch(&msg);
  134.                 break;
  135.     }
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TForm1::Button5MouseMove(TObject *Sender,
  139.       TShiftState Shift, int X, int Y)
  140. {
  141.         if(Button5->Tag==0)
  142.         {
  143.                 TCanvas *can = new TCanvas();
  144.                 HDC ae = GetDC(Button5->Handle);
  145.                 can->Handle = ae;
  146.                 /////////////////加底色,刷屏幕
  147.                 can->Brush->Style = bsClear;
  148.                 can->Brush->Color = clBackground;
  149.                 can->Pen->Color = clBackground;
  150.                 can->Pen->Width = 1;
  151.                 can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  152.                 /////////////////重画新的边框,并重填按钮色彩
  153.                 can->Brush->Style = bsClear;
  154.                 can->Brush->Color = TColor(0xEEF5FF);
  155.                 can->Pen->Color = TColor(0x25C1FF);
  156.                 can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  157.                 can->Font->Color = clBlack;
  158.                 can->Brush->Style = bsClear;
  159.                 can->TextOut(18, 5, "下一条");
  160.                 ReleaseDC(Button5->Handle,ae);
  161.                 delete  can;
  162.                 Button5->Tag=1;
  163.         }
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
  167.       int X, int Y)
  168. {
  169.         if(Button5->Tag==1)
  170.         {
  171.                 TCanvas *can = new TCanvas();
  172.                 HDC ae = GetDC(Button5->Handle);
  173.                 can->Handle = ae;
  174.                 /////////////////加底色,刷屏幕
  175.                 can->Brush->Style = bsClear;
  176.                 can->Brush->Color = clBackground;
  177.                 can->Pen->Color = clBackground;
  178.                 can->Pen->Width = 1;
  179.                 can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  180.                 /////////////////重画新的边框,并重填按钮色彩
  181.                 can->Brush->Style = bsClear;
  182.                 can->Brush->Color = TColor(0xEEF5FF);
  183.                 can->Pen->Color = TColor(0xEBCE87);
  184.                 can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  185.                 can->Font->Color = clBlack;
  186.                 can->Brush->Style = bsClear;
  187.                 can->TextOut(18, 5, "下一条");
  188.                 ReleaseDC(Button5->Handle,ae);
  189.                 delete  can;
  190.                 Button5->Tag=0;
  191.         }        
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TForm1::Button5MouseDown(TObject *Sender,
  195.       TMouseButton Button, TShiftState Shift, int X, int Y)
  196. {
  197.         TCanvas *can = new TCanvas();
  198.         HDC ae = GetDC(Button5->Handle);
  199.         can->Handle = ae;
  200.         /////////////////加底色,刷屏幕
  201.         can->Brush->Style = bsClear;
  202.         can->Brush->Color = clBackground;
  203.         can->Pen->Color = clBackground;
  204.         can->Pen->Width = 1;
  205.         can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  206.         /////////////////重画新的边框,并重填按钮色彩
  207.         can->Brush->Style = bsClear;
  208.         can->Brush->Color = TColor(0xCDB5A2);
  209.         can->Pen->Color = TColor(0x25C1FF);
  210.         can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  211.         can->Font->Color = clBlack;
  212.         can->Brush->Style = bsClear;
  213.         can->TextOut(18, 5, "下一条");
  214.         ReleaseDC(Button5->Handle,ae);
  215.         delete  can;
  216. }
  217. //---------------------------------------------------------------------------
  218. void __fastcall TForm1::Button5Click(TObject *Sender)
  219. {
  220.         TCanvas *can = new TCanvas();
  221.         HDC ae = GetDC(Button5->Handle);
  222.         can->Handle = ae;
  223.         /////////////////加底色,刷屏幕
  224.         can->Brush->Style = bsClear;
  225.         can->Brush->Color = clBackground;
  226.         can->Pen->Color = clBackground;
  227.         can->Pen->Width = 1;
  228.         can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  229.         /////////////////重画新的边框,并重填按钮色彩
  230.         can->Brush->Style = bsClear;
  231.         can->Brush->Color = TColor(0xCDB5A2); //
  232.         can->Pen->Color = TColor(0x25C1FF);  //黄色
  233.         can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  234.         can->Font->Color = clBlack;
  235.         can->Brush->Style = bsClear;
  236.         can->TextOut(18, 5, "下一条");
  237.         ReleaseDC(Button5->Handle,ae);
  238.         delete  can;
  239. }
  240. //---------------------------------------------------------------------------
  241. void __fastcall TForm1::Button5MouseUp(TObject *Sender,
  242.       TMouseButton Button, TShiftState Shift, int X, int Y)
  243. {
  244.        TCanvas *can = new TCanvas();
  245.         HDC ae = GetDC(Button5->Handle);
  246.         can->Handle = ae;
  247.         /////////////////加底色,刷屏幕
  248.         can->Brush->Style = bsClear;
  249.         can->Brush->Color = clBackground;
  250.         can->Pen->Color = clBackground;
  251.         can->Pen->Width = 1;
  252.         can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  253.         /////////////////重画新的边框,并重填按钮色彩
  254.         can->Brush->Style = bsClear;
  255.         can->Brush->Color = TColor(0xCDB5A2); //
  256.         can->Pen->Color = TColor(0x25C1FF);  //黄色
  257.         can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  258.         can->Font->Color = clBlack;
  259.         can->Brush->Style = bsClear;
  260.         can->TextOut(18, 5, "下一条");
  261.         ReleaseDC(Button5->Handle,ae);
  262.         delete  can;
  263. }
  264. //---------------------------------------------------------------------------
  265. void __fastcall TForm1::Button5KeyPress(TObject *Sender, char &Key)
  266. {
  267.          if(SetF==1)
  268.         {
  269.                 if(Key==13)
  270.                 {
  271.                         TCanvas *can = new TCanvas();
  272.                         HDC ae = GetDC(Button5->Handle);
  273.                         can->Handle = ae;
  274.                         /////////////////加底色,刷屏幕
  275.                         can->Brush->Style = bsClear;
  276.                         can->Brush->Color = clBackground;
  277.                         can->Pen->Color = clBackground;
  278.                         can->Pen->Width = 1;
  279.                         can->RoundRect(0,0,Button5->Width,Button5->Height,5,5);
  280.                         /////////////////重画新的边框,并重填按钮色彩
  281.                         can->Brush->Style = bsClear;
  282.                         can->Brush->Color = TColor(0xCDB5A2); //
  283.                         can->Pen->Color = TColor(0x25C1FF);  //黄色
  284.                         can->RoundRect(1,1,Button5->Width-2,Button5->Height-2,5,5);
  285.                         can->Font->Color = clBlack;
  286.                         can->Brush->Style = bsClear;
  287.                         can->TextOut(18, 5, "下一条");
  288.                         ReleaseDC(Button5->Handle,ae);
  289.                         delete  can;
  290.                 }
  291.         }
  292. }
  293. //---------------------------------------------------------------------------
  294. void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
  295.       TShiftState Shift)
  296. {
  297.         if(Key==VK_RETURN)
  298.                 Button5Click(Sender);
  299. }
  300. //---------------------------------------------------------------------------
  301. void __fastcall TForm1::Button5EndDock(TObject *Sender, TObject *Target,
  302.       int X, int Y)
  303. {
  304.                 int t;
  305.                 t++;
  306. }
  307. //---------------------------------------------------------------------------
  308. void __fastcall TForm1::Button5EndDrag(TObject *Sender, TObject *Target,
  309.       int X, int Y)
  310. {
  311.                 int t;
  312.                 t++;    
  313. }
  314. //---------------------------------------------------------------------------
  315. void __fastcall TForm1::Button5DragOver(TObject *Sender, TObject *Source,
  316.       int X, int Y, TDragState State, bool &Accept)
  317. {
  318.              int t;
  319.                 t++;            
  320. }
  321. //---------------------------------------------------------------------------
  322. void __fastcall TForm1::Button5DragDrop(TObject *Sender, TObject *Source,
  323.       int X, int Y)
  324. {
  325.              int t;
  326.                 t++;            
  327. }
  328. //---------------------------------------------------------------------------