Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. #include "Unit2.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.         : TForm(Owner)
  13. {
  14.   MyIcon=new TIcon();
  15.   TNotifyIconData IconData;
  16.   MyIcon->LoadFromFile("Icon1.ico");
  17.   IconData.cbSize=sizeof(IconData);
  18.   IconData.hWnd=Handle;
  19.   IconData.uID=100;
  20.   IconData.hIcon=MyIcon->Handle;
  21.   IconData.uFlags=NIF_ICON | NIF_MESSAGE | NIF_TIP;
  22.   IconData.uCallbackMessage=WM_USER+100;
  23.   strcpy(IconData.szTip,"托盘图标示例");
  24.   Shell_NotifyIcon(NIM_ADD,&IconData);
  25.   SetWindowLong(Application->Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
  26. }
  27. //---------------------------------------------------------------------------
  28. __fastcall TForm1::~TForm1()
  29. {
  30.   TNotifyIconData IconData;
  31.   IconData.cbSize=sizeof(IconData);
  32.   IconData.hWnd=Handle;
  33.   IconData.uID=100;
  34.   Shell_NotifyIcon(NIM_DELETE,&IconData);
  35.   delete MyIcon;
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TForm1::IconClick(TMessage& Msg)
  39. {
  40.   TPoint po;
  41.   if(Msg.LParam==WM_LBUTTONDBLCLK)
  42.   {
  43.     Form2->Show();
  44.   }
  45.   if(Msg.LParam==WM_RBUTTONDOWN)
  46.   {
  47.     GetCursorPos(&po);
  48.     PopupMenu1->Popup(po.x,po.y);
  49.   }
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TForm1::FormShow(TObject *Sender)
  53. {
  54.   Width=0;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::N2Click(TObject *Sender)
  58. {
  59.   Close();
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TForm1::N1Click(TObject *Sender)
  63. {
  64.   Form2->Show();
  65. }
  66. //---------------------------------------------------------------------------