• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Ease vs Size

Started by James C. Fuller, November 25, 2016, 03:52:43 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

James C. Fuller


bc9Basic HelloSDK using the NUWEN g++ distro.
  Exe size:22,528


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloSDK
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER.TXT"
$ONEXIT "NUWENGPP.BAT $FILE$ -m64 gui -municode"
'==============================================================================
$HEADER
    #include <windows.h>
    #include <tchar.h>
$HEADER

CONST    IDC_OK = 1001
CONST    IDC_CANCEL = 1002
CONST    IDC_TEXT = 1003

Dim UserName$
Function WinMain()
    Local As WNDCLASSEX wcx
    Local As MSG uMsg
    Local As HWND hWin,hText,hOk,hCancel
    Local As DWORD dwStyle,dwStyleEx
    Local As HFONT hFont
    Local As LOGFONT lf
    Dim As NONCLIENTMETRICS ncm
    Local As HDC hDc
    ncm.cbSize = sizeof(ncm)
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)
    hFont = CreateFontIndirect(&(ncm.lfMessageFont))

    Raw As char szClassName[]     =  "MyClassName"
    With wcx
        .cbSize        =  SIZEOF(wcx)
        .style         =  CS_HREDRAW | CS_VREDRAW
        .lpfnWndProc   =  WndProc
        .cbClsExtra    =  0
        .cbWndExtra    =  0
        .hInstance     =  hInst
        .hIcon         =  LoadIcon  (NULL, IDI_APPLICATION)
        .hCursor       =  LoadCursor(NULL, IDC_ARROW)
        .hbrBackground =  (HBRUSH)(COLOR_BTNFACE+1)
        .lpszMenuName  =  0
        .lpszClassName =  szClassName
        .hIconSm       =  LoadIcon  (NULL,IDI_APPLICATION)
    End With
    RegisterClassEx(&wcx)
    dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION
    dwStyleEx = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE
   
    hWin = CreateWindowEx(dwStyleEx,szClassName$,"What is your name? ", _
                          dwStyle, _
                          (GetSystemMetrics(SM_CXSCREEN) - 246) / 2, _
                          (GetSystemMetrics(SM_CYSCREEN) - 110) / 2, _
                          246, 110, 0,0, hInst, NULL)
                             
   
    hText = CreateWindowEx(WS_EX_CLIENTEDGE, _
                           "Edit", _
                           "", _
                           WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, _
                           21,20,201,19, _
                           hWin,IDC_TEXT,hInst,NULL)
    SendMessage(hText,WM_SETFONT,hFont,0)
    hOk = CreateWindowEx(0,"Button","OK", _
                         WS_CHILD | WS_VISIBLE | WS_TABSTOP, _
                         51,52,60,23,hWin,IDC_OK,hInst,NULL)
    SendMessage(hOk,WM_SETFONT,hFont,0)
    hCancel = CreateWindowEx(0,"Button","Cancel", _
                             WS_CHILD | WS_VISIBLE | WS_TABSTOP, _
                             126,52,60,23,hWin,IDC_CANCEL,hInst,NULL)
    SendMessage(hCancel,WM_SETFONT,hFont,0)

    SetFocus(hText)
   
    ShowWindow(hWin,SW_SHOW)
   
    While GetMessage(&uMsg,NULL,0,0)
        If IsDialogMessage(hWin,&uMsg) Then
            Iterate
        EndIf
        TranslateMessage(&uMsg)
        DispatchMessage(&uMsg)
    Wend
    If uMsg.wParam = 1 Then
        MessageBox(0,"Hello " & UserName$,"What's your Name",MB_OK)
    EndIf
    If hFont Then
        DeleteObject(hFont)
    End If   
    Function = uMsg.wParam
