如何用c++builder实现--把应用程序放入托盘中?
1、截获消息WM_SYSCOMMAND,是 SC_MINIMIZE 则 Hide();
2、截获消息WM_SHOWWINDOW,wParam 是FALSE 则 Hide();*****
问题在2上,如果只有1语句,点最小化按钮工作正常,在任务栏上点击无效。
加上2后,什么都不行???
问题点数:50、回复次数:4Top
1 楼hotyei(出于蓝胜于蓝)回复于 2000-10-26 07:39:00 得分 15
Sample面板不是有TrayIcon这样的控制吗?只要设置几个属性就可以隐藏、图标动画等效果了。Top
2 楼Raptor(猛禽)回复于 2000-10-26 10:47:00 得分 10
用控件吧,BCB5的控件有一点小问题,我改一下,在我的主页上,你试试:http://mentals.yes8.comTop
3 楼xujie2(笨啊笨)回复于 2000-10-26 13:06:00 得分 15
给你一段代码
unsigned int iconmessage ;
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <shellapi.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
iconmessage=RegisterWindowMessage("Sever");//iconmessage的定义在前面
Creaticon();
}
//---------------------------------------------------------------------------
void TForm1::RunProgram ()
{
// Select the program and how it will be run.
SHELLEXECUTEINFO execinfo ;
memset (&execinfo, 0, sizeof (execinfo)) ;
execinfo.cbSize = sizeof (execinfo) ;
execinfo.lpVerb = "open" ;
execinfo.lpFile ="djzc.exe";
execinfo.lpParameters ="";
execinfo.fMask = SEE_MASK_NOCLOSEPROCESS ;
execinfo.nShow = SW_SHOWDEFAULT ;
// Run the program.
if (! ShellExecuteEx (&execinfo))
{
ShowMessage ("Could not create process") ;
return ;
}
// Application->Minimize () ;
WaitForSingleObject (execinfo.hProcess, INFINITE) ;
// Application->Restore () ;
}
void TForm1::Creaticon()
{
NOTIFYICONDATA icondata ;
memset (&icondata, 0, sizeof (icondata)) ;
icondata.cbSize = sizeof (icondata) ;
icondata.hWnd = Handle ;
strncpy (icondata.szTip, "在线监测", sizeof (icondata.szTip)) ;
icondata.hIcon = Application->Icon->Handle ;
icondata.uCallbackMessage = iconmessage ;
icondata.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP ;
Shell_NotifyIcon (NIM_ADD, &icondata) ;
}
//---------------------------------------------------------------------------
void TForm1::Removeicon()
{
NOTIFYICONDATA icondata ;
memset (&icondata, 0, sizeof (icondata)) ;
icondata.cbSize = sizeof (icondata) ;
icondata.hWnd = Handle ;
Shell_NotifyIcon (NIM_DELETE, &icondata) ;
}
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == iconmessage)
{
if (Message.LParam == WM_LBUTTONDBLCLK)
{
Form1->Show();
}
return ;
}
TForm::WndProc (Message) ;
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Removeicon();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
if(Application->MessageBoxA("退出将使在线监测无法正常运行!","警告!",MB_ICONWARNING+MB_YESNO)==IDYES)
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Hide();
}
//---------------------------------------------------------------------------
Top
4 楼Darkblack(bloodmud)回复于 2000-10-26 23:57:00 得分 10
请看一下C++ Builder的例子程序,位于CBuilder的Examples目录下的 \Apps\TrayIconTop




