Solved

CRgn::CreateRectRgn not working

Posted on 2003-12-01
16
360 Views
Last Modified: 2013-11-20
Hi there,

I have a subclassed CRgn and I do the following in the contructor.CRect* bounds is a parameter
and it has x, y, width, height with values like 100, 100, 200, 300.

CreateRectRgnIndirect(bounds);
CRect* theBounds;
int result = GetRgnBox(theBounds);

now theBounds has values 0, 0, 0, 0 and result == NULLREGION.  I get the same result if I use CreateRectRgn or SetRectRgn, and if I do it outside the constructor. Why isn't the setting of the rect taking?

Thank you.
0
Comment
Question by:wilsonian
  • 9
  • 5
16 Comments
 
LVL 12

Expert Comment

by:migel
ID: 9856455
Hi!
right code.
CreateRectRgnIndirect(bounds);
CRect theBounds; << NOTE not pointer!
int result = GetRgnBox(&theBounds);
0
 

Author Comment

by:wilsonian
ID: 9861078
Actually my second line was CRect* theBounds = new CRect(); (sorry!) which I would expect to behave in the same way as your code.  And after trying it I can report that your code has exactly the same result as mine.  Unfortunately.

Let me add some more explanation, just to confuse the issue :-)

I have a subclass of CPropertyPage (call it A) which in turn has two subclasses (B and C). Class A has a CObArray which will hold objects of class HighlightingPhonemes, being the subclass of CRgn that is misbehaving.  Class A fills the array as follows:


CClientDC dc(this);
if (!highlightingPhonemes) highlightingPhonemes = new CObArray();
for (int i = 0; i < getCurrentWord()->getNumPhonemes(); i++) {
    CRect* boundsRect = getHighlightingPhonemeRect(i);
    highlightingPhonemes->Add(new HighlightingPhoneme(getCurrentWord()->getPhonemeAt(i),
        boundsRect, false));
    delete boundsRect;
    ((HighlightingPhoneme*)highlightingPhonemes->GetAt(i))->write(&dc);
}
DeleteDC(dc);

The constructor for HighlightingPhoneme goes:

HighlightingPhoneme::HighlightingPhoneme(Phoneme* thePhoneme, CRect* theBounds, bool ownsPhoneme)
{
    phoneme = thePhoneme;
    CreateRectRgnIndirect(theBounds);
    highlighted = false;
    owns = ownsPhoneme;
}

And write(CDC* dc) includes:

CRect boundsRect;
GetRgnBox(&boundsRect)

This works just fine in class B but does not work in class C.  Any idea why?
0
 
LVL 12

Expert Comment

by:migel
ID: 9865008
DeleteDC(dc); - strange code usually ClientDC destroyed in the destructor.
hmmm...
Did you check returned CRect* in the class C? Is it correct?
Can you show your code for class HighlightingPhonemes?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:wilsonian
ID: 9865354
The CRect going in is correct.

The reason I'm doing DeleteDC is because my boss told me I had to (not necessarily a wise reason, but I don't think it has any bearing on my current problem)
0
 

Author Comment

by:wilsonian
ID: 9865423
Do you want all of HighlightingPhoneme?
0
 
LVL 12

Expert Comment

by:migel
ID: 9867074
no!
may be you override  CreateRectRgnIndirect?
...
Can you check handle of the region getted after Call CreateRectRgnIndirect? What walue return this call?
0
 

Author Comment

by:wilsonian
ID: 9868827
Nope.
...
I'm not sure what you mean, GetRgnBox gets a CRect not a region.  Could you explain what you meant?

Thank you for the time you are putting in.

0
 
LVL 12

Expert Comment

by:migel
ID: 9873062
CreateRectRgnIndirect - creates windows GDI object and stores it in the class memeber - can you check it i debugger (may be this value is null)?

BOOL bRet =  GetRgnBox(&rect);
what bRet you get?
0
 

Author Comment

by:wilsonian
ID: 9878912
Not at work at the moment so can't check in debugger.

GetRgnBox returns an int, in my case it equals NULLREGION.
0
 

Author Comment

by:wilsonian
ID: 9894149
m_hObject is not null after call to CreateRectRgnIndirect.
0
 

Author Comment

by:wilsonian
ID: 9909995
Do you have any other ideas, migel or anyone else?
0
 
LVL 12

Expert Comment

by:migel
ID: 9911932
hmm
I have no Idea ....
Can you send me test project? (my email is migel.geo_at_yahoo.com substutute '_at_' by @)
0
 

Author Comment

by:wilsonian
ID: 9915202
Do you mean like a minimal app with the problem in it?  I don't think that will work, since like I said, the code works in other situations, so there must be something funky going on somewhere in my code that I'm not aware of, and I wouldn't know what to put in the minimal app to make it not work. If that makes sense.  Thank you for the offer though.
0
 

Author Comment

by:wilsonian
ID: 9954411
I have made the code do what I want without using the HighlightingPhoneme class, so I will ask to close the question. I suspect I am doing something pretty awful elsewhere in the code to cause the problem, so it may come back to haunt me :-) Thank you migel for all your suggestions.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9975511
PAQed, with points refunded (125)

Computer101
E-E Admin
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Login Script to Copy Folders 12 36
cat dog challenge 18 124
canBalance challenge 34 87
mapAB Challlenge 35 146
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

831 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