Solved

To Inthe only

Posted on 2000-03-21
23
315 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:Indefrei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 7
23 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642283
>To Inthe only

Alright, I keep my mouth shut. Barry, go ahead. I believe in you. Show us your skills   :o)
0
 
LVL 1

Author Comment

by:Indefrei
ID: 2642317
Don't laugh
I know,
that's basic
But it's a too long story
Indi
0
 
LVL 17

Accepted Solution

by:
inthe earned 50 total points
ID: 2642323
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:inthe
ID: 2642326
now someone tell me how wrong it is ..

nothing i do works correct first time ;-)hehe
0
 
LVL 1

Author Comment

by:Indefrei
ID: 2642340
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
 
LVL 1

Author Comment

by:Indefrei
ID: 2642351
Incredible
allways to slow
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642356
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
 
LVL 17

Expert Comment

by:inthe
ID: 2642371
one thing i am unsure of is the

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

end.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642422
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
 
LVL 1

Author Comment

by:Indefrei
ID: 2642433
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
 
LVL 17

Expert Comment

by:inthe
ID: 2642465
hey "Him" fan have you tried it yet ?
did it work ?

ps,
not my music taste,i prefer britney ;-)
0
 
LVL 1

Author Comment

by:Indefrei
ID: 2642474
Well,
Shocked or what
Sad
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642483
Barry, I just reported Indi's behavior to Customer Support. I'll tell you if there's any news...
0
 
LVL 1

Author Comment

by:Indefrei
ID: 2642485
Spears, you lonesomen ?
ThenI am sure you will like HIM
0
 
LVL 17

Expert Comment

by:inthe
ID: 2642543
hehe,

well i better go learn this visor thing ,it came today at last :-)
0
 
LVL 1

Author Comment

by:Indefrei
ID: 2642561
Hey, Eps,
In case, you did not understand
don't mind
and thanks
Indi
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642562
Have not seen or heard anything since I ordered mine. Not even a confirmation of my order.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642568
Hehe...

Did you wet your pants   ;o)
0
 
LVL 17

Expert Comment

by:inthe
ID: 2642623

   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
 
LVL 13

Expert Comment

by:Epsylon
ID: 2642633
Maybe some on EE can send one..?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2642776
probably easier to just make one ..ill look into it more tomorrow ..

 see ya :-)
0
 
LVL 1

Author Comment

by:Indefrei
ID: 2650918
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
 
LVL 17

Expert Comment

by:inthe
ID: 2651853
no problem ,im just glad it worked :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question