Solved

c++ to Delphi (Part of VNC code)

Posted on 2003-12-01
4
536 Views
Last Modified: 2010-04-05
OK. This has had me stumped all weekend. I am working on a partial conversion of the vnchooks.cpp file to delphi. I am looking at the code that handles the WM_PAINT message and am getting stumped on some pointer arithmetic.


As you can see, i've pretty much got it all comvertied, but I'm stuck on one line..  Hope somebody can help!

Heres the c++:
inline BOOL HookHandle(UINT MessageId, HWND hWnd, WPARAM wParam, LPARAM lParam)
{

      switch (MessageId)
      {
case WM_PAINT:
            if (prf_use_GetUpdateRect)
            {
                  HRGN region;
                  region = CreateRectRgn(0, 0, 0, 0);

                  // Get the affected region
                  if (GetUpdateRgn(hWnd, region, FALSE) != ERROR)
                  {
                        int buffsize;
                        UINT x;
                        RGNDATA *buff;
                        POINT TopLeft;

                        // Get the top-left point of the client area
                        TopLeft.x = 0;
                        TopLeft.y = 0;
                        if (!ClientToScreen(hWnd, &TopLeft))
                              break;

                        // Get the size of buffer required
                        buffsize = GetRegionData(region, 0, 0);
                        if (buffsize != 0)
                        {
                              buff = (RGNDATA *) new BYTE [buffsize];
                              if (buff == NULL)
                                    break;

                              // Now get the region data
                              if(GetRegionData(region, buffsize, buff))
                              {
                                    for (x=0; x<(buff->rdh.nCount); x++)
                                    {
                                          // Obtain the rectangles from the list
                                          RECT *urect = (RECT *) (((BYTE *) buff) + sizeof(RGNDATAHEADER) + (x * sizeof(RECT)));
                                          SendDeferredUpdateRect(
                                                hWnd,
                                                (SHORT) (TopLeft.x + urect->left),
                                                (SHORT) (TopLeft.y + urect->top),
                                                (SHORT) (TopLeft.x + urect->right),
                                                (SHORT) (TopLeft.y + urect->bottom)
                                                );
                                    }
                              }

                              delete [] buff;
                        }
                  }

                  // Now free the region
                  if (region != NULL)
                        DeleteObject(region);
            }
  }
Return True;
}



Heres what I've got so far:

function HookHandle(MessageID:Cardinal; hW:HWND; WPARAM: wParam; LPARAM: lParam): LResult;
var x:Integer;
  Region:HRGN;
  TopLeft:TPoint;
  buffsize:Integer;
  buff:PRGNDATA;
  Rect:TRect;

begin

case MessageID of
  WM_PAINT:
        begin


        region := CreateRectRgn(0, 0, 0, 0);
        if (GetUpdateRgn(hw,region,False) <> ERROR) then
                begin
                TopLeft.x := 0;
                TopLeft.y := 0;
                if (not ClientToScreen(hw, TopLeft)) then exit;
                        buffsize := GetRegionData(region, 0, 0);
                        if (buffsize <> 0) then
                                begin
                                new(Buff);

                                if GetRegionData(region, buffsize, buff) <> 0 then
                                        for x:=0 to buff.rdh.nCount -1 do
                                          begin

                                        // THIS IS THE LINE I CAN'T FIGURE OUT
                                        // RECT *urect = (RECT *) (((BYTE *) buff) + sizeof(RGNDATAHEADER) + (x * sizeof(RECT)));


                                        //Don't Worry about the SendDeferredUpdateRect line
                                          
                                          end;

                                Dispose(Buff);
                                end;
                end;
      if Region <> 0 then
        DeleteObject(region);
      end;

  end;

end;

0
Comment
Question by:rbohac
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
classmate earned 125 total points
ID: 9850973
{
I think this part is included in windows.pas
type
  PRect = ^TRect;
}

var
  urect : PRect;

begin
.
.
  urect := PRect (integer(buff) + sizeof(RGNDATAHEADER) + x*sizeof(TRect) );
.
.
end;

regards
classmate
0
 
LVL 6

Author Comment

by:rbohac
ID: 9851256
cool. Looks like it worked. Thank you!
0
 
LVL 2

Expert Comment

by:classmate
ID: 9851298
Any pointer type can be type-casted to integer, and type-casted back to any pointer type.
The integer type address value is useful when you need to calculate a memory address.

0
 

Expert Comment

by:thegetta
ID: 9852382
Listening
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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