Author Topic: Ease vs Size  (Read 18687 times)

0 Members and 2 Guests are viewing this topic.

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Ease vs Size
« on: November 25, 2016, 03:52:43 PM »
A study on ease of use versus application size. Generally it takes a lot more typing of source code to produce smaller exe files. Where is the tipping point where you give up smaller exe size and use binary or source code libraries to accomplish the same feat.
I will present a number of examples that produce equivalent Windows applications.
With the release of the Free PowerBasic classic compilers it also gives an opportunity to include these in my study. PowerBASIC has always been marketed as producing very small executables so I chose it and one of it's demos as the base application.

The PowerBASIC DDT dialogs use MS San Serif,8 for their font.
As of Vista MS switched to Segoe UI, 9 for its default font. I use this for all the bc9Basic demos so you will notice a difference in window and control sizes.

I also discovered what I consider a bug in the latest Visual Studio 2015 Community vc++ compiler.
After much discussion and research I have not found a suitable explanation or documentation on the change.
http://forums.codeguru.com/showthread.php?557721-Display-issues
http://www.jose.it-berater.org/smfforum/index.php?topic=5161.0
http://www.objreader.com/index.php?topic=73.0
http://stackoverflow.com/questions/11783086/get-exact-window-region-size-createwindow-window-size-isnt-correct-size-of-wi
http://stackoverflow.com/questions/27928254/adjustwindowrectex-and-getwindowrect-give-wrong-size-with-ws-overlapped

To begin the process I compiled and ran the PBWin9 HelloDDT.bas demo.
While running I fired up PBWinSpy and used it to created SDK source from the running HelloDDT.
I plopped this code into a new PbWin 9 source window, added callback code, named it HelloSDK and compiled it.
I used these SDK coordinates for all the bc9Basic SDK and CW apps.
Last I took the coordinates from HelloDDT and created a resource dialog using KetilO's resource editor:
https://svn.code.sf.net/p/fbedit/code/ResEd22

One thing to note is PowerBASIC 6/10 has dead code removal and an updated CWindow library which decreases the overall exe size.

All the bc9Basic demos are compiled as 64bit c++ unicode applications except Tiny C  and Pelles C.

What follows are the individual sources and the compiled exe sizes.

A composite will be presented at the end of the topic.


James

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #1 on: November 25, 2016, 03:53:59 PM »

This is the original.
PbWin 9 HelloDDT : Exe Size 20,480



'==============================================================================
'
'  HELLODDT.BAS for PowerBASIC for Windows
'  Copyright (c) 1997-2008 PowerBASIC, Inc.
'  All Rights Reserved.
'
'  A simple DDT dialog example.
'
'==============================================================================
' Metastatements
'
#COMPILER PBWIN 9
#COMPILE EXE
#DIM ALL
 '------------------------------------------------------------------------------
' Equates and global variables
'
%IDOK       = 1
%IDCANCEL   = 2
%IDTEXT     = 100
%BS_DEFAULT = 1
GLOBAL UserName AS STRING
'------------------------------------------------------------------------------
' OK button callback
'
CALLBACK FUNCTION OkButton () AS LONG
    IF CB.CTLMSG = %BN_CLICKED THEN
        CONTROL GET TEXT CB.HNDL, %IDTEXT TO UserName
        DIALOG END CB.HNDL, 1
        FUNCTION = 1
    END IF
END FUNCTION
'------------------------------------------------------------------------------
' Cancel button callback
CALLBACK FUNCTION CancelButton () AS LONG

    IF CB.CTLMSG = %BN_CLICKED THEN
        DIALOG END CB.HNDL, 0
        FUNCTION = 1
    END IF
END FUNCTION
'------------------------------------------------------------------------------
' Main application entry point...
FUNCTION PBMAIN() AS LONG
    LOCAL hDlg   AS DWORD
    LOCAL Result AS LONG
    '  Create a new dialog template
    DIALOG NEW 0, "What is your name?",,, 160, 50 TO hDlg
    '----------------------------------------------------------------
    '  Add controls to it
    CONTROL ADD TEXTBOX, hDlg, %IDTEXT, "", 14,  12, 134, 12
    CONTROL ADD BUTTON, hDlg, %IDOK, "OK", 34, 32, 40, 14,%BS_DEFAULT OR %WS_TABSTOP CALL OkButton
    CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 84, 32, 40, 14 CALL CancelButton
    '----------------------------------------------------------------
    '  Display the dialog
    DIALOG SHOW MODAL hDlg TO Result
    '----------------------------------------------------------------
    '  Check the Result at exit
    IF Result THEN
        MSGBOX "Hello " + UserName
    END IF
END FUNCTION



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #2 on: November 25, 2016, 03:55:29 PM »

PowerBASIC PbWin 9 SDK version.
  Exe Size: 25,600


'======================================================================
' Declares
'----------------------------------------------------------------------
#COMPILE EXE
'----------------------------------------------------------------------
#IF %PB_REVISION < &H1000 ' if compiler PBWIN9 or earlier
    %USEMACROS = 1
#ENDIF
#INCLUDE "WIN32API.INC"
'----------------------------------------------------------------------
%IDC_EDIT100       = 100
GLOBAL UserName AS STRING

