To Inthe only

well,
here are your pts for

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10314323 

but please answer this

In the q up above i start a prog to simulate a click.
That for i minimized the formular and made it a very very very tiny one,
so nobody can see it.
But it is still a formula
I give you parts of the code

unit ForeignButtonclicken1;
interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
   
  private
    { Private-Deklarationen }
  public
    { Public declarations }

end;

var
  Form1: TForm1;
  fensterhandle: THandle;

implementation

{$R *.DFM}
uses ShellAPI;

Function WindowCallback(WHandle : HWnd; Var Parm : Pointer) :
         Boolean; stdcall;
    {This function is called once for each window}
Var winString : PChar;
begin
    winString := Allocmem(255);
    GetWindowText(WHandle,winString,255);
    if AnsiStrPos(winstring,'AnyWindowProgram')<>nil then
    begin
      Fensterhandle:=whandle;//get the window you needed
      result:=false;//stop enumerate
    end
    else
      Result := True; {not find the window. Continue to enumerate
            windows}
    FreeMem(winString,255);
end;

procedure ClickOkButton(h:HWND);
var c : HWND;
    s : string;
    b : array[0..100] of char;
DlgID : Word;
begin;
    c := GetWindow(h, GW_CHILD); //get first child window
    repeat
        GetWindowText(c, @b, 100);
        s := string(b);
   DlgID  := GetDlgCtrlID(c);
        c := GetWindow(c, GW_HWNDNEXT); //get first child window
    until (c = 0) or (lowercase(s) = '&ok');
        PostMessage(h, wm_Command, DlgID, MakeLong(h, BN_Clicked));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   Sleep(5000);
   FensterHandle:=0;
   EnumWindows ( @WindowCallBack, 0);
   If Fensterhandle <> 0 then
   begin
       ClickOkButton(Fensterhandle);
       FensterHandle:=0;
   end;
   Form1.Close;
   application.Terminate;
end;

end.

So how can i do this (within formcreate) without having a formular
No TForm1 etc

Is this possible ?????

Hopefully waiting
Indi
LVL 1
IndefreiAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
intheConnect With a Mentor Commented:
hi there ;-)
ok make a new application and take out the form and unit1 (from "project" - "remove from project" menu.
click view - unit - project1  ..
(project1.dpr)

do as before adding your functions/procedures adding any extra units that hold any api calls you need to uses section..
if unit contains only 2-3 consts you need just add the consts directly to make your program smaller ,otherwise your compiling all of messages.pas into your program just for 1 line ..

your form create code goes in the last
begin
end.
block.so you final code look (i havent tested it btw):

program Project1;

uses
  Windows,
  ShellApi,Sysutils;

const
WM_COMMAND = $0111;
BN_CLICKED = 0;
var
 fensterhandle: THandle;

{$R *.RES}

Function WindowCallback(WHandle : HWnd; Var Parm : Pointer) :
         Boolean; stdcall;
    {This function is called once for each window}
Var winString : PChar;
begin
    winString := Allocmem(255);
    GetWindowText(WHandle,winString,255);
    if AnsiStrPos(winstring,'AnyWindowProgram')<>nil then
    begin
      Fensterhandle:=whandle;//get the window you needed
      result:=false;//stop enumerate
    end
    else
      Result := True; {not find the window. Continue to enumerate
            windows}
    FreeMem(winString,255);
end;

procedure ClickOkButton(h:HWND);
var c : HWND;
    s : string;
    b : array[0..100] of char;
DlgID : Word;
begin;
    c := GetWindow(h, GW_CHILD); //get first child window
    repeat
        GetWindowText(c, @b, 100);
        s := string(b);
   DlgID  := GetDlgCtrlID(c);
        c := GetWindow(c, GW_HWNDNEXT); //get first child window
    until (c = 0) or (lowercase(s) = '&ok');
 PostMessage(h,wm_Command,DlgID,MakeLong(h, BN_CLICKED));
end;

begin
   Sleep(5000);
   FensterHandle:=0;
   EnumWindows ( @WindowCallBack, 0);
   If Fensterhandle <> 0 then
  begin
    ClickOkButton(Fensterhandle);
    FensterHandle:=0;
    exit;
  end;

end.

hope it works as you need.
Regards Barry
0
 
EpsylonCommented:
>To Inthe only

Alright, I keep my mouth shut. Barry, go ahead. I believe in you. Show us your skills   :o)
0
 
IndefreiAuthor Commented:
Don't laugh
I know,
that's basic
But it's a too long story
Indi
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
intheCommented:
now someone tell me how wrong it is ..

nothing i do works correct first time ;-)hehe
0
 
IndefreiAuthor Commented:
Hi, Eps,
I wouldn't mind your answer
but you know the points go to Barry
so, let's see your attitude
Cheers
Indi
0
 
IndefreiAuthor Commented:
Incredible
allways to slow
0
 
EpsylonCommented:
Indi, don't worry. My knowledge about these things is terrible. I could have typed 'listening' in my previous comment but I just made some work of it by expressing my faith in Barry   :o)
0
 
intheCommented:
one thing i am unsure of is the

FensterHandle:=0;
exit;  <-- is it correct to put the exit here ?
end;

end.
0
 
EpsylonCommented:
From Delphi help:

If the current procedure is the main program, Exit causes the program to terminate.



The program will exit anyway so you can remove it...
0
 
IndefreiAuthor Commented:
You bastards
This time you get your damned pts, but
I'll never accept any answers again,
especially by Barry, he does not feel save, he
See you unsure people
and i like it
Indi
0
 
intheCommented:
hey "Him" fan have you tried it yet ?
did it work ?

ps,
not my music taste,i prefer britney ;-)
0
 
IndefreiAuthor Commented:
Well,
Shocked or what
Sad
0
 
EpsylonCommented:
Barry, I just reported Indi's behavior to Customer Support. I'll tell you if there's any news...
0
 
IndefreiAuthor Commented:
Spears, you lonesomen ?
ThenI am sure you will like HIM
0
 
intheCommented:
hehe,

well i better go learn this visor thing ,it came today at last :-)
0
 
IndefreiAuthor Commented:
Hey, Eps,
In case, you did not understand
don't mind
and thanks
Indi
0
 
EpsylonCommented:
Have not seen or heard anything since I ordered mine. Not even a confirmation of my order.
0
 
EpsylonCommented:
Hehe...

Did you wet your pants   ;o)
0
 
intheCommented:

   LoL

ps,
bloody need to buy a cable for visor to sync to pc and how funnee they dont ship internationaly yet ...just great ..
cant install any of the software ive been downloading for it ..
0
 
EpsylonCommented:
Maybe some on EE can send one..?
0
 
intheCommented:
probably easier to just make one ..ill look into it more tomorrow ..

 see ya :-)
0
 
IndefreiAuthor Commented:
Oh...missed the final Eps,
ho, ho ,  
cool n heavy
well, think i deserved it

p.s.
barry
the prog works without any change
smallest exe i ever got, great
0
 
intheCommented:
no problem ,im just glad it worked :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.