其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
进程通讯(自定义消息)

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

还是比较懒点,这个从一个朋友给的delphi版本的改过来的,本来不准备贴的,无奈问的朋友多~~~~~~~:(

分两部分
接收和发送,测试过了

发送
.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

#define WM_COMM WM_APP+100
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TButton *Button1;
        TButton *Button2;
        TButton *Button3;
        void __fastcall Button1Click(TObject *Sender);
        void __fastcall Button2Click(TObject *Sender);
        void __fastcall Button3Click(TObject *Sender);
private:
        bool ShowProcess(HWND Whandle); // User declarations
public:  // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

.cpp
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

#include "Windows.h"
#include "Messages.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        HWND whd;
        whd = FindWindow(NULL,"Receiver");
        ShowProcess(whd);
        ::SendMessage(whd,WM_COMM,0,0);
}
//---------------------------------------------------------------------------
bool TForm1::ShowProcess(HWND Whandle)
{
        //TODO: Add your source code here
        bool rtn = false;
        try{
                ShowWindow(Whandle,SW_RESTORE);
                SetForegroundWindow(Whandle);
                SetActiveWindow(Whandle);

                rtn = true;
        }
        catch(...)
        {
        }
        return rtn;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
        HWND whd;
        whd = FindWindow(NULL,"Receiver");
        ShowProcess(whd);
        ::SendMessage(whd,WM_COMM,0,1);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
        HWND whd;
        whd = FindWindow(NULL,"Receiver");
        ShowProcess(whd);
        ::SendMessage(whd,WM_COMM,1,0);       
}
//---------------------------------------------------------------------------

接收的

.h
//---------------------------------------------------------------------------

#ifndef ReceiverH
#define ReceiverH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>

#define WM_COMM WM_APP+100
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TEdit *Edit1;
private:
        void userpro(TMessage &msg); // User declarations
public:  // User declarations
        __fastcall TForm1(TComponent* Owner);
protected:
        BEGIN_MESSAGE_MAP
                VCL_MESSAGE_HANDLER(WM_COMM, TMessage, userpro)
        END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Receiver.h"

#include "Windows.h"
#include "Messages.hpp"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::userpro(TMessage &msg)
{
        //TODO: Add your source code here
        if(msg.WParam == 0 &&msg.LParam == 0)
                Edit1->Text = "命令一";
        if(msg.WParam == 0 && msg.LParam == 1)
                Edit1->Text = "命令二";
        if(msg.WParam == 1 && msg.LParam == 0)
                Edit1->Text = "命令三";
}




相关文章

相关软件