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
Solved

CRgn::CreateRectRgn not working

Posted on 2003-12-01
16
362 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 152
Prevent this page from creating additional dialogs. 3 611
Problem to event 3 102
how to split multiple lines delimiter : 8 109
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…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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