End Function
'==============================================================================
Callback Function WndProc()
    Static As int RetVal
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case IDC_CANCEL
                    RetVal = 0
                    SendMessage(CBHNDL,WM_CLOSE,0,0)
                Case IDC_OK
                    RetVal = 1
                    GetWindowText(GetDlgItem(CBHNDL,IDC_TEXT),UserName$,255)
                    SendMessage(CBHNDL,WM_CLOSE,0,0)
            End Select
        Case WM_DESTROY
            PostQuitMessage(RetVal)
            Exit Function
    End Select
End Function
   


James C. Fuller


bc9Basic HelloRES using a resource dialog and the NUWEN g++ distro
  Exe Size: 21,504


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Pb HelloDDT clone using a resource dialog script
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER.TXT"
$ONEXIT "NUWENGPP.BAT $FILE$ -m64 gui -municode"   
'==============================================================================
ENUM
    IDD_DLG1 =               1000
    IDC_EDT1
    IDC_BTN1
    IDC_BTN2
END ENUM

'==============================================================================
Function WinMain()
    Dim As int RetVal
    Global UserName$ * 128
    RetVal = DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DLG1),0,(DLGPROC)DlgProc,0)
    If  RetVal = -1 Then
        MessageBox(0,"DialogBoxparam error","ERROR",MB_OK)
        Function = EXIT_FAILURE
    EndIf

    If RetVal = 1 Then
        MessageBox(0,"Hello " & UserName$,"What's your name?",MB_OK)
    EndIf

    Function = EXIT_SUCCESS
End Function
'==============================================================================
DlgCallBack DlgProc()
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case IDCANCEL,IDC_BTN2
                    EndDialog(CBHNDL,0)
                Case IDC_BTN1
                    GetWindowText(CTLHNDL(IDC_EDT1),UserName$,SizeOf(UserName$))
                    EndDialog(CBHNDL,1)
            End Select
    End Select
End Function
'==============================================================================




James C. Fuller


bc9Basic HelloCW using José Roca's CWindow Framework with the NUWEN g++ distro
  exe size: 164,352


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'CWindow version of PBWin HelloDDT
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER.TXT"
$ONEXIT "NUWENGPP.BAT $FILE$ -m64 gui -municode -Wno-write-strings"
$HEADER
    #define _tmemcpy wmemcpy
$HEADER
'==============================================================================
$Include <Afx/CWindow.bi>
'==============================================================================
Dim UserName$
'------------------------------------------------------------------------------
ENUM
    ID_OK = 1001
    ID_CANCEL
    ID_TEXT
END ENUM
'==============================================================================
Function WinMain()
    Dim As int iRetVal
    Dim As HWND hWin
    Raw As HWND hEdit
    Raw As CWindow pWindow
    Dim As DWORD dwStyle,dwStyleEx
    dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION
    dwStyleEx = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE

    hWin = pWindow.Create(NULL, "What is your name?", &WndProc,0,0,296,143,dwStyle,dwStyleEx)
    hEdit = pWindow.AddControl("Edit",hWin,ID_TEXT,"",25,24,235,24)
    pWindow.AddControl("Button",hWin,ID_OK,"OK",60,64,70,28)
    pWindow.AddControl("Button",hWin,ID_CANCEL,"Cancel",147,64,70,28)
    pWindow.Center()
    SetFocus(hEdit)
    iRetVal = pWindow.Do_Events(CmdShow)
    If iRetVal = 1 Then
        MessageBox(0,"Hello " & UserName$,"What's your name?",MB_OK)
    EndIf
End Function
'==============================================================================
CallBack Function WndProc()
    Static RetVal
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case ID_OK
                    GetWindowText(CTLHNDL(ID_TEXT),UserName$,SizeOf(UserName$))
                    RetVal = 1
                    PostMessage(CBHNDL,WM_CLOSE,0,0)
                Case ID_CANCEL
                    RetVal = 0
                    PostMessage(CBHNDL,WM_CLOSE,0,0)
            End Select
        Case WM_DESTROY
            PostQuitMessage(RetVal)
    End Select
End Function



James C. Fuller


bc9Basic Hellobc9Dlg using in memory dialog with The Fred Harris TCLib.
  Exe Size: 7,168


