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

  • Home
  • SEARCH
  • 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 8399969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:26:38+00:00 2026-06-09T21:26:38+00:00

I am coding a screensaver program running on Windows. In preview mode, Windows calls

  • 0

I am coding a screensaver program running on Windows.

In preview mode, Windows calls the program this way :
Screensaver.exe /p ParentWindowHandle

However, when I make this call in my program :
BOOL res = GetClientRect(parentWindowHandle, rect)
res is FALSE, rect is NULL and I get ERROR_INVALID_WINDOW_HANDLE with GetLastError()

GetWindowRect gives me the same results.

But, if I make a call to BOOL res = IsWindow(parentWindowHandle) instead, I get res == TRUE. Does this not mean I have a valid window handle ?

The code looks like this :

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
    unsigned int handle = GetHandleFromCommandLine(pCmdLine); // Custom function (tested and approved :) )
    HWND parentWindowHandle = (HWND) handle;
    LPRECT rect = NULL;
    BOOL res = GetClientRect(parentWindowHandle, rect);
    // here, rect == NULL, res == FALSE and GetLastError() returns ERROR_INVALID_WINDOW_HANDLE

    // ...
    // ...
}
  • 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-09T21:26:40+00:00Added an answer on June 9, 2026 at 9:26 pm

    On 64-bit Windows, a window handle is 64 bits and cannot fit in an unsigned int, so your cast is producing a value that is an invalid window handle. You should modify your GetHandleFromCommandLine function so that it returns a proper HWND, not an unsigned int, and no type cast is necessary.

    Also, GetClientRect returns the rectangle by storing it into the value pointed at by the second parameter. If you pass it NULL, it has nowhere to store that, so it will either crash or fail with an invalid parameter error. To avoid that, pass in the address of a local variable:

    RECT rect;
    GetClientRect(..., &rect);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do coding this way pose any security risks? $test = $_GET['test']; if($test) { $sql
I´m coding a CSS menu for Wordpress and I have this stupid problem: I
***Coding in C# This works: NpgsqlConnection conn = new NpgsqlConnection(conx.getConexion()); conn.Open(); NpgsqlDataAdapter da =
When coding up, say, a registration form from scratch, does it make sense to
When coding up Ajax calls in ASP.Net MVC we have a lot of options
This coding i got from here. I get error in log cat view like
During coding I frequently encounter this situation: I have several objects ( ConcreteType1 ,
Coding in VB2008 with Net Framework 3.5 in Windows 7-32 bit. The code: TempUserPath
Coding in VB.Net Hi guys I've got this problem where I'm trying to assign
While coding with UITableView, I encounter this bug that I couldn't understand. I got

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.