Rookie Q: Release HDC?

Hi,

Imagine a little class like this:

class CMyClass
{
public:
    CMyClass(HDC hDC) {
        m_hDC = hDC;
    }

    HDC GetHDC() {
        return m_hDC;
    }

private:
    HDC m_hDC;
}


Now, in my CMyApp::OnView I do this:

void CMyApp::OnView(CDC* pDC)
{
    CMyClass mc(pDC->m_hDC);
}

Now, HDC is just an UINT, and all I am passing is this number.
I shouldn't have to do any relasing of anything, do I?
Or does my CMyClass class destructor have to do a DeleteObject(m_hDC) or
something?

Lisa


0
no6060 (315)
10/22/2004 9:44:27 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
387 Views

Similar Articles

[PageSpeed] 49

The HDC is part of the CDC class. Be sure not to delete it, or even 
store it (except if your object will only be valid from within the draw 
itself or if you have retrieved the HDC yourself). In this case, it 
should be fine the way you have it.

Lisa Pearlson wrote:
> Hi,
> 
> Imagine a little class like this:
> 
> class CMyClass
> {
> public:
>     CMyClass(HDC hDC) {
>         m_hDC = hDC;
>     }
> 
>     HDC GetHDC() {
>         return m_hDC;
>     }
> 
> private:
>     HDC m_hDC;
> }
> 
> 
> Now, in my CMyApp::OnView I do this:
> 
> void CMyApp::OnView(CDC* pDC)
> {
>     CMyClass mc(pDC->m_hDC);
> }
> 
> Now, HDC is just an UINT, and all I am passing is this number.
> I shouldn't have to do any relasing of anything, do I?
> Or does my CMyClass class destructor have to do a DeleteObject(m_hDC) or
> something?
> 
> Lisa
> 
> 

-- 
Maarten Kools
___________________________________________
Van Gennep - Media Automation Consulting bv
Burg. Stramanweg 105
1101 AA Amsterdam
The Netherlands

Phone:  +31-20-697 6029
Fax:    +31-20-697 2249
E-mail: mkools@vangennep.nl
WWW:    http://www.vangennep.nl
WWW:    http://www.vangennep.com
___________________________________________
0
mkools (57)
10/22/2004 10:05:36 AM
If all you are doing is passing in the View's pDC for your little class to 
use and work on, then NO you don't need to delete it. However if create 
other graphic objects in you class including MemoryDC 's then you will need 
to delete them when you have finished with them.

A quick and dirty method to check and see if you have got it right is to 
bring Task Manager up and get it to show you the number of GDI objects for 
each process. Then repeatedly cover and uncover your view with another 
application (like notepad or whatever), and if the GDI objects of your 
process keep climbing, then you know that you are not releasing and deleting 
objects correctly.

M

"Lisa Pearlson" <no@spam.plz> wrote in message 
news:uqSRwuBuEHA.3188@TK2MSFTNGP15.phx.gbl...
> Hi,
>
> Imagine a little class like this:
>
> class CMyClass
> {
> public:
>    CMyClass(HDC hDC) {
>        m_hDC = hDC;
>    }
>
>    HDC GetHDC() {
>        return m_hDC;
>    }
>
> private:
>    HDC m_hDC;
> }
>
>
> Now, in my CMyApp::OnView I do this:
>
> void CMyApp::OnView(CDC* pDC)
> {
>    CMyClass mc(pDC->m_hDC);
> }
>
> Now, HDC is just an UINT, and all I am passing is this number.
> I shouldn't have to do any relasing of anything, do I?
> Or does my CMyClass class destructor have to do a DeleteObject(m_hDC) or
> something?
>
> Lisa
>
> 


0
10/22/2004 10:09:11 AM
You seem to be right, I see nothing bad in the code in itself, but what 
is the problem?
Ther does not seem any reason that you delete an object that you have 
not created.


Lisa Pearlson wrote:

> Hi,
> 
> Imagine a little class like this:
> 
> class CMyClass
> {
> public:
>     CMyClass(HDC hDC) {
>         m_hDC = hDC;
>     }
> 
>     HDC GetHDC() {
>         return m_hDC;
>     }
> 
> private:
>     HDC m_hDC;
> }
> 
> 
> Now, in my CMyApp::OnView I do this:
> 
> void CMyApp::OnView(CDC* pDC)
> {
>     CMyClass mc(pDC->m_hDC);
> }
> 
> Now, HDC is just an UINT, and all I am passing is this number.
> I shouldn't have to do any relasing of anything, do I?
> Or does my CMyClass class destructor have to do a DeleteObject(m_hDC) or
> something?
> 
> Lisa
> 
> 
0
pierre8740 (42)
10/22/2004 10:31:24 AM
Reply:

