SelLangForm.pas
上传用户:sxtzxj
上传日期:2013-10-05
资源大小:577k
文件大小:5k
源码类别:

Windows编程

开发平台:

C++ Builder

  1. unit SelLangForm;
  2. {
  3.   Inno Setup
  4.   Copyright (C) 1997-2006 Jordan Russell
  5.   Portions by Martijn Laan
  6.   For conditions of distribution and use, see LICENSE.TXT.
  7.   "Select Language" form
  8.   $jrsoftware: issrc/Projects/SelLangForm.pas,v 1.15 2006/06/26 06:18:28 jr Exp $
  9. }
  10. interface
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13.   SetupForm, StdCtrls, ExtCtrls, NewStaticText, BitmapImage;
  14. type
  15.   TSelectLanguageForm = class(TSetupForm)
  16.     SelectLabel: TNewStaticText;
  17.     LangCombo: TComboBox;
  18.     OKButton: TButton;
  19.     CancelButton: TButton;
  20.     IconBitmapImage: TBitmapImage;
  21.   private
  22.     { Private declarations }
  23.   public
  24.     { Public declarations }
  25.     constructor Create(AOwner: TComponent); override;
  26.   end;
  27. function AskForLanguage: Boolean;
  28. implementation
  29. uses
  30.   Struct, Msgs, MsgIDs, Main;
  31. {$R *.DFM}
  32. var
  33.   DefComboWndProcW, PrevComboWndProc: Pointer;
  34. function NewComboWndProc(Wnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
  35. stdcall;
  36. begin
  37.   case Msg of
  38.     { CB_ADDSTRING must pass to the default Unicode combo box window procedure
  39.       since PrevWndProc is an ANSI window procedure and calling it would result
  40.       in Unicode->ANSI conversion. Do the same for CB_GETLBTEXT(LEN) so that
  41.       MSAA sees Unicode strings. }
  42.     CB_ADDSTRING, CB_GETLBTEXT, CB_GETLBTEXTLEN:
  43.       Result := CallWindowProcW(DefComboWndProcW, Wnd, Msg, wParam, lParam)
  44.   else
  45.     Result := CallWindowProcW(PrevComboWndProc, Wnd, Msg, wParam, lParam);
  46.   end;
  47. end;
  48. function AskForLanguage: Boolean;
  49. { Creates and shows the "Select Language" dialog. Returns True and activates
  50.   the selected language if the user clicks OK, or False otherwise. }
  51. var
  52.   LangForm: TSelectLanguageForm;
  53.   ClassInfo: TWndClassW;
  54.   I, J: Integer;
  55.   LangEntry: PSetupLanguageEntry;
  56.   N: String;
  57. begin
  58.   LangForm := TSelectLanguageForm.Create(Application);
  59.   try
  60.     { On NT, make it possible to add Unicode strings to our ANSI combo box by
  61.       installing a window procedure with special CB_ADDSTRING handling.
  62.       Yeah, this is a hack; it's too hard to create a native Unicode control
  63.       in Delphi. }
  64.     if Win32Platform = VER_PLATFORM_WIN32_NT then begin
  65.       if GetClassInfoW(0, 'COMBOBOX', ClassInfo) then begin
  66.         DefComboWndProcW := ClassInfo.lpfnWndProc;
  67.         Longint(PrevComboWndProc) := SetWindowLongW(LangForm.LangCombo.Handle,
  68.           GWL_WNDPROC, Longint(@NewComboWndProc));
  69.       end;
  70.     end;
  71.     for I := 0 to Entries[seLanguage].Count-1 do begin
  72.       LangEntry := Entries[seLanguage][I];
  73.       if (I = ActiveLanguage) or (LangEntry.LanguageCodePage = 0) or
  74.          (LangEntry.LanguageCodePage = GetACP) or
  75.          (shShowUndisplayableLanguages in SetupHeader.Options) then begin
  76.         { Note: LanguageName is Unicode }
  77.         N := LangEntry.LanguageName + #0#0;  { need wide null! }
  78.         if Win32Platform = VER_PLATFORM_WIN32_NT then
  79.           J := SendMessageW(LangForm.LangCombo.Handle, CB_ADDSTRING, 0,
  80.             Longint(PWideChar(Pointer(N))))
  81.         else
  82.           J := LangForm.LangCombo.Items.Add(WideCharToString(PWideChar(Pointer(N))));
  83.         if J >= 0 then
  84.           LangForm.LangCombo.Items.Objects[J] := TObject(I);
  85.       end;
  86.     end;
  87.     LangForm.LangCombo.ItemIndex := LangForm.LangCombo.Items.IndexOfObject(TObject(ActiveLanguage));
  88.     if LangForm.LangCombo.Items.Count > 1 then begin
  89.       Result := (LangForm.ShowModal = mrOK);
  90.       if Result then begin
  91.         I := LangForm.LangCombo.ItemIndex;
  92.         if I >= 0 then
  93.           SetActiveLanguage(Integer(LangForm.LangCombo.Items.Objects[I]));
  94.       end;
  95.     end
  96.     else begin
  97.       { Don't show language dialog if there aren't multiple languages to choose
  98.         from, which can happen if only one language matches the user's code
  99.         page. }
  100.       Result := True;
  101.     end;
  102.   finally
  103.     LangForm.Free;
  104.   end;
  105. end;
  106. { TSelectLanguageForm }
  107. constructor TSelectLanguageForm.Create(AOwner: TComponent);
  108. begin
  109.   inherited;
  110.   InitializeFont;
  111.   Center;
  112.   Caption := SetupMessages[msgSelectLanguageTitle];
  113.   SelectLabel.Caption := SetupMessages[msgSelectLanguageLabel];
  114.   OKButton.Caption := SetupMessages[msgButtonOK];
  115.   CancelButton.Caption := SetupMessages[msgButtonCancel];
  116.   IconBitmapImage.Bitmap.Canvas.Brush.Color := Color;
  117.   IconBitmapImage.Bitmap.Width := Application.Icon.Width;
  118.   IconBitmapImage.Bitmap.Height := Application.Icon.Height;
  119.   IconBitmapImage.Bitmap.Canvas.Draw(0, 0, Application.Icon);
  120.   IconBitmapImage.Width := IconBitmapImage.Bitmap.Width;
  121.   IconBitmapImage.Height := IconBitmapImage.Bitmap.Height;
  122. end;
  123. end.