Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2003.11.17;
Скачать: [xml.tar.bz2];

Вниз

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 вся ветка

Форум: "WinAPI";
Текущий архив: 2003.11.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.01 c
1-56591
bon
2003-11-06 10:13
2003.11.17
PageControl


14-56809
Vlad Oshin
2003-10-28 10:27
2003.11.17
Бизнес по-русски. Тотализатор. :)


1-56719
webpauk
2003-11-06 17:03
2003.11.17
Переопределение размерности свойства


14-56897
Сатир
2003-10-25 18:14
2003.11.17
Воспроизведение анимированных gif-ов на делфийской форме


1-56561
Lamerr
2003-11-06 12:14
2003.11.17
WordApplication





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский