首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

求API大侠,怎么在程序中控制一个可执行程序,运行,然后最小化到托盘

2012-03-11 
求API大侠,如何在程序中控制一个可执行程序,运行,然后最小化到托盘 - C++ Builder / Windows SDK/API我的

求API大侠,如何在程序中控制一个可执行程序,运行,然后最小化到托盘 - C++ Builder / Windows SDK/API
我的程序,运行后要用到第三方软件,现在想用我的程序控制此软件的运行,为防止被不小心关闭,想控制它最小化到托盘,如QQ一样;我听说用API能实现此功能,我是初次接触API不知道怎么实现;
如能提供源代码更好,分好商量!

[解决办法]
WinExec
[解决办法]

C/C++ code
//托盘图标NOTIFYICONDATA icondata;//------------------------------------------------//***********************TrayIco编程*******************************************////*                     气泡提示的实现                                        *////*                     title:气泡提示标题栏                                  *////*                     info:气泡提示的内容                                   *////*******************AddTrayIcon(String title,String info)****************//void  TRAYICON::AddTrayIcon(AnsiString title,AnsiString info){    memset(&icondata,0,sizeof(icondata));    icondata.cbSize=sizeof(icondata);    icondata.hWnd=m_hWnd;    icondata.hIcon=Application->Icon->Handle;    strncpy(icondata.szTip,Application->Title.c_str(),sizeof(icondata.szTip));    //自定义消息用于鼠标右键popumenu的实现    icondata.uCallbackMessage=ICON_MESSAGE;    icondata.uFlags=NIF_MESSAGE|NIF_INFO|NIF_ICON;    icondata.uTimeout=500;    icondata.dwInfoFlags=NIIF_INFO;    strcpy(icondata.szInfoTitle,title.c_str());    strcpy(icondata.szInfo,info.c_str());    Shell_NotifyIcon(NIM_ADD,&icondata);}
[解决办法]
A控制B,


A 调用ShellExecute或WinExec 调用B,

然后A发消息给B,B收到消息后,最小化到托盘(托盘程序看上面的老大)

消息发送接收网上N多
[解决办法]
一般情况下,估计 LZ 使用 ShellExecute 就可以满足了。


需要更高级的,那就不是 ShellExecute 了,而是采用 Windows Pipe 技术了。
[解决办法]
WinForm
C/C++ code
#pragma oncenamespace ForWinFormTest {    using namespace System;    using namespace System::ComponentModel;    using namespace System::Collections;    using namespace System::Windows::Forms;    using namespace System::Data;    using namespace System::Drawing;    /// <summary>    /// Form1 摘要    ///    /// 警告: 如果更改此类的名称,则需要更改    ///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的    ///          “资源文件名”属性。否则,    ///          设计器将不能与此窗体的关联    ///          本地化资源正确交互。    /// </summary>    public ref class Form1 : public System::Windows::Forms::Form    {    public:        Form1(void)        {            InitializeComponent();            //            //TODO: 在此处添加构造函数代码            //        }    protected:        /// <summary>        /// 清理所有正在使用的资源。        /// </summary>        ~Form1()        {            if (components)            {                delete components;            }        }    private: System::Windows::Forms::NotifyIcon^  notifyIcon1;    private: System::Windows::Forms::ContextMenuStrip^  contextMenuStrip1;    private: System::Windows::Forms::ToolStripMenuItem^  HopeToolStripMenuItem;    private: System::Windows::Forms::ToolStripMenuItem^  OKToolStripMenuItem;    private: System::Windows::Forms::ToolStripMenuItem^  RealToolStripMenuItem;    protected:     private: System::ComponentModel::IContainer^  components;    private:        /// <summary>        /// 必需的设计器变量。        /// </summary>#pragma region Windows Form Designer generated code        /// <summary>        /// 设计器支持所需的方法 - 不要        /// 使用代码编辑器修改此方法的内容。        /// </summary>        void InitializeComponent(void)        {            this->components = (gcnew System::ComponentModel::Container());            System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));            this->notifyIcon1 = (gcnew System::Windows::Forms::NotifyIcon(this->components));            this->contextMenuStrip1 = (gcnew System::Windows::Forms::ContextMenuStrip(this->components));            this->HopeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());            this->OKToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());            this->RealToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());            this->contextMenuStrip1->SuspendLayout();            this->SuspendLayout();            //             // notifyIcon1            //             this->notifyIcon1->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"notifyIcon1.Icon")));            this->notifyIcon1->Text = L"真的可以吗?";            this->notifyIcon1->Visible = true;            this->notifyIcon1->Click += gcnew System::EventHandler(this, &Form1::notifyIcon1_Click);            //             // contextMenuStrip1            //             this->contextMenuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {this->HopeToolStripMenuItem,                 this->OKToolStripMenuItem, this->RealToolStripMenuItem});            this->contextMenuStrip1->Name = L"contextMenuStrip1";            this->contextMenuStrip1->Size = System::Drawing::Size(99, 70);            //             // HopeToolStripMenuItem            //             this->HopeToolStripMenuItem->Name = L"HopeToolStripMenuItem";            this->HopeToolStripMenuItem->Size = System::Drawing::Size(152, 22);            this->HopeToolStripMenuItem->Text = L"希望";            //             // OKToolStripMenuItem            //             this->OKToolStripMenuItem->Name = L"OKToolStripMenuItem";            this->OKToolStripMenuItem->Size = System::Drawing::Size(152, 22);            this->OKToolStripMenuItem->Text = L"可以";            //             // RealToolStripMenuItem            //             this->RealToolStripMenuItem->Name = L"RealToolStripMenuItem";            this->RealToolStripMenuItem->Size = System::Drawing::Size(98, 22);            this->RealToolStripMenuItem->Text = L"真的";            //右键菜单            this->notifyIcon1->ContextMenuStrip = contextMenuStrip1;            //this->ContextMenuStrip = contextMenuStrip1;            //             // Form1            //             this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;            this->ClientSize = System::Drawing::Size(292, 268);            this->Name = L"Form1";            this->Text = L"Form1";            this->SizeChanged += gcnew System::EventHandler(this, &Form1::Form1_SizeChanged);            this->contextMenuStrip1->ResumeLayout(false);            this->ResumeLayout(false);        }#pragma endregion    private: System::Void Form1_SizeChanged(System::Object^ sender, System::EventArgs^ e)           {               if (this->WindowState == FormWindowState::Minimized)//最小化                  {                   this->ShowInTaskbar = false;                   this->notifyIcon1->Visible = true;               }              }       private: System::Void notifyIcon1_Click(System::Object^ sender, System::EventArgs^ e)           {               if (this->WindowState == FormWindowState::Minimized)                   this->WindowState = FormWindowState::Normal;               this->Activate();               this->notifyIcon1->Visible = false;               this->ShowInTaskbar = true;              }    };} 

热点排行