Overriding the Create method
- From: "slycaper" <sly_caper@xxxxxxxxxxxxxxxxx>
- Date: Tue, 14 Mar 2006 09:51:34 -0700
I want to change my window attributes before the window is automatically
created for my activex control. In order to do this I was instructed to
write my own Create method. I assume this means override the Create method.
In any case I have done this. My problem is I'm looking to change my window
to use the OWNDC. I want my window to own that DC for the lifetime of the
window in hopes that I can access that DC at any time from another thread
(for the purposes of drawing to it). The create method I'm overriding is
here:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HWND Create( HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName =
NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam
= NULL)
{
if (T::GetWndClassInfo().m_lpszOrigName == NULL)
T::GetWndClassInfo().m_lpszOrigName = GetWndClassName();
ATOM atom = T::GetWndClassInfo().Register(&m_pfnSuperWindowProc);
dwStyle = T::GetWndStyle(dwStyle);
dwExStyle = T::GetWndExStyle(dwExStyle);
// set caption
if (szWindowName == NULL)
szWindowName = T::GetWndCaption();
return CWindowImplBaseT< TBase, TWinTraits >::Create(hWndParent, rect,
szWindowName,
dwStyle, dwExStyle, MenuOrID, atom, lpCreateParam);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I've taken that and turned it into this:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HWND CSchemOGLControl::Create(HWND hWndParent, _U_RECT rect, LPCTSTR
szWindowName, DWORD dwStyle, DWORD dwExStyle,
_U_MENUorID MenuOrID, LPVOID lpCreateParam)
{
WNDCLASS wc; // Windows Class Structure
HINSTANCE hInstance = NULL;
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC
For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "MyNewClass"; // Set The Class Name
ATOM atom = RegisterClass(&wc);
if (GetWndClassInfo().m_lpszOrigName == NULL)
GetWndClassInfo().m_lpszOrigName = "MyNewClass"; //GetWndClassName();
/////////no longer used/////////ATOM atom =
GetWndClassInfo().Register(&m_pfnSuperWindowProc);
dwStyle = GetWndStyle(dwStyle);
dwExStyle = GetWndExStyle(dwExStyle);
// set caption
if (szWindowName == NULL)
szWindowName = GetWndCaption();
return CWindowImplBaseT<CWindow, CControlWinTraits>::Create(hWndParent,
rect, szWindowName,
dwStyle, dwExStyle, MenuOrID, atom, lpCreateParam);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The only real change I made was to the window class. I created a slightly
customized window class. I register that class and then I try to use it.
The returned handle from the call to create in my overridden function is
NULL. I'm very new to trying to do this so I'm not surprised it doesn't
work. If anyone can offer any suggestions that would be much appreciated.
Thanks
.
- Follow-Ups:
- Re: Overriding the Create method
- From: Igor Tandetnik
- Re: Overriding the Create method
- Prev by Date: Re: WM_MOUSEHOVER
- Next by Date: Re: WM_MOUSEHOVER
- Previous by thread: Simple COM created with ATL COM wizard - can I modify methods easily?
- Next by thread: Re: Overriding the Create method
- Index(es):
Relevant Pages
|