tags:

views:

399

answers:

3

I'm trying to set the text on the "save" button of the Windows "Save file as..." dialog.

I've set up the hook, received the message, found the button (nb. If I call "GetWindowText()" I see "&Save" so I know it's the right button).

Next I changed the text using "SetWindowText()" (and called "GetWindowText()" to check it - the text is correct).

But ... the button still says "Save".

I can change the "Cancel" button using the exact same code - no problem. What's so special about the "Save" button? How can I change it.

Code (for what it's worth):

static UINT_PTR CALLBACK myHook(HWND hwnd, UINT msg, WPARAM, LPARAM)
{
  if (msg == WM_INITDIALOG) {
    wchar_t temp[100];
    HWND h = GetDlgItem(GetParent(hwnd),IDOK);
    GetWindowTextW(h,temp,100);     // temp=="&Save"
    SetWindowTextW(h,L"Testing");
    GetWindowTextW(h,temp,100);     // temp=="Testing"
  }
}
A: 

You probably need to redraw the window after setting the text.

Try calling UpdateWindow() after setting the text.

SimonV
Nope, I tried that.
Jimmy J
A: 

Use CDM_SETCONTROLTEXT message to set the text rather than mess with SetWindowText directly, i.e.

SendMessage(hwnd, CDM_SETCONTROLTEXT, IDOK, L"Testing");

http://msdn.microsoft.com/en-us/library/ms646960(VS.85).aspx has more on customizing open/save dialogs

Michael
Tried that as well...nb. I can set the text of the "Cancel" button perfectly well using the exact same code (swapping IDOK for IDCANCEL, obviously".The "Save" button seems to be doing something weird.
Jimmy J
What version of Windows are you on? Can you post the code you use to invoke the save dialog?
Michael
+1  A: 

I finally made it work....

I'm pretty sure there's something funny going on with the "Save" button but this code will wrestle it into submission:

// I replace the dialog's WindowProc with this
static WNDPROC oldProc = NULL;
static BOOL CALLBACK buttonSetter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    // Set the button text on every window redraw....
 if (msg == WM_ERASEBKGND) {
  SetDlgItemTextW(hwnd,IDOK,L"OK");
 }
 return oldProc(hwnd, msg, wParam, lParam);
};

// This is the callback for the GetWriteName hook
static UINT_PTR CALLBACK GWNcallback(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 HWND dlg = GetParent(hwnd);
 if (msg == WM_INITDIALOG) {
  oldProc = (WNDPROC)GetWindowLongPtr(dlg, GWL_WNDPROC);
  if (oldProc !=0) {
   SetWindowLongPtr(dlg, GWL_WNDPROC, (LONG)buttonSetter);
  }
 }
    // We need extra redraws to make our text appear...
 InvalidateRect(dlg,0,1);
}
Jimmy J