Solved

c++ to Delphi (Part of VNC code)

Posted on 2003-12-01
4
542 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
[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
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month5 days, 21 hours left to enroll

627 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