用户名: 密码: 免费注册 忘记密码? 网站地图 | 加入收藏 | 设为首页
首页 | 新闻 | 工具 | 系统 | 办公 | 聊天 | 多媒体 | 网页 | 运营 | 平面 | 欣赏 | 数据库 | 程序 | 服务器 | 组网
网页 | 3dmax | Ghost | Windows Xp| Dreamweaver | photoshop | Flash | office | Alexa | Css | QQ | Asp | PHP | Jsp | Access
Flash MX 2004入门 | 网站推广策略 | CorelDRAW入门 | ASP学习 | 网站建设大师功 | Word入门
  iTbulo.com > 学院 > 程序开发教程 > CC++教程 > 文章正文
用C++ 开发特殊的屏幕显示效果
iTbulo.COM 2006-4-29 佚名()

以前,程序员在DOS平台下开发应用软件时,都会利用DOS的开放性特点,通过中断编写出一些特殊的显示效果,以此来给自己的程序增加一些有趣的特色。然而,随着面向Windows的编程和可视化的第四代开发工具的逐步使用,人们越来越被Windows的统一的编程风格所束缚,同时由于Windows直接管理中断,想用原来的方法来实现一些特殊的显示效果变得越来越困难了。

  那么,在Windows时代程序员如何来实现窗口的特殊效果呢?实际上,由于整个Windows是图形显示系统,因此对系统而言,用户程序的每一个界面、窗口都是系统的一个画布。程序员可以利用这一特点来实现窗口的特殊效果。

  最近笔者利用C++ Builder 5.0 Enterprise成功的实现了该项功能,现介绍如下:

  1、在BCB中建立一个工程文件project1.dpr,在Form1中添加如下控件:

   控件名称           属性         值

   TForm             Color       clBtnText

   TMainMenu           Name        MainMneu1

   TImage             Name         Image1

                  Align       alClient

                  AutoSize       True

  同时在 MainMenu1控件中增加一个菜单项,其属性为:

   Name             Caption

   Items1           图像从中间往左右分出

   Items2           图像从左右往中间合进

   Items3           图像从中间往上下分出

   Items4           图像从上下往中间合进

   Items5           图像从左移入

   Items6           图像从右移入

   Items7           图像从上移入

   Items8           图像从下移入

   Items9           图像从左刷屏显示

   Items10          图像从右刷屏显示

   Items11          图像从上刷屏显示

   Items12          图像从下刷屏显示

   Items13          图像从上往下流水

   Items14          图像从下往上流水

   Items15          图像圆形展出

   Items16          图像左右错移

   Items17          图像上下错移

  同时在Unit.cpp中的private中添加如下变量:

  private:

   BITMAP bm;

   Graphics::TBitmap *Bitmap1;

   int i,j;

   int WideHalf;

   TRect Dest1,Source1,Dest2,Source2;

  int HeightHalf;

  HRGN MyRgn;

  2、在Form1的OnCreate事件中添加如下代码:

  void __fastcall TForm1::FormCreate(TObject *Sender)//进行图像特效显示的初始化操作//

  {      

    Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();//定义一个图象句柄//

     Bitmap1->LoadFromFile("C:\\factory.bmp");//设定所要特效显示的图象为factory.bmp//

     if(GetDeviceCaps(Form1->Canvas->Handle,BITSPIXEL)==8)//取得显示窗口的颜色属性//

     {

      GetObject(Bitmap1->Handle,sizeof(BITMAP),(LPSTR)bm);

      if (bm.bmBitsPixel==8)//如果特效显示的图象颜色属性为256色//

      {

       SelectPalette(Form1->Canvas->Handle,Bitmap1->Palette,FALSE);//从特效显示的颜色画板中提取配色方案//

       RealizePalette(Form1->Canvas->Handle); //在显示窗口中设置配色方案//

      }

      Bitmap->HandleType=bmDDB;

       }

     }    

  3、在Items1的OnClieck事件中添加如下代码:

  void__fastcall TForm1::Item1Click(TObject *Sender)

  {      //图象从中间往左右分出//

  Form1->Refresh( );

  WideHalf=Bitmap1->Width/2+Bitmap1->Width%2;

  for(i=0;i<=WideHalf; i++)

   {

   Dest1=Rect(WideHalf-i,0,WideHalf+i,Bitmap1->Height);

   Source1=Rect(WideHalf-i,0,WideHalf+i,Bitmap1->Height);

   Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);

   for(j=0;j<10000;j++);//图像的延迟显示//

  }

   }

  4、在Items2的OnClieck事件中添加如下代码:

  void__fastcall TForm1::Item2Click(TObject *Sender)

  {                   //图像从左右往中间合进//

  Form1->Refresh( );

   WideHalf=Bitmap1->Width/2+Bitmap1->Width%2;

   Form1->Refresh( );

   for(i=0;i<=WideHalf;i++)

   {

   Source1=Dest1=Rect(0,0,i,Bitmap1->Height);

   Source2=Dest2=Rect(Bitmap1->Width-i,0,Bitmap->Width,Bitmap1->Height);

   Form1->Canvas->CopyRect(Dest1,Bimap1->Canvas,Source1);

   Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);

   for(j=0;j<10000;j++);

   }

  }

  5、在Items3的OnClieck事件中添加如下代码:

  void__fastcall TForm1::Item3Click(TObject *Sender)

  {           //图像从中间往上下分出//

  Form1->Refresh( );

   HeightHAlf=Bittmap1->Height/2+Bitmap1->Height%2;

   for(i=0;i<=HeightHalf;i++)

   {

   Dest1=Rect(0,HeightHalf-i,Bitmap1->Width,HeightHalf);

   Source1=Rect(0,0,BmpHandle->Width,i);

   Dest2=Rect(0,HeightHaf,Bitmap1->Width,HeightHalf+i);

   Source2=Rect(0,Bitmap1->Height-i,Bitmap1->Width,Bitmap1->height);

   Form1->Canvas->CopyRect(Dest1,BmpHandle->Canvas,Source1);

   Form1->Canvas->CopyRect(Dest2,BmpHandle->Canvas,Source2);

   for(j=0;j<10000;j++);

   }

  }

  6、在Items4的OnClieck事件中添加如下代码:

  void__fastcall TForm1::Item4Click(TObject *Sender)

  {                 //图像从上下往中间合进//

  Form1->Refresh( );

   HeightHalf=Bitmap1->Height/2+Bitmap1->Height%2;

   for(i=0;i<=HeightHalf;i++)

   {

   Dest1=Rect(0,0,Bitmap1->Width,i);

   Source1=Rect(0,HeightHalf-i,Bitmap1->Width,HeightHalf);

   Dest2=Rect(0,Bitmap1->Height-i,

         Bitmap1->Width,Bitmap1->Height);

   Source2=Rect(0,HeightHalf,Bitmap1->Width,HeightHalf+i);

   Form1->Canvas->CopyRect(Dest1,Bitmap1->Canvas,Source1);

   Form1->Canvas->CopyRect(Dest2,Bitmap1->Canvas,Source2);

   for(j=0;j<10000;j++);

   }

  } (未完)

[1] [2] 下一页

文章搜索
相关资讯
相关文章 相关下载
C++ 中不规则窗体的快速显示
在 C++ 中控制Windows关机
用C++在WIN.INI中保存信息
5.运算符
4.变量
焦点信息