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 7893565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:09:53+00:00 2026-06-03T07:09:53+00:00

I am using GetWindowRect from the windows API to get the bounds of a

  • 0

I am using GetWindowRect from the windows API to get the bounds of a running application, I then use these bounds to screenshot the application.

My code works for about 10 programs I have tested, notepad.exe and a few others, however the one app I want to use it with RocLink800 it returns static values that are incorrect regardless of the applications location.

Code is C# .NET

    [StructLayout(LayoutKind.Sequential)]
    public struct RECT
    {
        public int X;
        public int Y;
        public int Width;
        public int Height;
    }

    [DllImport("user32.dll", SetLastError = true)]
    static extern bool GetWindowRect(IntPtr hWnd, ref RECT Rect);

    IntPtr error = GetWindowRect(proc.MainWindowHandle, ref rect);

    ... main code
    while (error == (IntPtr)0)
    {
        error = GetWindowRect(proc.MainWindowHandle, ref rect);
    }

    int width = rect.right - rect.left;
    int height = rect.bottom - rect.top;

Now all applications this returns the correct width and height, with roclink800 it returns an error value of 1 indicating successs but it returns the following values regardless of the applications location:

rect.right = 960
rect.left = 960
rect.bottom = 600
rect.top = 600

I am completely stumped why this is happening or how to rectify it, roclink800 is an old program ported from the windows95 days so perhaps it is using some odd api, if this is the case are there any alternatives from the windows API (user32.dll) to obtaining its screen coordinates?

I guess I could force the application to go fullscreen and screen capture it this way but it is less elegant.

Ideas anyone?

edit: My code for getting the handle

        Process roclink = new Process();
        roclink.StartInfo.FileName = "C:/Program Files (x86)/ROCLINK800/Roclink.exe";
        //roclink.StartInfo.FileName = "notepad.exe";
        roclink.Start();
        IntPtr error = GetWindowRect(roclink.MainWindowHandle, ref rect);

OR

        try
        {
            proc = Process.GetProcessesByName("roclink")[0];
        }
        catch (IndexOutOfRangeException e)
        {
            return null;
        }

Both chunks of code return the same IntPtr and they both return 960,960,600,600 however if I call

int error = SetWindowPos(roclink.MainWindowHandle, HWND_TOPMOST, 0, 0, 25,50, SWP_SHOWWINDOW);

Then I get the returned coordinates being 0,0,25,50 yet the applications size does not change.

I have tried breaking the program, closing roclink and the SetWindowPos and GetWindowRect both return 0 and do not return the false values indicating that the handle is indeed the correct handle.

So it seems this application cannot have its windowsize set or gotten via windowsAPI, anyone got any clues why this may be?

roclink.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;

This also is ignored and the application will not open in fullscreen, simply the size it was last opened in.

edit: The only solution I can come up with is to make a copy of roclink.exe and open it manually by hand fullscreen then close it, providing no one else opens this file it will always open full screen, this is dodgy and I do not like it but unless anyone has any ideas why this is the case I may have to go with this. 🙁

  • 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-06-03T07:09:55+00:00Added an answer on June 3, 2026 at 7:09 am

    I think it is obvious that in the case of your application the MainWindowHandle is not the actual ‘main window’ the application launches.

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

Sidebar

Related Questions

I have code that makes a screenshot of the window using winapi. Then I
Is it possible to set the taskbar position/width/height using the windows API? I'm running
Using DMD 2.057, I cannot get the following code to compile: import std.stdio; import
Using LINQ on collections, what is the difference between the following lines of code?
this code works fine: procedure TForm2.Timer1Timer(Sender: TObject); var Text: string; begin SetLength (Text,555); GetWindowText
I can get the coordinates of a windows entire area, and the coordinates of
I'm looking at handling longer file paths in my windows application. Currently, I have
I'am using the below code to copy paste..but it doesnt copy the whole context
I know I am probably missing something, but I can't seem to get windows
Using the WinApi GetWindowRect() it returns the complete window size, but I would like

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.