Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.11.17;
Скачать: CL | DM;

Вниз

EnumForms   Найти похожие ветки 

 
Dmk ©   (2003-08-29 00:55) [0]

Функция возвращает список ВСЕХ форм для ВСЕХ принтеров установленных в системе. Может я MSDN неправильно прочитал?

Вот выдержка из MSDN 98:

EnumForms
The EnumForms function enumerates the forms supported by the specified printer.

BOOL EnumForms(
HANDLE hPrinter, // handle to printer object
DWORD Level, // data-structure level
LPBYTE pForm, // points to buffer that receives form info.
// structure array
DWORD cbBuf, // count of bytes in buffer
LPDWORD pcbNeeded, // points to variable to receive count of
// bytes copied or required
LPDWORD pcReturned // points to variable to receive count of
// structures copied
);

Parameters
hPrinter
Handle to the printer for which the forms should be enumerated.


Вот мой код:

Procedure EnumForms;
var
EnumResult: LongBool;
cbBufSize: DWord;
BytesNeeded: DWord;
BytesReturned: DWord;
FormsPointer: Pointer;
Counter: DWord;
StructAddr: DWord;

begin
If FPrnHandle = 0 then Exit;

BytesNeeded := 0;

EnumResult := EnumForms(FPrnHandle, 1, @FFormInfo_1, 0, BytesNeeded, BytesReturned);

If (not EnumResult) and (BytesNeeded <> 0) then
begin
GetMem(FormsPointer, BytesNeeded);

cbBufSize := BytesNeeded;

EnumResult := EnumForms(FPrnHandle, 1, FormsPointer, cbBufSize, BytesNeeded, BytesReturned);

If not EnumResult then raise Exception.Create("Enumerate forms error!");

With PrintForm do
begin
PaperBox.Items.Clear;

StructAddr := DWord(FormsPointer);

For Counter := 0 to BytesReturned - 1 do
begin
Move(Pointer(StructAddr)^, FFormInfo_1, FFormInfoSize);

PPaper := FFormInfo_1.pName;

PrintForm.PaperBox.Items.Add(PPaper);

Inc(StructAddr, FFormInfoSize);
end;

PaperBox.ItemIndex := 0;
end;//With

FreeMem(FormsPointer, BytesNeeded);
end;//If not EnumResult
end;



Судя по MSDN, должны возвращатся формы для
выбранного принтера открытого функцией OpenPrinter.
Или я не прав?


 
Vlad Oshin ©   (2003-08-29 17:36) [1]


> The EnumForms function enumerates the forms supported by
> the specified printer


> Функция возвращает список ВСЕХ форм для ВСЕХ принтеров установленных
> в системе.

не правильно :)


 
jonni ©   (2003-08-29 18:09) [2]

> The EnumForms function enumerates the forms supported by
> the specified printer

финкция EnumForms перебирает все формы поддерживаемый ОПРЕДЕЛЁННЫМ принтером.


 
Dmk ©   (2003-08-29 22:15) [3]

2 Vlad Oshin © (29.08.03 17:36) [1]
2 jonni © (29.08.03 18:09) [2]

Спасибо конечно.
Но первое предложение - это утверждение,
а в конце сообщения был вопрос.

Перефразирую.
Почему эта функция возвращает мне список всех
форм имеющихся у всех принтеров в системе, а не
только для одного принтера на который указывает
FPrnHandle в моем коде?????


 
Dmk ©   (2003-08-31 22:11) [4]

Никто не знает?


 
Ates   (2003-09-19 04:40) [5]

procedure EnumPrinterForms(Proc: TGetStrProc);
type
TPaperNames = array[1..256, 0..63] of Char;
PPaperNames = ^TPaperNames;
var
Index,Count: integer;
PaperNames: PPaperNames;
DevMode: THandle;
Device, Driver, Port: array[0..MAX_PATH] of Char;
begin
if (Printer.Printers.Count <> 0) then
begin
Printer.GetPrinter(@Device, @Driver, @Port, DevMode);
if (GlobalSize(DevMode) <> 0) and (GlobalLock(DevMode) <> nil) then
begin
Count := DeviceCapabilities(Device, Port, DC_PAPERNAMES, nil,
PDevMode(GlobalLock(DevMode)));
if Count > 0 then
begin
GetMem(PaperNames, Count * 64);
try
DeviceCapabilities(Device, Port, DC_PAPERNAMES, PChar(PaperNames),
PDevMode(GlobalLock(DevMode)));
for Index := 1 to Count do Proc(PaperNames^[Index]);
finally
FreeMem(PaperNames);
end;
end;
end;
end;
end;


 
Ates   (2003-09-19 04:41) [6]

EnumForms
The EnumForms function enumerates the forms supported by the specified printer.


 
Ates   (2003-09-19 04:42) [7]

procedure EnumFormNames(Names: TStrings);
var
Buffer, FormInfo: PChar;
Count, NumInfo: DWORD;
I: Integer;
Device, Driver, Port: array[0..MAX_PATH] of Char;
hDevice: THandle;
begin
if (Names = nil) then Names := TStringList.Create else Names.Clear;
if (Printer.Printers.Count <> 0) then
begin
Printer.GetPrinter(@Device, @Driver, @Port, hDevice);
if GlobalSize(hDevice) <> 0 then
begin
Count := 0;
EnumForms(hDevice, 1, nil, 0, Count, NumInfo);
if Count = 0 then
begin
ShowMessage(IntToStr(GetLastError));
Exit;
end;
GetMem(Buffer, Count);
try
if not EnumForms(hDevice, 1, PByte(Buffer), Count, Count, NumInfo)
then Exit;
FormInfo := Buffer;
for I := 0 to NumInfo -1 do
with PFormInfo1(FormInfo)^ do
begin
Names.Add(pName); //diger bilgilerde eklenebilir
Inc(FormInfo, sizeof(TFormInfo1));
end;
finally
FreeMem(Buffer, Count);
GlobalUnLock(hDevice);
end;
end;
end;
end;


 
Dmk ©   (2003-09-20 14:26) [8]

2 Ates
Угу. Это я уже попробовал.
Насчет GetDeviceCaps сомнений нет. Функция возвращает
"корректное" кол-во форм. А вот
EnumForms помоему описанию не соответствует.
Кроме того:

Printer.GetPrinter(@Device, @Driver, @Port, hDevice);
if GlobalSize(hDevice) <> 0 then
begin
Count := 0;
EnumForms( hDevice, 1, nil, 0, Count, NumInfo);
if Count = 0 then
begin
ShowMessage(IntToStr(GetLastError));
Exit;
end;

Всегда будет Exit, т.к. hDevice - это не дескриптор принтера,
а дескриптор объекта памяти для структуры DevMode.
EnumForms требует дескриптор принтера, который получается
с помощью OpenPrinter.

PS. EnumForms возвращает все формы для всех принтеров.
Хотя это и не соответствует описанию, что очень странно.


 
Dmk ©   (2003-09-20 14:27) [9]

GetDeviceCaps. Извиняюсь - DeviceCapabilities.



Страницы: 1 вся ветка

Текущий архив: 2003.11.17;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.028 c
1-56723
Makhanev A.S.
2003-11-07 00:11
2003.11.17
TAction - Shortcut...


1-56613
Zorlag
2003-11-05 19:59
2003.11.17
Помогите, пожалуйста с отправкой письма через Delphi!


1-56668
Innz
2003-11-07 18:13
2003.11.17
считывание из файла


1-56691
-=GUEST=-
2003-11-07 13:20
2003.11.17
Expert для форматирования исходников


7-56924
Sergei
2003-09-08 12:19
2003.11.17
Печать