Solved

A doubt on accelerator & tab order

Posted on 2001-08-05
16
243 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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
Hi Zoppo,
   I have already added the WS_EX_CONTROLPARENT style to propertysheet. Even then its not working.

Prasanth
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
hmm, sorry, maybe you need to set this style to the parent of the property sheets (the tab control).
0
 

Author Comment

by:prasanthpooyath
Comment Utility
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
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:prasanthpooyath
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
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 30

Accepted Solution

by:
Zoppo earned 100 total points
Comment Utility
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
Comment Utility
Hey,,,, Thanx a lot... That worked well.. You were really helpfull.. Once again thanx a lot .....  :-)
0
 

Author Comment

by:prasanthpooyath
Comment Utility
Thanx !!!! You were really detail and helpfull ... Best Wishes...
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
you're welcome...

have a nice day,

regards,

ZOPPO
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now