Similar Artilces:

Next Scheduled Release in February 2007?
At Convergence last Spring the CRM team repeated numerous times that they were on a rapid development and release schedule and that partner and customers should look forward to a release in February 2007. I don't see any documentation about what's in store for 2007 -- though I have learned more from colleagues who resell SalesForce.com about what's in store for that CRM solution. Where can I learn more so I can help better service our customers and prospects? Search on google and news.google.com for crm titan to get the current public information. As always any dates ment...

=?UTF-8?Q?=E2=99=A5=24=24=24=E2=99=A5_I_want_to_tell_you_about_great_site_I_foun?= =?UTF-8?Q?d=2C_There_you_can_Found_For_YUo_Easy_Way_To_Make_M=E2=98=BANEY_ONLI?= =?UTF-8?Q?NE=21=E2=99=A5_=24=24=24?=
=A2=BE=A2=BE=A2=BE They pay to read e-mail, visit web sites and much more..= It is very simple page Where you can found way How to make cash ONLINE... http://www.wix.com/Raimundas/1 =A2=BE=A2=BE=A2=BE ...

Q: Apply recipient policy to users
Hi I would like to apply recipient policy to two users only. Those users have nothing in common. 1. Can I select two users based on their name / logon name? how? (I am able to select only one. not two). 2. Is it possible to apply a recipient policy to an AD security group? thanks yoni Hi, With the correct ldap query in the recipient policy you can select one user or the other. But if you have only 2 users why don't you enter something on the user accouints that you can search for in the ldap query? Leif "yoni" <yoni@discussions.microsoft.com> wrote in message n...

=?iso-8859-1?q?=FF=FE__being_added_to_Messages_from_OWA_2003_when_outlook_98_client_replies?=
=FF=FE being added to Messages from OWA 2003 when outlook 98 client replies or forwards a message. When it is recived by another client it shows up as garbage. Every thing I can find on =FF=FE is referenced back to outlook express, but outlook express is not invovled in any of the transactions. Even if the 98 client is set to send in plain text it will add thses charecters to the body of the message. Any one else seen this before? ...

Can I calculate a field with 2 different filter criteria in one q
Hi, I have a data source table with a customer name field and various metrics fields, I'd like to sum metric "a" based on customer name being like "abc" and another sum of metric "a" where the customer name is NOT LIKE "abc" in one query, but I can't seem to figure this out, but, I'm a novice at this. Best I can figure is 2 different queries, then a 3rd query to bring the two together. Thanks -- Jim jimd wrote: >Hi, I have a data source table with a customer name field and various metrics >fields, I'd like to sum metric &...

Stop forgetting to make attachements to emails with confirmation q
Too often I get or send an email that should have an attachment, but I forget to make the attachment. It would be great if outlook had the option to turn on a confirmation question if I am sending an email that contains words like, "Attached or attachment" and there was no attachment to the email. A simple "Did you intend to attach a file?" would be great. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message p...

A7Soft announced JExamXML release
A7Soft is pleased to announce the release of JExamXML a java based freeware command line tool for comparing and merging XML files. A7Soft JExamXML is available for download at http://www.a7soft.com This software can be used either as a standalone program or as a jar file class library that is integrated with your own java application. Pure java architecture allows running JExamXML on heterogeneous hardware platforms. ...

Where are the objects (rookie)?
After creating e.g. a check box in a MFC application form I wonder how I get access to the properties of this check box in my application I would expect something like m_checkbox1->checked = True to be possible, but I guess this is not the VC++ concept That is, I cant find any objects to manipulate. How do you do this Regard Balde Balder wrote: > After creating e.g. a check box in a MFC application form I wonder > how I get access to the properties of this check box in my application. > > I would expect something like > m_checkbox1->checked = True; > to be...

Rookie needs help
I'll try to explain this the best way I can:I have created a simple database with a few tables, a couple of queries, a few reports and 1 form. When I designed the "main" table that holds the major data, I needed some information to be "looked up" when inputting the data into the form. So I created a sperate table that holds the information for the first table.Then I went back to the first table and created a "lookup field" to search through. The 2nd table has 2 columns...my question is: When I create a report, how can I define which of those 2 columns sho...

XSLT planning for next release
Hi, We are planning what features /improvements need to go in the next release for XSLT. We are making these decisions based on customer input and feedback. So I would like to hear your views on what you would like to see in the release of XSLT. We are evaluating XSLT 2.0 - 1. Do we need to support XSLT 2.0 ? 2. What are the most useful features of XSLT 2.0 that you would like to see implemented? (like grouping , support for datetime etc) 3. Do you believe support for the entire 2.0 spec is useful? If yes , why? XSLT over large documents - 1. What are some of the large doc...

[ANN] VTD-XML extended edition released
The Java version of extended VTD-XmL is released and available for download. This version supports 256 GB max file sizes and memory mapped capabilities. The updated documentation is also available for download. In short, you can basically do full XPath query on documents that are bigger than memory space available on your machine. A special thanks to Duane May who provided value suggestions and inputs and helped refine the VTD specs to make this happen. To download the package and the documentation, go to https://sourceforge.net/project/downloading.php?group_id=110612&use_mirror=&fil...

Outlook 2003 - Calendar
Just got Outlook 2003 today!! (step one of an enterprise wide rollout that will lead to an upgrade to 2007...) I have two questions on the Calendar - my preferred view is work week: - Can you get the Weekday names to appear at the top of the columns? - Can you amend the calendar view to just display the work hours? (Cant imagine planning too many work appointments between 00 and 07 am!!) Thanks I'm using OL2003, and the day names do appear at the top of the column, like: Friday, March 12. Maybe a service pack issue? You can set your work hours, and everything outside of t...

=?Utf-8?Q?=E2=80=9COut_of_Memory=E2=80=9D_error_when_pasti?= =?Utf-8?Q?ng_formula_down_rows_in_Microsof?= =?Utf-8?Q?t.?=
Hi Azan, Could you give an example of the troublesome formula. Please include the complete question in the body of your posting, even if it is so short that it can be repeated word for word in the subject. --- HTH, David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001] My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm Search Page: http://www.mvps.org/dmcritchie/excel/search.htm "Azan Shahzad" <Azan Shahzad@discussions.microsoft.com> wrote ... ...

Release problem
Hello, I have released an application to my customer. It works fine but the problem is while launching it launches installer of some other tool. A cancel on that will launch my application. Do you have any idea as to what could be wrong? Regards, Subhash "Subhash Badri" <subhash.badri@in.bosch.com> wrote in message news:d1e42b$bgq$1@ns2.fe.internet.bosch.com... > Hello, > > I have released an application to my customer. It works fine but the > problem is while launching it launches installer of some other tool. A > cancel on that will launch my applicatio...

Q: how to set the default arranged by
Outlook 2007 Every time I create a new mail folder the "Arranged By: starts out as "From", I virtually always want to arrange by "Date". Can anybody please let me know how to control the initial Arranged By setting for every time I create a new mail folder. Thanks, mdj. Reset the view - date should be default. If it needs set on every folder, see http://www.outlook-tips.net/howto/grouping.htm for the method to globally change views. -- Diane Poremsky [MVP - Outlook] Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.s...

=?Utf-8?Q?=C2=BFcomo_quito_la_proteccion_de_un_?= =?Utf-8?Q?libro=3F?=
por favor que alguien me ayude necesito desactivar la proteccion de un libro por que necesito modificar unos datos pero todas las opciones estan desabilitadas Diana -- Perdone mi espanol pobre -- se me hace 30 anos que no he hablado. La proteccion fue activizada por la persona que construyo el libro, o hizo las modificaciones ultimas. Se necesita una "password" (palabra secreta) para activizarla. Usted la tiene que aprender de ese persona. Despues, click "Tools", y "Protection", y "Unprotect Workbook". Entre la palabra secreta, y estara lis...

Anyone suggest why FindWindow returns NULL in release build?
I'm running a service and send information to an application via a CopyData structure HWND hWnd = FindWindow(NULL, "ServiceManager"); if(hWnd) { ... } only FindWindow returns NULL in Release mode. Ta! ah hah... in the Services administrator make sure 'Allow Service To Interact With Desktop' is ticked. ...

