Delphi Programming / Object Pascal
サイトのトップページへ リンクのページへ ロゴマーク
[掲載 2016年05月13日] [更新 2016年05月13日] Delphi サンプルプログラム集
   
018_プリントサーバのプロパティのダイアログを表示
動作確認等 Windows 7 U64(SP1) + Delphi XE(UP1) Pro
018_PrintServerDialog.zip [537 KB] 2016年05月13日版 (EXE 同梱)







01_プリントサーバのプロパティのダイアログを表示


[プリントサーバのプロパティ] のダイアログを表示するサンプルです.
64 ビット Windows には,このダイアログは 64 ビット版しかありません.そこで,Windows のビットバージョンを判定して,64 ビット版のダイアログを表示するようにしています.
Windows 7 以降では,起動時に表示するタブを t オプションで指定できます.0 が [用紙] タブ, 1 が [ポート] タブです.

このダイアログで設定した内容の全てが対象のプリンタで使用できるわけではありません.使用可能なプロパティは,プリンタとプリンタドライバによります.


rundll32 printui.dll,PrintUIEntry /s                   //Window 2000以降で使用可能
rundll32 printui.dll,PrintUIEntry /s /t0 /n\\machine   //Windows 7 以降で使用可能
printui /s                                             //Windows 7 以降で使用可能


図1
ダイアログを表示

リスト1
プリントサーバのプロパティのダイアログの表示
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private 宣言 }
  public
    { Public 宣言 }
  end;

var
  Form1: TForm1;

implementation

uses
  ShellAPI;

{$R *.dfm}

//-----------------------------------------------------------------------------
//  32ビットのWindowsか64ビットのWindowsかを調べる関数
//  64ビット版のWindowsの場合はTrueを返す
//-----------------------------------------------------------------------------
function Is64bitWindows: Boolean;
var
  Wow64Proc : function(hProcess: THandle; var Wow64: BOOL): BOOL stdcall;
  RetFlag   : LongBool;
begin
  @Wow64Proc := GetProcAddress(GetModuleHandle('Kernel32.dll'), 'IsWow64Process');
  if @Wow64Proc <> nil then begin
    Wow64Proc(GetCurrentProcess, RetFlag);

    if SizeOf(THandle) = 4 then begin
      Result := RetFlag;
    end else
    if SizeOf(THandle) = 8 then begin
      Result := True;
    end;
  end else begin
    //Windows XPの64ビット版か
    Result := CheckWin32Version(5, 2);
  end;
end;

//=============================================================================
//  [プリントサーバのプロパティ]ダイアログを表示
//
//  ShellExecuteの使用にはusesにShellAPIが必要
//=============================================================================
procedure TForm1.Button1Click(Sender: TObject);
var
  LCmdExe   : string;
  LCmdParam : string;
begin
  //64ビットWindowsの場合で32ビットEXEの場合
  if (Is64bitWindows) and (SizeOf(Pointer) = 4) then begin
    LCmdExe := 'C:\Windows\Sysnative\rundll32';
  end else begin
    LCmdExe := 'rundll32';
  end;
  LCmdParam := 'printui.dll,PrintUIEntry /s';

  ShellExecute(0, nil, PChar(LCmdExe), PChar(LCmdParam), nil, SW_SHOWNORMAL);
end;

end.