娱乐一下,窗口跳舞

luoshupeng 2008-12-31 11:07:09


看代码吧。

.h 头文件
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TEdit *Edit1;
TEdit *Edit2;
TButton *Button1;
TLabel *Label1;
TLabel *Label2;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Edit1KeyPress(TObject *Sender, char &Key);
void __fastcall FormShow(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

.cpp 实现文件
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int nTime = StrToInt(Edit1->Text);
int nArea = StrToInt(Edit2->Text);
if ( (nTime<0||nTime>20) ||(nArea>20||nArea<0) )
{
ShowMessage("输入错误,请输入1-20之间的数");
return;
}
for (int i=0;i<nTime;++i)
{
MoveWindow(this->Handle, this->Left-nArea, this->Top-nArea, this->Width, this->Height, true);
Sleep(20);
MoveWindow(this->Handle, this->Left+nArea, this->Top+nArea, this->Width, this->Height, true);
Sleep(20);
MoveWindow(this->Handle, this->Left-nArea, this->Top-nArea, this->Width, this->Height, true);
Sleep(20);
MoveWindow(this->Handle, this->Left+nArea, this->Top+nArea, this->Width, this->Height, true);
Sleep(20);
MoveWindow(this->Handle, this->Left, this->Top, this->Width, this->Height, true);
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
//控制Edit1只能输入数字
if ( (Key<'0'||Key>'9') && (Key != '\b') )
{
Key = 0;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
//控制Edit2只能输入数字
SetWindowLong(Edit2->Handle, GWL_STYLE, GetWindowLong(Edit2->Handle,GWL_STYLE)|ES_NUMBER);
}
//---------------------------------------------------------------------------
...全文
136 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangwuji155 2009-01-04
  • 打赏
  • 举报
回复
您访问的资源不存在
被删了?
Jonix 2009-01-04
  • 打赏
  • 举报
回复
不错啊
jingzhongrong 2009-01-04
  • 打赏
  • 举报
回复
不错不错。
springworker 2009-01-04
  • 打赏
  • 举报
回复
不错!收藏!
haduke 2009-01-01
  • 打赏
  • 举报
回复
好东西,接分才是王道!
littlefish0101 2009-01-01
  • 打赏
  • 举报
回复
好东西,收藏一下
laowang2 2009-01-01
  • 打赏
  • 举报
回复
不错不错。
jxw1987628 2008-12-31
  • 打赏
  • 举报
回复
// 呵呵 ,顶
TripH0101 2008-12-31
  • 打赏
  • 举报
回复
好,接分
jaffy 2008-12-31
  • 打赏
  • 举报
回复
好,接分

SendMessage(this->Handle,WM_SYSCOMMAND,SC_MONITORPOWER,1);
大伟 2008-12-31
  • 打赏
  • 举报
回复
2008年见到的最后一个有趣的程序
samchoy 2008-12-31
  • 打赏
  • 举报
回复
很好很强大

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