Obtaining CWnd

I using a function to get information about the current DC. In this case, I 
want to grab the current DC and save it off so that I might modify it to 
retrieve information about a particular font. CClientDC wants a CWnd *. 
Previously, I would save a ptr to the main application window but I'm trying 
to provide a better encapsulation so I don't have to rely on an external ptr 
of sorts. Is there an API call that will allow me to get the pointer to the 
main application (process)?

This is a scaled down implementation of the function -

CSize DisplayHandler::TextDimension(const TCHAR *T)
{
    CSize tdim;

    CClientDC dc(???); // this currently uses a ptr to the main app window.

    // save dc
    CDC disDC;
   // setup up disDC as I need
     tdim = disDC.GetTextExtent(T);
   // restore dc
        RestoreDC();

    return tdim;
}

Thanks in advance,

-John


0
jggarcia1 (5)
8/30/2005 1:44:04 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
794 Views

Similar Articles

[PageSpeed] 41

::AfxGetApp()  But you should pass the pointer of the window you are working
with to the DisplayHandler class instead of it grabbing a window pointer on
it's own that would make DisplayHandler modular.

AliR.

"J Garcia" <jggarcia@nospam.controlgaging.com> wrote in message
news:OB1ZkjWrFHA.1028@TK2MSFTNGP12.phx.gbl...
> I using a function to get information about the current DC. In this case,
I
> want to grab the current DC and save it off so that I might modify it to
> retrieve information about a particular font. CClientDC wants a CWnd *.
> Previously, I would save a ptr to the main application window but I'm
trying
> to provide a better encapsulation so I don't have to rely on an external
ptr
> of sorts. Is there an API call that will allow me to get the pointer to
the
> main application (process)?
>
> This is a scaled down implementation of the function -
>
> CSize DisplayHandler::TextDimension(const TCHAR *T)
> {
>     CSize tdim;
>
>     CClientDC dc(???); // this currently uses a ptr to the main app
window.
>
>     // save dc
>     CDC disDC;
>    // setup up disDC as I need
>      tdim = disDC.GetTextExtent(T);
>    // restore dc
>         RestoreDC();
>
>     return tdim;
> }
>
> Thanks in advance,
>
> -John
>
>
>


0
AliR3470 (3235)
8/30/2005 3:21:35 PM
Not clear why this has any value.  And having a pointer to the main application doesn't
seem to provide much help either. The problem is that you need to worry about whether the
output is to a window or to a display. GetTextExtent applies to whatever window you have,
so your code would be ignoring the side effects of a SetFont on a window.  So you would be
limited to using whatever font was associated with some particular window.  

Saving DCs doesn't seem to be a good strategy for most applications, and saving a DC to an
unrelated window will simply produce unrelated results.  Why would you think that having
the DC for the main app window would give anything worthwhile for any other window? 

Presumably you have a complex computation; it should be done in the context of the window
you need to compute the size for, or as a static method that simply takes a CWnd * for the
window you care to use.  Given a CClientDC for a given window, what does the "disDC" have
to exist for?
				joe

On Tue, 30 Aug 2005 09:44:04 -0400, "J Garcia" <jggarcia@nospam.controlgaging.com> wrote:

>I using a function to get information about the current DC. In this case, I 
>want to grab the current DC and save it off so that I might modify it to 
>retrieve information about a particular font. CClientDC wants a CWnd *. 
>Previously, I would save a ptr to the main application window but I'm trying 
>to provide a better encapsulation so I don't have to rely on an external ptr 
>of sorts. Is there an API call that will allow me to get the pointer to the 
>main application (process)?
>
>This is a scaled down implementation of the function -
>
>CSize DisplayHandler::TextDimension(const TCHAR *T)
>{
>    CSize tdim;
>
>    CClientDC dc(???); // this currently uses a ptr to the main app window.
>
>    // save dc
>    CDC disDC;
>   // setup up disDC as I need
>     tdim = disDC.GetTextExtent(T);
>   // restore dc
>        RestoreDC();
>
>    return tdim;
>}
>
>Thanks in advance,
>
>-John
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
9/8/2005 3:49:29 AM
Reply:

Similar Artilces:

Obtaining CWnd
I using a function to get information about the current DC. In this case, I want to grab the current DC and save it off so that I might modify it to retrieve information about a particular font. CClientDC wants a CWnd *. Previously, I would save a ptr to the main application window but I'm trying to provide a better encapsulation so I don't have to rely on an external ptr of sorts. Is there an API call that will allow me to get the pointer to the main application (process)? This is a scaled down implementation of the function - CSize DisplayHandler::TextDimension(const TCHAR *T...

Obtaining variables during a userform_initialize event
I am using the worksheet_beforedoubleclick event to open a userform. During the userform_initialize event I need to obtain value of the 'target' arguement that is referenced in the worksheet_beforedoubleclick event. How can I obtain this value? Do I need to go with a public variable? --- Message posted from http://www.ExcelForum.com/ It depends on how and where you are going to use the variable populated with the target.value --- Message posted from http://www.ExcelForum.com/ ...

Problems in the string articlexml obtained
string strColumnSetXml = "<columnset>"; strColumnSetXml += "<column>title</column>"; strColumnSetXml += "<column>description</column>"; strColumnSetXml += "<column>number</column>"; strColumnSetXml += "<column>articlexml</column>"; strColumnSetXml += "<column>modifiedon</column>"; strColumnSetXml += "</columnset>"; // Retrieve the article return article.Retrieve(userAuth, articleId, strColumnSetXml); When i execute the code above, in the column xml i o...

Obtaining the correct results from a two table query
I have two tables say A and B, what I am trying to achieve with the query is just to display records that have the received field ticked in table A and the colour field in table B not containing �Y�. How do I modify the code below to achieve this? SELECT A_Date, A.Received, A.ID, B. Colour FROM A LEFT JOIN B ON DDP_A.Main = B.Main WHERE (((A.Received)= -1) AND ((B.Colour <> �Y�)); jo@jo.uk wrote: >I have two tables say A and B, what I am trying to achieve with the query is >just to display records that have the received field ticked in table A and >the colo...

How to obtain a median?
Hello the graphic design tool allows the user to obtain the mean of a column of numbers in a table. Is there a suggested way to obtain a median? Thank you, Keith There is nothing built in that does that. You will have to write the code to do it for you. Here is some info on the rules for calculating a median: http://www.mathsisfun.com/median.html -- Dave Hargis, Microsoft Access MVP "Keith" wrote: > Hello > the graphic design tool allows the user to obtain the mean of a column of > numbers in a table. Is there a suggested way to obtain a median? > Thank you, &...

How to obtain process handle ??
I want my application obtain HANDLE to itself. How do this ?? -- __ phoenix_ phoenix_@wp.pl "phoenix" <phoenix_@wp.pl> wrote in message news:bn3pn0$28t$1@nemesis.news.tpi.pl... > I want my application obtain HANDLE to itself. How do this ?? > GetWindowThreadProcessId >I want my application obtain HANDLE to itself. How do this ?? GetCurrentProcess Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq > GetWindowThreadProcessId The return value is the identifier of the thread that created the window!!! It is not a handle - (maybe i am wrong, but the identif...

Where to obtain IR Blaster?
System - Vista Ultimate Hauppauge TV card Issues : Comcast conversion to digital (DTA) I used the system for basic cable access. I have the directions for installing Comcast DTA in Widows Media Center. It appears that I need a USB IR receiver for this to work. What is the product name and where can I obtain one. Thanks in advance -- ***************** John Lenz JohnLenz@comcast.net The IR blaster is an emitter, you'll need both the emitter and receiver to control the cable box. Generally, it's cheaper to just buy the remote kit that included the IR s...

Forcing the creation of a CDockablePane in a CWnd
Please how can I force the creation of a pane inside a CWnd and make it take the full space of that CWnd ? Am I only complled to using it inside a CFrame and to using the DockPane methods ? Is there a turn-around please ? Thank you in advance. ...

Obtaining values from datafile
Hi i would like to know how to obtain values from a datafile and store it into edit controls... If i enter a particular value similar to that in a data file then i need to get all the correspnding values into other edit control ????????? (1) Open the file (2) Read a record (3) Put the values in edit controls (4) Repeat steps 2 and 3 as necessary SetWindowText works very well for putting values into edit controls. GetWindowText for retrieving them. See my essays (such as Avoiding GetDlgItem) on my MVP Tips site. You could even use UpdateData if you don't mind all the other cumbersome f...

obtaining more relevant templates
Dear All Is there anywhere I can beg borrow or buy publisher templates more applicable to the UK. Regards -- nebb ...

Obtaining the CString buffer
Hello everybody. I have a class to encrypt data and its functions are: void Encrypt(unsigned char* buf, size_t n) void Decrypt(unsigned char* buf, size_t n) As you can see they need a char buffer, I want to encrypt/decrypt a CString, How can I obtain the CString buffer? 'CString::GetBuffer()' need the buffer length, how can I obtain it? CStrings could be ANSI or UNICODE. Thanks in advance, William GS William GS wrote: > Hello everybody. > I have a class to encrypt data and its functions are: > > void Encrypt(unsigned char* buf, size_t n) > void Decrypt(unsigned ch...

How rreliable is the CLSID method of obtaining a file location?
Folks I'm wanting to determine the version of various DAO, MSJet, ACE and ADO DLLs. One means of doing this is by using a CSIDL to get to C:\Program Files\Common Files\system\ado\msado15.dll (or close and then adding on system\ado as requiired.) Elsewhere it has been suggested that I should use the CLSID. In this case the entire key is HKEY_CLASSES_ROOT\CLSID\{00000535-0000-0010-8000-00AA006D2EA4}\InprocServer32 which I got from http://support.microsoft.com/kb/266668 Is this a relable method especially if dealing with other language OSs? Is this the best, recommended...

How to obtain the Distribution List of a Sender
Hello, I'd like to know if it's possible to find if the sender of a mail over Exchange server is a member of an specific Distribution List (in Exchange) so this mail can be automatically marked. In other words, i´d like to konw if i can acces the organizational address book. I'm afraid no but i ask here to confirm it. I'm using Outlook 2003. If i used Outlook 2007 would it be possible? The solution should't show any prompts because a macro has to do this job on the Inbox folder automatically. Lot of thanks, Alberto. The GAL (Global Addr...

eConnect Unable to obtain the next note index
Hi, I am trying to import data of PO from Excel to GP through eConnect. When I write a code on taPOHdr, I get error " eConnect Unable to obtain the next note index". Does any one have any idea why I am having this problem? Thanks ...

obtaining deleated mail
Had e-mail that were deleted when closing outlook. Is there a way to date back and get old e-mails back off the hard drive? Dawn <dawn@summitactivities.com> wrote: > Had e-mail that were deleted when closing outlook. Is > there a way to date back and get old e-mails back off the > hard drive? http://www.howto-outlook.com/howto/restoredeleteditemsfromanoutlookpst.htm -- Brian Tillman ...

how can i obtain polynomial constants when using trendlines.
how can i obtain polynomial constants when using trendlines. i sometimes need to used these constants in other calculations but must manually enter them in another context. Hi, Let's suppose that the x- and y- ranges are in A2:A51 and B2:B51 respectively, and you are fitting a 6-order polynomial to your data. Select a 7 column x 1 row area, enter the following formula, and confirm with CTRL-SHIFT-ENTER. =LINEST(B2:B51,A2:A51^{0,1,2,3,4,5,6},0,) The formula will return the 7 coefficients, starting from the zeroth order and ending with the 6th order. If you want to have the co...

Obtaining Path of the file/folder ?
Hi I have an mfc dialog based demo application. I wanted to add my application's entry in the Windows Explorer's context menu, which i m able to successfully by making some additions to the registry. Now whenever the user right clicks on some folder/file,the context menu displays my application's entry which gets executed when the user clicks on it. How can i obtain the path of the file/folder on which the user right clicked ? Waiting for suggestions Regards >I have an mfc dialog based demo application. >I wanted to add my application's entry in the Windows Expl...

How do you obtain a Window Handle?
I am a beginner and having a very difficult time with some tasks. Does anyone have a COMPLETE example of how to obtain the handle of a Child window in VC++ 6? All the examples I have found contain incomplete information. It is as-if one needed to know the handle to the window to obtain the handlt to the window. I've tried ever process I can find in my MSDN Library and they all seen to compare with a cat chasing it's own tail. Take a look at the CWnd::GetWindow() member function. You should be able to pass GW_CHILD and then GW_NEXT in a loop to get all the child windows of a given...

Obtain Top Value from Table
I am attempting to pull a random set of records using a Random Number and the Top Value function. The Top Value changes depending on the specific group I am looking at so I would like to obtain the Top Value from a table rather than entering manually. First, the appropriate statistically significant sample size is determined for each group in my table by the query below. The sample size and group information are added to [tbl_tt_sample_size]. INSERT INTO tbl_tt_sample_size ( MonthSample, Code, Fac, Sample ) SELECT DateSerial(Year(Date()),Month(Date()),0) AS MonthSer, tbl_t...

How to obtain mainboard information via WMI class Win32_Baseboard ?
every Guru: I know the matherboard information is contained WMI class Win32_Baseboard, but how can get the class object ? any one could give me some sample code ? ...

Obtain server IP
Is there a way for my Access 2000 application to progammatically determine the IP address of another computer it has browsed to? You should be able to adapt the code found at http://vbnet.mvps.org/index.html?code/network/iplookup.htm to do this in your db. -- Hope this helps, Daniel Pineault http://www.cardaconsultants.com/ For Access Tips and Examples: http://www.devhut.net Please rate this post using the vote buttons if it was helpful. "Pastor Del" wrote: > Is there a way for my Access 2000 application to progammatically determine > the IP a...

how to direct keyboard input to a CWnd added to CDialog? #2
I have added a CWnd object to a CDialog for the purposes of drawing inside the CDialog. I would like the CWnd object to respond to keyboard input. Any input not handled by CWnd should then be handled by CDialog. Can anyone explain/illustrate how this is done? Thanks for all suggestions and help. Ian ...

Obtaining series of data that adds up to a particular large figure
I have a large figure and series of other small figures on differen rows. How do I get the different sets of small figures that exactly or almos add up to the large figure:confused ----------------------------------------------- ~~ Message posted from http://www.ExcelTip.com ~~View and post usenet messages directly from http://www.ExcelForum.com You can try to use solver under tools>solver (if it is not there select it from under tools>add-ins and keep the office/excel cd handy and follow instructions) Put the series of small figures in a range, select that range and click in the n...

obtaining mailbox size
does anyone know of anyway to dump the size of indiviual mailbox's to a file. I am just looking to get the mailbox size. i cant find anything on the MS site. Thanks Jason Hi Jason, One way that you can do this is to open up the Exchange System Manager and navigate down to the mailbox store that the user is on. You can then expand the mailbox store and you will see "Mailboxes" listed below it. Right-click on "Mailboxes" and choose Export List. This will save out all of the details that you see when you click on Mailboxes. You could then open this file up in Excel ...

MS Query
Hi thanks for any advice you can offer. Attempting to build a pivot table using external data, connecting to a Microsoft SQL Server. I paste the SQL that I use in Enterprise Mgr directly into MS Query. When I execute the query, the dataset is displayed in MS Query - all 107,000 records. When I ask MS Query to return the data to Excel, I get this message: "Problems Obtaining Data." Help. Thanks, gt Which version of excel are you using? All versions except 2007 have a limit of 65536 rows and cannot present your data that exceeds 100000 rows On Oct 26, 10:07 pm, gtgtgt <g...