• Welcome to Jose's Read Only Forum 2023.
 

QHTM Headers

Started by José Roca, May 01, 2009, 04:47:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
QHTM, by GypsySoft, is a Windows HTML control that allows to place HTML content on any window, any device context, on a report, on a button or even in a tooltip.

QHTM is written entirely in C++ and does not rely on MFC, nor does it need IE installed. Instead QHTM uses direct Win32 API calls which makes it very fast and very light.

There is a free version can be used in freeware but not in commercial software.

GypsySoft Web Site: http://www.gipsysoft.com/

The attached file includes my translation of the C++ header to PowerBASIC, posted here with permission of Russ Freeman, the author of QHTM.

This is minimal SDK example that creates an instance of the QHTM control, loads an HTML page and processes the noficiations sent by the control.


' ========================================================================================
' QHTM example
' José Roca, May 2009.
' Adapted from the PowerBASIC DDT example by Peter Scheutz.
' ========================================================================================

' SED_PBWIN
#COMPILE EXE
#DIM ALL
#INCLUDE "QHTM.INC"

%IDC_QHTM = 101

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

   LOCAL hr AS LONG
   LOCAL hwndMain AS DWORD
   LOCAL hCtl 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
   LOCAL lResult AS LONG

   ' // REQUIRED: Initialize QHTM
   lResult = QHTM_Initialize(hInstance)
   IF lResult = 0 THEN
      MSGBOX "Failed to initialize QHTM"
      EXIT FUNCTION
   END IF

   ' // Default font
   hFont = GetStockObject(%DEFAULT_GUI_FONT)

   ' // Register the window class
   szClassName        = "MyClassName"
   wcex.cbSize        = SIZEOF(wcex)
   wcex.style         = %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 = "QHTM Test"

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

   ' // Calculate the position and nSize of the window
   nWidth  = (((rc.nRight - rc.nLeft)) + 2) * 0.60   ' 60% of the client screen width
   nHeight = (((rc.nBottom - rc.nTop)) + 2) * 0.60   ' 60% 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 nSize
                             nHeight, _                        ' initial y nSize
                             %NULL, _                          ' parent window handle
                             0, _                              ' window menu handle
                             hInstance, _                      ' program instance handle
                             BYVAL %NULL)                      ' creation parameters

   ' // Create an instance of QHTM
   hCtl = CreateWindowEx(0, $QHTM_CLASSNAME, "", %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_FLAT, _
          0, 0, 0, 0, hWndMain, %IDC_QHTM, hInstance, BYVAL %NULL)
   IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0
   ' // Load the HTML file (change path if needed)
   QHTM_LoadFromFile hCtl, EXE.Path$ & "QHTM_About.html"

   ' // Show the window
   ShowWindow hwndMain, nCmdShow
   UpdateWindow hwndMain

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

   FUNCTION = uMsg.wParam

   ' // Shutdown QHTM
   lResult = QHTM_Uninitialize
   IF lResult = 0 THEN
      MSGBOX "Failed to uninitialize QHTM"
   END IF

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 rc AS RECT

   SELECT CASE wMsg

      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_COMMAND
         SELECT CASE LOWRD(wParam)
            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hwnd, %WM_CLOSE, 0, 0
                  FUNCTION = 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE %WM_SIZE
         ' // Resize the control
         IF wParam <> %SIZE_MINIMIZED THEN
            GetClientRect hwnd, rc
            MoveWindow GetDlgItem(hwnd, %IDC_QHTM), 10, 10, rc.nRight - rc.nLeft - 20, rc.nBottom - rc.nTop - 20, %TRUE
         END IF

      CASE %WM_NOTIFY
         ' // Process notification messages
         LOCAL pQHTMLink AS NMQHTM PTR
         pQHTMLink = lParam
         ' // If it comes from the QHTM control...
         IF @pQHTMLink.hdr.idFrom = %IDC_QHTM THEN
            ' // If it comes from an hyperlink...
            IF @pQHTMLink.hdr.code = %QHTMN_HYPERLINK THEN
               MSGBOX "You clicked " & @pQHTMLink.@pcszLinkText
               ' // Return False to prevent QHTM default action
               @pQHTMLink.resReturnValue = %FALSE
            END IF
         END IF

      CASE %WM_DESTROY
         PostQuitMessage 0
         EXIT FUNCTION

   END SELECT

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

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