NIKHIL
NIKHIL

Reputation: 17

Resizing window not working properly MFC

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??

Upvotes: 0

Views: 2193

Answers (2)

UweBaemayr
UweBaemayr

Reputation: 2319

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.

Upvotes: 0

AnatolyS
AnatolyS

Reputation: 4319

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/

Upvotes: 1

Related Questions