'======================================================================
FUNCTION WINMAIN (BYVAL hInst AS DWORD, BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpszCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
'----------------------------------------------------------------------
' Program entrance
'----------------------------------------------------------------------
  LOCAL hDlg AS DWORD, hCtl AS DWORD, hEdit As DWORD ,hFont AS DWORD, _
        sBuf AS STRING, wc AS WndClassEx, szClassName AS ASCIIZ * 80

  hFont = GetStockObject(%DEFAULT_GUI_FONT)

  szClassName      = "MyClassName"
  wc.cbSize        = SIZEOF(wc)
  wc.style         = %CS_HREDRAW OR %CS_VREDRAW
  wc.lpfnWndProc   = CODEPTR(WndProc)
  wc.cbClsExtra    = 0
  wc.cbWndExtra    = 0
  wc.hInstance     = hInst
  wc.hIcon         = LoadIcon  (%NULL, BYVAL %IDI_APPLICATION)
  wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
  wc.hbrBackground = %COLOR_3DFACE + 1
  wc.lpszMenuName  = %NULL
  wc.lpszClassName = VARPTR(szClassName)
  wc.hIconSm       = LoadIcon  (%NULL, BYVAL %IDI_APPLICATION)
  CALL RegisterClassEx (wc)

  hDlg = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE, szClassName, "What is your name?", _
              %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION OR _
              %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT OR %DS_MODALFRAME OR _
              %DS_CENTER, _
              (GetSystemMetrics(%SM_CXSCREEN) - 246) / 2, _
              (GetSystemMetrics(%SM_CYSCREEN) - 110) / 2, _
               246, 110, 0, 0, GetModuleHandle(""), BYVAL %NULL)

  hEdit = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", BYVAL %NULL, _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL, _
               21, 20, 201, 19, _
               hDlg, %IDC_EDIT100, GetModuleHandle(""), BYVAL %NULL)

  IF hFont THEN SendMessage hEdit, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "OK", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               51, 52, 60, 23, _
               hDlg, %IDOK, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "Cancel", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               126, 52, 60, 23, _
               hDlg, %IDCANCEL, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  ShowWindow hDlg, nCmdShow
  SetFocus(hEdit)
  UpdateWindow hDlg


  LOCAL Msg AS tagMsg
  WHILE GetMessage(Msg, %NULL, 0, 0)
      IF IsDialogMessage(hDlg,Msg) = 0 Then
          TranslateMessage Msg
          DispatchMessage Msg
      END IF
  WEND
  If msg.wParam Then
      MSGBOX "Hello " + UserName
  End If
  FUNCTION = msg.wParam
END FUNCTION


'======================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD,  BYVAL wMsg AS DWORD, _
                  BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
