Changing CFileDialog Ok title
Serge Lalonde -- serge@infolytica.qc.ca
Thursday, October 17, 1996
Environment: VC++ 4.2, NT 4.0
Hi there!
I'm subclassing the Explorer style CFileDialog to implement an exporting
facility in my program. I'd like to change the default Ok button to
say "Export" instead of "Save". Sounds easy enough. Here is the code
I use to subclass the dialog in the constructor:
IExportDialog::IExportDialog
(LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags,
LPCTSTR lpszFilter,
CWnd *pParentWnd)
: CFileDialog(FALSE, lpszDefExt, lpszFileName, dwFlags, _T("AutoCAD DXF Version 11+ (*.dxf)|*.dxf||"), pParentWnd)
{
m_ofn.lpstrTitle= _T("Export");
return;
}
I expected that the title of the dialog would also be used in the button,
but that isn't the case. So I overridded the OnInitDone() method and tried
to change it there. The problem is that I can't even get the button's
CWnd! None of the below worked and I'm pretty much out of ideas. I know it
can be done because Dev Studio does it in their Insert files into project
dialog. Am I missing something obvious?
CWnd *pWindow= FindWindow(_T("CButton"), _T("Save")); // Returns NULL
CWnd *pWindow= GetDlgItem(IDOK); // Returns NULL
CWnd *pWindow= GetDescendantWindow(IDOK); // Returns NULL
CWnd *pWindow= cwSetDlgItemText(IDOK, _T("Export")); // Returns NULL
I even tried iterating through its child windows but GetWindow(GW_CHILD)
returns NULL.
--
Have a tremendous day!
_/_/_/_/ _/_/_/_/ _/_/_/ _/_/_/ _/_/_/_// 300 Leo Parizeau, Suite 2222
_/ _/ _/ _/ _/ _/ / Montreal, PQ, Canada H2W 2P4
_/_/_/_/ _/_/_/ _/_/_/_/ _/ _/_/ _/_/_/ / Voice: (514) 849-8752 x236
_/ _/ _/ _/ _/ _/ _/ /__Fax: (514) 849-4239__
_/_/_/_/ _/_/_/_/ _/ _/ _/_/_/ _/_/_/_/ Lalonde, Infolytica Corp.
Norman L Covington -- doubleM@cris.com
Friday, October 18, 1996
[Mini-digest: 8 responses]
I just did this, smile. There is a message if you look into the internals of
the MFC. I created a member function called SetControlText(int nID, LPSTR
lpszTitle);
Following is the code I used to change the OK button to Select ---- For
information on the IDs for the control within the CFileDialog you can look
at the resource in FileOpen.dlg within the \MSDEV\Include.
By the way there is a function within CFileDialog to hide controls as well,
it's public and it's name is HideControl(int nID);
void CMyFileDialog::SetControlText(int nID, LPSTR lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT(m_ofn.Flags & OFN_EXPLORER);
GetParent()->SendMessage(CDM_SETCONTROLTEXT, (WPARAM)nID, (LPARAM)lpszText);
}
So, in the InitDialog for you CMyFileDialog you would call the member
function as follows (FOR THE OK BUTTON OR "OPEN" BUTTON IN WIN95/WINNT 4.0):
SetControlText(IDOK,"Export");
I did not use TCHAR nor LPCTSTR as MS did not use the code in their
HideControl Function which also uses a message to hide the text.
Norman
At 01:42 PM 10/17/96 EDT, you wrote:
>Environment: VC++ 4.2, NT 4.0
>
>Hi there!
>
>I'm subclassing the Explorer style CFileDialog to implement an exporting
>facility in my program. I'd like to change the default Ok button to
>say "Export" instead of "Save". Sounds easy enough. Here is the code
>I use to subclass the dialog in the constructor:
>
>IExportDialog::IExportDialog
> (LPCTSTR lpszDefExt,
> LPCTSTR lpszFileName,
> DWORD dwFlags,
> LPCTSTR lpszFilter,
> CWnd *pParentWnd)
> : CFileDialog(FALSE, lpszDefExt, lpszFileName, dwFlags, _T("AutoCAD DXF
Version 11+ (*.dxf)|*.dxf||"), pParentWnd)
>{
> m_ofn.lpstrTitle= _T("Export");
>
> return;
>}
>
>I expected that the title of the dialog would also be used in the button,
>but that isn't the case. So I overridded the OnInitDone() method and tried
>to change it there. The problem is that I can't even get the button's
>CWnd! None of the below worked and I'm pretty much out of ideas. I know it
>can be done because Dev Studio does it in their Insert files into project
>dialog. Am I missing something obvious?
>
>CWnd *pWindow= FindWindow(_T("CButton"), _T("Save")); // Returns NULL
>CWnd *pWindow= GetDlgItem(IDOK); // Returns NULL
>CWnd *pWindow= GetDescendantWindow(IDOK); // Returns NULL
>CWnd *pWindow= cwSetDlgItemText(IDOK, _T("Export")); // Returns NULL
>
>I even tried iterating through its child windows but GetWindow(GW_CHILD)
>returns NULL.
>
>--
>Have a tremendous day!
> _/_/_/_/ _/_/_/_/ _/_/_/ _/_/_/ _/_/_/_// 300 Leo Parizeau, Suite 2222
> _/ _/ _/ _/ _/ _/ / Montreal, PQ, Canada H2W 2P4
> _/_/_/_/ _/_/_/ _/_/_/_/ _/ _/_/ _/_/_/ / Voice: (514) 849-8752 x236
> _/ _/ _/ _/ _/ _/ _/ /__Fax: (514) 849-4239__
>_/_/_/_/ _/_/_/_/ _/ _/ _/_/_/ _/_/_/_/ Lalonde, Infolytica Corp.
>
>
-----From: Geoffrey Nicholls
The following code successfully changes the text on the OK button. At least
it did in NT 3.51 and Win 95.
BOOL DStoreDialog::OnInitDialog( )
{
CWnd * cwndOk;
// try reasonable approach to get ok button
cwndOk = GetDlgItem( IDOK );
if ( !cwndOk )
{
// windows 95 new way of doing this
cwndOk = GetParent( )->GetDlgItem( IDOK );
}
// override text
ASSERT_VALID( cwndOk );
cwndOk->SetWindowText( "&Export" );
// done
return( CFileDialog::OnInitDialog( ) );
}
--------------------------------------
Geoffrey Nicholls
Gazelle Software
415/323-5545 (voice)
415/323-1913 (fax)
http://www.gazelle.com
667 Marion Ave
Palo Alto, CA, 94301
--------------------------------------
-----From: jkrupa@ix.netcom.com (Jerry Krupa)
As you have already figured out the dialog item you want to change is
IDOK. So, one solution to your problem is to send the dialog item a
message in OnInitDialog():
// set the save button to read "Export"
CWnd* pWnd = this->GetParent();
::SendMessage ((pWnd->GetDlgItem(IDOK))->GetSafeHwnd(),
WM_SETTEXT,
0,
(LPARAM)(LPCTSTR) "Export");
This works for dialogs derived from CFileDialog. I'm not sure about your
comment that you subclassed the dialog. The MFC docs tell you to derive
from CFileDialog if you want special processing. I have successfully
used this solution to change the Open button to read Ok and this
solution should work for the save dialog, although I have not tried it.
Initially, I tried to figure out a MFC solution for this problem, but
gave up and reverted back to my SDK training. Maybe someone else has a
more elegant MFC solution.
--
-- Jerry Krupa, jkrupa@ix.netcom.com
Written 10/19/96 @ 07:14
-----From: John Young
>Am I missing something obvious?
Not obvious, but if all you want to do is change the text, try...
void CExportFileDialog::OnInitDone()
{
CFileDialog::OnInitDone();
SetControlText (IDOK, "&Export");
}
This works for me using VC++ 4.0, Win95. It sends the CDM_SETCONTROLTEXT
message to the control. I think the reason you couldn't get the CWnd for
the control is because there isn't one. It's a Windows control.
-John
John Young, Yaesu Musen Co., Ltd., Tokyo, Japan.
Computers do what you tell them to do, not what you want them to do.
-----From: "Robertson David"
You have to do the work with controls in the OnInitDone member
for Explorer-style dialogs.
I think you also need to use the SetControlText() function to
change the button's text.
-----From: Igor Nedelko
As soon as your class IExportDialog is derived from CFileDialog,you can
just include in your resource file the default CFileDialog dialog box
template, and modify it to suit the needs of your dialog box ( change
the button name to "Export"). When modifying a default template, be sure
to leave all existing controls there, you can move them around and
make'em invisible, but they must exist. You can add new controls if
desired. (The default dialog box templates can be found in the
\MSVC\INCLUDE with .DLG file extension.).Note that the default dialog
box templates contain constant identifiers such as cmb1, lst1, stc1, and
so forth. These constants are defined in the DLGS.H file, located in the
\\MSVC\INCLUDE directory. You must include this file in your
application's .RC file as well.( Using App Studio, choose Set Includes
from the File menu and enter #include "dlgs.h" in the Read-Only Symbol
Directives edit control.).
Regards,
Igor
-----From: "avi"
Hi Leo:
Derive a class from CFileDialog, handle OnInitDialog, in which call the =
CFileDialog::OnInitDialog and then do a GetDlgItem(IDOK), (the "Save" =
button has a control id of 1), once you get the window handle do a =
SetWindowText.
Avi
-----From: "Greg Tighe"
Try calling any of these methods using your parent window instead,
i.e.
GetParent()->GetDlgItem(IDOK);
This should do the trick.
-Greg Tighe
Applied Intelligent Systems, Inc.
Ann Arbor, MI
gdt@aisinc.com
| Вернуться в корень Архива
|