Solved

CRgn::CreateRectRgn not working

Posted on 2003-12-01
16
357 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to delete all specified values regedit 38 278
bigDiff challenge 17 84
sum67 challenge 35 93
Thin secure Windows 10 5 75
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now