Overriding the Create method

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Access ATL object in MFC
    ... > player,CMediaBookmarker, which is a ATL window class to my mfc sdi ... > // Initialize COM. ... > // Initialize ATL. ... >> That's a window class derived from CWindowImpl, ...
    (microsoft.public.vc.atl)
  • Re: Problem with CreateWindowEx
    ... When I?m, actually trying to add a window, GetLatsErrorreturns 1407. ... window class could not be found!!!!! ... you know that the API call failed! ... compare the GetLastError code, you would compare it to ERROR_SUCCESS. ...
    (microsoft.public.vc.mfc)
  • Re: Comprehensive List of Graphical User Interface Controls?
    ... Then there's the control that is used ... You can't even tell from the class names; in MFC, for example, if you create a new window ... unrelated to the window class name, there is no way to tell what any given mouse click, ...
    (microsoft.public.vc.mfc)
  • Re: How to close Peghelp
    ... You can probably do this by matching the window class rather than the text. ... In case you are wondering why I need to close Peghelp from within my installer, ... keeps your Help file open even after Peghelp is minimized. ...
    (microsoft.public.pocketpc.developer)
  • Re: Hiding a Window
    ... I will experiment with the APIs ... To use the window class name really isn't a bad habit. ... Of course you can make a guess by retrieving additional ...
    (microsoft.public.vb.winapi)