Comment définir le texte sur le bouton «Enregistrer» dans la boîte de dialogue de fichier de Windows?

StackOverflow https://stackoverflow.com/questions/612119

  •  03-07-2019
  •  | 
  •  

Question

J'essaie de définir le texte sur "Enregistrer". bouton de Windows " Enregistrer le fichier sous ... " dialogue.

J'ai configuré le point d'ancrage, reçu le message, trouvé le bouton (nb. Si j'appelle " GetWindowText () ", je vois "& amp; Enregistrer", alors je sais que c'est le bouton droit).

Ensuite, j'ai modifié le texte en utilisant " SetWindowText () " (et a appelé " GetWindowText () " pour le vérifier - le texte est correct).

Mais ... le bouton indique toujours "Enregistrer".

Je peux modifier le " Annuler " bouton utilisant le même code exact - pas de problème. En quoi le " Enregistrer " bouton? Comment puis-je le changer.

Code (pour ce que ça vaut):

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"
  }
}
Était-ce utile?

La solution

Je l'ai finalement fait fonctionner ....

Je suis presque sûr qu'il se passe quelque chose de drôle avec l'option "Enregistrer". bouton mais ce code va le combattre dans la soumission:

// 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);
}

Autres conseils

Vous devez probablement redessiner la fenêtre après avoir défini le texte.

Essayez d'appeler UpdateWindow () après avoir défini le texte.

Utilisez le message CDM_SETCONTROLTEXT pour définir le texte plutôt que de vous fâcher directement avec SetWindowText, c.-à-d..

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

http://msdn.microsoft.com/ en-us / library / ms646960 (VS.85) .aspx en savoir plus sur la personnalisation des boîtes de dialogue d'ouverture / enregistrement

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top