$CPP
$NOMAIN
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"
'==============================================================================
Dim UserName$
'------------------------------------------------------------------------------
ENUM
    ID_OK = 1001
    ID_CANCEL
    ID_TEXT
END ENUM
'==============================================================================
Function WinMain()
    Dim As int RetVal
    Dim lpdp As PDLGTEMPLATEEX
    SetProcessDPIAware()
    lpdp = bc9_Dialog("What is your name",0,0,160,50,0,0,"Segoe UI",9)
    bc9_Input("",&lpdp,ID_TEXT,14,12,134,12)
    bc9_Button("OK",&lpdp,ID_OK,34,32,40,14)
    bc9_Button("Cancel",&lpdp,ID_CANCEL,84,32,40,14)
    RetVal = bc9_DlgShowModal(lpdp,MDlgProc)
    If  RetVal = -1 Then
        MsgBox("BAD")
        Function = EXIT_FAILURE
    EndIf
    If RetVal = 1 Then
        MsgBox("Hello " & UserName$)
    EndIf
    Function = EXIT_SUCCESS
End Function
'==============================================================================
Begin Modal Dialog As MDlgProc
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case ID_OK
                    GetWindowText(CTLHNDL(ID_TEXT),UserName$,SizeOf(UserName$))
                    EndDialog(CBHNDL,1)
                Case ID_CANCEL   
                    EndDialog(CBHNDL,0)
            End Select
    End Select
End Dialog
'==============================================================================



James C. Fuller


bc9Baisc HelloSDK using SDK style code with the Fred Harris TCLib
  Exe Size: 8,192



'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloSDK
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"
$HEADER
    #pragma comment(lib,"gdi32.lib")        /*'ForCreateFont*
$HEADER
'==============================================================================
CONST    IDC_OK = 1001
CONST    IDC_CANCEL = 1002
CONST    IDC_TEXT = 1003

Dim UserName$
'==============================================================================
'Because of a bug (feature) in vc++ 19.
'==============================================================================
Sub SetClientSize(hwnd As HWND,nWidth As Long,nHeight,rxRatio = 1 As Single,ryRatio = 1 As Single)
    Dim As RECT rc,rcTemp
   ' // Convert the client rectangle to a window rectangle.
   ' // The AdjustWindowRectEx function cannot take menu wrapping into account
   ' // because it doesn't know which menu we are using.
    SetRect(&rc,0,0,nWidth * rxRatio,nHeight * ryRatio)
    Raw As HANDLE hMenu = GetMenu(hwnd)
    Raw As DWORD dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE)
    AdjustWindowRectEx(&rc, dwStyle, (hMenu <> NULL), GetWindowLongPtr(hwnd, GWL_EXSTYLE))
   ' // If there is a menu, we need to check how much wrapping occurs when we set
   ' // the window to the width specified by AdjustWindowRectEX and an infinite
   ' // amount of height. An infinite height allows us to see every single menu wrap.
    If hMenu <> NULL Then
        rcTemp = rc
        rcTemp.bottom = 0x7FFF   ' // "Infinite" height
        SendMessage(hwnd, WM_NCCALCSIZE, 0, (LPARAM) &rcTemp)
        ' // Adjust our previous calculation to compensate for menu wrapping.
        rc.bottom = rc.bottom + rcTemp.top
    EndIf
   ' // The AdjustWindowRectEx function does not take the WS_VSCROLL or WS_HSCROLL
   ' // styles into account. To account for the scroll bars, we need to call the
   ' // GetSystemMetrics function with SM_CXVSCROLL or SM_CYHSCROLL.
    If (dwStyle & WS_HSCROLL) = WS_HSCROLL Then
        rc.bottom = rc.bottom + GetSystemMetrics(SM_CYHSCROLL)
    End If
    If (dwStyle & WS_VSCROLL) = WS_VSCROLL THEN
        rc.right = rc.right + GetSystemMetrics(SM_CXVSCROLL)
    End If
    Raw As Long cx  = rc.right - rc.left, cy = rc.bottom - rc.top

    SetWindowPos(hwnd, NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE)
   
End Sub
'==============================================================================
Function WinMain()
    Local As WNDCLASSEX wcx
    Local As MSG uMsg
    Local As HWND hWin,hText,hOk,hCancel
    Local As DWORD dwStyle,dwStyleEx
    Local As HFONT hFont
    Local As LOGFONT lf
    Dim As NONCLIENTMETRICS ncm
    'Local As HDC hDc
    ncm.cbSize = sizeof(ncm)
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)
    hFont = CreateFontIndirect(&(ncm.lfMessageFont))

    Raw As char szClassName[]     =  "MyClassName"
    With wcx
        .cbSize        =  SIZEOF(wcx)
        .style         =  CS_HREDRAW | CS_VREDRAW
        .lpfnWndProc   =  WndProc
        .cbClsExtra    =  0
        .cbWndExtra    =  0
        .hInstance     =  hInst
        .hIcon         =  LoadIcon  (NULL, IDI_APPLICATION)
        .hCursor       =  LoadCursor(NULL, IDC_ARROW)
        .hbrBackground =  (HBRUSH)(COLOR_BTNFACE+1)
        .lpszMenuName  =  0
        .lpszClassName =  szClassName
        .hIconSm       =  LoadIcon  (NULL,IDI_APPLICATION)
    End With
    RegisterClassEx(&wcx)
    dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION
    dwStyleEx = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE
   
    hWin = CreateWindowEx(dwStyleEx,szClassName$,"What is your name? ", _
                          dwStyle, _
                          0, _
                          0, _
                          0, 0, NULL,NULL, hInst, NULL)
                             
    SetClientSize(hWin,240,81)
   
    hText = CreateWindowEx(WS_EX_CLIENTEDGE, _
                           "Edit", _
                           "", _
                           WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, _
                           21,20,201,19, _
                           hWin,IDC_TEXT,hInst,NULL)
    SendMessage(hText,WM_SETFONT,hFont,0)
    hOk = CreateWindowEx(0,"Button","OK", _
                         WS_CHILD | WS_VISIBLE | WS_TABSTOP, _
                         51,52,60,23,hWin,IDC_OK,hInst,NULL)
    SendMessage(hOk,WM_SETFONT,hFont,0)
    hCancel = CreateWindowEx(0,"Button","Cancel", _
                             WS_CHILD | WS_VISIBLE | WS_TABSTOP, _
                             126,52,60,23,hWin,IDC_CANCEL,hInst,NULL)
    SendMessage(hCancel,WM_SETFONT,hFont,0)
    SetFocus(hText)
    Center(hWin)
   
    ShowWindow(hWin,SW_SHOW)
   
    While GetMessage(&uMsg,NULL,0,0)
        If IsDialogMessage(hWin,&uMsg) Then
            Iterate
        EndIf
        TranslateMessage(&uMsg)
        DispatchMessage(&uMsg)
    Wend
    If uMsg.wParam = 1 Then
        MessageBox(0,"Hello " & UserName$,"What's your Name",MB_OK)
    EndIf
    If hFont Then
        DeleteObject(hFont)
    End If   
    Function = uMsg.wParam
End Function
'==============================================================================
Callback Function WndProc()
    Static As int RetVal
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case IDC_CANCEL
                    RetVal = 0
                    SendMessage(CBHNDL,WM_CLOSE,0,0)
                Case IDC_OK
                    RetVal = 1
                    GetWindowText(GetDlgItem(CBHNDL,IDC_TEXT),UserName$,255)
                    SendMessage(CBHNDL,WM_CLOSE,0,0)
            End Select
        Case WM_DESTROY
            PostQuitMessage(RetVal)
            Exit Function
    End Select
End Function
   


James C. Fuller


bc9Basic HelloRES using a resource dialog with the Fred Harris TCLib.
  Exe Size: 5,632



