Wednesday, October 31, 2007

Bug in Rich Edit control

Basically this not a vc++ bug. Its actually a bug in the RichEdit control so the bug belongs to windows.

Check the picture...
What you see inside the red circle is the caret of rich edit control. It passed the boundaries of rich edit control and moved to the dialog.

Step to reproduce.

1. Create a dialog based application and place a rich edit control on it.
2. Give the Multi line and Auto HSCROLL style.
3. Now run the application and click inside the rich edit, and keep on pressing space bar. You can see the caret crossing the boundary of rich edit and starts moving through the dialog.
This problem exists in vista and XP. But I didn't find a place to report this bug to Microsoft. I searched the whole internet to find some one already reported this problem. But coudn't find any. I dont know why such a problem haven't been noticed for the past 12 years( 12 years because I think the problem exists in the rich edit of 95 also ).

Tuesday, October 30, 2007

Hide / Minimize dialog on startup

Have you ever tried to minimize a dialog during the startup of a dialog based application? The problem is in a dialog based application, we will not get the control after the dialog is completely created. Even a call to ShowWindow() from the OnInitDialog() function, will not work. So what will we do if we got such a requriment? Well I got a simple technique for doing this by modifying the InitInstance() function of the app class.

The code for creating a dialog in the InitInstance() function will look like this.

CDialogBasedDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();

My idea is to change this code a little as follows..

CDialogBasedDlg dlg;
if(dlg.Create( CDialogBasedDlg::IDD ))
{
dlg.ShowWindow( SW_HIDE );
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.RunModalLoop();
}


Actually inside the MFC framework, the DoModal() function calls the CreateDlgIndirect() and then RunModalLoop(). It also handles the tasks such as disabling the parent window etc. In our case the dialog itself is the parent window so do haven't to worry about such things.