|
-
September 29th, 2005, 09:43 AM
#1
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...
-
September 29th, 2005, 10:22 AM
#2
Re: HWND handle
The handle of the window. If you have a CWnd object you can use GetSafeHwnd() to get its handle.
-
September 29th, 2005, 10:44 AM
#3
Re: HWND handle
This is the only CWnd i have in all the project:
CSubtitlesDlg::CSubtitlesDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSubtitlesDlg::IDD, pParent)
{
...
-
September 29th, 2005, 11:21 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|