'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Pb HelloDDT clone using a resource dialog script
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"   
'==============================================================================
ENUM
    IDD_DLG1 =               1000
    IDC_EDT1
    IDC_BTN1
    IDC_BTN2
END ENUM
Dim UserName$
'==============================================================================
Function WinMain()
    Dim As int RetVal
    RetVal = DialogBoxParam(hInst,MAKEINTRESOURCE(IDD_DLG1),0,(DLGPROC)DlgProc,0)
    If  RetVal = -1 Then
        MsgBox("BAD")
        Function = EXIT_FAILURE
    EndIf

    If RetVal = 1 Then
        MessageBox(0,"Hello " & UserName$,"What's your name?",MB_OK)
    EndIf

    Function = EXIT_SUCCESS
End Function
'==============================================================================
DlgCallBack DlgProc()
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case IDCANCEL,IDC_BTN2
                    EndDialog(CBHNDL,0)
                Case IDC_BTN1
                    GetWindowText(CTLHNDL(IDC_EDT1),UserName$,SizeOf(UserName$))
                    EndDialog(CBHNDL,1)
            End Select
    End Select
End Function
'==============================================================================




James C. Fuller


bc9Basic HelloCW using José Roca's CWindow framework and the Fred Harris TCLib
  Exe Size: 17,920


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'CWindow version of PBWin HelloDDT
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"   
'==============================================================================
$HEADER
    #include <commctrl.h>                    / *'ForCWindow
    #pragma comment(lib,"comctl32.lib")        /*'ForCWindow*
    #pragma comment(lib,"gdi32.lib")        /*'ForCWindow*
    #pragma comment(lib,"advapi32.lib")        /*'ForDPIaware check*/
$HEADER
'==============================================================================
$Include <Afx/CWindow.bi>
'==============================================================================
Dim UserName$
'------------------------------------------------------------------------------
ENUM
    ID_OK = 1001
    ID_CANCEL
    ID_TEXT
END ENUM
'==============================================================================
Function WinMain()
    Dim As int iRetVal
    Dim As HWND hWin,hEdit
    Raw As CWindow pWindow
   
    Raw As DWORD dwStyle = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION
    Raw As DWORD dwStyleEx = WS_EX_DLGMODALFRAME | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE

    hWin = pWindow.Create(NULL, "What is your name?", &WndProc,0,0,296,143,dwStyle,dwStyleEx)
    hEdit = pWindow.AddControl("Edit",hWin,ID_TEXT,"",25,24,235,24)
    pWindow.AddControl("Button",hWin,ID_OK,"OK",60,64,70,28)
    pWindow.AddControl("Button",hWin,ID_CANCEL,"Cancel",147,64,70,28)
    pWindow.Center()
    SetFocus(hEdit)
    iRetVal = pWindow.Do_Events(CmdShow)
    If iRetVal = 1 Then
        MessageBox(0,"Hello " & UserName$,"What's your name?",MB_OK)
    EndIf
End Function
'==============================================================================
CallBack Function WndProc()
    Static RetVal
    Select Case CBMSG
        Case WM_COMMAND
            Select Case CBCTL
                Case ID_OK
                    GetWindowText(CTLHNDL(ID_TEXT),UserName$,SizeOf(UserName$))
                    RetVal = 1
                    PostMessage(CBHNDL,WM_CLOSE,0,0)
                Case ID_CANCEL
                    RetVal = 0
                    PostMessage(CBHNDL,WM_CLOSE,0,0)
            End Select
        Case WM_DESTROY
            PostQuitMessage(RetVal)
    End Select
End Function



James C. Fuller

Here is the composite of all the tests

PbWin9
  HelloDDT      20,480
  HelloSDK      25,600
  HelloRES      14,336
  HelloCW       66,048
PbCC5
  HelloJcfDlg   17,408
  HelloSDK      12,800
  HelloRES      10,240
  HelloCW       66,560
PbWin10
  HelloDDT      48,128  (Pbwin9 source)     
  HelloSDK      20,480
  HelloRES      18,944
  HelloCW       36,352
PBCC6
  HelloJcfDlg   26,112
  HelloSDK      21,504
  HelloRES      19,968
  HelloCW       36,864
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
bc9Basic using PellesC 8.0
  Hellobc9Dlg   33,280 (dpi aware, win ver,Common Controls manifest )
  HelloSDK      30,208 (dpi aware, win ver,Common Controls manifest )
  HelloRES      28,672
  HelloCW         NA  CWindow is c++ only

bc9Basic using Visual Studio 2015 libraries
  Hellobc9Dlg   87,552
  HelloSDK      86,528 (no manifest)
  HelloSDK      87,040 (Common Controls manifest)
  HelloSDK      88,576 (dpi aware, win ver,Common Controls manifest )
  HelloRES      86,528 (dpi aware, win ver,Common Controls manifest )
  HelloCW      123,904 (dpi aware, win ver,Common Controls manifest )

bc9Basic using NUWEN g++ distro
  Hellobc9Dlg   23,552 (dpi aware, win ver,Common Controls manifest )
  HelloSDK      19,456 (no manifest)
  HelloSDK      20,992 (Common Controls manifest)
  HelloSDK      22,528 (dpi aware, win ver,Common Controls manifest )
  HelloRES      21,504 (dpi aware, win ver,Common Controls manifest )
  HelloCW      164,352 (dpi aware, win ver,Common Controls manifest )

bc9Basic using 64bit Tiny C
  Hellobc9Dlg    8,704 (no manifest)
  Hellobc9Dlg    9,216 (Common Controls manifest)
  HelloSDK       7,168 (no manifest)
  HelloSDK       7,680 (Common Controls manifest)
  HelloSDK       9,216 (dpi aware, win ver,Common Controls manifest )
  HelloRES       5,120 (no manifest)
  HelloRES       5,632 (Common Controls manifest)
  HelloRES       7,680 (dpi aware, win ver,Common Controls manifest )
  HelloCW          NA  CWindow is c++ only

bc9Basic using TCLib
  Hellobc9Dlg    7,168 (no manifest)
  Hellobc9Dlg    7,680 (Common Controls manifest)
  Hellobc9Dlg    9,126 (dpi aware, win ver,Common Controls manifest ) 
  HelloSDK       8,192 (no manifest)
  HelloSDK       8,704 (Common Controls manifest)
  HelloSDK      10,240 (dpi aware, win ver,Common Controls manifest )
  HelloRES       5,632 (no manifest)
  HelloRES       6,144 (Common Controls manifest)
  HelloRES       8,192 (dpi aware, win ver,Common Controls manifest )
  HelloCW       17,920
  HelloCW       19,968 (dpi aware, win ver,Common Controls manifest )

James C. Fuller

After doing all these tests my preference is José's CWindow framework along with my version on Fred's TCLib. It adds about 10k to your app but I'm happy with the trade off as the Framework is dynamite.
If you want/need REALLY small apps, resource dialogs are the way to go.
If you use a full manifest they will be dpi aware. They will not size exactly the same as using CWindow as they are based on the font/size used. My tests show the text to NOT be fuzzy.

I want to thank José and Fred for the work they have done on their respective projects.

James




Frederick J. Harris

Just a note about your first PowerBASIC Windows 9 SDK example.  Its this one...


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

'======================================================================
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 " + szBuffer
  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
           GetWindowText(GetDlgItem(hWnd,%IDC_EDIT100),szBuffer,64)
           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


When I compiled that 'as is' with PB 10, I got a 50,176 byte executable.  The reason I tested it was because I immediately noted that while you claimed it to be SDK, it wasn't, as you have one DDT statement in it, which causes the whole DDT code from the compiler to be pulled in.  The offending statement is the Control Get Text statement to pull the text out of the edit control.  If you substitute GetWindowText() as I've done above, the executable shrinks to 10,752 bytes, that is, 40 K less.

Frederick J. Harris

I see that Control Get Text must have just slipped in unbeknownst to you Jim, as some of your other SDK examples use GetWindowText().  Sorry!

Frederick J. Harris

By the way, I'm seeing 5,120 ansi with my x64 Visual Studio 2008 (vc15) - TCLib, but without a manifest.  Actually (and now I'm revealing my real ignorance), I don't even know how to include that xptheme manifest in my programs.  I tried it but what I tried didn't work.  Doesn't matter.  I dislike everything about the modern interface look, so I just ignore it.  It isn't necessary for my work.  I don't sell any software, and as I said, I prefer the older look.

Frederick J. Harris

Your work here is certainly interesting Jim.  But I keep falling back on the idea that to really compare programming languages, one has to use examples where string handling is involved.  You know, to avoid an apples to oranges comparison.

In the case of String Classes, for a long time I wondered why the C++ Standard Library String Class had to be so much larger than mine in terms of what it adds to an executable.  For a time I thought it might simply be because of the way it was constructed, having a base class of basic_string or whatever it is; I forget.  But it only recently dawned on me the reason is really because of C++ Exception Handling.  That's really a complicated and sophisticated affair, and makes just about any comparison with other languages an apples to oranges comparison, i.e., all is not equal.

Your point about windows created with resource dialogs is well taken.  Its easy to understand how that's an efficient approach as all the functionality is within Windows dlls; one doesn't have to write code to create the windows. 

James C. Fuller

Fred,
  Here is my TCLIB batch file.
It will auto compile and add an rc file of the same name as the c++ file located in the same directory.
James


::=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
:: Batch file for creating 64 bit applications with TCLib targeted c++ source.
:: usage: TCLIB.BAT MainFile  (no ext .cpp assumed)
::=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
@setlocal enableextensions enabledelayedexpansion
@ECHO OFF
REM ==============================================================================
REM For use with Vista+
SET WIN_VER=/DWINVER=_WIN32_WINNT_VISTA /D_WIN32_WINNT=_WIN32_WINNT_VISTA
REM ==============================================================================

SET F=%~nx1
IF EXIST "%F%.cpp" (
  SET FN="%F%.cpp"
  GOTO start
)
GOTO usage

:start

SET XTYPE=x86_amd64
CALL "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%

IF EXIST "%F%.rc" (
  ECHO Compiling resources.....
  Rc "%F%"
  SET VRES="%F%.res"
)
:: DO IT
cl %FN%  /O1 /Os /Gy /GS- /GR- /Gs9999999 /Zc:sizedDealloc- %WIN_VER% /link /OPT:REF /STACK:0x100000,0x100000 TCLib.lib kernel32.lib user32.lib %VRES% %2 %3 %4 %5 %6


ECHO Finished!
IF EXIST "%F%.obj" del "%F%.obj"
IF EXIST "Strings.obj" del "Strings.obj"

GOTO done

:usage
ECHO **************************************************************
ECHO  Usage:  TCLIB.BAT MainFile  no ext .cpp assumed
ECHO **************************************************************
:done


James C. Fuller

Fred,
  I think you can leave out the theme stuff but still get dpi compatibility and no fuzzy text by using this manifest?
James


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">

      <assemblyIdentity version="1.0.0.0"
         processorArchitecture="amd64"
         name="ApplicationName"
         type="win32"/>
      <description>Optional description of your application</description>

      <asmv3:application>
         <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
         </asmv3:windowsSettings>
      </asmv3:application>

      <!-- Compatibility section -->
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
         <application>
            <!--The ID below indicates application support for Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
            <!--The ID below indicates application support for Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!--This Id value indicates the application supports Windows 8 functionality-->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!--This Id value indicates the application supports Windows 8.1 functionality-->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
            <!-- This Id value indicates the application supports Windows 10 functionality-->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>           
         </application>
       </compatibility>

      <!-- Trustinfo section -->
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
         <security>
            <requestedPrivileges>
               <requestedExecutionLevel
                  level="asInvoker"
                  uiAccess="false"/>
               </requestedPrivileges>
         </security>
      </trustInfo>


   </assembly>