'----------------------------------------------------------------------
' Main Window procedure
'----------------------------------------------------------------------
  STATIC RetVal AS LONG
  SELECT CASE wMsg
  CASE %WM_CREATE
      'A good place to initiate things, declare variables,
      'create controls and read/set settings from a file, etc.
      '-------------------------------------------------------

  CASE %WM_COMMAND
      'Messages from controls and menu items are handled here.
      '-------------------------------------------------------
      SELECT CASE LOWRD(wParam)
      CASE %IDCANCEL  ' <- Esc key also triggers %IDCANCEL
          IF HIWRD(wParam) = %BN_CLICKED OR HIWRD(wParam) = 1 THEN
              SendMessage hWnd, %WM_DESTROY, wParam, lParam
              RetVal = 0
              FUNCTION = 0 : EXIT FUNCTION
          END IF

      CASE %IDOK      ' <- Enter key usually triggers %IDOK
         IF HIWRD(wParam) = %BN_CLICKED OR HIWRD(wParam) = 1 THEN
           CONTROL GET TEXT hWnd,%IDC_EDIT100 To UserName
           RetVal = 1
           SendMessage hWnd, %WM_DESTROY, wParam, lParam
         END IF
      END SELECT


  CASE %WM_DESTROY
      ' is sent when program ends - a good place to delete any created objects and
      ' store settings in file for next run, etc. Must send PostQuitMessage to end
      ' properly in SDK-style dialogs. The PostQuitMessage function sends a WM_QUIT
      ' message to the program's (thread's) message queue, and then WM_QUIT causes
      ' the GetMessage function to return zero in WINMAIN's message loop.
      '----------------------------------------------------------------------------
      PostQuitMessage RetVal
      FUNCTION = 0 : EXIT FUNCTION


  END SELECT

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



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #3 on: November 25, 2016, 03:57:44 PM »

PowerBASIC PBWin 9 HelloRES using a resource dialog.
  Exe Size: 14,336


#COMPILER PBWIN 9
#COMPILE EXE
#DIM ALL
#INCLUDE "Win32API.inc"
#RESOURCE "HelloRes.pbr"
'==============================================================================
%IDD_DLG1 = 1000
%IDC_TEXT = 1001
%IDC_OK = 1002
%IDC_CANCEL = 1003
'==============================================================================
GLOBAL UserName As ASCIIZ * 255
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG
    DIM RetVal AS LONG
    RetVal = DialogBoxParam(hInstance, BYVAL %IDD_DLG1, 0, CODEPTR(DlgProc), BYVAL 0)
    If RetVal = -1 Then
        MsgBox "ERROR"
        Exit Function
    End If
    If RetVal = 1 Then
        MsgBox "Hello " & UserName
    End If
End Function
'==============================================================================
FUNCTION DlgProc(BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    Select Case uMsg
        Case %WM_COMMAND
            Select Case LO(WORD,wParam)
                Case %IDC_OK
                    GetWindowText(GetDlgItem(hwnd,%IDC_TEXT),UserName,255)
                    EndDialog(hwnd,1)
                Case %IDC_CANCEL
                    EndDialog(hwnd,0)
            End Select       
    End Select
    Function = 0
END FUNCTION



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #4 on: November 25, 2016, 03:59:09 PM »

PowerBASIC PBWin 9 HelloCW which uses an early version of José Roca's CWindow framework.
Exe Size: 66,048


#COMPILE EXE[/color]
#DIM ALL
#INCLUDE ONCE "CWindow.Inc"
#INCLUDE ONCE "WinCtrl.inc"
'==============================================================================
%IDC_OK = 1001
%IDC_CANCEL = 1002
%IDC_TEXT = 1003
'------------------------------------------------------------------------------
GLOBAL UserName As ASCIIZ * 255
'------------------------------------------------------------------------------
Function PbMain()
    Local RetVal As Long
    Local hFont As Long
    Local pWindow As IWindow
    Local dwStyle As DWORD,dwStyleEx As DWORD
      Local hCtl As DWORD
    dwStyle = %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION
    dwStyleEx = %WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE
    pWindow = CLASS "CWindow"
    IF ISNOTHING(pWindow) THEN EXIT FUNCTION
    pWindow.CreateWindow(%NULL,"What's your name?",0,0,246,110,dwStyle,DwStyleEx,CODEPTR(WindowProc))
    dwStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL
    dwStyleEx = %WS_EX_CLIENTEDGE
    hCtl = pWindow.AddControl("Edit",pWindow.hwnd,%IDC_TEXT,"",21,20,201,19,dwStyle,dwStyleEx)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    hCtl = pWindow.AddControl("Button",pWindow.hwnd,%IDC_OK,"OK",51,52,60,23,-1,-1)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    hCtl = pWindow.AddControl("Button",pWindow.hwnd,%IDC_CANCEL,"Cancel",126,52,60,23,-1,-1)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    Window_Center(pWindow.hwnd)
    SetFocus(GetDlgItem(pWindow.hwnd,%IDC_TEXT))
    RetVal = pWindow.DoEvents()
    If RetVal = 1 Then
        MsgBox "Hello " & UserName
    End If
End Function
'==============================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    STATIC Retval As Long
    SELECT CASE uMsg
        CASE %WM_COMMAND
            SELECT CASE LO(WORD, wParam)
                CASE %IDC_CANCEL
                   ' // If the Escape key has been pressed...
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      RetVal = 0
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                   END IF
                CASE %IDC_OK
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      RetVal = 1
                      GetWindowText(GetDlgItem(hwnd,%IDC_TEXT),UserName,255)
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                   END IF
                   
            END SELECT
    CASE %WM_DESTROY
        ' // End the application
        PostQuitMessage Retval
        EXIT FUNCTION
    END SELECT
   
    FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
End Function


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #5 on: November 25, 2016, 04:00:29 PM »

PowerBASIC PBCC 6 HelloJcfDlg using my in memory dialog code to mimic PBWin DDT code.
  Exe Size: 26,112


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloJcfDlg
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#COMPILE EXE
#DIM ALL
#CONSOLE OFF

#INCLUDE "WIN32API.INC"
#INCLUDE "JCFRTDLG.BAS"
'==============================================================================
GLOBAL ghInst         AS LONG
GLOBAL ghDlg          AS LONG
GLOBAL gsDlgTemplate  AS STRING
GLOBAL UserName       As ASCIIZ *255
'==============================================================================
%IDC_OK       = 1001
%IDC_CANCEL   = 1002
%IDC_TEXT     = 1003
'==============================================================================
FUNCTION PBMAIN () AS LONG
  DIM RetVal            AS DWORD, _
      Dlg_Style         AS DWORD, _
      Dlg_ExStyle       AS DWORD, _
      Dlg_HelpId        AS DWORD, _
      Dlg_Left          AS INTEGER, _
      Dlg_Top           AS INTEGER, _
      Dlg_Width         AS INTEGER, _
      Dlg_Height        AS INTEGER, _
      Dlg_Menu          AS STRING, _
      Dlg_Class         AS STRING, _
      Dlg_Caption       AS STRING, _
      Font_PointSize    AS INTEGER, _
      Font_Weight       AS INTEGER, _
      Font_Italic       AS INTEGER, _
      Font_TypeFace     AS STRING

    DIM Ctl_Left      AS INTEGER, _
        Ctl_Top       AS INTEGER, _
        Ctl_Width     AS INTEGER, _
        Ctl_Height    AS INTEGER, _
        Ctl_Id        AS DWORD, _
        Ctl_HelpId    AS DWORD, _
        Ctl_Style     AS DWORD, _
        Ctl_ExStyle   AS DWORD, _
        Ctl_Class     AS STRING, _
        Ctl_Text      AS STRING, _
        Ctl_Extra     AS STRING
    DIM lpDlgProc         AS DWORD
    lpDlgProc = CODEPTR(Dlg_Proc )

    Dlg_Style = %WS_BORDER OR _
                %WS_CAPTION OR _
                %DS_MODALFRAME OR _
                %DS_SETFONT OR _
                %WS_VISIBLE OR _
                %WS_SYSMENU OR _
                %WS_POPUP
    Dlg_ExStyle = 0
    Dlg_HelpId = 0
    Dlg_Left = 0
    Dlg_Top = 0
    Dlg_Width = 160
    Dlg_Height = 50

    Dlg_Menu = ""
    Dlg_Caption = "What's your name?"
    Font_PointSize = 8
    Font_Weight = 400
    Font_Italic = 0
    Font_TypeFace = "MS Sans Serif"

  DlgTemplate_Create gsDlgTemplate, _
                     Dlg_Style, _
                     Dlg_ExStyle, _
                     Dlg_HelpId, _
                     Dlg_Left, _
                     Dlg_Top, _
                     Dlg_Width, _
                     Dlg_Height, _
                     Dlg_Menu, _
                     Dlg_Class, _
                     Dlg_Caption, _
                     Font_PointSize, _
                     Font_Weight, _
                     Font_Italic, _
                     Font_TypeFace
    Ctl_Style = %ES_LEFT OR %WS_CHILD OR %WS_BORDER OR %WS_TABSTOP OR %WS_VISIBLE
    Ctl_Id = %IDC_TEXT
    Ctl_Class = "EDIT"
    Ctl_Left = 14
    Ctl_Top = 12
    Ctl_Width = 134
    Ctl_Height = 12
    GOSUB AddControl

    Ctl_Style = %BS_PUSHBUTTON OR %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP
    Ctl_Class = "BUTTON"
    Ctl_Left = 34
    Ctl_Top = 32
    Ctl_Height = 14
    Ctl_Width = 40
    Ctl_Id = %IDC_OK
    Ctl_Text = "Ok"
    GOSUB AddControl

    Ctl_Left = 84
    Ctl_Id = %IDC_CANCEL
    Ctl_Text = "Cancel"
    GOSUB AddControl

    RetVal = DialogBoxIndirectParam(ghInst, BYVAL STRPTR(gsDlgTemplate), 0, lpDlgProc, 0)
    IF RetVal = -1 THEN
        PRINT "No Go"
        WAITKEY$
    END IF
    If RetVal = 1 Then
        MessageBox(0,"Hello " & UserName,"What's your Name",%MB_OK)
    End If

    EXIT FUNCTION


AddControl:
  DlgTemplate_AddControl gsDlgTemplate, _
                           Ctl_Left, _
                           Ctl_Top, _
                           Ctl_Width, _
                           Ctl_Height, _
                           Ctl_Id, _
                           Ctl_HelpId, _
                           Ctl_Style, _
                           Ctl_ExStyle, _
                           Ctl_Class, _
                           Ctl_Text, _
                           Ctl_Extra
RETURN

END FUNCTION
'==============================================================================
FUNCTION Dlg_Proc(BYVAL hDlg AS DWORD,BYVAL wMsg AS DWORD,BYVAL wParam AS DWORD,BYVAL lParam AS LONG) AS LONG
    SELECT CASE wMsg
        CASE %WM_INITDIALOG
            CenterWindow(hDlg)
        CASE %WM_COMMAND
            SELECT CASE LO(WORD,wParam)
                CASE %IDC_OK
                    GetWindowText(GetDlgItem(hDlg,%IDC_TEXT),UserName,255)
                    EndDialog(hDlg,1)
                CASE %IDC_CANCEL
                    EndDialog(hDlg,2)
            END SELECT
    END SELECT
    FUNCTION = 0
END FUNCTION

'==============================================================================


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #6 on: November 25, 2016, 04:01:23 PM »

PowerBASIC PBCC 6 HelloSDK
  Exe Size: 21,504



#COMPILE EXE[/color]
#DIM ALL
#CONSOLE OFF
%USEMACROS = 1
#INCLUDE "Win32API.inc"
%IDC_OK = 1001
%IDC_CANCEL = 1002
%IDC_TEXT = 1003
GLOBAL UserName As ASCIIZ * 255
'==============================================================================
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG


    LOCAL Msg       AS tagMsg
    LOCAL wce       AS WndClassEx
    LOCAL szAppName AS ASCIIZ * 80
    LOCAL hWnd      AS DWORD,hEdit As DWORD, hCtl As DWORD ,hFont As DWORD
       hFont = GetStockObject(%DEFAULT_GUI_FONT)
    szAppName         = "HelloWin"
    wce.cbSize        = SIZEOF(wce)
    wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
    wce.lpfnWndProc   = CODEPTR(WndProc)
    wce.cbClsExtra    = 0
    wce.cbWndExtra    = 0
    wce.hInstance     = hInstance
    wce.hIcon         = %NULL
    wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
    wce.hbrBackground = %COLOR_BTNFACE + 1
    wce.lpszMenuName  = %NULL
    wce.lpszClassName = VARPTR(szAppName)
    wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)

    RegisterClassEx wce

  hWnd = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE, szAppName, "What is your name?", _
              %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION OR _
              %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT OR %DS_MODALFRAME OR _
              %DS_CENTER, _
              (GetSystemMetrics(%SM_CXSCREEN) - 246) / 2, _
              (GetSystemMetrics(%SM_CYSCREEN) - 110) / 2, _
               246, 110, 0, 0, GetModuleHandle(""), BYVAL %NULL)

  hEdit = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", BYVAL %NULL, _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL, _
               21, 20, 201, 19, _
               hWnd, %IDC_TEXT, GetModuleHandle(""), BYVAL %NULL)

  IF hFont THEN SendMessage hEdit, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "OK", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               51, 52, 60, 23, _
               hWnd, %IDC_OK, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "Cancel", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               126, 52, 60, 23, _
               hWnd, %IDC_CANCEL, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  ShowWindow hWnd, iCmdShow
  SetFocus(hEdit)
  UpdateWindow hWnd



    ' Display the window on the screen
    ShowWindow hWnd, iCmdShow
    UpdateWindow hWnd
    DO WHILE GetMessage(Msg, %NULL, 0, 0)
        If IsDialogMessage(hWnd, Msg) = 0 Then
            TranslateMessage Msg
            DispatchMessage Msg
        End If
    LOOP

    If msg.wParam = 1 Then
        MessageBox(0,"Hello " & UserName,"What's your Name",%MB_OK)
    End If
    Function = 0
END FUNCTION
'==============================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                  BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
    STATIC RetVal AS LONG

  SELECT CASE wMsg

  CASE %WM_COMMAND
      'Messages from controls and menu items are handled here.
      '-------------------------------------------------------
      SELECT CASE LOWRD(wParam)
      CASE %IDC_CANCEL  ' <- Esc key also triggers %IDCANCEL
          IF HIWRD(wParam) = %BN_CLICKED THEN
              RetVal = 0
              SendMessage hWnd, %WM_CLOSE,0,0
              FUNCTION = 0 : EXIT FUNCTION
          END IF

      CASE %IDC_OK      ' <- Enter key usually triggers %IDOK
         IF HIWRD(wParam) = %BN_CLICKED THEN
           'CONTROL GET TEXT hWnd,%IDC_TEXT To UserName
           GetWindowText(GetDlgItem(hWnd,%IDC_TEXT),UserName$,255)
           RetVal = 1
           SendMessage hWnd, %WM_CLOSE, 0,0
             FUNCTION = 0 : EXIT FUNCTION
         END IF
      END SELECT
  CASE %WM_CLOSE
      DestroyWindow(hWnd)
      Function = 0
  CASE %WM_DESTROY
      ' is sent when program ends - a good place to delete any created objects and
      ' store settings in file for next run, etc. Must send PostQuitMessage to end
      ' properly in SDK-style dialogs. The PostQuitMessage function sends a WM_QUIT
      ' message to the program's (thread's) message queue, and then WM_QUIT causes
      ' the GetMessage function to return zero in WINMAIN's message loop.
      '----------------------------------------------------------------------------
      PostQuitMessage RetVal
      FUNCTION = 0 : EXIT FUNCTION


  END SELECT



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


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #7 on: November 25, 2016, 04:02:39 PM »

PowerBASIC PBCC 6 HelloRES using a resource dialog
  Exe Size: 19,968


#COMPILE EXE
#DIM ALL
#CONSOLE OFF
%USEMACROS = 1
#INCLUDE "Win32API.inc"
#RESOURCE RES,"HelloRES.RES"
%IDD_DLG1 = 1000
%IDC_TEXT = 1001
%IDC_OK = 1002
%IDC_CANCEL = 1003
'==============================================================================
GLOBAL UserName As ASCIIZ * 255
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG
    DIM RetVal AS LONG
    UserName = SPACE$(0)
    RetVal = DialogBoxParam(hInstance, BYVAL %IDD_DLG1, 0, CODEPTR(DlgProc), BYVAL 0)
    If RetVal = -1 Then
        MessageBox(0, "ERROR","ERROR",%MB_OK)
        Exit Function
    End If
    If RetVal = 1 Then
        MessageBox(0, "Hello " & UserName,"What's your name?",%MB_OK)
    End If
End Function
'==============================================================================
FUNCTION DlgProc(BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    Select Case uMsg
        Case %WM_COMMAND
            Select Case LO(WORD,wParam)
                Case %IDC_OK
                    GetWindowText(GetDlgItem(hwnd,%IDC_TEXT),UserName,255)
                    EndDialog(hwnd,1)
                Case %IDC_CANCEL
                    EndDialog(hwnd,0)
            End Select       
    End Select
    Function = 0
END FUNCTION



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #8 on: November 25, 2016, 04:03:42 PM »

PowerBASIC PBCC 6 HelloCW using José Roca's CWindow Framework
 Exe Size 36,864


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloCW
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#COMPILE EXE
#DIM ALL
#CONSOLE OFF
#INCLUDE ONCE "CWindow.Inc"
'==============================================================================
%IDC_OK = 1001
%IDC_CANCEL = 1002
%IDC_TEXT = 1003
'------------------------------------------------------------------------------
GLOBAL UserName As ASCIIZ * 255
'------------------------------------------------------------------------------
Function PbMain()
    Local RetVal As Long
    Local hFont As Long
    Local pWindow As IWindow
    Local dwStyle As DWORD,dwStyleEx As DWORD
      Local hCtl As DWORD
    dwStyle = %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION
    dwStyleEx = %WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE
    pWindow = CLASS "CWindow"
    IF ISNOTHING(pWindow) THEN EXIT FUNCTION
    pWindow.CreateWindow(%NULL,"What's your name?",0,0,246,110,dwStyle,dwStyleEx,CODEPTR(WindowProc))
    dwStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL
    dwStyleEx = %WS_EX_CLIENTEDGE
    hCtl = pWindow.AddControl("Edit",pWindow.hwnd,%IDC_TEXT,"",21,20,201,19,dwStyle,dwStyleEx)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    hCtl = pWindow.AddControl("Button",pWindow.hwnd,%IDC_OK,"OK",51,52,60,23,-1,-1)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    hCtl = pWindow.AddControl("Button",pWindow.hwnd,%IDC_CANCEL,"Cancel",126,52,60,23,-1,-1)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    AfxCenterWindow(pWindow.hwnd)
    SetFocus(GetDlgItem(pWindow.hwnd,%IDC_TEXT))
    RetVal = pWindow.DoEvents()
    If RetVal = 1 Then
        MessageBox(0, "Hello " & UserName,"What's your name?",%MB_OK)
    End If
End Function
'==============================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    STATIC Retval As Long
    SELECT CASE uMsg
        CASE %WM_COMMAND
            SELECT CASE LO(WORD, wParam)
                CASE %IDC_CANCEL
                   ' // If the Escape key has been pressed...
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      RetVal = 0
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                   END IF
                CASE %IDC_OK
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      RetVal = 1
                      GetWindowText(GetDlgItem(hwnd,%IDC_TEXT),UserName,255)
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                   END IF
                   
            END SELECT
    CASE %WM_DESTROY
        ' // End the application
        PostQuitMessage Retval
        EXIT FUNCTION
    END SELECT
   
    FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
End Function


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #9 on: November 25, 2016, 04:05:15 PM »

PowerBASIC PbWin 10 HelloDDT:
  Exe Size 48,128


'==============================================================================
'
'  HELLODDT.BAS for PowerBASIC for Windows
'  Copyright (c) 1997-2008 PowerBASIC, Inc.
'  All Rights Reserved.
'
'  A simple DDT dialog example.
'
'==============================================================================
' Metastatements
'
#COMPILER PBWIN 10
#COMPILE EXE
#DIM ALL
 '------------------------------------------------------------------------------
' Equates and global variables
'
%IDOK       = 1
%IDCANCEL   = 2
%IDTEXT     = 100
%BS_DEFAULT = 1
GLOBAL UserName AS STRING
'------------------------------------------------------------------------------
' OK button callback
'
CALLBACK FUNCTION OkButton () AS LONG
    IF CB.CTLMSG = %BN_CLICKED THEN
        CONTROL GET TEXT CB.HNDL, %IDTEXT TO UserName
        DIALOG END CB.HNDL, 1
        FUNCTION = 1
    END IF
END FUNCTION
'------------------------------------------------------------------------------
' Cancel button callback
CALLBACK FUNCTION CancelButton () AS LONG

    IF CB.CTLMSG = %BN_CLICKED THEN
        DIALOG END CB.HNDL, 0
        FUNCTION = 1
    END IF
END FUNCTION
'------------------------------------------------------------------------------
' Main application entry point...
FUNCTION PBMAIN() AS LONG
    LOCAL hDlg   AS DWORD
    LOCAL Result AS LONG
    '  Create a new dialog template
    DIALOG NEW 0, "What is your name?",,, 160, 50 TO hDlg
    '----------------------------------------------------------------
    '  Add controls to it
    CONTROL ADD TEXTBOX, hDlg, %IDTEXT, "", 14,  12, 134, 12
    CONTROL ADD BUTTON, hDlg, %IDOK, "OK", 34, 32, 40, 14,%BS_DEFAULT OR %WS_TABSTOP CALL OkButton
    CONTROL ADD BUTTON, hDlg, %IDCANCEL, "Cancel", 84, 32, 40, 14 CALL CancelButton
    '----------------------------------------------------------------
    '  Display the dialog
    DIALOG SHOW MODAL hDlg TO Result
    '----------------------------------------------------------------
    '  Check the Result at exit
    IF Result THEN
        MSGBOX "Hello " + UserName
    END IF
END FUNCTION



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #10 on: November 25, 2016, 04:06:47 PM »

PowerBASIC PBWin 10 HelloSDK
  Exe Size 20,480



#COMPILE EXE
#DIM ALL
%USEMACROS = 1
#INCLUDE "Win32API.inc"
%IDC_OK = 1001
%IDC_CANCEL = 1002
%IDC_TEXT = 1003
GLOBAL UserName As ASCIIZ * 255
'==============================================================================
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG


    LOCAL Msg       AS tagMsg
    LOCAL wce       AS WndClassEx
    LOCAL szAppName AS ASCIIZ * 80
    LOCAL hWnd      AS DWORD,hEdit As DWORD, hCtl As DWORD ,hFont As DWORD
       hFont = GetStockObject(%DEFAULT_GUI_FONT)
    szAppName         = "HelloWin"
    wce.cbSize        = SIZEOF(wce)
    wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
    wce.lpfnWndProc   = CODEPTR(WndProc)
    wce.cbClsExtra    = 0
    wce.cbWndExtra    = 0
    wce.hInstance     = hInstance
    wce.hIcon         = %NULL
    wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
    wce.hbrBackground = %COLOR_BTNFACE + 1
    wce.lpszMenuName  = %NULL
    wce.lpszClassName = VARPTR(szAppName)
    wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)

    RegisterClassEx wce

  hWnd = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE, szAppName, "What is your name?", _
              %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION OR _
              %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT OR %DS_MODALFRAME OR _
              %DS_CENTER, _
              (GetSystemMetrics(%SM_CXSCREEN) - 246) / 2, _
              (GetSystemMetrics(%SM_CYSCREEN) - 110) / 2, _
               246, 110, 0, 0, GetModuleHandle(""), BYVAL %NULL)

  hEdit = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", BYVAL %NULL, _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL, _
               21, 20, 201, 19, _
               hWnd, %IDC_TEXT, GetModuleHandle(""), BYVAL %NULL)

  IF hFont THEN SendMessage hEdit, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "OK", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               51, 52, 60, 23, _
               hWnd, %IDC_OK, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "Cancel", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               126, 52, 60, 23, _
               hWnd, %IDC_CANCEL, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  ShowWindow hWnd, iCmdShow
  SetFocus(hEdit)
  UpdateWindow hWnd



    ' Display the window on the screen
    ShowWindow hWnd, iCmdShow
    UpdateWindow hWnd
    DO WHILE GetMessage(Msg, %NULL, 0, 0)
        If IsDialogMessage(hWnd, Msg) = 0 Then
            TranslateMessage Msg
            DispatchMessage Msg
        End If
    LOOP

    If msg.wParam = 1 Then
        MessageBox(0,"Hello " & UserName,"What's your Name",%MB_OK)
    End If
    Function = 0
