Solved

c++ to Delphi (Part of VNC code)

Posted on 2003-12-01
4
533 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

16 Experts available now in Live!

Get 1:1 Help Now