Last month we showed you how to extend the common dialogs using dialog templates. Sometimes, however you only want to change the caption of an existing button on a common dialog. If, for example, you want to use the open dialog to allow your users to delete a file then you would probably want the Open button to show “Delete” rather than “Open.” This is accomplished rather easily in the dialog’s OnShow event handler. In your event handler you can simply do this:
HWND hWndDlg =
GetParent(OpenDialog1->Handle);
HWND hWndBtn = GetDlgItem(hWndDlg, 1);
SetWindowText(hWndBtn, "&Delete");
I first obtain the dialog’s window handle by calling GetParent() passing the Handle property as a parameter. It is important to understand that the dialog’s Handle property is the window handle of a child dialog created by Windows, not the handle to the file open dialog itself. Calling GetParent() gives us a window handle to the file open dialog itself. Next I call GetDlgItem() to get the window handle of a control on the dialog. In this case I pass the handle to the dialog and a resource ID of 1, the resource ID of the dialog’s Open button. I used the resource editor from Borland C++ 5.02 to determine the control ID of the open button. I simply loaded COMDLG32.DLL in the resource editor and spied on the file open dialog resource.
Changing the caption of a button on a common dialog is easy provided you know how the common dialogs are structured.