Como definir o texto no botão “salvar” no diálogo de arquivo do Windows?
Pergunta
Estou tentando definir o texto no botão "Salvar" do "arquivo Salvar como ..." Windows diálogo.
Eu configurei o gancho, recebeu a mensagem, encontrada no botão (nb. Se eu chamo de "GetWindowText()
" Eu vejo "& Save" assim que eu sei que é o botão direito).
Em seguida eu mudei o texto usando "SetWindowText()
" (e chamado de "GetWindowText()
" para verificá-lo - o texto está correto).
Mas ... o botão ainda diz "Save".
Eu posso mudar o botão "Cancelar" usando exatamente o mesmo código - não há problema. O que há de tão especial sobre o botão "Save"? Como posso mudá-lo.
Code (para o que vale a pena):
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"
}
}
Solução
Eu finalmente fez funcionar ....
Eu tenho certeza que há algo engraçado acontecendo com o botão "Save", mas este código lutará lo em sua apresentação:
// 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);
}
Outras dicas
Você provavelmente precisará redesenhar a janela depois de definir o texto.
Tente chamar UpdateWindow () depois de definir o texto.
Use CDM_SETCONTROLTEXT mensagem para definir o texto em vez de mexer com SetWindowText directamente, i.
SendMessage(hwnd, CDM_SETCONTROLTEXT, IDOK, L"Testing");
http://msdn.microsoft.com/ en-us / library / ms646960 (VS.85) .aspx tem mais sobre a personalização / open save diálogos