Byte-aligning a window

This is a discussion on Byte-aligning a window within the Windows Programming forums, part of the Platform Specific Boards category; I'm having trouble getting a child window byte-aligned. How to go about this? I've tried using the Create() function in ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    1

    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 )

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    70
    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;
    }

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, 06:49 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09: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, 01:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21