PBCC 6 Gui Example
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Test using a resource dialog with a class name as an sdk window
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#COMPILE EXE
#CONSOLE OFF
#DIM ALL
#INCLUDE ONCE "Windows.Inc"
#INCLUDE ONCE "PbLib610.Bas"
#RESOURCE RES, "RcDlgClass2.res"
'==============================================================================
%IDD_DLG1 = 1000
%IDC_BTN1 = 1001
'==============================================================================
Function WinMain (Byval hInstance As LONG, _
Byval hPrevInstance As LONG, _
Byval lpCmdLine As STRINGZ PTR, _
Byval iCmdShow As LONG) AS LONG
Local Msg As TAGMSG
Local hWnd As LONG
Local hBkBrush As LONG
hBkBrush = CreateSolidBrush(GetSysColor(%COLOR_BTNFACE))
hWnd = CreateMainWindow(hInstance,%IDD_DLG1,hBkBrush)
If hWnd = 0 Then
Exit Function
End If
ShowWindow hWnd,%SW_SHOW
While GetMessage(Msg, Byval %NULL, 0, 0)
hWnd = GetFormHandle(GetFocus())
If (hWnd = %NULL) OR (IsDialogMessage(hWnd, Msg) = 0) Then
TranslateMessage Msg
DispatchMessage Msg
End If
Wend
If hBkBrush Then
DeleteObject hBkBrush
End If
Function = Msg.wParam
End Function
'==============================================================================
Function CreateMainWindow (Byval hInstance As LONG , _
Byval DlgId As LONG , _
Byval hBkBrush As LONG) As Long
Local szClassName As ASCIIZ * 80
Local wce As WNDCLASSEX
Local hWnd As LONG
If IsFalse(hBkBrush) Then
hBkBrush = GetStockObject(%WHITE_BRUSH)
End If
szClassName = "JcfMainWin"
wce.cbSize = SizeOf(wce)
wce.style = %CS_HREDRAW Or %CS_VREDRAW
wce.cbWndExtra = %DLGWINDOWEXTRA
wce.lpfnWndProc = CodePtr(MainWndProc)
wce.hInstance = hInstance
wce.hIcon = LoadIcon( hInstance, Byval(%IDI_WINLOGO))
wce.hCursor = LoadCursor(%NULL, Byval %IDC_ARROW)
wce.hbrBackground = hBkBrush
wce.lpszClassName = VarPtr(szClassName)
wce.hIconSm = LoadIcon(hInstance, Byval %IDI_APPLICATION)
If RegisterClassEx(wce) = 0 Then
MessageBox(GetActiveWindow(),"RegisterClassEx Error","Registration Error",%MB_OK)
Function = 0
End If
hWnd = CreateDialogParam(hInstance,Byval MAKEINTRESOURCE(DlgId),0,0,0)
If hWnd = 0 Then
MessageBox(GetActiveWindow(),"CreateDialogParam Failed","Creation Error",%MB_OK)
End If
Function = hWnd
End Function
'==============================================================================
WinCallback(MainWndProc)
Select Case CB_MSG
Case %WM_CLOSE
DestroyWindow(CB_HWND)
Case %WM_DESTROY
PostQuitMessage 0
Case %WM_COMMAND
If (CB_CTLMSG = %BN_CLICKED) And ( CB_CTL = %IDC_BTN1) Then
PostMessage CB_HWND,%WM_CLOSE,0,0
End If
End Select
EndWinCallback
'==============================================================================
A PowerBASIC Console Compiler example using a resource dialog to create a main SDK style Window.
#5: hide the console
#6: ALWAYS use Dim All
#7: Jose Includes
#8: My Pb library
#9: link in the res dialog
#11-12: Dialog and control res id's
#14-43: Your standard WinMain Procedure
#19-21 Dimension Local variables
#23: Create a background brush for the main window
#24: Create the Window and return its handle. If it fails with a zero, get otta here
#29: Display the Window
#30-36: Your Standard Windows Message Loop. The GetFormHandle function is located in PbLib610.Bas
#39: Destroy what we create!
#45-81: The CreateMainWindow function.
#49-51 Dim local variables
#53-55: If we don't have a back ground brush passed to the function; create one
#57: Use this class name in your resource DIALOGEX script
#60: DO NOT FORGET THIS LINE ->
#61: Tell Windows where our callback function is located
#69: Register the class and exit if it fails
#74: Create our Main Window. Make sure parameter(4) is zero. This works because windows will use the callback value placed in the WNDCLASSEX structure.
#80: return the handle or zero if the creation failed.
#83-94 The callback procedure for the Main Window. WinCallback, EndWinCallback, and the CB_ items are PbLib610.bas MACROs