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