• Welcome to Theos PowerBasic Museum 2017.

PROBLEM HOSTING PDF DOC

Started by Emanuele Colombo, June 25, 2013, 05:11:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Emanuele Colombo

I used this code (from this forum, thanks) for a long time, and it's always worked properly.
I realized that it is still working perfectly on my old XP32, but it does not work on WIN7-SP1-64
(at the moment, I can not try on a WIN7-32 machine).
Instead of the PDFdocument, when I launch the program I see a Dialog without text message
and a OK button, like shown by the ouput.jpg attached.
May be some incompatibility between PB10 and 64 bits systems?
You can find joint a zip file with document, code and exe.
I wrote this problem in powerbasic forum with no luck.

Added:
Some time, the code seems to work. I mean, the first time I lunch the exe or
re-compile the code,  all seems to work. I close the compiler, or the application,
and the next time nothing is working more, with the ouput in attached jpg.
Also I tried with a 32 bits machine, with same result.
Where can be the matter?
Thanks in advance to everybody can help.


' ########################################################################################
' WebBrowser example - Hosting a PDF document
' ########################################################################################

' SED_PBWIN - Use the PBWIN compiler
#COMPILE EXE   "Test.exe"
#DIM ALL
#INCLUDE "OLECON.INC"     ' // Ole Container
#INCLUDE "EXDISP.INC"     ' // WebBrowser Control
#INCLUDE "MSHTML.INC"     ' // MSHTML

%IDC_IEWB = 101

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG

   LOCAL hWndMain    AS DWORD
   LOCAL hFont       AS DWORD
   LOCAL wcex        AS WNDCLASSEX
   LOCAL szClassName AS ASCIIZ * 80
   LOCAL rc          AS RECT
   LOCAL szCaption   AS ASCIIZ * 255
   LOCAL nLeft       AS LONG
   LOCAL nTop        AS LONG
   LOCAL nWidth      AS LONG
   LOCAL nHeight     AS LONG

   OC_WinInit  ' Initialize the Ole Container

   hFont = GetStockObject(%ANSI_VAR_FONT)

   ' Register the window class
   szClassName        = "WebBrowser"
   wcex.cbSize        = SIZEOF(wcex)
   wcex.style         = 0 '%CS_HREDRAW OR %CS_VREDRAW
   wcex.lpfnWndProc   = CODEPTR(WndProc)
   wcex.cbClsExtra    = 0
   wcex.cbWndExtra    = 0
   wcex.hInstance     = hInstance
   wcex.hCursor       = LoadCursor (%NULL, BYVAL %IDC_ARROW)
   wcex.hbrBackground = %COLOR_3DFACE + 1
   wcex.lpszMenuName  = %NULL
   wcex.lpszClassName = VARPTR(szClassName)
   wcex.hIcon         = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Sample, if resource icon: LoadIcon(hInst, "APPICON")
   wcex.hIconSm       = LoadIcon (%NULL, BYVAL %IDI_APPLICATION) ' Remember to set small icon too..
   RegisterClassEx wcex

   ' Window caption
   szCaption = "WebBrowser Demo: Embedding Acrobat Reader"

   ' Retrieve the size of the working area
   SystemParametersInfo %SPI_GETWORKAREA, 0, BYVAL VARPTR(rc), 0

   ' Calculate the position and size of the window
   nWidth  = (((rc.nRight - rc.nLeft)) + 2) * 0.75   ' 75% of the client screen width
   nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.70   ' 70% of the client screen height
   nLeft   = ((rc.nRight - rc.nLeft) \ 2) - nWidth \ 2
   nTop    = ((rc.nBottom - rc.nTop) \ 2) - (nHeight \ 2)

   ' Create a window using the registered class
   hWndMain = CreateWindowEx(%WS_EX_CONTROLPARENT, _           ' extended style
                             szClassName, _                    ' window class name
                             szCaption, _                      ' window caption
                             %WS_OVERLAPPEDWINDOW OR _
                             %WS_CLIPCHILDREN, _               ' window style
                             nLeft, _                          ' initial x position
                             nTop, _                           ' initial y position
                             nWidth, _                         ' initial x size
                             nHeight, _                        ' initial y size
                             %NULL, _                          ' parent window handle
                             0, _                              ' window menu handle
                             hInstance, _                      ' program instance handle
                             BYVAL %NULL)                      ' creation parameters

   ' Show the window
   ShowWindow hWndMain, nCmdShow
   UpdateWindow hWndMain

   ' Message handler loop
   LOCAL uMsg AS tagMsg
   WHILE GetMessage(uMsg, %NULL, 0, 0)
      IF ISFALSE OC_ForwardMessage(GetFocus, uMsg) THEN
         IF ISFALSE IsDialogMessage(hWndMain, uMsg) THEN
            TranslateMessage uMsg
            DispatchMessage uMsg
         END IF
      END IF
   WEND

   FUNCTION = uMsg.wParam

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG

   LOCAL hr            AS LONG
   LOCAL hCtl          AS DWORD
   LOCAL rc            AS RECT
   LOCAL vUrl          AS VARIANT
   LOCAL pIWebBrowser2 AS IWebBrowser2

   SELECT CASE wMsg

      CASE %WM_CREATE
         ' Get the coordinates of the main window client area
         GetClientRect hWnd, rc
         ' Create an instance of the WebBrowser Control using ATL as the OLE container
         hCtl = CreateWindowEx(0, $OC_CLASSNAME, "Shell.Explorer", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_BORDER, _
                0, 0, 0, 0, hWnd, %IDC_IEWB, GetModuleHandle(""), BYVAL %NULL)

         ' Set the focus in the WebBrowser Control
         SetFocus hCtl
         ' Get a pointer to the IWebBrowser2 interface
         pIWebBrowser2 = OC_GetDispatch(GetDlgItem(hWnd, %IDC_IEWB))
         IF ISOBJECT(pIWebBrowser2) THEN
            ' Load the PDF document
            vUrl = EXE.PATH$ & "Test.pdf"
            pIWebBrowser2.Navigate2(vUrl)
            ' Release the interface
            pIWebBrowser2 = NOTHING
         END IF

      CASE %WM_SIZE
         ' Resizes the control
         IF wParam <> %SIZE_MINIMIZED THEN
            GetClientRect hWnd, rc
            MoveWindow GetDlgItem(hWnd, %IDC_IEWB), 0, 0, rc.nRight - rc.nLeft - 0, rc.nBottom - rc.nTop - 0, %TRUE
         END IF

      CASE %WM_COMMAND
         SELECT CASE LO(WORD, wParam)
            CASE %IDCANCEL
               IF HI(WORD, wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE %WM_SYSCOMMAND
         ' Capture this message and send a WM_CLOSE message
         IF (wParam AND &HFFF0) = %SC_CLOSE THEN
            SendMessage hWnd, %WM_CLOSE, 0, 0
            EXIT FUNCTION
         END IF

      CASE %WM_DESTROY
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam)

END FUNCTION   
[\code]

José Roca

Works fine in my computer with Windows 7 64 bit.