END FUNCTION
'==============================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                  BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
    STATIC RetVal AS LONG

  SELECT CASE wMsg

  CASE %WM_COMMAND
      'Messages from controls and menu items are handled here.
      '-------------------------------------------------------
      SELECT CASE LOWRD(wParam)
      CASE %IDC_CANCEL  ' <- Esc key also triggers %IDCANCEL
          IF HIWRD(wParam) = %BN_CLICKED THEN
              RetVal = 0
              SendMessage hWnd, %WM_CLOSE,0,0
              FUNCTION = 0 : EXIT FUNCTION
          END IF

      CASE %IDC_OK      ' <- Enter key usually triggers %IDOK
         IF HIWRD(wParam) = %BN_CLICKED THEN
           'CONTROL GET TEXT hWnd,%IDC_TEXT To UserName
           GetWindowText(GetDlgItem(hWnd,%IDC_TEXT),UserName$,255)
           RetVal = 1
           SendMessage hWnd, %WM_CLOSE, 0,0
             FUNCTION = 0 : EXIT FUNCTION
         END IF
      END SELECT
  CASE %WM_CLOSE
      DestroyWindow(hWnd)
      Function = 0
  CASE %WM_DESTROY
      ' is sent when program ends - a good place to delete any created objects and
      ' store settings in file for next run, etc. Must send PostQuitMessage to end
      ' properly in SDK-style dialogs. The PostQuitMessage function sends a WM_QUIT
      ' message to the program's (thread's) message queue, and then WM_QUIT causes
      ' the GetMessage function to return zero in WINMAIN's message loop.
      '----------------------------------------------------------------------------
      PostQuitMessage RetVal
      FUNCTION = 0 : EXIT FUNCTION

  END SELECT

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


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #11 on: November 25, 2016, 04:07:38 PM »

PowerBASIC PbWin 10 HelloRES using a resource dialog
  Exe Size 18,944


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloRES
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#COMPILER PBWIN 10
#COMPILE EXE
#DIM ALL
#INCLUDE "Win32API.inc"
#RESOURCE RES "HelloRES.RES"
'==============================================================================
%IDD_DLG1 = 1000
%IDC_TEXT = 1001
%IDC_OK = 1002
%IDC_CANCEL = 1003
'==============================================================================
GLOBAL UserName As ASCIIZ * 255
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG
    DIM RetVal AS LONG
    UserName = SPACE$(0)
    RetVal = DialogBoxParam(hInstance, BYVAL %IDD_DLG1, 0, CODEPTR(DlgProc), BYVAL 0)
    If RetVal = -1 Then
        MsgBox "ERROR"
        Exit Function
    End If
    If RetVal = 1 Then
        MsgBox "Hello " & UserName
    End If
End Function
'==============================================================================
FUNCTION DlgProc(BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    Select Case uMsg
        Case %WM_COMMAND
            Select Case LO(WORD,wParam)
                Case %IDC_OK
                    GetWindowText(GetDlgItem(hwnd,%IDC_TEXT),UserName,255)
                    EndDialog(hwnd,1)
                Case %IDC_CANCEL
                    EndDialog(hwnd,0)
            End Select       
    End Select
    Function = 0
END FUNCTION



Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #12 on: November 25, 2016, 04:08:24 PM »

PowerBASIC PBWin 10 HelloCW using José Roca's CWindow Framework.
  Exe Size: 36,352


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloCW 36,352
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "CWindow.Inc"
'==============================================================================
%IDC_OK = 1001
%IDC_CANCEL = 1002
%IDC_TEXT = 1003
'------------------------------------------------------------------------------
GLOBAL UserName As ASCIIZ * 255
'------------------------------------------------------------------------------
Function PbMain()
    Local RetVal As Long
    Local hFont As Long
    Local pWindow As IWindow
    Local dwStyle As DWORD,dwStyleEx As DWORD
      Local hCtl As DWORD
    dwStyle = %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION
    dwStyleEx = %WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE
    pWindow = CLASS "CWindow"
    IF ISNOTHING(pWindow) THEN EXIT FUNCTION
    pWindow.CreateWindow(%NULL,"What's your name?",0,0,246,110,dwStyle,dwStyleEx,CODEPTR(WindowProc))
    dwStyle = %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL
    dwStyleEx = %WS_EX_CLIENTEDGE
    hCtl = pWindow.AddControl("Edit",pWindow.hwnd,%IDC_TEXT,"",21,20,201,19,dwStyle,dwStyleEx)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    hCtl = pWindow.AddControl("Button",pWindow.hwnd,%IDC_OK,"OK",51,52,60,23,-1,-1)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    hCtl = pWindow.AddControl("Button",pWindow.hwnd,%IDC_CANCEL,"Cancel",126,52,60,23,-1,-1)
    SendMessage hCtl,%WM_SETFONT,pWindow.hFont,0
    AfxCenterWindow(pWindow.hwnd)
    SetFocus(GetDlgItem(pWindow.hwnd,%IDC_TEXT))
    RetVal = pWindow.DoEvents()
    If RetVal = 1 Then
        MsgBox "Hello " & UserName
    End If
End Function
'==============================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
    STATIC Retval As Long
    SELECT CASE uMsg
        CASE %WM_COMMAND
            SELECT CASE LO(WORD, wParam)
                CASE %IDC_CANCEL
                   ' // If the Escape key has been pressed...
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      RetVal = 0
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                   END IF
                CASE %IDC_OK
                   IF HI(WORD, wParam) = %BN_CLICKED THEN
                      ' // ... close the application by sending a WM_CLOSE message
                      RetVal = 1
                      GetWindowText(GetDlgItem(hwnd,%IDC_TEXT),UserName,255)
                      SendMessage hwnd, %WM_CLOSE, 0, 0
                   END IF
                   
            END SELECT
    CASE %WM_DESTROY
        ' // End the application
        PostQuitMessage Retval
        EXIT FUNCTION
    END SELECT
   
    FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
End Function


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #13 on: November 25, 2016, 04:09:24 PM »

PowerBASIC PBCC 6 HelloJcfDlg using my in memory dialog code to mimic PBWin DDT code.
  Exe Size: 26,112


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloJcfDlg
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#COMPILE EXE
#DIM ALL
#CONSOLE OFF

#INCLUDE "WIN32API.INC"
#INCLUDE "JCFRTDLG.BAS"
'==============================================================================
GLOBAL ghInst         AS LONG
GLOBAL ghDlg          AS LONG
GLOBAL gsDlgTemplate  AS STRING
GLOBAL UserName       As ASCIIZ *255
'==============================================================================
%IDC_OK       = 1001
%IDC_CANCEL   = 1002
%IDC_TEXT     = 1003
'==============================================================================
FUNCTION PBMAIN () AS LONG
  DIM RetVal            AS DWORD, _
      Dlg_Style         AS DWORD, _
      Dlg_ExStyle       AS DWORD, _
      Dlg_HelpId        AS DWORD, _
      Dlg_Left          AS INTEGER, _
      Dlg_Top           AS INTEGER, _
      Dlg_Width         AS INTEGER, _
      Dlg_Height        AS INTEGER, _
      Dlg_Menu          AS STRING, _
      Dlg_Class         AS STRING, _
      Dlg_Caption       AS STRING, _
      Font_PointSize    AS INTEGER, _
      Font_Weight       AS INTEGER, _
      Font_Italic       AS INTEGER, _
      Font_TypeFace     AS STRING

    DIM Ctl_Left      AS INTEGER, _
        Ctl_Top       AS INTEGER, _
        Ctl_Width     AS INTEGER, _
        Ctl_Height    AS INTEGER, _
        Ctl_Id        AS DWORD, _
        Ctl_HelpId    AS DWORD, _
        Ctl_Style     AS DWORD, _
        Ctl_ExStyle   AS DWORD, _
        Ctl_Class     AS STRING, _
        Ctl_Text      AS STRING, _
        Ctl_Extra     AS STRING
    DIM lpDlgProc         AS DWORD
    lpDlgProc = CODEPTR(Dlg_Proc )

    Dlg_Style = %WS_BORDER OR _
                %WS_CAPTION OR _
                %DS_MODALFRAME OR _
                %DS_SETFONT OR _
                %WS_VISIBLE OR _
                %WS_SYSMENU OR _
                %WS_POPUP
    Dlg_ExStyle = 0
    Dlg_HelpId = 0
    Dlg_Left = 0
    Dlg_Top = 0
    Dlg_Width = 160
    Dlg_Height = 50

    Dlg_Menu = ""
    Dlg_Caption = "What's your name?"
    Font_PointSize = 8
    Font_Weight = 400
    Font_Italic = 0
    Font_TypeFace = "MS Sans Serif"

  DlgTemplate_Create gsDlgTemplate, _
                     Dlg_Style, _
                     Dlg_ExStyle, _
                     Dlg_HelpId, _
                     Dlg_Left, _
                     Dlg_Top, _
                     Dlg_Width, _
                     Dlg_Height, _
                     Dlg_Menu, _
                     Dlg_Class, _
                     Dlg_Caption, _
                     Font_PointSize, _
                     Font_Weight, _
                     Font_Italic, _
                     Font_TypeFace
    Ctl_Style = %ES_LEFT OR %WS_CHILD OR %WS_BORDER OR %WS_TABSTOP OR %WS_VISIBLE
    Ctl_Id = %IDC_TEXT
    Ctl_Class = "EDIT"
    Ctl_Left = 14
    Ctl_Top = 12
    Ctl_Width = 134
    Ctl_Height = 12
    GOSUB AddControl

    Ctl_Style = %BS_PUSHBUTTON OR %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP
    Ctl_Class = "BUTTON"
    Ctl_Left = 34
    Ctl_Top = 32
    Ctl_Height = 14
    Ctl_Width = 40
    Ctl_Id = %IDC_OK
    Ctl_Text = "Ok"
    GOSUB AddControl

    Ctl_Left = 84
    Ctl_Id = %IDC_CANCEL
    Ctl_Text = "Cancel"
    GOSUB AddControl

    RetVal = DialogBoxIndirectParam(ghInst, BYVAL STRPTR(gsDlgTemplate), 0, lpDlgProc, 0)
    IF RetVal = -1 THEN
        PRINT "No Go"
        WAITKEY$
    END IF
    If RetVal = 1 Then
        MessageBox(0,"Hello " & UserName,"What's your Name",%MB_OK)
    End If

    EXIT FUNCTION


AddControl:
  DlgTemplate_AddControl gsDlgTemplate, _
                           Ctl_Left, _
                           Ctl_Top, _
                           Ctl_Width, _
                           Ctl_Height, _
                           Ctl_Id, _
                           Ctl_HelpId, _
                           Ctl_Style, _
                           Ctl_ExStyle, _
                           Ctl_Class, _
                           Ctl_Text, _
                           Ctl_Extra
RETURN

END FUNCTION
'==============================================================================
FUNCTION Dlg_Proc(BYVAL hDlg AS DWORD,BYVAL wMsg AS DWORD,BYVAL wParam AS DWORD,BYVAL lParam AS LONG) AS LONG
    SELECT CASE wMsg
        CASE %WM_INITDIALOG
            CenterWindow(hDlg)
        CASE %WM_COMMAND
            SELECT CASE LO(WORD,wParam)
                CASE %IDC_OK
                    GetWindowText(GetDlgItem(hDlg,%IDC_TEXT),UserName,255)
                    EndDialog(hDlg,1)
                CASE %IDC_CANCEL
                    EndDialog(hDlg,2)
            END SELECT
    END SELECT
    FUNCTION = 0
END FUNCTION

'==============================================================================


Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: Ease vs Size
« Reply #14 on: November 25, 2016, 04:10:46 PM »

PowerBASIC PBCC 6 HelloSDK
  Exe Size: 21,504



#COMPILE EXE
#DIM ALL
#CONSOLE OFF
%USEMACROS = 1
#INCLUDE "Win32API.inc"
%IDC_OK = 1001
%IDC_CANCEL = 1002
%IDC_TEXT = 1003
GLOBAL UserName As ASCIIZ * 255
'==============================================================================
FUNCTION WINMAIN (BYVAL hInstance     AS DWORD, _
                  BYVAL hPrevInstance AS DWORD, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG


    LOCAL Msg       AS tagMsg
    LOCAL wce       AS WndClassEx
    LOCAL szAppName AS ASCIIZ * 80
    LOCAL hWnd      AS DWORD,hEdit As DWORD, hCtl As DWORD ,hFont As DWORD
       hFont = GetStockObject(%DEFAULT_GUI_FONT)
    szAppName         = "HelloWin"
    wce.cbSize        = SIZEOF(wce)
    wce.STYLE         = %CS_HREDRAW OR %CS_VREDRAW
    wce.lpfnWndProc   = CODEPTR(WndProc)
    wce.cbClsExtra    = 0
    wce.cbWndExtra    = 0
    wce.hInstance     = hInstance
    wce.hIcon         = %NULL
    wce.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
    wce.hbrBackground = %COLOR_BTNFACE + 1
    wce.lpszMenuName  = %NULL
    wce.lpszClassName = VARPTR(szAppName)
    wce.hIconSm       = LoadIcon(hInstance, BYVAL %IDI_APPLICATION)

    RegisterClassEx wce

  hWnd = CreateWindowEx(%WS_EX_DLGMODALFRAME OR %WS_EX_CONTROLPARENT OR %WS_EX_WINDOWEDGE, szAppName, "What is your name?", _
              %WS_POPUP OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CAPTION OR _
              %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT OR %DS_MODALFRAME OR _
              %DS_CENTER, _
              (GetSystemMetrics(%SM_CXSCREEN) - 246) / 2, _
              (GetSystemMetrics(%SM_CYSCREEN) - 110) / 2, _
               246, 110, 0, 0, GetModuleHandle(""), BYVAL %NULL)

  hEdit = CreateWindowEx(%WS_EX_CLIENTEDGE, "Edit", BYVAL %NULL, _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_AUTOHSCROLL, _
               21, 20, 201, 19, _
               hWnd, %IDC_TEXT, GetModuleHandle(""), BYVAL %NULL)

  IF hFont THEN SendMessage hEdit, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "OK", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               51, 52, 60, 23, _
               hWnd, %IDC_OK, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  hCtl = CreateWindowEx(0, "Button", "Cancel", _
              %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP, _
               126, 52, 60, 23, _
               hWnd, %IDC_CANCEL, GetModuleHandle(""), BYVAL %NULL)
  IF hFont THEN SendMessage hCtl, %WM_SETFONT, hFont, 0

  ShowWindow hWnd, iCmdShow
  SetFocus(hEdit)
  UpdateWindow hWnd



    ' Display the window on the screen
    ShowWindow hWnd, iCmdShow
    UpdateWindow hWnd
    DO WHILE GetMessage(Msg, %NULL, 0, 0)
        If IsDialogMessage(hWnd, Msg) = 0 Then
            TranslateMessage Msg
            DispatchMessage Msg
        End If
    LOOP

    If msg.wParam = 1 Then
        MessageBox(0,"Hello " & UserName,"What's your Name",%MB_OK)
    End If
    Function = 0
END FUNCTION
'==============================================================================
FUNCTION WndProc (BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, _
                  BYVAL wParam AS DWORD, BYVAL lParam AS LONG) EXPORT AS LONG
    STATIC RetVal AS LONG

  SELECT CASE wMsg

  CASE %WM_COMMAND
      'Messages from controls and menu items are handled here.
      '-------------------------------------------------------
      SELECT CASE LOWRD(wParam)
      CASE %IDC_CANCEL  ' <- Esc key also triggers %IDCANCEL
          IF HIWRD(wParam) = %BN_CLICKED THEN
              RetVal = 0
              SendMessage hWnd, %WM_CLOSE,0,0
              FUNCTION = 0 : EXIT FUNCTION
          END IF

      CASE %IDC_OK      ' <- Enter key usually triggers %IDOK
         IF HIWRD(wParam) = %BN_CLICKED THEN
           'CONTROL GET TEXT hWnd,%IDC_TEXT To UserName
           GetWindowText(GetDlgItem(hWnd,%IDC_TEXT),UserName$,255)
           RetVal = 1
           SendMessage hWnd, %WM_CLOSE, 0,0
             FUNCTION = 0 : EXIT FUNCTION
         END IF
      END SELECT
  CASE %WM_CLOSE
      DestroyWindow(hWnd)
      Function = 0
  CASE %WM_DESTROY
      ' is sent when program ends - a good place to delete any created objects and
      ' store settings in file for next run, etc. Must send PostQuitMessage to end
      ' properly in SDK-style dialogs. The PostQuitMessage function sends a WM_QUIT
      ' message to the program's (thread's) message queue, and then WM_QUIT causes
      ' the GetMessage function to return zero in WINMAIN's message loop.
      '----------------------------------------------------------------------------
      PostQuitMessage RetVal
      FUNCTION = 0 : EXIT FUNCTION

  END SELECT

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