Getting Page Number of PDF document from Adobe Reader's ActiveX control
I'm successfully using Delph 7 and the ActiveX control of Adobe Reader version 7 to extract the page number from an open PDF document housed in the ActiveX component (TAcroPDF). I am interested in upgrading to the latest Adobe reader but something changed in Adobe Reader 8 (and 9) that pr开发者_开发百科evented me from upgrading (I have not tested Adobe 10/X). With Adobe 7, I use the Windows SDK function EnumChildWindows to gather the child windows of my form containing the TAcroPDF component and find a control with the name AVPageNumView, then FindWindowEx to get its handle. Then I call SendMessage to get the text of that control which has the page number information. With Adobe 8 and 9, window/control AVPageNumView is no longer there it seems. Thus I am stuck in Adobe 7 and still looking for a way to get the page number, preferably Adobe 9 or 10/X. The goal would be to not have to do a complete rewrite with another technology, but I am open to that if its the only solution.
Thanks, Michael
You're using a wndclass name (AVPageNumView
). Obviously, the class name has changed in the new version. You can use something like WinDowse to investigate the windows in the newer version of Reader to find out the new class names. Update your code to first check for the old wndclass; if it's not found, try and find the new one.
function EnumWindowProc(pHwnd: THandle; Edit: Integer): LongBool; stdcall;
function GetWindowTxt(gwtHwnd: THandle): string;
var dWTextBuf: PChar;
TextLen: Integer;
begin
TextLen := SendMessage(gwtHwnd, WM_GetTextLength, 0, 0);;
dWTextBuf := StrAlloc(TextLen + 1);
SendMessage(gwtHwnd, WM_GetText, TextLen + 1, Integer(dWTextBuf));
Result := dWTextBuf;
StrDispose(dWTextBuf);
end;
function GetClassNameTxt(gcnHwnd: THandle): string;
var dWClassBuf: PChar;
begin
dWClassBuf := StrAlloc(1024);
GetClassName(gcnHwnd, dWClassBuf, 1024);
Result := dWClassBuf;
StrDispose(dWClassBuf);
end;
begin
Result := LongBool(True);
if (GetClassNameTxt(pHwnd) = 'AVL_AVView') and (GetWindowTxt(pHwnd) = 'AVPageView') then
begin
TEdit(Edit).Text := GetWindowTxt(FindWindowEx(pHwnd, 0, 'RICHEDIT50W', nil));
Result := LongBool(False);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumChildWindows(AcroPDF1.Handle, @EnumWindowProc, LongInt(Edit1));
end;
精彩评论