Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7570961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:32:59+00:00 2026-05-30T15:32:59+00:00

i want convert this c++ code in C#: RECT rcCurrent; ::GetWindowRect ( hwndChild, &rcCurrent

  • 0

i want convert this c++ code in C#:

RECT rcCurrent;
::GetWindowRect ( hwndChild, &rcCurrent );
::MapWindowPoints ( NULL, hWnd, reinterpret_cast<LPPOINT>(&rcCurrent), 2);

But i don’t know how transform :

reinterpret_cast<LPPOINT>(&rcCurrent)

How to cast System.Windows.Rect to System.Windows.Point ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:33:00+00:00Added an answer on May 30, 2026 at 3:33 pm
    RECT rcCurrent; ::GetWindowRect ( hwndChild, &rcCurrent );
    ::MapWindowPoints ( NULL, hWnd, reinterpret_cast<LPPOINT>(&rcCurrent), 2);
    

    What this code is doing is getting the bounding rectangle (rcCurrent) of a child window (hwndChild) with respect to the client area of a presumably parent window (hWnd) – or determining where a child window is inside its parent.

    The first line gets the full rectangle of the child, borders and all, but it gets returned in screen coordinates.

    The second line maps those points from screen coordinates (indicated by the first NULL parameter) to coordinates relative to the client-area of hWnd.

    Win32 doesn’t have a “get location within parent” call, so this is the nearest roundabout equivalent.

    What the cast is doing here is taking advantage of the fact that a Win32 RECT has the exact same memory layout as two back-to-back POINTs, so calling MapWindowPoints with cPoints=2 will map a whole RECT in one go. This usage is actually documented in MSDN, and even gets special treatment in right-to-left mirroring modes to ensure that whole rectangles get mapped properly when mapped from a left-to-right-layout desktop to a right-to-left application, and vice-versa! (If you don’t plan on using R-to-L mirroring so that localized versions of your apps can run on Hebrew or Arabic, you don’t need to worry about this.)

    —

    The correct way to translate this to C# depends on where you’re starting from and what you’re trying to achieve. If you’re converting an app wholesale from C++ to C#, and you have Control-derived objects for the parent and the child, you can just use child.Location to get the position relative to the parent.

    —

    On the other hand, if you are porting code that is written in terms of HWNDs and has to remain that way even when ported to C# (eg. because it’s working against HWNDs from another process or doesn’t know the underlying framework of the HWNDs), then your best bet would be to define P/Invoke versions of RECT and POINT, and the key thing here is to define a P/Invoke version of MapWindowPoints that will work on RECT. (I’m assuming you’re somewhat familiar with P/Invoke here…) Usually MapWindowPoints is defined as (from pinvoke.net):

    [DllImport("user32.dll", SetLastError=true)]
    public static extern int MapWindowPoints(IntPtr hwndFrom, IntPtr hwndTo, ref POINT lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
    

    …and you can use this version to map a single POINT (always passing in cPoints as 1). You can then also define a version that works with RECT:

    [DllImport("user32.dll", SetLastError=true)]
    public static extern int MapWindowPoints(IntPtr hwndFrom, IntPtr hwndTo, ref RECT lpPoints, [MarshalAs(UnmanagedType.U4)] int cPoints);
    

    And when calling this latter version, always pass in cPoints as 2. Calling this would then be the exact C# equivalent of the original C++ MapWindowPoints call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert function object to function. I wrote this code, but it
I want to convert this url: module-apple-get.html?term=st to file.php?module=apple&func=get&term=st I 've wrote this code
I have the following code in Ruby. I want to convert this code into
I want to convert a jpg file to png, but when I run this
I want to convert <p>Code is following</p> <pre> &lt;html&gt;<br>&lt;/html&gt; </pre> to <p>Code is following</p>
I want to convert an iplimage to a cv::mat (not CvMat). With this code
I want to convert this code into PHP, it's a function that hides layers
I want to convert this LINQ code var x = from nm in names
I have this code in Java and I want to convert it to C#.
I want to convert this C++ code to C#: typedef struct consoleCommand_s { char*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.