rookie Q:
Hi, Probably another lame question to piss some people off who feel I should know better: What's the difference in custructors between them. What's the name for either way? class CMyClass { public: m_iItem; CMyClass() : m_iItem(0) } and ... class CMyClass { public: m_iItem; CMyClass() { m_iItem = 0; } } ? Take a look at the following link http://msdn.microsoft.com/msdnmag/issues/0400/c/ -- Cheers Check Abdoul [VC++ MVP] ----------------------------------- "Lisa Pearlson" <no@spam.plz> wrote in message news:uNkU5kJvEH...

Exchange SP2 release date?
Does anyone know a release date for SP2 other then "late 2005" Thanks On Mon, 1 Aug 2005 13:25:20 -0400, "Peretz Stern" <peretzstern@optonline.net> wrote: >Does anyone know a release date for SP2 other then "late 2005" > >Thanks > Yes, 2005 - Autumn/Winter (Q4) It'll be ready when it's ready. Are you another one of the folk who are hovering around the 16GB limit and don't need the features of Enterprise apart from the additional storage? Yup. "Mark Arnold [MVP]" <mark@mvps.org> wrote in message news:8tnse154...

Exchange 2003 SP2 Q
Dear all, I have a few fundamental questions. 1) Can Antivirus software for Exchange Server that uses AVAPI Version 2 corrupt the store database? 2) Is it possible for MAPI client like outlook 2002 and 2003 corrupt the store database? 3) Can third party backup software corrupt the store during backup? Thanks. Regards, Kueh. 1. I've never seen this happen, though I wouldn't say it is impossible. 2. Same as 1. 3. I've never seen the backup software itself corrupt a mailbox store. Usually, backup software is one of the mechanisms to let you know that there is corruption...

Rookie Needs help
Can anyone tell me how to write a formula that will make a cell self delete after a given time? There is no such thing.. -- Regards, Peo Sjoblom "Curt" <anonymous@discussions.microsoft.com> wrote in message news:14f801c42671$d33803c0$a001280a@phx.gbl... > Can anyone tell me how to write a formula that will make a > cell self delete after a given time? > Hi Curt! As Peo says, this is a no can do for any formula or function. The best you can do by formula is to modify the return of your formula using something like: =IF(TODAY()>--"2004-04-01",...

rookie question
Hi! Is there any free program/plug in which adds some new graphs to my Excel 2003? Or some not free programs? Thnx! There are lots of Excel-compatible programs which offer more charting features. These include: Sigmaplot at http://www.systat.com/products/SigmaPlot/ Origin at: http://www.originlab.com/ Crystal xcelsius at: http://www.xcelsius.com/ Statographics: http://www.statgraphics.com/ best wishes -- Bernard V Liengme www.stfx.ca/people/bliengme remove caps from email "Nevermind" <nevermind@hotmail.com> wrote in message news:f4jfql$708$1@ss408.t-com.hr... > H...

=?Utf-8?Q?hyperlinks_into_excel_to_an_exce?= =?Utf-8?Q?l_file_on_a_network_share_doesn=C2=B4?= =?Utf-8?Q?t?=
All hyperlinks created into excel to an excel file on the network does not work. They are accessible via explorer. We are working on terminal server 2003 with office 2007. ...

Q: CHtmlView::OnNavigateComplete2
OnNavigateComplete2 Called after a navigation to a hyperlink completes (on either a window or frameset element). That's what the documentation says. But I only want to be notified when the whole frameset is loaded, not for each frame. Does somebody know how that can be done? TIA, Hans I've had better luck w/ OnDocumentComplete. You receive an event for each frame. Compare the URL provided with the originally requested URL to determine if the entire load is complete. --------------------------------------------------- Automate your software builds with Visual Build Pro http://ww...

List of fixes between the last beta release and the RTM release
Does anyone know of a source of a list of fixes that were implemented (particularly those that are visible to the users) between the latest beta of Ms CRM 3.0 and the RTM version of MS CRM 3.0? In particular, I'm hoping that the web browser phone activity has been fixed - in the beta version it has a sender and recipient, and the close statuses are Sent and Cancelled. Thanks Gill Opsis www.opsis.com.au Gill, I am not aware of any published list of fixes. -- Matt Parks MVP - Microsoft CRM "Gill" <gill@nospam_opsis.com.au> wrote in message news:3BF83113-E47D-4...