unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Grids; type TForm1 = class(TForm) Panel5: TPanel; Panel3: TPanel; Panel1: TPanel; Button1: TButton; Panel4: TPanel; GroupBox1: TGroupBox; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; CheckBox4: TCheckBox; CheckBox5: TCheckBox; CheckBox6: TCheckBox; CheckBox7: TCheckBox; CheckBox8: TCheckBox; CheckBox9: TCheckBox; CheckBox10: TCheckBox; CheckBox11: TCheckBox; CheckBox12: TCheckBox; CheckBox13: TCheckBox; CheckBox14: TCheckBox; CheckBox15: TCheckBox; CheckBox16: TCheckBox; CheckBox17: TCheckBox; CheckBox18: TCheckBox; CheckBox19: TCheckBox; CheckBox20: TCheckBox; CheckBox21: TCheckBox; CheckBox22: TCheckBox; CheckBox23: TCheckBox; CheckBox24: TCheckBox; CheckBox25: TCheckBox; PrinterSetupDialog1: TPrinterSetupDialog; SGrid1: TStringGrid; procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button1Click(Sender: TObject); procedure SGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); private { Private 宣言 } FPaperList : TStringList; FSourceList : TStringList; procedure List_DEVMODEInfo(ADevMode : PDeviceMode); public { Public 宣言 } end; var Form1: TForm1; implementation uses Printers, WinSpool, PaperListUnit; {$R *.dfm} { TForm1 } //============================================================================= // 用紙サイズとデフォルトビン装置のリストを別ユニットに用意した関数で作成 // // SGrid1.BorderStyle := bsNone; // SGrid1.Enabled := True; // SGrid1.Options := [goRowSelect]; // にしている //============================================================================= procedure TForm1.FormShow(Sender: TObject); begin FPaperList := TStringList.Create; FSourceList := TStringList.Create; MakePaperList(FPaperList, FSourceList); SGrid1.Cells[0,0] := 'メンバー'; SGrid1.Cells[1,0] := '意味'; SGrid1.Cells[2,0] := '値'; end; //============================================================================= // TStringListを解放 //============================================================================= procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin FreeAndNil(FPaperList); FreeAndNil(FSourceList); end; //============================================================================= // プリンタの設定ダイアログを表示して,設定した内容のDEVMODE構造体の各面罵の // 値をTListViewに表示 //============================================================================= procedure TForm1.Button1Click(Sender: TObject); var LDevice : array[0..MAX_PATH-1] of Char; LDriver : array[0..MAX_PATH-1] of Char; LPort : array[0..MAX_PATH-1] of Char; LDeviceMode : THandle; LDevMode : PDeviceMode; begin if PrinterSetupDialog1.Execute then begin //現在のプリンタに関する情報を取り出す Printer.GetPrinter(LDevice, LDriver, LPort, LDeviceMode); //ADeviceModeのメモリをロックしDEVMODEのポインタを取得 LDevMode := GlobalLock(LDeviceMode); try //実際にDEVMODEの値をTListViewに表示するルーチンを実行 List_DEVMODEInfo(LDevMode); finally //ロック解除 GlobalUnlock(LDeviceMode); end; end; end; //============================================================================= // TStringGridのOnDrawCellイベント処理 // TStringGridの描画処理 // プログラムの動作自体には直接関係なし.なくてもよい //============================================================================= procedure TForm1.SGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var LuFormat : Cardinal; begin if (gdFixed in State) then begin with SGrid1.Canvas do begin Brush.Color := $00EBEBEB; FillRect(Rect); Font.Color := clBlack; Rect.Left := Rect.Left + 5; LuFormat := DT_LEFT or DT_SINGLELINE or DT_VCENTER; DrawText(Handle, PChar(SGrid1.Cells[ACol,ARow]), -1, Rect,LuFormat); end; end else begin with SGrid1.Canvas do begin if gdSelected in State then begin Brush.Color := $00EFEED3; end else begin Brush.Color := clWhite; end; FillRect(Rect); Font.Color := clBlack; Rect.Left := Rect.Left + 5; LuFormat := DT_LEFT or DT_SINGLELINE or DT_VCENTER; DrawText(Handle,PChar(SGrid1.Cells[ACol, ARow]), -1, Rect,LuFormat); end; end; end; //----------------------------------------------------------------------------- // DEVMODEの値をTListViewに表示するルーチン //----------------------------------------------------------------------------- procedure TForm1.List_DEVMODEInfo(ADevMode: PDeviceMode); var i : Integer; LIndex : Integer; LWordValue : LongWord; LValue : Cardinal; LListFlag : Boolean; LiRow : Integer; begin //設定をサポートするメンバーをチェック CheckBox1.Checked := (ADevMode.dmFields and DM_ORIENTATION) <> 0; CheckBox2.Checked := (ADevMode.dmFields and DM_PAPERSIZE) <> 0; CheckBox3.Checked := (ADevMode.dmFields and DM_PAPERLENGTH) <> 0; Checkbox4.Checked := (ADevMode.dmFields and DM_PAPERWIDTH) <> 0; CheckBox5.Checked := (ADevMode.dmFields and DM_SCALE) <> 0; CheckBox6.Checked := (ADevMode.dmFields and DM_COPIES) <> 0; CheckBox7.Checked := (ADevMode.dmFields and DM_DEFAULTSOURCE) <> 0; CheckBox8.Checked := (ADevMode.dmFields and DM_PRINTQUALITY) <> 0; CheckBox9.Checked := (ADevMode.dmFields and DM_POSITION) <> 0; CheckBox10.Checked := (ADevMode.dmFields and DM_COLOR) <> 0; CheckBox11.Checked := (ADevMode.dmFields and DM_DUPLEX) <> 0; CheckBox12.Checked := (ADevMode.dmFields and DM_YRESOLUTION) <> 0; CheckBox13.Checked := (ADevMode.dmFields and DM_TTOPTION) <> 0; CheckBox14.Checked := (ADevMode.dmFields and DM_COLLATE) <> 0; CheckBox15.Checked := (ADevMode.dmFields and DM_FORMNAME) <> 0; CheckBox16.Checked := (ADevMode.dmFields and DM_LOGPIXELS) <> 0; CheckBox17.Checked := (ADevMode.dmFields and DM_BITSPERPEL) <> 0; CheckBox18.Checked := (ADevMode.dmFields and DM_PELSWIDTH) <> 0; CheckBox19.Checked := (ADevMode.dmFields and DM_PELSHEIGHT) <> 0; CheckBox20.Checked := (ADevMode.dmFields and DM_DISPLAYFREQUENCY) <> 0; CheckBox21.Checked := (ADevMode.dmFields and DM_DISPLAYFREQUENCY) <> 0; CheckBox22.Checked := (ADevMode.dmFields and DM_ICMMETHOD) <> 0; CheckBox23.Checked := (ADevMode.dmFields and DM_ICMINTENT) <> 0; CheckBox24.Checked := (ADevMode.dmFields and DM_MEDIATYPE) <> 0; CheckBox25.Checked := (ADevMode.dmFields and DM_DITHERTYPE) <> 0; SGrid1.RowCount := 29; LiRow := 1; SGrid1.Cells[0, LiRow] := 'dmDeviceName'; SGrid1.Cells[1, LiRow] := 'デバイス名'; SGrid1.Cells[2, LiRow] := ADevMode^.dmDeviceName; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmSpecVersion'; SGrid1.Cells[1, LiRow] := 'DEVMODEバージョン'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmSpecVersion); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDriverVersion'; SGrid1.Cells[1, LiRow] := 'ドライババージョン'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmDriverVersion); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmSize'; SGrid1.Cells[1, LiRow] := 'DEVMODE構造体のサイズ'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmSize); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDriverExtra'; SGrid1.Cells[1, LiRow] := 'DEVMODE構造体に続くデータのバイト数'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmDriverExtra); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmOrientation'; SGrid1.Cells[1, LiRow] := '用紙向き'; if ADevMode^.dmOrientation = DMORIENT_PORTRAIT then begin SGrid1.Cells[2, LiRow] := 'DMORIENT_PORTRAIT'; end else begin SGrid1.Cells[2, LiRow] := 'DMORIENT_LANDSCAPE'; end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmPaperSize'; SGrid1.Cells[1, LiRow] := '用紙サイズ'; LListFlag := False; LIndex := ADevMode^.dmPaperSize; for i := 0 to FPaperList.Count - 1 do begin if LIndex=Integer(FPaperList.Objects[i]) then begin SGrid1.Cells[2, LiRow] := FPaperList[i]; LListFlag := True; break; end; end; //上記のどれにも該当しない場合はdmPaperSizeの値を表示 if LListFlag = False then begin SGrid1.Cells[2,LiRow] := IntToStr(ADevMode^.dmPaperSize); end; //用紙幅 inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmPaperLength'; SGrid1.Cells[1, LiRow] := '0.1mm単位のユーザ定義用紙長さ'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmPaperLength); //用紙長さ inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmPaperWidth'; SGrid1.Cells[1, LiRow] := '0.1mm単位のユーザ定義用紙幅'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmPaperWidth); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmScale'; SGrid1.Cells[1, LiRow] := '用紙拡大倍率'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmScale); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmCopies'; SGrid1.Cells[1, LiRow] := 'コピー数'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmCopies); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDefaultSource'; SGrid1.Cells[1, LiRow] := 'デフォルトビン装置'; LListFlag := False; LIndex := ADevMode^.dmDefaultSource; for i := 0 to FSourceList.Count - 1 do begin if LIndex=Integer(FSourceList.Objects[i]) then begin SGrid1.Cells[2, LiRow] := FSourceList[i]; LListFlag := True; break; end; end; //上記のどれにも該当しない場合はdmDefaultSourceの値を表示 if LListFlag = False then begin SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmDefaultSource); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmPrintQuality'; SGrid1.Cells[1, LiRow] := '印刷品質'; LWordValue := ADevMode^.dmPrintQuality; if LWordValue = DMRES_DRAFT then begin SGrid1.Cells[2, LiRow] := 'DMRES_DRAFT'; end else if LWordValue = DMRES_LOW then begin SGrid1.Cells[2, LiRow] := 'DMRES_LOW'; end else if LWordValue = DMRES_MEDIUM then begin SGrid1.Cells[2, LiRow] := 'DMRES_MEDIUM'; end else if LWordValue=DMRES_HIGH then begin SGrid1.Cells[2, LiRow] := 'DMRES_HIGH'; end else begin //上記のどれにも該当しない場合はdmPrintQualityの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmPrintQuality); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmColor'; SGrid1.Cells[1, LiRow] := 'カラーモード'; if ADevMode^.dmColor = DMCOLOR_COLOR then begin SGrid1.Cells[2, LiRow] := 'DMCOLOR_COLOR'; end else if ADevMode^.dmColor = DMCOLOR_MONOCHROME then begin SGrid1.Cells[2, LiRow] := 'DMCOLOR_MONOCHROME'; end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDuplex'; SGrid1.Cells[1, LiRow] := '両面印刷'; LIndex := ADevMode^.dmDuplex; if LIndex = DMDUP_SIMPLEX then begin SGrid1.Cells[2, LiRow] := 'DMDUP_SIMPLEX'; end else if LIndex = DMDUP_HORIZONTAL then begin SGrid1.Cells[2, LiRow] := 'DMDUP_HORIZONTAL'; end else if LIndex = DMDUP_VERTICAL then begin SGrid1.Cells[2, LiRow] := 'DMDUP_VERTICAL'; end else begin //上記のどれにも該当しない場合はdmDoplexの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmDuplex); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmYResolution'; SGrid1.Cells[1, LiRow] := 'Y方向の印刷品質'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmYResolution); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmTTOption'; SGrid1.Cells[1, LiRow] := 'TrueTypeフォントの印刷方法'; LIndex := ADevMode^.dmTTOption; if LIndex = DMTT_BITMAP then begin SGrid1.Cells[2,LiRow] := 'DMTT_BITMAP'; end else if LIndex = DMTT_DOWNLOAD then begin SGrid1.Cells[2, LiRow] := 'DMTT_DOWNLOAD'; end else if LIndex = DMTT_DOWNLOAD_OUTLINE then begin SGrid1.Cells[2, LiRow] := 'DMTT_DOWNLOAD_OUTLINE'; end else if LIndex = DMTT_SUBDEV then begin SGrid1.Cells[2, LiRow] := 'DMTT_SUBDEV'; end else begin //上記のどれにも該当しない場合はdmTTOptinの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmTTOption); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmCollate'; SGrid1.Cells[1, LiRow] := 'ページ揃えの指定'; LIndex := ADevMode^.dmCollate; if LIndex = DMCOLLATE_TRUE then begin SGrid1.Cells[2, LiRow] := 'DMCOLLATE_TRUE'; end else if LIndex = DMCOLLATE_FALSE then begin SGrid1.Cells[2, LiRow] := 'DMCOLLATE_FALSE'; end else begin //上記のどれにも該当しない場合はdmCollateの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmCollate); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmFormName'; SGrid1.Cells[1, LiRow] := '使用用紙名'; SGrid1.Cells[2, LiRow] := ADevMode^.dmFormName; //ディスプレイ関係は参考のため表示 //これらの値はChangeDisplaySettings関数等でディスプレイの設定を行う場合 //に利用するメンバー inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmLogPixels'; SGrid1.Cells[1, LiRow] := 'ディスプレイのインチ当たりピクセル'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmLogPixels); SGrid1.Cells[0, LiRow] := 'dmBitsPerPel'; SGrid1.Cells[1, LiRow] := 'ディスプレイ色解像度'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmBitsPerPel); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmPelsWidth'; SGrid1.Cells[1, LiRow] := 'ディスプレイピクセル幅'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmPelsWidth); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmPelsHeight'; SGrid1.Cells[1, LiRow] := 'ディスプレイピクセル高さ'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmPelsHeight); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDisplayFlags'; SGrid1.Cells[1, LiRow] := 'ディスプレイモード'; LValue := ADevMode^.dmDisplayFlags; if LValue = DM_GRAYSCALE then begin SGrid1.Cells[2, LiRow] := 'DM_GRAYSCALE '; end else; if LValue = DM_INTERLACED then begin SGrid1.Cells[2, LiRow] := 'DM_INTERLACED'; end else begin SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmDisplayFlags); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDisplayFrequency'; SGrid1.Cells[1, LiRow] := 'ディスプレイ動作周波数'; SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmDisplayFrequency); inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmICMMethod'; SGrid1.Cells[1, LiRow] := '非ICMアプリケのICM処理方法'; LValue := ADevMode^.dmICMMethod; if LValue = DMICMMETHOD_NONE then begin SGrid1.Cells[2, LiRow] := 'DMICMMETHOD_NONE'; end else if LValue = DMICMMETHOD_SYSTEM then begin SGrid1.Cells[2, LiRow] := 'DMICMMETHOD_SYSTEM'; end else if LValue = DMICMMETHOD_DRIVER then begin SGrid1.Cells[2, LiRow] := 'DMICMMETHOD_DRIVER'; end else if LValue = DMICMMETHOD_DEVICE then begin SGrid1.Cells[2, LiRow] := 'DMICMMETHOD_DEVICE'; end else if LValue = DMICMMETHOD_USER then begin SGrid1.Cells[2, LiRow] := 'DMICMMETHOD_USER'; end else begin //上記のどれにも該当しない場合はdmICMMethodの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmICMMethod); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmICMIntent'; SGrid1.Cells[1, LiRow] := '非ICMアプリのカラーマッチング方法'; LValue := ADevMode^.dmICMIntent; if LValue = DMICM_SATURATE then begin SGrid1.Cells[2, LiRow] := 'DMICM_SATURATE'; end else if LValue = DMICM_CONTRAST then begin SGrid1.Cells[2, LiRow] := 'DMICM_CONTRAST'; end else if LValue = DMICM_COLORMETRIC then begin SGrid1.Cells[2, LiRow] := 'DMICM_COLORMETRIC'; end else if LValue = DMICM_USER then begin SGrid1.Cells[2, LiRow] := 'DMICM_USER'; end else begin //上記のどれにも該当しない場合はdmICMIntentの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmICMIntent); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmMediaType'; SGrid1.Cells[1, LiRow] := '印刷用紙の種類'; LValue := ADevMode^.dmMediaType; if LValue = DMMEDIA_STANDARD then begin SGrid1.Cells[2, LiRow] := 'DMMEDIA_STANDARD'; end else if LValue = DMMEDIA_TRANSPARENCY then begin SGrid1.Cells[2, LiRow] := 'DMMEDIA_TRANSPARENCY'; end else if LValue = DMMEDIA_GLOSSY then begin SGrid1.Cells[2, LiRow] := 'DMMEDIA_GLOSSY'; end else if LValue = DMMEDIA_USER then begin SGrid1.Cells[2, LiRow] := 'DMMEDIA_USER'; end else begin //上記のどれにも該当しない場合はdmMediatypeの値を表示 SGrid1.Cells[2, LiRow] := IntToStr(ADevMode^.dmMediaType); end; inc(LiRow); SGrid1.Cells[0, LiRow] := 'dmDitherType'; SGrid1.Cells[1, LiRow] := 'ディザリング処理'; LValue := ADevMode^.dmDitherType; if LValue = DMDITHER_NONE then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_NONE'; end else if LValue = DMDITHER_COARSE then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_COARSE'; end else if LValue = DMDITHER_FINE then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_FINE'; end else if LValue = DMDITHER_LINEART then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_LINEART'; end else if LValue = DMDITHER_ERRORDIFFUSION then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_ERRORDIFFUSION'; end else if LValue = DMDITHER_GRAYSCALE then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_GRAYSCALE'; end else if LValue = DMDITHER_USER then begin SGrid1.Cells[2, LiRow] := 'DMDITHER_USER'; end else begin //上記のどれにも該当しない場合 SGrid1.Cells[2, LiRow] := ''; end; end; end.
|