Solved

CRgn::CreateRectRgn not working

Posted on 2003-12-01
16
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 

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

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 200
Folder Comparison 12 55
ShiftLeft challenge 21 88
c++  placing data into a form and an editbox 5 23
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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