K Given a specific Window Name you can grab the handle to the window you wish to draw on..
EDIT: Here you go.. This should definitely do it:
Script To Test it:
{$I SRL/SRL.Simba}
type
Form = record
Drawing: TForm;
end;
var
InterfaceForm: Form;
procedure Form_Init;
begin
with InterfaceForm do
begin
Drawing := CreateForm;
with Drawing do
begin
Left := 376;
Top := 175;
BorderStyle := bsNone;
Caption := 'Drawing';
ClientHeight := 201;
ClientWidth := 304;
Color := 0;
Font.Color := clWindowText;
Font.Height := - 11;
Font.Name := 'Tahoma';
Font.Style := [];
PixelsPerInch := 96;
end;
end;
end;
procedure Form_SafeInit;
var
v: TVariantArray;
begin
SetLength(v, 0);
ThreadSafeCall('Form_Init', v);
end;
function Form_ShowModal: Boolean;
begin
InterfaceForm.Drawing.SHOW;
Result := InterfaceForm.Drawing.Showing;
end;
function Form_SafeShowModal: Boolean;
var
v: TVariantArray;
begin
SetLength(v, 0);
Result := ThreadSafeCall('Form_ShowModal', v);
end;
procedure FreeDrawingForm;
begin
FreeForm(InterfaceForm.Drawing);
end;
Procedure SetFormGUI(FormHandle, Width, Height: Integer; ParentTitle, ParentClass: String; FormPosition: TPoint);
var
Path: String;
begin
Path := IncludePath + 'FormGUI.INI';
WriteINI('FormInfo', 'Changed', 'Y', Path);
WriteINI('FormInfo', 'FormHandle', ToStr(FormHandle), Path);
WriteINI('FormInfo', 'ParentTitle', ParentTitle, Path);
WriteINI('FormInfo', 'ParentClass', ParentClass, Path);
WriteINI('FormInfo', 'ChildPosition', '[' + ToStr(FormPosition) + ']', Path);
WriteINI('FormInfo', 'ChildWidth', ToStr(Width), Path);
WriteINI('FormInfo', 'ChildHeight', Height, Path);
end;
var
TPA: TPointArray;
TPAArea: TBox;
begin
Form_SafeInit;
Form_SafeShowModal;
AddOnTerminate('FreeDrawingForm');
TPA := TPAFromBox(IntToBox(0, 0, 20, 20));
TPAArea := GetTPABounds(TPA);
SetFormGUI(InterfaceForm.Drawing.Handle, 1 + (TPAArea.X2 - TPAArea.X1), 1 + (TPAArea.Y2 - TPAArea.Y1), 'Diablo', 'Class', Point(0, 0));
//Every time you pass different parameters to SetFormGUI, you should destroy the form first and remake it using SafeINIT and safe show modal.
InterfaceForm.Drawing.CANVAS.Pen.COLOR := CLRed;
InterfaceForm.Drawing.CANVAS.Rectangle(0, 0, 20, 20); //Make sure ur drawing doesn't go out of the bounds of your form!
end.
New Extension:
[PHP]
Program WindowHandles;
const
LWA_COLORKEY = 1;
LWA_ALPHA = 2;
LWA_BOTH = 3;
WS_EX_LAYERED = $80000;
GWL_EXSTYLE = - 20;
type
TCharArray = array of Char;
GUIInput = record
FormHandle: Integer;
ParentTitle: String;
ParentClass: String;
ChildPosition: TPoint;
ChildWidth: Integer;
ChildHeight: Integer;
//TPAToDebug: TPointArray;
end;
var
SimbaMenu, FormGUI: TMenuItem;
Extensions: string;
FormTitleBarName: PChar;
UserGUIInfo: GUIInput;
Thread: TTimer;
Function FindWindow(ClassName, WindowName: PChar): HWND; external 'FindWindowA@User32.dll stdcall';
Function SetParent(Child, Parent: HWND): HWND; external 'SetParent@User32.dll stdcall';
Function SetWindowPos(Handle, HandleAfter: HWND; X, Y, CX, CY: Integer; Flags: Word): Boolean; external 'SetWindowPos@User32.dll stdcall';
Function GetWindowLong(Handle: HWND; nIndex: LongInt): LongInt; external 'GetWindowLongA@User32.dll stdcall';
Function SetWindowLong(Handle: HWND; nIndex: LongInt; dwNewLong: Longint): LongInt; external 'SetWindowLongA@User32.dll stdcall';
Function SetLayeredWindowAttributes(Handle: HWND; Color, Alpha: Longint; dwFlags: Byte): Boolean; external 'SetLayeredWindowAttributes@User32.dll stdcall';
Procedure SetWindowTransparent(Handle: HWND; Color: LongInt; nTrans: Integer);
var
Attribute: LongInt;
begin
Attribute := GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, Attribute or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, Color, nTrans, 1);
end;
Procedure SetFormTransparent(ClassName, WindowName: PChar);
begin
SetWindowTransparent(FindWindow(ClassName, WindowName), 0, LWA_COLORKEY);
end;
Function FindSmart: HWND;
var
Smart: HWND;
begin
Smart := FindWindow('SunAwtFrame', '');
Result := Smart;
end;
Procedure SetParentSmart(Sender: TObject);
var
FormHandle, SmartHandle: HWND;
begin
FormTitleBarName := 'FormGUI';
FormHandle := FindWindow('', FormTitleBarName);
SmartHandle := FindSmart;
if ((SmartHandle <> 0) and (FormHandle <> 0)) then
begin
SetParent(FormHandle, SmartHandle);
SetWindowPos(FormHandle, 0, 6, 345, 505, 128, 1);
end;
FormTitleBarName := 'FormBTN';
FormHandle := FindWindow('', FormTitleBarName);
if ((SmartHandle <> 0) and (FormHandle <> 0)) then
begin
SetParent(FormHandle, SmartHandle);
SetWindowPos(FormHandle, 0, 476, 324, 505, 128, 1);
end;
end;
Function StringToTPA(TPA: String): TPointArray;
var
I, J, X, Y: Integer;
Str: String;
TempTPA: TPointArray;
begin
if (ExecRegExpr('^\[\([0-9]*,(\s*|^\s)[0-9]*\)*', TPA) and ExecRegExpr('\)\]$', TPA)) then
begin
if (Not ExecRegExpr('~|!|@|#|\$|%|\^|&|\*|_|\+|=|{|}|"|''|:|;|\.|<|>|\?|/|[a-z]|[A-Z]|(\[-|-\(|\)-|\),-|-\])|\\|\.|(\((\s*|^\s)\()|(,(\s*|^\s),)|(\)(\s*|^\s)\))', TPA)) then
begin
writeln('TPA String is a Valid TPointArray Match.');
For I:= 1 To High(TPA) do
begin
if (TPA
= '(') then
begin
Inc(I);
while (ExecRegExpr('[0-9]', TPA)) do
begin
str:= str + TPA;
Inc(I);
if (TPA = ',') then
begin
X:= StrToInt(str);
str:= '';
break;
end;
end;
end;
if (TPA = ',') then
begin
I:= I + 2;
while (ExecRegExpr('[0-9]', TPA)) do
begin
str:= str + TPA;
Inc(I);
if (TPA = ')') then
begin
Y:= StrToInt(str);
str:= '';
break;
end;
end;
I:= I - 1;
end;
if (TPA = ')') then
begin
SetLength(TempTPA, Length(TempTPA) + 1);
TempTPA[J]:= Point(X, Y);
Inc(J);
SetLength(Result, Length(TempTPA));
Result:= TempTPA;
end;
end;
end else
begin
writeln('Invalid String To TPointArray Match!');
SetLength(Result, 1);
Result[0]:= Point(-99999, -99999);
end;
end else
begin
writeln('Invalid String To TPointArray Match!');
SetLength(Result, 1);
Result[0]:= Point(-99999, -99999);
end;
end;
Function GetUserInput: Boolean;
var
Path: String;
TempTPA: TPointArray;
begin
Path := IncludePath + 'FormGUI.INI';
Result := False;
If (UpperCase(ReadINI('FormInfo', 'Changed', Path)) = 'Y') then
begin
UserGUIInfo.FormHandle := StrToIntDef(ReadINI('FormInfo', 'FormHandle', Path), -1);
UserGUIInfo.ParentTitle := ReadINI('FormInfo', 'ParentTitle', Path);
UserGUIInfo.ParentClass := ReadINI('FormInfo', 'ParentClass', Path);
TempTPA := StringToTPA(ReadINI('FormInfo', 'ChildPosition', Path));
UserGUIInfo.ChildPosition := TempTPA[0];
UserGUIInfo.ChildWidth := StrToIntDef(ReadINI('FormInfo', 'ChildWidth', Path), 0);
UserGUIInfo.ChildHeight := StrToIntDef(ReadINI('FormInfo', 'ChildHeight', Path), 0);
//UserGUIInfo.TPAToDebug := StringToTPA(ReadINI('FormInfo', 'TPAToDebug', Path));
Result := True;
end;
end;
Function ValidWindowInfo(Info: GUIInput): Boolean;
begin
Result := (Length(Info.ParentTitle) > 0) or (Length(Info.ParentClass) > 0);
end;
Procedure ValidateUserInput(Sender: TObject);
var
Path: String;
begin
Path := IncludePath + 'FormGUI.INI';
If (FileExists(Path)) then
If GetUserInput then
begin
WriteINI('FormInfo', 'Changed', 'N', Path);
If ValidWindowInfo(UserGUIInfo) then
If (UserGUIInfo.FormHandle > 0) then
begin
If ((UserGUIInfo.ChildPosition.X >= 0) AND (UserGUIInfo.ChildPosition.Y >= 0)) then
SetWindowPos(UserGUIInfo.FormHandle, 0, UserGUIInfo.ChildPosition.X, UserGUIInfo.ChildPosition.Y, UserGUIInfo.ChildWidth, UserGUIInfo.ChildHeight, 4);
SetParent(UserGUIInfo.FormHandle, FindWindow(UserGUIInfo.ParentClass, UserGUIInfo.ParentTitle));
end;
end;
end;
Procedure Thread_Init;
begin
Thread := TTimer.Create(nil);
Thread.ONTIMER := @ValidateUserInput;
Thread.INTERVAL := 5000;
Thread.ENABLED := True;
end;
Procedure Init;
begin
SimbaMenu := TMenuItem.Create(Simba_MainMenu);
SimbaMenu.Caption := 'FormGUI';
Simba_MainMenu.Items.Add(SimbaMenu);
FormGUI := TMenuItem.Create(SimbaMenu);
FormGUI.Caption := 'FormGUI';
FormGUI.ShortCut := 123;
FormGUI.OnClick := @ValidateUserInput;
SimbaMenu.Add(FormGUI);
Thread_Init;
end;
Function GetName: string;
begin
result := 'FormGUI';
end;
Function GetVersion: string;
begin
result := '1.0';
end;
Procedure Free;
begin
end;
Procedure Attach;
begin
writeln(' FormGUI By Ggzz ');
Writeln('# FormGUI Simba Extension #');
end;
Procedure Detach;
begin
writeln('FormGUI: GoodBye!');
end;
begin
end.
[/PHP]