-
Byte-aligning a window
I'm having trouble getting a child window byte-aligned. How to go about this? I've tried using the Create() function in my view class like this:
BOOL CFractalView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
WNDCLASS CFractalViewWndClass;
GetClassInfo(AfxGetInstanceHandle(), lpszClassName, &CFractalViewWndClass);
CFractalViewWndClass.style |= CS_BYTEALIGNCLIENT;
lpszClassName = AfxRegisterWndClass(CFractalViewWndClass.style);
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
It works if I change the argument in AfxRegisterWndClass to just CS_BYTEALIGNCLIENT, but then the client area appears strangely when I start up the program (the background then is the same as what's behind the program window). Other than that it does actually work, but I figure I'd be better off combining the CS_BYTEALIGNCLIENT with the settings already in there. But if I do that (as the code above shows), I get an error that reports it cannot create an empty document. Is my approach plain wrong or is it a stupid small mistake? (please let it be the first, I hate those simple mistakes :) )
-
I would suggest to redefine
CWnd::PreCreateWindow (CREATESTRUCT &)
member function in your view class, rather than CWnd::Create ().
It is virtual and is called from CWnd::Create () during view creation process and before the window becomes visible. By redefining it you can customize window appearance in better way.
BOOL CFractalView::PreCreateWindow (CREATESTRUCT& cs)
{
if (!CView::PreCreateWindow (cs))
return FALSE;
LPCTSTR lpszNewClassName = ::AfxRegisterWndClass (
CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT,
IDC_ARROW,
(HBRUSH) (COLOR_3DFACE + 1)
);
cs.lpszClass = (LPCSTR) lpszNewClassName;
return TRUE;
}