如何将我的窗口放入系统托盘?

wangjue28 2002-05-22 07:51:00
不要菜单
只需要放入,显示一个图标而已
越简单越好
...全文
50 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
我来看看CB 2002-05-22
  • 打赏
  • 举报
回复
该控件在Samples面板中
mygodness 2002-05-22
  • 打赏
  • 举报
回复
还是用trayicon简单
mygodness 2002-05-22
  • 打赏
  • 举报
回复
是啊,非常简单,加入该控件后,只要设置visible为true,然后再在窗体上加一个imagelist,然后放好图片,然后在trayicon的icon属性里改成imagelist1,就好了,这可以满足你的要求
40Star 2002-05-22
  • 打赏
  • 举报
回复
统一 child_bj(今天能看见山)
僵哥 2002-05-22
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <shellapi.h>
#include "main.h"
#include "Pass.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
FirstRun=true;

bCanClose=true;

}
//---------------------------------------------------------------------------
__fastcall TMainForm::~TMainForm()
{



}

void _fastcall TMainForm::CMEraseBkgnd(TMessage TWMEraseBkgnd)
{
Brush->Style=bsClear;
}


void __fastcall TMainForm::OkBtnClick(TObject *Sender)
{


if(PassEdit->Text==PassSet->NewPass)
{

SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,false,&pOld,SPIF_UPDATEINIFILE);
ReleaseCapture();
::ShowCursor(true);
ClipCursor(NULL);
ShowWindow(Handle,SW_HIDE);
//GetWindow()
bCanClose=true;
PassEdit->Text="";
}


else
{
bCanClose=false;
MessageBox(0,"无效的密码,请重新输入!","系統鎖",MB_OK|MB_ICONERROR
|MB_TASKMODAL);
PassEdit->Text="";
PassEdit->SetFocus();
}







}
//---------------------------------------------------------------------------

void __fastcall TMainForm::FormCreate(TObject *Sender)
{
MainForm->Width=GetSystemMetrics(0);
MainForm->Height=GetSystemMetrics(1);
MainForm->Left=0;
MainForm->Top=0;
Panel1->Left=(GetSystemMetrics(0)-Panel1->Width)/2;
Panel1->Top=(GetSystemMetrics(1)-Panel1->Height)/2;
TrayMessage(NIM_ADD,"系统锁");
index=0;
add=true;

}
//---------------------------------------------------------------------------



bool __fastcall TMainForm::TrayMessage(DWORD dwMessage,AnsiString pszTip)
{
NOTIFYICONDATA tnd;

memset(&tnd,0,sizeof(tnd));

tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = Handle;
tnd.uID = 0;
tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnd.hIcon = Application->Icon->Handle;
lstrcpyn(tnd.szTip, pszTip.c_str(), sizeof(tnd.szTip));
tnd.uCallbackMessage = MYWM_NOTIFY;


if (dwMessage == NIM_DELETE)
{
tnd.hIcon = NULL;
tnd.szTip[0] = '\0';
}

return (Shell_NotifyIcon(dwMessage, &tnd));
}
void __fastcall TMainForm:: MyNotify(TMessage& Msg)
{

POINT MousePos;

switch(Msg.LParam)
{
case WM_RBUTTONDOWN:
if (GetCursorPos(&MousePos))
{
PopupMenu1->PopupComponent = MainForm;
SetForegroundWindow(Handle);
PopupMenu1->Popup(MousePos.x, MousePos.y);
}
break;

case WM_LBUTTONDBLCLK:
LockSys->Click();
break;

default:
break;
}
TForm::Dispatch(&Msg);

}

void __fastcall TMainForm::LockSysClick(TObject *Sender)
{
TRect rt;
ShowWindow(Handle,SW_SHOWNORMAL);
::SetForegroundWindow(Handle);
GetWindowRect(Handle,&rt);
ClipCursor(&rt);
// ::SetCursor(LoadCursor(NULL,IDC_NO));

SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,true,&pOld,SPIF_UPDATEINIFILE);

}
//---------------------------------------------------------------------------


void __fastcall TMainForm::FormActivate(TObject *Sender)
{




if (FirstRun)
{

ShowWindow(Handle,SW_HIDE);
FirstRun=false;
}
if(PassSet->FirstUse)
if(PassSet->ShowModal()==mrOk)
PassSet->FirstUse=false;


}
//---------------------------------------------------------------------------

void __fastcall TMainForm::ExitClick(TObject *Sender)
{
TrayMessage(NIM_DELETE,"");
Close();
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::PassItemClick(TObject *Sender)
{

PassSet->ShowModal();


}
//---------------------------------------------------------------------------


void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
CanClose=bCanClose;
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Timer1Timer(TObject *Sender)
{

Label1->Left=Panel1->Width-index;
index++;
if(index>Panel1->Width+Label1->Width)index=0;

}
//---------------------------------------------------------------------------

child_bj 2002-05-22
  • 打赏
  • 举报
回复
在BCB5的SAMPLES控件页面里有个TRAYICON控件,非常好用,一看就会。

13,825

社区成员

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

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