极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10935|回复: 0

(自定义消息)

[复制链接]
发表于 2015-6-16 22:31:43 | 显示全部楼层 |阅读模式
还是比较懒点,这个从一个朋友给的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);        
}
//---------------------------------------------------------------------------

接收的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-18 11:39 , Processed in 0.044078 second(s), 17 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表