Solved

A doubt on accelerator & tab order

Posted on 2001-08-05
16
247 Views
Last Modified: 2013-11-20
I have implemented property sheet inside a modal dialog box( as given in CodeGuru by Zafir Anjum ). My property sheet has 8 pages. Each page is having lots of controls. The parent dialog box is also having some buttons. I have given accelerators for those buttons.

1) The problem is that when ever the focus is on the property sheet those accelarators are not working. Actually I have overridden the PreTranslateMessage() of the dialog to to add accelarators. Can someone help me out from this.

2) Another problem is regarding the Tab order. When I press tab key only the first control inside every property page is getting focused. After that the focus is changed to buttons in my dialog box. I have got lots of control in each page which are not getting focused by the tab key. I think I have a solution for this but don't how to achieve it. If I give the dialog box buttons a tab order starting with the biggest tab order in my property sheet, this may get solved. But how can I give a constant tab order the buttons?

Hope someone out there have a solution for my problems.
0
Comment
Question by:prasanthpooyath
  • 10
  • 6
16 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6354947
Hi ,

1) try to add a PreTranslateMessage to the property sheets too and there call the parent dialog's PreTranslateMessage first.

the problem 2) may get solved with assigning the WS_EX_CONTROLPARENT style to the property sheets.

hope that helps,

ZOPPO
0
 

Author Comment

by:prasanthpooyath
ID: 6355186
Hi Zoppo,
   I have already added the WS_EX_CONTROLPARENT style to propertysheet. Even then its not working.

Prasanth
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6355194
hmm, sorry, maybe you need to set this style to the parent of the property sheets (the tab control).
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:prasanthpooyath
ID: 6355212
Parent of my propertysheet is a Modal Dialog box. So u mean that I should set that style to my dialog box?
0
 

Author Comment

by:prasanthpooyath
ID: 6355223
Parent of my propertysheet is a Modal Dialog box. So u mean that I should set that style to my dialog box?
0
 

Author Comment

