15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Setting the default push-button using BS_DEFPUSHBUTTON

Andi Giri -- agiri@ctiis.com
Monday, September 23, 1996

Environment: Win95, VC++ 4.2

In a dialog box, I am trying to set the default pushbutton with
SetButtonStyle(), instead of specifying DEFPUSHBUTTON in the Resource
(.RC) file.
Basically, I am reusing a dialog for various scenarios, and would like
to
have either IDOK or IDC_ADD (a button defined in teh .RC file) act as
the default pushbutton.  Both are defined as just PUSHBUTTONs in the RC
file.

Code follows:
BOOL CFaxEntryDlg::OnInitDialog() 
{
	if (condition_met)
	{
		CButton *cAdd;
		cAdd = (CButton *) GetDlgItem(IDC_ADD);
		cAdd->SetButtonStyle(cAdd->GetButtonStyle() | 		BS_DEFPUSHBUTTON);
	}
}

I have tried this code in OnInitDialog(), OnShowWindow(), OnCtlColor().
I used Spy to look at the IDC_ADD button's style right from when it
received WM_CREATE; I started with BS_PUSHBUTTON, then got set to
BS_DEFPUSHBUTTON all the time when I called SetButtonStyle(), but when
the dialog drew itself, the style would change back to BS_PUSHBUTTON.

Where is the problem?  Is there any other later message than
WM_SHOWWINDOW where I can shove this code?


Andi



Brad Wilson/Crucial Software -- crucial@pobox.com
Tuesday, September 24, 1996

[Mini-digest: 11 responses]

> In a dialog box, I am trying to set the default pushbutton with
> SetButtonStyle(), instead of specifying DEFPUSHBUTTON in the Resource
> (.RC) file.

Have you tried calling SetDefID() instead?

--
Brad Wilson             | crucial@pobox.com   http://www.thebrads.com/bradw
Objectivist Philosopher |
Software Engineer       | "How can you say you like my noise
Web Page Designer       |              when I haven't made a sound?"
System Administrator    |                               - Harry Connick Jr.

-----From: "Cunningham Graham, IK 23" 

well somewhere there is a technical note on this cause I doubt I would
have found it myself :-) but anyway here is the code to change the
default pushbutton to another button on the same dialog

//make the search button the default	
	m_OKButton.SetButtonStyle( (m_OKButton.GetButtonStyle() &
	SetDefID(IDC_SELT_SEARCH);
	m_SearchButton.SetButtonStyle( (m_SearchButton.GetButtonStyle() &
BS_DEFPUSHBUTTON) );

Graham Cunningham
00 41 31 338 0633

-----From: David.Lowndes@bj.co.uk

Andi,

Hae a look at Knowledge Base article Q67655 "Changing/Setting the Default
Push Button in a Dialog Box". That says you need to do 3 actions to change
the default push button:

"To change the default push button, perform the following three steps:
 
1. Send the BM_SETSTYLE message to the current default push button to
   change its border to that of a regular push button.
 
2. Send a DM_SETDEFID message to the dialog box to change the ID of the
   default push button.
 
3. Send the BM_SETSTYLE message to the new default push button to
   change its border to that of a default push button.
"

Dave Lowndes
-----From: Phil Reeves 

I think there's a CDialog::SetDefID function

Philip Reeves
Knowledge Engineer

*************************************
Royal Brompton Hospital
Sydney Street
London
SW3 6NP
UK
Tel: +44 (0)171 351 8702
Fax: +44 (0)171 351 8743
e-mail: p.reeves@rbh.nthames.nhs.uk
web: http://www.rbh.nthames.nhs.uk
*************************************

-----From: Davidovich Dmitry 

Try SetDefID(IDC_ADD) instead.
+++++++++++++++++++++++++++++++++++++++++
Dmitry Davidovich
CS Tel Aviv University
dmitry@enigma.co.il
ddmitry@libra.math.tau.ac.il
+++++++++++++++++++++++++++++++++++++++++

-----From: groftde@ebs.ac.com (Derek F. Groft - UTL)


Have you tried
	pDlg->SetDefID( IDC_ADD );

	or

	pDlg->SendMessage( DM_SETDEFID, IDC_ADD );

You should be able to do either of these from any callback.

-----From: kitk@mudshark.sunquest.com (Kit Kauffmann)

Use SetDefID (DM_SETDEFID) instead

-----From: "Oefelein, Martin" 

Use SetDefID (IDC_ADD).

ciao,
   Martin

-----From: chris.downs@slug.org (Chris Downs)

 Call CDialog::OnInitDialog() as the first thing in the above proc.  
 Then in  CFaxEntryDlg::OnInitDialog(), return FALSE when done.  
 Your IDC_ADD button will then display as a default push button.


---
 * Blue Wave/QWK v2.12 *
-----From: David Watt 

You need to use a different message to make this work.  Check out
DM_SETDEFID in the help -- it works.  Setting the button style alone doesn't.

- Dave

----
David Watt                           Finnigan Corp.
watt@finnigan.com                    (408) 433-4828 ext. 2664

Defn:  Millihelen -- the amount of beauty required to launch one ship.

-----From: dima@ssm6000.samsung.ru (Dulepov Dmitry)

        [Mailer: "Groupware E-Mail". Version 1.0]


I had that problem too. Try this code (it works in my applications)=
:

void CMyDlg::SetDefButton(int nID)
{
    CWnd*    pButton;
    DWORD    dwDefInfo =3D SendMessage(DM_GETDEFID, 0, 0L);

    if (HIWORD(dwDefInfo) & DC_HASDEFID && (int)LOWORD(dwDefInfo) !=
=3D nID)
     {
        // Reset 'DefButton' style
        pButton =3D GetDlgItem((int)LOWORD(dwDefInfo));
        if (pButton)
            pButton->SendMessage(BM_SETSTYLE, LOWORD(BS_PUSHBUTTON)=
 | LOWORD((pButton->GetStyle() & ~BS_DEFPUSHBUTTON)), MAKELPARAM(TR=
UE, 0));
    }
 =

    SendMessage(DM_SETDEFID, (WPARAM)nID, 0L);
    pButton =3D GetDlgItem(nID);
    if (pButton)
    {
        pButton->SendMessage(BM_SETSTYLE, LOWORD(BS_DEFPUSHBUTTON) =
| LOWORD((pButton->GetStyle() & ~BS_PUSHBUTTON)), MAKELPARAM(TRUE, =
0));
        pButton->SetFocus(hButton);        // Optional!
    }
}


You can call this function from OnInitDialog() in your class.


Good luck!

Dmitry A. Dulepov
Groupware Group
Samsung Electronics Co., Ltd., Russian Research Center
Tel.: +7(095)213-9207
Fax.: +7(095)213-9196
E-Mail (Internet): dima@ssm6000.samsung.ru




| Вернуться в корень Архива |