SetFocus with CEdit control and CDialog

  • Thread starter Thread starter slender_bamboo
  • Start date Start date
S

slender_bamboo

Guest
Setting focus on startup of the modal dialog works well.
But after typing in the text, I click on a button on the dialog to save.
The first click on the button does not get into the button method.
A second click does the trick.
What's missing? Why do I need to do two clicks?


I try setting focus on the CEdit control on the dialog init.

BOOL CXXXNoteDlg:
emotion-3.gif
nInitDialog()
{
CDialog:
emotion-3.gif
nInitDialog();
OutputDebugString("Initing the Dialog -- Setting the focus");
mySetFocus();
return FALSE;
}

void CXXXNoteDlg::mySetFocus()
{
m_Edit2.SetFocus();
}

m_Edit2 is of type CExtendedEdit which is subclassed from CEdit.


I wonder if the problem happens because I've subclassed the CEdit control. The only reason I did that was to be able to implement Ctrl-A which for some reason does not seem to be available in the standard CEdit control.

I launch the dialog by :

dlg.DoModal();

The init method of the dialog does seem to give keyboard focus to the CEdit control and does accept key strokes.
But when I hover the mouse over the Done button, the button does not change to show that it is active. I click the button once and then I can move the mouse over buttons and they have a change in color around their edges to indicate that I can click on them, and then clicking on them work OK.

I also notice that after the first click on a button of the dialog that the CEdit control still accepts text input. And then clicking on the button works. That's the state that I'd like the dialog to be in when it pops up.

Here isd the CExtendedEdit class:

#include "stdafx.h"
#include "ExtendedEdit.h"

CExtendedEdit::CExtendedEdit(void)
{
}

CExtendedEdit::~CExtendedEdit(void)
{
}


BEGIN_MESSAGE_MAP(CExtendedEdit, CEdit)
ON_WM_GETDLGCODE()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()

UINT CExtendedEdit:
emotion-3.gif
nGetDlgCode()
{
return DLGC_WANTARROWS|DLGC_WANTALLKEYS|DLGC_WANTCHARS;
}

void CExtendedEdit:
emotion-3.gif
nKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{

if((nChar == 0x41) && ((GetKeyState(VK_CONTROL) & 0x8000) != 0))
{
SetSel(0, -1);
}else{
CEdit:
emotion-3.gif
nKeyDown(nChar, nRepCnt, nFlags);
}
}

Continue reading...
 
Back
Top