Recently I have faced with very strange behavior of the Windows "Button" control having BS_MULTILINE style, which looks like bug in Windows. To reproduce it, make the following:
(1) Create new project with Visual Studio 2012 Project Wizard; choose "MFC application";
(2) On "Application Type" page choose "Dialog based" + "MFC standard";
(3) On "Advanced Features" page keep only "Common Control Manifest";
(4) In the generated "Resource.h" file add the line #define IDC_LONG_TEXT 103
;
(5) In the generated <project-name>.rc file replace "TODO" static text inside the main dialog definition by the lines:
LTEXT "BUG IN WINDOWS COMMON CONTROLS.\nButton containing image and text does not work with BS_MULTILINE style.",IDC_STATIC,10,10,250,20
PUSHBUTTON "Very Long Text.",IDC_LONG_TEXT,10,35,250,45,BS_LEFT | BS_TOP | BS_MULTILINE | BS_FLAT
(6) In the generated <project-name>Dlg.cpp file, in the OnInitDialog()
handler, add the following code after "TODO" comment line:
CString strOrigText, strLongText;
CWnd* pButton = GetDlgItem(IDC_LONG_TEXT);
pButton->GetWindowText(strOrigText);
for (int i = 0; i < 10; ++i)
strLongText += strOrigText;
pButton->SetWindowText(strLongText);
pButton->SendMessage(BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)m_hIcon);
(7) Build and run the program. You will see that the button text is drawn in the upper-right corner of the button. If you comment the last line in the above code, the text will be drawn correctly.
Does anybody faced with the same problem? Is it really a bug? If so, how it can be submitted to Microsoft?