Cómo configurar el texto en el & # 8220; guardar & # 8221; botón en el cuadro de diálogo de Windows?
Pregunta
Estoy tratando de establecer el texto en " guardar " botón de Windows " Guardar archivo como ... " diálogo.
Configuré el enlace, recibí el mensaje, encontré el botón (nb. Si llamo " GetWindowText ()
" Veo " & amp; Save " entonces sé que es el botón derecho).
Luego cambié el texto usando " SetWindowText ()
" (y llamado " GetWindowText ()
" para verificarlo, el texto es correcto).
Pero ... el botón todavía dice " Guardar " ;.
Puedo cambiar el " Cancelar " botón con el mismo código exacto, no hay problema. ¿Qué tiene de especial el " Guardar " ¿botón? ¿Cómo puedo cambiarlo?
Código (para lo que vale):
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"
}
}
Solución
Finalmente lo hice funcionar ....
Estoy bastante seguro de que está pasando algo divertido con " Guardar " botón, pero este código luchará para que se envíe:
// 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);
}
Otros consejos
Probablemente deba volver a dibujar la ventana después de configurar el texto.
Intenta llamar a UpdateWindow () después de configurar el texto.
Use el mensaje CDM_SETCONTROLTEXT para configurar el texto en lugar de desordenar con SetWindowText directamente, es decir,
SendMessage(hwnd, CDM_SETCONTROLTEXT, IDOK, L"Testing");
http://msdn.microsoft.com/ en-us / library / ms646960 (VS.85) .aspx tiene más información sobre la personalización de los diálogos de abrir / guardar