作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Windows“将文件另存为...”对话框的“保存”按钮上设置文本。
我已经设置了钩子(Hook),收到了消息,找到了按钮(注意,如果我调用“GetWindowText()
”,我会看到“&Save”,所以我知道它是正确的按钮)。
接下来,我使用“SetWindowText()
”更改了文本(并调用了“GetWindowText()
”来检查它——文本是正确的)。
但是......按钮仍然显示“保存”。
我可以使用完全相同的代码更改“取消”按钮 - 没问题。 “保存”按钮有什么特别之处?我怎样才能改变它。
代码(对于它的值(value)):
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"
}
}
最佳答案
我终于让它工作了......
我很确定“保存”按钮会发生一些有趣的事情,但是这段代码会努力将其提交:
// 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);
}
关于winapi - 如何在 Windows 文件对话框的 "save"按钮上设置文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/612119/
我是一名优秀的程序员,十分优秀!