Solved

To Inthe only

Posted on 2000-03-21
23
284 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
  • 8
  • 8
  • 7
23 Comments
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
>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
Comment Utility
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
Comment Utility
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
 
LVL 17

Expert Comment

by:inthe
Comment Utility
now someone tell me how wrong it is ..

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

Author Comment

by:Indefrei
Comment Utility
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
Comment Utility
Incredible
allways to slow
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
hey "Him" fan have you tried it yet ?
did it work ?

ps,
not my music taste,i prefer britney ;-)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:Indefrei
Comment Utility
Well,
Shocked or what
Sad
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
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
Comment Utility
Spears, you lonesomen ?
ThenI am sure you will like HIM
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
hehe,

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

Author Comment

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

Expert Comment

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

Expert Comment

by:Epsylon
Comment Utility
Hehe...

Did you wet your pants   ;o)
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility

   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
Comment Utility
Maybe some on EE can send one..?
0
 
LVL 17

Expert Comment

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

 see ya :-)
0
 
LVL 1

Author Comment

by:Indefrei
Comment Utility
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
Comment Utility
no problem ,im just glad it worked :-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now