0
votes

I have created a customized class with inheriting CDockablepane in SDI application MFC. for ex.

class CLoginPage :  public CDockablePane
{
    public:
    CLoginPage();
protected:
    CStatic lbl_username;
    CStatic lbl_password;
    CEdit txt_username;
    CEdit txt_password;
    CButton btn_login;
    CButton btn_Signup;
protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnSize(UINT nType, int cx, int cy);

    DECLARE_MESSAGE_MAP()
};

in .cpp I override oncreate function and onsize funtion

int CLoginPage::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDockablePane::OnCreate(lpCreateStruct) == -1)
        return -1;

    if(!lbl_username.Create(_T("User Name"), WS_CHILD | WS_VISIBLE, CRect(150, 150, 100, 30), this, ID_STATIC_USERNAME))
    {
        TRACE0("Failed to create userName in LoginPage window\n");
        return -1;
    }
 ......................................same for other control
}


void CLoginPage::OnSize(UINT nType, int cx, int cy)
{
    CDockablePane::OnSize(nType, cx, cy);

    // Tab control should cover the whole client area:
    CRect rectClient;
    this->GetWindowRect(rectClient);

    lbl_username.SetWindowPos (NULL, rectClient.left+150, rectClient.top+150, 100, 30, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
.............................same for other control
}

when I run this it is displaying correctly as present in below image.

enter image description here

but after resize login window or move login window, it display very badly. please see below image

enter image description here

I don't know how to resolve this. Do I need to do something in WM_PAINT message or something else. I tried a lot but i din't get any option. Can someone please help me on this??

2
Not immediately clear, why you specify values for X and Y in your call to SetWindowPos even though you are telling the system, that it should ignore those values (SWP_NOMOVE). Anyway, your issue is one of these: 1 Your WM_PAINT message handler is buggy. 2 Your WM_ERASEBKGND message handler is inappropriate. 3 Your window class registration is missing the CS_HREDRAW/CS_VREDRAW window class styles. In other words: It's in the code we cannot see. Please show a minimal reproducible example. - IInspectable
I Have not handled WM_PAINT or WM_ERASEBKGND messages. How I called this Login window is present below: CString strLoginPageWnd; bNameValid = strLoginPageWnd.LoadString(IDS_LOGINPAGE_WND); ASSERT(bNameValid); if (!m_wndLoginPage.Create(strLoginPageWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_LOGINPAGEWND, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | CBRS_TOP | CS_HREDRAW | CS_VREDRAW | CBRS_FLOAT_MULTI)) { TRACE0("Failed to create LoginPage window\n"); return FALSE; // failed to create }m_wndLoginPage.EnableDocking(CBRS_ALIGN_ANY); DockPane(&m_wndLoginPage); - NIKHIL
Where did you read, that you can mix window styles with class styles? CS_HREDRAW and CS_VREDRAW can only be used when registering a window class. - IInspectable

2 Answers

1
votes

You want to change position but why do you pass SWP_NOMOVE into SetWindowPos?

Do you know that in Visual Studio 2015 you have possibility to manage dialog layout with dynamic layouts: https://msdn.microsoft.com/en-us/library/mt270148.aspx ? The best dynamic layouts tutorial is http://mariusbancila.ro/blog/2015/07/27/dynamic-dialog-layout-for-mfc-in-visual-c-2015/

0
votes

For the record, the MFC drawing problem -- stuttering lines when moving or sizing a tool window or tool bar was a Windows bug and only occurred with multiple monitors. It was fixed in Windows 10 1803 but reintroduced in 1809 and fixed in March, 2020 in 1903 and 1909.

https://support.microsoft.com/en-us/help/4541335/windows-10-update-kb4541335

The description in the KB article (must expand collapsed links):

Addresses a drawing issue with the Microsoft Foundation Class (MFC) toolbar that occurs when dragging in a multi-monitor environment.