?
Solved

Reading of graphical output of another application (D7)

Posted on 2011-09-30
6
Medium Priority
?
285 Views
Last Modified: 2013-11-22
I have a very old application that doesn't have logging capabilities. It has only graphical representation of information needed. I attached link to a picture where different readings can be seen.
Vertical indicator with scale that has zero in the middle.

I need a code that can read and log that indicator's reading to a file, with frequency up to once per second.

I have an idea in general how it should be done but no idea how to code it.

So, in general:
1. it needs to get window handle base on window's name
2. make screenshot of rectangle one pixel wide and 100% of indicator's high
3. find current reading (background is constant, so, the needed reading is a border between color and background)
4. write it to a log file

I hope the description is clear.

sc.gif
0
Comment
Question by:3axap
[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
  • 4
6 Comments
 
LVL 25

Expert Comment

by:epasquier
ID: 36895970
don't have time to piece it together. you had the methodology right.
here is how to get a window by its title
function SearchMainWindowByName(Start:String;Mid:String='';UpC:boolean=True):THandle;
type
 RR=Record
     S,M:String;
     L:integer;
     U:boolean;
     hWindow:HWND;
    end;
 pRR=^RR;
Var
 R:RR;
 function EnumProcess(hHwnd: HWND; lParam : integer): boolean; stdcall;
 var
  pPid : DWORD;
  title, ClassName : string;
  R:pRR;
 begin
  //if the returned value in null the
  //callback has failed, so set to false and exit.
  if (hHwnd=0) then result := false else
   begin
    R:=pRR(lParam);
    //additional functions to get more
    //information about a process.
    //get the Process Identification number.
{$ifdef VER140}
      GetWindowThreadProcessId(hHwnd,pPid);
{$else}
      GetWindowThreadProcessId(hHwnd,@pPid);
{$endif}
    SetLength(ClassName, 255);
    SetLength(ClassName,
              GetClassName(hHwnd,
                           PChar(className),
                           Length(className)));
    SetLength(title, 255);
    SetLength(title, GetWindowText(hHwnd, PChar(title), Length(title)));
    //Display the process information
    //by adding it to a list box
    if Assigned(SearchWindowList) Then SearchWindowList.Add
      ('Class Name = ' + className +
       '; Title = ' + title +
       '; HWND = '+ IntToStr(hHwnd) +
       '; Pid = ' + IntToStr(pPid));
    if R^.U Then
     begin
      Title:=UpperCase(title);
      ClassName:=UpperCase(ClassName);
     end;
    if Copy(title,1,R^.L)=R^.S Then
     begin
      if (R^.M='') Or (Pos(R^.M,title)>0)
        Then R^.hWindow:=hHwnd;
     end Else
    if Copy(ClassName,1,R^.L)=R^.S Then
     begin
      if (R^.M='') Or (Pos(R^.M,ClassName)>0)
        Then R^.hWindow:=hHwnd;
     end;
    Result := R^.hWindow=0;
  end;
 end;
begin
 R.hWindow:=0;
 if UpC Then
  begin
   R.S:=UpperCase(Start);
   R.M:=UpperCase(Mid);
  end Else
  begin
   R.S:=Start;
   R.M:=Mid;
  end;
 R.L:=Length(Start);
 R.U:=Upc;
 if Assigned(SearchWindowList) Then SearchWindowList.Clear;
 EnumWindows(@EnumProcess,Integer(@R));
 Result:=R.hWindow;
end;

Open in new window

0
 
LVL 25

Expert Comment

by:epasquier
ID: 36895971
here is how to get the window as bitmap

ScreenShot(WinHandle, Bmp, True ); // true = client area
procedure ScreenShot(hWin:THandle;destBitmap : TBitmap;ClientArea:Boolean=True);
var
   w,h : integer;
   DC : HDC;
   r : TRect;
begin
 if ClientArea then
  begin
   dc := GetDC(hWin) ;
   GetClientRect(hWin,r);
  end else
  begin
   dc := GetWindowDC(hWin) ;
   GetWindowRect(hWin,r) ;
  end;
 w := r.Right - r.Left;
 h := r.Bottom - r.Top;
 try
  destBitmap.Width := w;
  destBitmap.Height := h;
  BitBlt(destBitmap.Canvas.Handle,
         0,
         0,
         destBitmap.Width,
         destBitmap.Height,
         DC,
         0,
         0,
         SRCCOPY) ;
 finally
  ReleaseDC(hWin, DC) ;
 end;
end;

Open in new window

0
 
LVL 25

Accepted Solution

by:
epasquier earned 1600 total points
ID: 36895973
then with the bitmap, you use bmp.canvas.Pixels[X,Y] and test the color to find when it's not grey (starting from top to middle and bottom to middle)
0
Independent Software Vendors: 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!

 

Author Comment

by:3axap
ID: 36896017
Pasquier, thank you.
Actually "test the color to find when it's not grey (starting from top to middle and bottom to middle)" is the hardest part for me :o)
I'll try to get those peices together.

Speed wise, base on your experience, is this methodology optimal enough to run with 1Hz frequency and don't eat much CPU time?
0
 
LVL 25

Expert Comment

by:epasquier
ID: 36896045
sure.
0
 
LVL 27

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 400 total points
ID: 36909484

For detecting colors:

...
bmp: TBitmap;
...
if bmp.Canvas.Pixels[x, y] = clGray then ....

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 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