Erro ao usar GWW_HINSTANCE

Delphi

14/03/2008

Estou querendo utilizar a variável GWW_HINSTANCE para poder enviar msg para outro programa, mas meu delphi não a encontra.

Me falaram q ela se localiza num desses 3 caras ae:
Windows, WinTypes, WinProcs

Mas ainda assim não obtenho sucesso... Alguém poderia me ajudar?

Vlw


Jakefrog

Jakefrog

Curtidas 0

Respostas

Massuda

Massuda

14/03/2008

GWW_HINSTANCE é coisa do tempo do Windows 3, nem existe hoje em dia. O que você pretende fazer?


GOSTEI 0
Jakefrog

Jakefrog

14/03/2008

Um programa para enviar Mensagem para outro programa. Aí achei um exemplo que utiliza esse cara!

Olha ele ae em negrito lem baixo.


unit Unit1;

interface

uses

SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;

type

TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
AppInst: THandle;
AppWind: THandle;
public
{ Public declarations }
end;

var

Form1: TForm1;

implementation

{$R *.DFM}

uses ShellAPI;

procedure SendShift(H: HWnd; Down: Boolean);
var
vKey, ScanCode, wParam: Word;

lParam: longint;
begin

vKey := $10;
ScanCode := MapVirtualKey(vKey, 0);
wParam := vKey or ScanCode shl 8;
lParam := longint(ScanCode) shl 16 or 1;
if not (Down) then
lParam := lParam or $C0000000;
SendMessage(H, WM_KEYDOWN, vKey, lParam);
end;

procedure SendCtrl(H: HWnd; Down: Boolean);
var
vKey, ScanCode, wParam: Word;

lParam: longint;
begin

vKey := $11;
ScanCode := MapVirtualKey(vKey, 0);
wParam := vKey or ScanCode shl 8;
lParam := longint(ScanCode) shl 16 or 1;
if not (Down) then
lParam := lParam or $C0000000;
SendMessage(H, WM_KEYDOWN, vKey, lParam);
end;

procedure SendKey(H: Hwnd; Key: char);
var
vKey, ScanCode, wParam: Word;

lParam, ConvKey: longint;
Shift, Ctrl: boolean;
begin

ConvKey := OemKeyScan(ord(Key));
Shift := (ConvKey and $00020000) <> 0;
Ctrl := (ConvKey and $00040000) <> 0;
ScanCode := ConvKey and $000000FF or $FF00;
vKey := ord(Key);
wParam := vKey;
lParam := longint(ScanCode) shl 16 or 1;
if Shift then
SendShift(H, true);
if Ctrl then
SendCtrl(H, true);
SendMessage(H, WM_KEYDOWN, vKey, lParam);
SendMessage(H, WM_CHAR, vKey, lParam);
lParam := lParam or $C0000000;
SendMessage(H, WM_KEYUP, vKey, lParam);
if Shift then
SendShift(H, false);
if Ctrl then
SendCtrl(H, false);
end;

function EnumFunc(Handle: HWnd; TF: TForm1): Bool; far;
begin

TF.AppWind := 0;
[b:c04d958e04]if GetWindowWord(Handle, GWW_HINSTANCE) = TF.AppInst then [/b:c04d958e04]
TF.AppWind := Handle;
result := (TF.AppWind = 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
Text: array[0..255] of char;
begin

AppInst := ShellExecute(Handle, ´open´, ´notepad.exe´, nil, ´´, SW_NORMAL);
EnumWindows(@EnumFunc, longint(self));
AppWind := GetWindow(AppWind, GW_CHILD);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin

SendKey(AppWind, ´T´);
SendKey(AppWind, ´e´);
SendKey(AppWind, ´s´);
SendKey(AppWind, ´t´);
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin

if AppWind <> 0 then
SendKey(AppWind, Key);
end;

end.


GOSTEI 0
Massuda

Massuda

14/03/2008

Use GWL_HINSTANCE ao inves de GWW_HINSTANCE.


GOSTEI 0
Jakefrog

Jakefrog

14/03/2008

Eh, parou de dar q não localizava, mas deu erro! Bem vou ver se acho algum outro modo! OBrigado pela atenção!


GOSTEI 0
Massuda

Massuda

14/03/2008

Talvez ajude... No CD do Delphi costuma(va) ter uma unit chamada SNDKEY32.PAS que envia ´teclas´ para outro programa.


GOSTEI 0
POSTAR