procedure TForm1.Button2Click(Sender: TObject);
var
  hModule:Thandle;
  Pcall:pointer;
  fhwid:Integer;
  fpid:Integer;
begin
    hModule:=LoadLibrary('Dll.dll');
    if hModule<>0 then
    begin
    Pcall:=GetProcAddress( hModule,'installKeyProc');
    installkeyProc:=Pcall;
    if (Pcall=nil) then
     begin
     self.Caption:='未成功获取函数地址';
     exit;
     end;     fhwid:=FindWindow(nil,'Form1');//这里是找到窗口标题文本名。把找到的这个参数传入即可  这里根据标题文本名字来修改这个即可
     installkeyProc(fhwid);     // self.Caption:='无法得到PID';
    end;
     FreeLibrary(hModule);end;通过热键注入EXE中的代码library Dll;{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }uses
  SysUtils,
  windows,
  Classes,
Dllform in 'Dllform.pas' {Form1};{$R *.res}
var
keyhhk: HHOOK ;Function keyproc(icode,wp,lp:integer):DWORD;stdcall;   //键盘HOOK回调函数
begin
  if (icode=HC_ACTION) then
            begin
              if (wp=VK_HOME)and ((1 shl 31)and lp=0) then
              begin
              if form1=nil then  Form1:=Tform1.Create(nil);
                form1.Visible:=not form1.Visible;
              end;
            end;
 keyProc:=CallNextHookEx(keyhhk,icode,wp,lp);
end;
Function installKeyProc(hwid:Integer):boolean;stdcall;
var
 h:HWND;
 GameTid:THandle;
 //inclass:string;
begin
    Result:=false;
   // inclass:=hwclass;
    h:=hwid;
   // ;    if h=0 then
    begin
    Messagebox(0,'未找到进程','error',0);
    exit;
    end;
    GameTid:=GetWindowThreadProcessId(h);
    if GameTid=0 then
    begin
    Messagebox(0,'无法获得线程ID','error',0);
    exit;
    end;
    keyhhk:=SetWindowsHookEx(WH_KEYBOARD,@Keyproc,GetModuleHandle('dll.dll'),GameTid);
    if keyhhk>0 then
    Result:=true;
end;
procedure DllEnterProc(reason:integer);
begin
   case reason of
   windows.DLL_PROCESS_ATTACH: begin end;
   windows.DLL_PROCESS_DETACH: begin Form1.Free;form1:=nil; end;
   end;
end;
exports   //导出函数
  installKeyProc;begin
dllProc:=@DllEnterProc;
end.
这个是DLL部分的代码
这个是通过 热键HOME键可以呼出 注入的DLL(呼出其中的窗体)
现在我的要求是 DLL已经成功的注入到EXE当中了 
我想通过进程的键盘消息 来实现 跟热键HOME键一样的效果
不知道DELPHI下怎么实现?
还有下面这段C++的代码 是不是也是实现 我的目标
DWORD g_processID;   //进程句柄
DWORD g_ThreadID;    //线程句柄
CRITICAL_SECTION g_hCritical;  //windows 锁句柄(确切的应该叫关键代码段)
bool IsExsit(CString strExeFile)
{
   //加锁
 ::EnterCriticalSection(&g_hCritical);
    CString strFileName;
    bool bFound = false;
 
    PROCESSENTRY32 pe32 = {sizeof(pe32)};
    HANDLE hSnapShot = NULL;
   //系统内进行进程快照
 hSnapShot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS|TH32CS_SNAPNOHEAPS, 0);
    if (hSnapShot == INVALID_HANDLE_VALUE)
 {
  //如果快照失败,释放锁
  ::LeaveCriticalSection(&g_hCritical);
        return bFound;
 }
    //遍历这些快照后的结果,直到找到我们需要的进程,如果没有找到就返回失败
    BOOL bFlag = ::Process32First(hSnapShot, &pe32);
    while (bFlag)
    {
        strFileName = CString(pe32.szExeFile);
  if (strFileName==strExeFile)
        {
            bFound = true;
   g_processID = pe32.th32ProcessID;   
            break;
        }
        bFlag = ::Process32Next(hSnapShot, &pe32);
    }
    //关闭系统快照
    ::CloseToolhelp32Snapshot(hSnapShot);
//释放锁 
::LeaveCriticalSection(&g_hCritical);
 return bFound;
}
     //首先查看该进程是否存在,同时找到该进程的进程id
    if(IsExsit(_T("myapp")))
{
     HWND hwnd=::FindWindow(NULL,_T("myapp"));
    if (hwnd)
    {
         //根据句柄查找到该窗口对应的线程
         g_ThreadID = GetWindowThreadProcessId(hwnd,&g_processID);---貌似是得到窗体的线程ID 
         //发送消息
         ::PostThreadMessage(g_ThreadID,WM_KEYUP,13,13);----不明白这里参数的含义
    }
}
热键 消息消息通讯 Delphi