gpt4 book ai didi

winapi - 如何在 Windows 文件对话框的 "save"按钮上设置文本?

转载 作者:行者123 更新时间:2023-12-01 12:43:38 24 4
gpt4 key购买 nike

我正在尝试在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com