How to set the text on the "Save" button in the Windows file dialog box?

I am trying to set the text to the "Save" button in the "Save file as ..." dialog box.

I set the hook, received the message, found the button (nb. If I call " GetWindowText()" I see "and" Save ", so I know that this is the right button).

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

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

I can change the Cancel button using the same code - no problem. What is 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"
  }
}
+3
3

, , ...

, - "", :

// I replace the dialog 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);
}
+1

, .

UpdateWindow() .

0

Use the CDM_SETCONTROLTEXT message to set the text and not the mess using SetWindowText directly, i.e.

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

http://msdn.microsoft.com/en-us/library/ms646960(VS.85).aspx has more options for setting up open / save dialogs

0
source

Source: https://habr.com/ru/post/1704228/


All Articles