Solved

CRgn::CreateRectRgn not working

Posted on 2003-12-01
16
354 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 122
Adapt this command to show who installed 29 102
EvenOdd challenge 10 83
how to split multiple lines delimiter : 8 54
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

758 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

18 Experts available now in Live!

Get 1:1 Help Now