My headers provide a framework that can be used both by PBWIN and PBCC users to build GUI and Graphic applications.
The following example, compilable with PBCC 6+ embeds an instance of the WebBrowser control. #CONSOLE OFF has been used to disable the console.
Code:
#COMPILE EXE #CONSOLE OFF #DIM ALL %UNICODE = 1 ' // Include files for external files %USEWEBBROWSER = 1 ' // Use the WebBrowser control #INCLUDE ONCE "CWindow.inc" ' // CWindow class ' // Identifier %IDC_WEBBROWSER = 101 ' ######################################################################################## ' Main ' ######################################################################################## FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG ' // Set process DPI aware IF AfxGetWindowsVersion => 6 THEN SetProcessDPIAware ' // Create an instance of the class LOCAL pWindow AS IWindow pWindow = CLASS "CWindow" IF ISNOTHING(pWindow) THEN EXIT FUNCTION ' // Create the main window pWindow.CreateWindow(%NULL, "AddWebBrowser Template", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc)) ' // Set the client siz pWindow.SetClientSize 600, 350 ' // Center the window pWindow.CenterWindow ' // Add a WebBrowser control LOCAL hCtl AS DWORD LOCAL bstrURL AS WSTRING ' // You can pass a URL bstrURL = "http://www.jose.it-berater.org/smfforum/index.php" ' // or a path to an Active document file (Excel, Word or PDF) ' bstrURL = EXE.Path$ & "Test.xls" ' <-- change me! ' bstrURL = EXE.Path$ & "JetSQL.doc" ' <-- change me! ' bstrURL = EXE.Path$ & "COMCollections.pdf" ' <-- change me! ' // or a fragment of HTML code (remember to always start with "MSHTML:") ' bstrURL = "MSHTML:<HTML><BODY>This is a line of text</BODY></HTML>" ' // or a web page (remember to always start with "MSHTML:") ' LOCAL s AS WSTRING ' LOCAL bstrName AS WSTRING ' S = "MSHTML:<?xml version=""1.0""?>" ' s += "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">" & $CRLF ' s += "<html xmlns=""http://www.w3.org/1999/xhtml"">" & $CRLF ' s += "<head>" & $CRLF ' s += "<title>Image Test</title>" & $CRLF ' s += "</head>" & $CRLF ' s += "<body scroll=" & $DQ & "auto" & $DQ & " style=" & $DQ & "MARGIN: 0px 0px 0px 0px" & $DQ & " >" & $CRLF ' bstrName = EXE.Path$ & "Ciutat_de_les_Arts_i_de_les_Ciencies_02.jpg" ' s += "<img src=" & $DQ & bstrName & $DQ & " alt=" & $DQ & bstrName & $DQ & " title=" & $DQ & bstrName & $DQ & " " ' s += "/>" & $CRLF ' s += "</body>" & $CRLF ' s += "</html>" & $CRLF ' bstrURL = s ' // Create the control hCtl = pWindow.AddWebBrowserControl(pWindow.hwnd, %IDC_WEBBROWSER, bstrURL, NOTHING, 0, 0, pWindow.ClientWidth, pWindow.ClientHeight) ' // Default message pump (you can replace it with your own) pWindow.DoEvents(nCmdShow) END FUNCTION ' ######################################################################################## ' ======================================================================================== ' Main callback function. ' ======================================================================================== FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG STATIC hInstance AS DWORD ' // Instance handle STATIC lpc AS CREATESTRUCT PTR ' // Pointer to the creation parameters STATIC pWindow AS IWindow ' // Reference to the IWindow interface SELECT CASE uMsg CASE %WM_CREATE ' // Pointer to the creation parameters lpc = lParam ' // Instance handle hInstance = @lpc.hInstance ' // Get a reference to the IWindow interface from the CREATESTRUCT structure pWindow = CWindow_GetObjectFromCreateStruct(lParam) EXIT FUNCTION CASE %WM_SYSCOMMAND ' // Capture this message and send a WM_CLOSE message ' // Note: Needed with some OCXs, that otherwise remain in memory IF (wParam AND &HFFF0) = %SC_CLOSE THEN SendMessage hwnd, %WM_CLOSE, 0, 0 EXIT FUNCTION END IF CASE %WM_COMMAND SELECT CASE LO(WORD, wParam) CASE %IDCANCEL ' // If the Escape key has been pressed... IF HI(WORD, wParam) = %BN_CLICKED THEN ' // ... close the application by sending a WM_CLOSE message SendMessage hwnd, %WM_CLOSE, 0, 0 EXIT FUNCTION END IF END SELECT CASE %WM_SIZE IF wParam <> %SIZE_MINIMIZED THEN ' // Resize the control pWindow.MoveWindow GetDlgItem(hwnd, %IDC_WEBBROWSER), 0, 0, pWindow.ClientWidth, pWindow.ClientHeight, %TRUE END IF CASE %WM_DESTROY ' // End the application PostQuitMessage 0 EXIT FUNCTION END SELECT ' // Pass unprocessed messages to Windows FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam) END FUNCTION ' ========================================================================================
Leave a comment: