CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: HWND handle

  1. #1
    Join Date
    Aug 2005
    Location
    Barcelona, Spain
    Posts
    40

    HWND handle

    Hi folks!

    I'm working on a MFC project and i've got a question to make. The project i'm involved in, is a dialog based aplication. So, the Wizard took the first steps of the work. I'm basing the program on an example that has been created entirely programming, and it makes reference to a HWND handle variable that is necessary to pass to one of the methods.

    The code is like this:

    Code:
     HRESULT CText::BlendText(HWND hwndApp, TCHAR *szNewText)
    {
        
    	LONG cx, cy;
                    HRESULT hr;
    	CSubtitlesDlg dialog;
    
    	// Create a device context compatible with the current window
    	HDC hdc= GetDC(hwndApp);
    	HDC hdcBmp = CreateCompatibleDC(hdc);
    
    	// Write with a known font by selecting it into our HDC
                    HFONT hOldFont = (HFONT) SelectObject(hdcBmp, g_hFont);
    
    	// Determine the length of the string, then determine the
                    // dimensions (in pixels) of the character string using the
                    // currently selected font.  These dimensions are used to create
                    // a bitmap below.
                    int nLength, nTextBmpWidth, nTextBmpHeight;
                    SIZE sz={0};
    
    	nLength = (int) _tcslen(szNewText);
    	GetTextExtentPoint32(hdcBmp, szNewText, nLength, &sz);
    	nTextBmpHeight = sz.cy;
                    nTextBmpWidth  = sz.cx;
    
                    // Create a new bitmap that is compatible with the current 
                    //window
                    HBITMAP hbm = CreateCompatibleBitmap(hdc, nTextBmpWidth,   
                    nTextBmpHeight);
                    ReleaseDC(hwndApp, hdc);
    
    	// Select our bitmap into the device context and save the old one
                    BITMAP bm;
    	HBITMAP hbmOld;
    	GetObject(hbm, sizeof(bm), &bm);
    	hbmOld = (HBITMAP)SelectObject(hdcBmp, hbm);
     ...
    I make a reference to this method in another class like this:
    Code:
     hr = Text.BlendText(___________, Text.g_szAppText);
    <- I need to know what to put in here

    Does anybody know which method do i need to use in order to get this handle to the window i'm working with? I wonder if the question is clear, but i'll try!! Many thanks. Serj.
    Last edited by Siddhartha; September 29th, 2005 at 09:47 AM. Reason: Added Code-Tags...

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: HWND handle

    The handle of the window. If you have a CWnd object you can use GetSafeHwnd() to get its handle.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Aug 2005
    Location
    Barcelona, Spain
    Posts
    40

    Re: HWND handle

    This is the only CWnd i have in all the project:

    CSubtitlesDlg::CSubtitlesDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CSubtitlesDlg::IDD, pParent)
    {

    ...

  4. #4
    Join Date
    May 1999
    Location
    West Sussex, England
    Posts
    1,939

    Re: HWND handle

    If the function that calls Text.BlendText is a member of your CSubtitlesDlg class, then you can just place GetSafeHwnd(). But the window must exist at the time of the call to get a valid HWND.
    Please use meaningful question titles - "Help me" does not let me know whether I can help with your question, and I am unlikely to bother reading it.
    Please remember to rate useful answers. It lets us know when a question has been answered.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured