?
Solved

Region Handles and GetWindowRgn

Posted on 2003-03-16
4
Medium Priority
?
595 Views
Last Modified: 2010-10-05
I recently started exploring the use of regions to skin my program but I am having a terrible experience with them.  My current problem is concerning GetWindowRgn which always returns ERROR no matter what.  I don't quite understand the following quote from MSDN:

"After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy of the region. Thus, you should not make any further function calls with this region handle. In particular, do not close this region handle."

and the relationship it might have with my problem.  Does this mean that as soon as you call SetWindowRgn the region handle is no longer valid and cannot be used anywhere else in the program yet not be deleted?

Using a fresh region handle as such:

HRGN hRgn;
GetWindowRgn(hwnd, hRgn);

always returns ERROR even though hwnd has been assigned a region previously in the program successfuly.
Calling GetLastError() gives me a value of 6 (ERROR_INVALID_HANDLE)

What could be the cause of this return value constantly and what are its workarounds?

0
Comment
Question by:georgiek50
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 8149700
an error will be returned if the window doesn't have a region. did you set one with SetWindowRgn?
0
 
LVL 1

Author Comment

by:georgiek50
ID: 8150881
Yes, I have set a region for the button and I figured out the solution.  MSDN conveniently forgot to mention in their documentation that GetWindowRgn will not work unless the HRGN receiving the copy of the region already has a region of its own eg. CreateRectRgn and assignining it to the new region handle BEFORE you call GetWindowRgn?  This I can not explain, it's backwards logic to me.
0
 
LVL 6

Accepted Solution

by:
PlanetCpp earned 225 total points
ID: 8151521
it needs a null region, one made with 0,0,0,0,
you also can't use combinergn with an empty region handle, you have to create one first also.
0
 
LVL 1

Author Comment

by:georgiek50
ID: 8152107
Yes, I realized that last night, I just don't know why it wasn't mentioned anywhere in MSDN leading to the loss of 15 hours from my day...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Simple Linear Regression
Introduction to Processes

578 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