InputBox函数显示的对话框按钮是英文的,些不协调,怎样更改?

解决方案 »

  1.   

    使用钩子就可以了。我是用C++Builder的,对Pascal语言不熟,你将
    下面的代码翻译为Delphi就可以了。static HHOOK hHook = NULL;long CALLBACK CBTFun(int nCode, WPARAM wParam, LPARAM lParam)
    {
        long ret;
        HWND hWnd;    if (nCode==HCBT_ACTIVATE) {
            ret = CallNextHookEx(hHook,
                nCode, wParam, lParam);
            if (UnhookWindowsHookEx(hHook))
                hHook = NULL;
            hWnd = FindWindowEx((HWND)wParam,
                NULL, "TButton", "OK");
            SetWindowText(hWnd, "确定");
            hWnd = FindWindowEx((HWND)wParam,
                NULL, "TButton", "Cancel");
            SetWindowText(hWnd, "取消");
            return ret;
        }
        return CallNextHookEx(hHook, nCode,
            wParam, lParam);
    }//调用时的代码:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)
            CBTFun, 0, GetCurrentThreadId());
        ShowMessage(InputBox("Caption","Prompt",""));
        if (hHook) UnhookWindowsHookEx(hHook);
    }
      

  2.   

    在工程中添加Consts单元,然后修改SMsgDlgCancel这个常熟,以及它周围的常数,修改成中文,试试看。
      

  3.   

    我改写成 Delphi 的代码,不知道有没有问题(我是用C++Builder的):function MyInputBox(const ACaption, APrompt, ADefault: string): string;
    var
      hHook: HHOOK;  function CBTFun(int nCode, WPARAM wParam, LPARAM lParam): Long;
      var
        ret: Long;
        hWnd: HWND;    if nCode=HCBT_ACTIVATE then
        begin
          Result := CallNextHookEx(hHook,
                nCode, wParam, lParam);
          if UnhookWindowsHookEx(hHook) then
             hHook := Nil;
          hWnd := FindWindowEx(HWND(wParam),
             Nil, 'TButton', 'OK');
          SetWindowText(hWnd, '确定');
          hWnd := FindWindowEx(HWND(wParam),
             Nil, 'TButton', 'Cancel');
          SetWindowText(hWnd, '取消');
          Exit;
        end;    Result := CallNextHookEx(hHook, nCode,
            wParam, lParam);
      end;begin
      hHook := SetWindowsHookEx(WH_CBT, @CBTFun,
          0, GetCurrentThreadId);
      Result = InputBox(ACaption, APrompt, ADefault);
      if hHook<>Nil then UnhookWindowsHookEx(hHook);
    end;
      

  4.   

    使用上面的 MyInputBox 代替VCL的 InputBox.