by:prasanthpooyath
ID: 6355231
I tried that 2.. Again not working.. :-( I have used a custom made spin control in each of my pages. I have a feeling that after the focus is in this spin control, it is not moving to the next item in the page. I have used the code from CodeGuru for the spin control. (http://codeguru.earthweb.com/controls/SpinEdit.html ) Can that be my problem?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6355234
no, sorry, I think I get a bit confuzed with property-sheets and -pages.

I think it needs to be somehow like this:
dialog: doesn't need special styles for this
property-sheet (the tab control as parent of the property pages): need style WS_EX_CONTROLPARENT
property-page (the child dialogs): set style DS_CONTROL for these

see MSDN about DS_CONTROL:
----------------------------------------------------------------------------------------
DS_CONTROL: Creates a dialog box that works well as a child
 window of another dialog box, much like a page in a property
sheet. This style allows the user to tab among the control
windows of a child dialog box, use its accelerator keys, and so on.
----------------------------------------------------------------------------------------

maybe this helps solving the accelerator problem too.

ZOPPO
0
 

Author Comment

by:prasanthpooyath
ID: 6355237
I tried that 2.. Again not working.. :-( I have used a custom made spin control in each of my pages. I have a feeling that after the focus is in this spin control, it is not moving to the next item in the page. I have used the code from CodeGuru for the spin control. (http://codeguru.earthweb.com/controls/SpinEdit.html ) Can that be my problem?
0
 

Author Comment

by:prasanthpooyath
ID: 6355251
I tried that 2.. Again not working.. :-( I have used a custom made spin control in each of my pages. I have a feeling that after the focus is in this spin control, it is not moving to the next item in the page. I have used the code from CodeGuru for the spin control. (http://codeguru.earthweb.com/controls/SpinEdit.html ) Can that be my problem?
0
 

Author Comment

by:prasanthpooyath
ID: 6355281
I tried setting DS_CONTROL style with my property pages. Again not working. I think the spincontrol is troubling me 'cos after the focus is in the spincontrol only this problem arises. Thanx for the accelerator help. I added the PreTranslateMessage to my property sheet and i think its working fine.
 
     I need another favour. In each of my propery pages I have lot of controls including edit controls, radio buttons, check boxes etc. I was thinking of a good way to handle these controls. Like, if I use the DDX/DDV for each control its virtually impossible. Is it possible to add an array of controls(ex. Edit controls) in DDX/DDV? Since I have a lot of edit controls, I thought this would be the best idea. Do u have any idea on this?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6355380
well, you can use an array of i.e. CEdit controls, i.e.:

// sample for four edit controls

// in header
const int iEditNum = 4;
const int iEditCtrl[iEditNum] = {
 IDC_EDIT1,
 IDC_EDIT2,
 IDC_EDIT3,
 IDC_EDIT4,
};

class CDtDlg : public CDialog
{
...
public:
// Dialog Data
 //{{AFX_DATA(CDtDlg)
 enum { IDD = IDD_DT_DIALOG };
 //}}AFX_DATA
 CString     m_szEdit[iEditNum]; // make sure this is outside of AFX_DATA block
...
}

// in .cpp file
CDtDlg::CDtDlg(CWnd* pParent /*=NULL*/)
     : CDialog(CDtDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CDtDlg)
 //}}AFX_DATA_INIT
 for ( int i = 0; i < iEditNum; i++ )
  m_szEdit[i] = _T("");
...
}

void CDtDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CDtDlg)
 //}}AFX_DATA_MAP
 for ( int i = 0; i < iEditNum; i++ )
 {
  DDX_Text(pDX, iEditCtrl[i], m_szEdit[i]);
 }
}


hope that helps,

ZOPPO


BTW, to find out if other problem really comes form the spin control simply try the same dialog without using these spin controls...
0
 

Author Comment

by:prasanthpooyath
ID: 6357745
I tried replacing the SpinControls with an edit control and it work out well. So the problem resides in the SpinConrtol( http://codeguru.earthweb.com/controls/SpinEdit.html ). BTW, I had a problem with the PreTranslateMessage() part. I had actually called the parent windows PreTranslate first and then the CPropertySheet one to return.

BOOL CDDEPropertySheet::PreTranslateMessage(MSG* pMsg)
{

this->GetParent()->PreTranslateMessage(pMsg);

return CPropertySheet::PreTranslateMessage(pMsg);

}

But I had problems with this sending messages twice to the propertysheet. So now I have made it to return this->GetParent()->PreTranslateMessage(pMsg); I hope there is no problems with this.
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 100 total points
ID: 6358466
well, prasanthpooyath, I think best would be to do it somehow like this:

BOOL CDDEPropertySheet::PreTranslateMessage(MSG* pMsg)
{
 BOOL bRet = GetParent()->PreTranslateMessage(pMsg);
 if ( !bRet )
  bRet = CPropertySheet::PreTranslateMessage(pMsg);
 return bRet;
}

otherwise maybe you'll getting problems with pressing
CTRL-ENTER within multi-line edit controls with style
ES_WANTRETURN within property-pages.


Further, I took a look at code for this SpinEdit-control and
think I found the bug. Replace in CSpinEdit::ShowEdit()
following code
...
else if( nChar == VK_TAB )
{
 GetParent()->SetFocus();
}
...
with this code:
...
else if( nChar == VK_TAB )
{
 ((CDialog*)GetParent())->NextDlgCtrl();
}
...

In this way it worked for me.

cheers,

ZOPPO
0
 

Author Comment

by:prasanthpooyath
ID: 6358483
Hey,,,, Thanx a lot... That worked well.. You were really helpfull.. Once again thanx a lot .....  :-)
0
 

Author Comment

by:prasanthpooyath
ID: 6358485
Thanx !!!! You were really detail and helpfull ... Best Wishes...
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 6358526
you're welcome...

have a nice day,

regards,

ZOPPO
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 675
either24  challenge 19 97
sumHeights  challenge 17 71
Sed question 2 86
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question