• Welcome to Jose's Read Only Forum 2023.
 

Ease vs Size

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

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

James C. Fuller


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



James C. Fuller


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


James C. Fuller


bc9Basic Hellobc9Dlg using Pelles C 8.0
  Exe size: 33,280


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' Hellobc9Dlg
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$ONEXIT "PEL.BAT $FILE$ -m64 gui"
'==============================================================================
Dim UserName$
'------------------------------------------------------------------------------
ENUM
    ID_OK = 1001
    ID_CANCEL
    ID_TEXT
END ENUM
'==============================================================================
Function WinMain()
    Dim As int RetVal
    Dim lpdp As PDLGTEMPLATEEX
    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


bc9Basic HelloSDK using PellesC 8.0
  Exe Size: 30,208



'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloSDK
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$ONEXIT "PEL.BAT $FILE$ -m64 gui"
'==============================================================================
$HEADER
    #include <windows.h>
    #pragma comment(lib,"User32.lib")
    #pragma comment(lib,"gdi32.lib")       
$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
    Dim As NONCLIENTMETRICS ncm
    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 Pelles C 8.0
  Exe Size: 28,672


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Pb HelloDDT clone using a resource dialog script
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'$ZTRACE
$NOMAIN
$ONEXIT "PEL.BAT $FILE$ -m64 gui"
'==============================================================================
$HEADER
    #include <windows.h>
    #pragma comment(lib,"User32.lib")
    #pragma comment(lib,"gdi32.lib")       
$HEADER
'==============================================================================
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 Hellobc9Dlg using 64 bit Tiny C
  Exe Size: 8,704


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' bc9Basic version HelloDDT
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$ONEXIT "TC926_64.BAT $FILE$"
'==============================================================================
Dim UserName$
'------------------------------------------------------------------------------
ENUM
    ID_OK = 1001
    ID_CANCEL
    ID_TEXT
END ENUM
'==============================================================================
Function WinMain()
    Dim As int RetVal
    Dim lpdp As PDLGTEMPLATEEX
    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 = 1
    EndIf
    If RetVal = 1 Then
        MsgBox("Hello " & UserName$)
    EndIf
    Function = 0
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



bc9Basic HelloSDK using 64 bit Tiny C
  exe size: 7,168


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloSDK
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$ONEXIT "TC926_64.BAT $FILE$ -m64"
'==============================================================================
$HEADER
    #include <windows.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 64 bit Tiny C with a resource dialog.
  exe size: 5,120


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

$NOMAIN
$ONEXIT "TC926_64.BAT $FILE$"   
$HEADER
#include <windows.h>
$HEADER
'==============================================================================
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 = 1
    EndIf

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

    Function = 0
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
'==============================================================================




Patrice Terrier

James--

Are you aware that your SDK code is not safe, because the class registration could failed, as well as the creation of the window itself.
Also it is considered a good practice (but not realy needed) to unregister a class when you do not use it anymore.

And about Ease vs Size, i would say that Size doesn't really matter when you start from an existing Template, it is just as easy as using cut and paste (except for the first time, of course).  :)

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

James C. Fuller

Patrice,
  Yeah a bit of an oversight but this is just an article comparing methods not a tutor on windows programming. ( I don't think I have ever had it fail??)
No matter how you get the code (typing or cut and paste) it just reflects what's needed.

James


James C. Fuller


bc9Basic Hellobc9Dlg using an in memory dynamic dialog and Visual Studio 2015.
  Exe Size 87,552


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$NOMAIN
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "VSCPP.BAT $FILE$ -m64 gui"
'==============================================================================

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


bc9Basic HelloSDK using Visual Studio 2015
  Exe File Size 88,576


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'HelloSDK
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "VSCPP.BAT $FILE$ -m64 gui"
'==============================================================================

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,hCurFont
    Local As LOGFONT lf
    Dim As NONCLIENTMETRICS ncm
    Local As HDC hDc
    'This should return the Segoe UI,9 font
    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)
    hDc = GetDC(hWin)
   
    ReleaseDC(hWin,hDc)
    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 and Visual Studio 2015 Community
  Exe Size: 86,528


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

$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "VSCPP.BAT $FILE$ -m64 gui"   
'==============================================================================
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

#28
bc9Basic using HelloCW José Roca's CWindow Framework and Visual Studio 2015 Community
  Exe Size: 123,904


'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'CWindow version of PBWin HelloDDT
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "VSCPP.BAT $FILE$ -m64 gui"   
'==============================================================================
' CWindow source
$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
    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 an in memory dynamic dialog with the NUWEN g++ distro.
  Exe Size: 86,528



'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
' bc9Basic version of PBWin9/10 HelloDDT
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$NOMAIN
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER.TXT"
$ONEXIT "NUWENGPP.BAT $FILE$ -m64 gui -municode"
'==============================================================================
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
'==============================================================================