Author Topic: PowerBASIC Barebone version  (Read 293 times)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1821
    • zapsolution
PowerBASIC Barebone version
« on: March 21, 2021, 02:27:06 pm »
This is a simplified version of CanaryBay, without bells and whistles.

The purpose of this code is to help you understand what is going on...

The CanaryBay project is a compound application mixing the core WV2B binary EXE (written in C++) within a host application that could be written with any programming language.

Compound application is using interprocess to communicate together via a specific registered message:
gP.WM_BROWSER = RegisterWindowMessage("WM_BROWSER") '// Send/Get messages to/from the Browser

The inital parameters are shared using a config file (szConfig) to setup the WV2B behavior when firing the browser.
Code: [Select]
    dwExStyle as dword
    dwStyle as dword
    hParent as dword
    x as long
    y as long
    w as long
    h as long
    onTABclose as WSTRING * %MAX_PATH
    defaultURL as WSTRING * %MAX_PATH
end type
The names of the SETBIN structure are self explanatory, and are used to setup the CreateWindowEx of the main Browser window.

Use of region SetBrowserRegion
creates a hole region within the host window to display WV2B runing like a child process.

The host application can listen WV2B messages from the ProcessBrowserMessage subroutine.
For now WM_NCDESTROY is sent when the last Browser TAB is closing.

Firing the browser is done with buttons using the WM_COMMAND message from the standard Wndproc
Code: [Select]
    case %WM_COMMAND:
         local wP as long
         wP = LOINT(wParam)
         select case long wP
         case %IDC_BTN1
              function = 0: exit function
         case %IDC_BTN2
              function = 0: exit function
         case %IDC_EXIT
              if gP.hBrowser then SendMessage(gP.hBrowser, %WM_CLOSE, 0, 0)
              function = 0: exit function
         end select
StartBrowser being the master API to fire WV2B.

The "PowerBASIC" button is firing a standard website.
The "D3D video" button is firing a video, just to show you that WV2B itself being a "Direct 3D" application, is using the latest web technology.
The "Exit" button is meant to shut down the whole compound application.

The main window of the host application is a bare one, using only
This means no caption, no border, nothing related to the NonClient_AREA, thus freeing us of the Windows default interactions.
However the standard behavior of a caption bar is emulated to move the window around, and changing the caption color to figure the gain or lost of focus.

About the coding style:
It is using the core SDK syntax API, that is the only way to write portable code, because the core API is the common denominator understood by all Windows languages.

If you appreciate this code, please consider to make a donation to support my work.


(BTW, this is a custom 3D model running in my ObjReader 3D engine, and available in the "car" collection for free)

If you have questions about this code, feel free to post them here.
« Last Edit: March 21, 2021, 03:18:14 pm by Patrice Terrier »
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1821
    • zapsolution
Re: PowerBASIC Barebone version
« Reply #1 on: March 22, 2021, 03:04:32 pm »
I did a mistake while cleaning the code, the part shown in red below must be kept

sub StartBrowser(sURL as string)
    '// if the Browser is already running, then shut it down in order to create a brand new page
    if (IsWindow(gP.hBrowser)) then
        SendMessage(gP.hBrowser, %WM_CLOSE, 0, 0)
        gP.hBrowser = 0
    end if

    local fname as string: fname = "WV2B"
    local szConfig as asciiz * %MAX_PATH: szConfig = fTempPath() + fname + ".bin"

    '// Customize the Browser size
    local cfg as SETBIN, x, y, w, h as long
    BrowserLocation(x, y, w, h)

    cfg.dwExStyle = %WS_EX_TOOLWINDOW '// Don't show the Browser icon on the taskbar
    cfg.dwStyle = %WS_POPUP or %WS_VISIBLE
    cfg.hParent = gP.hMain
    cfg.x = x
    cfg.y = y
    cfg.w = w
    cfg.h = h
    cfg.onTABclose = ""
    cfg.defaultURL = ""
    '// Create the config file
    local fHandle as long
    fHandle = CreateFile(szConfig, %GENERIC_WRITE, 0, byval %NULL, %CREATE_ALWAYS, %FILE_ATTRIBUTE_NORMAL, byval %NULL)
    if (fHandle <> -1) then
        local BytesWritten as long
        WriteFile(fHandle, byval varptr(cfg), sizeof(cfg), BytesWritten, byval %NULL)
    end if

    '// Fire the Browser
    local hWnd as dword
    hWnd = CreateBrowserProcess(ExePath() + fname + ".exe", sURL)

    if (hWnd) then ' 03-22/2021 this code was put in REM in Barebone, that is an error it should be kept.
        local hCtrl as dword
        hCtrl = GetDlgItem(gP.hMain, %IDC_BROWER_CONTAINER)
        if (IsWindowVisible(hCtrl)) then ShowWindow(hCtrl, %SW_HIDE)
        gP.hBrowser = hWnd
    end if

end sub

I have also added a new ProcessBrowserMessage, to display the name of the URL entered by the user in the navigate field.

'// This is the place to handle the messages sent by the browser (search for gP.WM_BROWSER in WndProc)
sub ProcessBrowserMessage(byval wParam as dword, byval lParam as long)
    if wParam = %WM_NCDESTROY then '// Last Browser TAB is closing
        if gP.hRgn then
            DeleteObject(gP.hRgn): gP.hRgn = 0
            SetWindowRgn(gP.hMain, gP.hRgn, %False)
'            if (IsWindowVisible(GetDlgItem(gP.hMain, %IDC_UNDOCK))) then
'                local r as rect, p as POINT
'                GetWindowRect(GetDlgItem(gP.hMain, %IDC_BROWER_CONTAINER), r)
'                p.x = r.nLeft: p.y = r.nTop: ScreenToClient(gP.hMain, p)
'                MoveWindow(GetDlgItem(gP.hMain, %IDC_BROWER_CONTAINER), p.x, p.y + gP.dock_offset, rWidth(r), rHeight(r) - gP.dock_offset, %TRUE)
'            end if
            ShowWindow(GetDlgItem(gP.hMain, %IDC_BROWER_CONTAINER), %SW_SHOW)
'            ShowWindow(GetDlgItem(gP.hMain, %IDC_UNDOCK), %SW_HIDE)
'            ShowWindow(GetDlgItem(gP.hMain, %IDC_DOCK), %SW_HIDE)


        end if
    elseif wParam = %WM_SETTEXT then
        local szText AS ASCIIZ * %MAX_PATH
        local Length AS LONG
        Length = GetWindowText(GetDlgItem(gP.hMain, %IDC_BROWER_CONTAINER), szText, SIZEOF(szText))
        if Length then zTrace(szText)
    end if

end sub

« Last Edit: March 22, 2021, 07:23:11 pm by Patrice Terrier »
(Always working with the latest Windows version available...)