社区
VCL组件使用和开发
帖子详情
如何让程序启动时直接缩小到托盘区??
zhgwbzhd
2009-01-20 09:49:54
我的程序是一个service程序。
在服务启动时,
Form1 = new TForm1(NULL);
Form1->Show();
在Form1内有TrayIcon1控件。
我目前只能在计算机启动之后。单击一个键来实现缩到托盘区。
我想让计算机启动时,自动缩到托盘区。该怎么搞呢???
谢谢啊!
...全文
268
5
打赏
收藏
如何让程序启动时直接缩小到托盘区??
我的程序是一个service程序。 在服务启动时, Form1 = new TForm1(NULL); Form1->Show(); 在Form1内有TrayIcon1控件。 我目前只能在计算机启动之后。单击一个键来实现缩到托盘区。 我想让计算机启动时,自动缩到托盘区。该怎么搞呢??? 谢谢啊!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhgwbzhd
2009-01-21
打赏
举报
回复
OK!我决定不用service程序了。
一般的应用程序没问题,就是这个方法。
zhgwbzhd
2009-01-20
打赏
举报
回复
哦??
哥们我这行怎么出错呢??
Application->ShowMainForm=false;
jaffy
2009-01-20
打赏
举报
回复
这个可以实现,我刚刚试了的,就是有最小化的效果不好
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ShowWindow(Application->Handle,SW_HIDE);
Application->ShowMainForm=false;
TrayIcon1->Minimize();
}
//---------------------------------------------------------------------------
jaffy
2009-01-20
打赏
举报
回复
project1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", frmMain);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TfrmMain), &frmMain);
Application->ShowMainForm=false;
Application->Run();
...
unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::IconTray(TMessage &Msg)
{
if(Msg.LParam==WM_LBUTTONUP || Msg.LParam==WM_RBUTTONUP)
DelIcon();
TForm::Dispatch(&Msg);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::AddIcon()
{
nid.cbSize=sizeof(TNotifyIconData);
nid.hWnd=Handle;
nid.uID=0;
nid.uFlags=NIF_MESSAGE | NIF_ICON | NIF_TIP;
nid.uCallbackMessage=WM_MENUMSG;
nid.hIcon=Application->Icon->Handle;
strcpy(nid.szTip,"My TrayIcon 2005");
Shell_NotifyIcon(NIM_ADD,&nid);
ShowWindow(Application->Handle,SW_HIDE);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::DelIcon()
{
ShowWindow(Application->Handle,SW_SHOW);
Application->Restore();
this->Show();
SetForegroundWindow(Handle);
Shell_NotifyIcon(NIM_DELETE,&nid);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormClose(TObject *Sender, TCloseAction &Action)
{
nid.cbSize=sizeof(TNotifyIconData);
nid.hWnd=Handle;
nid.uID=0;
Shell_NotifyIcon(NIM_DELETE,&nid);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
AddIcon();
this->Hide();
}
//---------------------------------------------------------------------------
unit1.h
class TfrmMain : public TForm
{
__published: // IDE-managed Components
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
protected:
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_MENUMSG,TMessage,IconTray)
END_MESSAGE_MAP(TForm)
public: // User declarations
__fastcall TfrmMain(TComponent* Owner);
TNotifyIconData nid;
MESSAGE void __fastcall IconTray(TMessage &Msg);
void __fastcall AddIcon();
void __fastcall DelIcon();
};
jaffy
2009-01-20
打赏
举报
回复
Application->Minimize();
VCL组件使用和开发
604
社区成员
13,459
社区内容
发帖
与我相关
我的任务
VCL组件使用和开发
C++ Builder VCL组件使用和开发
复制链接
扫一扫
分享
社区描述
C++ Builder VCL组件使用和开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章