Thread: Byte-aligning a window

  1. #1
    Registered User
    Join Date
    Dec 2001

    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); |= CS_BYTEALIGNCLIENT;

    lpszClassName = AfxRegisterWndClass(;

    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 )

  2. #2
    Registered User
    Join Date
    Dec 2001
    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.lpszClass = (LPCSTR) lpszNewClassName;

    return TRUE;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM