Solved

SetWindowRgn

Posted on 2001-09-12
14
987 Views
Last Modified: 2013-12-03
Hi, experts.
   I have a problrm with setWindowRgn. I continuously resize my window and every time I set a new region for my window. Everything works fine, but after some time I start experiencing something like "internal windows resource leaks" - when I drag the window it is being dragged slower and slower, and not only that it affects all other non-rectangular windows, like I tried to run Winamp or Odigo they were also slow, but as soon as I closed my application, Winamp and Odigo... started moving fastly without any delay while gragging, seems like when I close my appl. resources are cleaned up, but how can I do it at arun time?
0
Comment
Question by:alex108
  • 5
  • 3
  • 2
  • +2
14 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 6478814
After you've set the new region, you have to delete the old one with "DeleteObject".

Something like this:

[creating]
wnd = CreateWindow(...);
rgn = CreateRectRgn(...);
SetWindowRgn(wnd, rgn, ...);

[changing region]
oldRgn = rgn;
rgn = CreateRectRgn(...);
SetWindowRgn(wnd, rgn, ...);
DeleteObject(oldRgn);

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6478818
P.S: "rgn" should be a global variable in this case, or a class variable, while "oldRgn" could be a local one.
0
 

Author Comment

by:alex108
ID: 6479461
I tried that and so many other things - it doesn,t solve the problem.
Take in your own CWnd(CDialog) derived class in OnSize
do something like:

void CMyWnd::OnSize(UINT nType, int cx, int cy)
{
     CCustomizedDlg::OnSize(nType, cx, cy);
     HRGN oldRgn = m_hRgn;
     m_hRgn = CreateEllipticRgn(0,0,cx, cy+40);
     //SetWindowRgn(NULL,FALSE);
     SetWindowRgn(hRgn,TRUE);
     DeleteObject(oldRgn);
}

and then try to drag the window after resizing for a while
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6480348
Just one more try, before I invest the time to test it myself: Could you please call SetWindowRgn with "FALSE". Just to make sure, that that won't fix the problem... If it does not, I will try this whole thing myself.

Regards, Madshi.
0
 

Author Comment

by:alex108
ID: 6481798
Unfortunately it doesn't.
Regards, Alex
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 6483920
SDK says: "After a successful call to SetWindowRgn, the system owns the region specified by the region handle hRgn. The system does not make a copy of the region. Thus, you should not make any further function calls with this region handle. In particular, do not close this region handle".

Try just this:

void CMyWnd::OnSize(UINT nType, int cx, int cy)
{
    CCustomizedDlg::OnSize(nType, cx, cy);
    SetWindowRgn(CreateEllipticRgn(0,0,cx, cy+40),TRUE);
}
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 20

Expert Comment

by:Madshi
ID: 6484449
Yes, according to the documentation Nick seems to be right. However, the only full example I found on www.Microsoft.com DOES delete the old region:

http://msdn.microsoft.com/code/default.asp?url=/msdn-files/026/001/876/NonRect/Source%20Files/MainFrm_cpp.asp

Strange thing.

Regards, Madshi.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 6485121
>>DOES delete the old region:

I did not in my program, and all worked fine.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6485527
>> I did not in my program, and all worked fine.

Yeah, but that's no proof. As it is with memory/resource leaks: All seems to work fine until you've consumed all available resources (at least in win9x).

But as I said in my previous comment: I guess that you're right and that Windows actually does delete the old region itself. I just found it a bit strange, that the only full example contradicts the documentation...
0
 

Author Comment

by:alex108
ID: 6486238
Sorry, but it's not gonna solve the problem, whether you delete old region or not. Interesting enough, if you set rectangular regions you don't feel resoource leaks, only non-rectangular is a problem.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6492989
>>you don't feel resoource leaks
May be problem in other place of your apps.
For detect memory leaks I use TaskInfo2000 from
www.iarsn.com  Try it!
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10680282
PAQed, with points refunded (100)

modulo
Community Support Moderator
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
Duplicates in Aggregate Query 3 33
How to get/set directory for Word dialog box using VSTO 4 38
mixing C++ & C# in Vis Studio 2013 7 139
Dir function fails on mapped drives 28 123
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

13 Experts available now in Live!

Get 1:1 Help Now