• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

first week with PB

Started by Fabio Stranieri, December 11, 2008, 09:17:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Fabio Stranieri

I don't see a section "despair PB newbie" :'(. I come from some year of VB6. In the last year my doubtful is where to begin to work..... I want leave Microsoft........ok.....i want to try PB. But for me is very difficult. Of my old love VB6 there is nothing. I have opend a file RMCHART.bas.................i have understand NOTHING. Where is the code that build a form? What is
%ID_RMC1 = %WM_USER+1024 emmmm oppsss maybe  it is a costant!!!! It's better to install FireFly trial..... Here the enviroment is familiar. Mmm i want to add a ocx!!! Yes after 3 hour mabe i win (vb6 3 second), and i don't know if in 3 week i build a little little little program that will work!!! ooppp where is Form load? mmm Maybe WM_COMMAND? I don't belive!!!  OK I want read help file....nothing i don't understand where is my old form load!!!! Can i open with firefly a .bas file of PB? I don't belive!!

Hi guys, i'm not crazy.....i well become crazy....in 3 or 4 week!!! For know i'm desperate!!! But i must to pass this terrible step!!

Where i can found little VB6 program and the same program write with PB. I think that in this mode i undrstand the difference!!!

excuse me for the disturb..

Best of all

Fabio

José Roca

 
Welcome to the forum,

I'm afraid that very little of what you have learned with VB6 will be of any use to program with PB. Where is your form load and OCXs? Nowhere. We use the Windows API and the Windows Common Controls. Where are your events? Nowhere. The Windows API uses messages and callback functions.

First you have to decide if you want to use DDT (Dynamic Dialog Tools), natively supported by the compiler, or SDK-style programming.

For DDT, here are some tutorials: http://www.powerbasic.com/support/quickstart/index.html

For SDK-style programming, here are some tutorials: http://www.jose.it-berater.org/smfforum/index.php?board=285.0

DDT users post in the PowerBASIC forum. This forum is the home of a bunch of nuts that prefer to use SDK-style programming. We have discussed our reasons here: http://www.jose.it-berater.org/smfforum/index.php?topic=1129.15

If you choose SDK-style programming, you will find in this forum tons of headers and examples.

Then there are the forums of the providers of visual designers for PB:

PBForms: http://www.powerbasic.com/products/pbforms/default.asp
Firefly: http://planetsquires.com/support/index.php
Phoenix: http://www.phnxthunder.com/forums/phpBB2/
PwrDev: http://www.hellobasic.com/cgi-bin/forum/YaBB.pl
EZGUI: http://chrisboss.hypermart.net/cgi-bin/Ultimate.cgi?action=intro

PBForms uses DDT; Firefly and Phoenix use SDK; PwrDev can use both SDK and DDT, and EZGUI uses a DLL runtime.

And last, but not the least, thinBasic is an interpreter written mainly with PowerBASIC: http://www.thinbasic.com

Fabio Stranieri

#2
Josè thank a lot for your answer.

>I'm afraid that very little of what you have learned with VB6 will be of any use to program with PB.

I'm the some fears, but this is not a problem. With VB6 i have build program that work for years!! Now i must do the same thing with PB.

>First you have to decide if you want to use DDT (Dynamic Dialog Tools), natively supported by the compiler, or SDK-style programming.

DDT style is for me....decided. I'm sorry, but you must endure me in also this forum!!!

Regards


Eros Olmi

Quote from: Fabio Stranieri on December 12, 2008, 09:09:35 AM
SDK style is for me....decided. I'm sorry, you must endure me in this forum!!!

Ciao Fabio.

I'm sure that if your target is to get good feeling with PB compilers, apart the official PB forum, this is absolutely the best place to go.
Spend a little time to navigate the many subforums here and you will find so much work done by José and others posted with great generosity. A real PB and in general programming mine.

Have fun
Eros
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Fabio Stranieri

Ciao Eros,

thank a lot for your advice. I'm sure that this forum is the best asset. Now i'm look Firefly and Phoenix.
I'm like phoenix, but is it a active project?

For Josè
>Where are your events? Nowhere

ok but the FUNCTION Form1_InitWindow is not a event function?

Regards

Fabio


Eros Olmi

Quote from: Fabio Stranieri on December 12, 2008, 10:37:46 AM
I'm like phoenix, but is it a active project?
As far as I know it is active. Maybe not so active or its activity is not so visiblle. Maybe you have to ask to its support forum.

Quote from: Fabio Stranieri on December 12, 2008, 10:37:46 AM
ok but the FUNCTION Form1_InitWindow is not a event function?
Yes/No
Name of the function seems resemble VB6 style but in PB (or any other programming language not wrapping SDK in a framework, for example pure C) it is just a normal function whose name is well written and easy to understand. Just this.
It is programmer responsability to fire that function in window callback function when the correct message is handled.

Ciao
Eros
thinBasic Script Interpreter - www.thinbasic.com | www.thinbasic.com/community
Win7Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Patrice Terrier

#6
BareBone SDK window


'+--------------------------------------------------------------------------+
'|                                   MINI                                   |
'|                                                                          |
'|                      Create an empty SDI SDK window                      |
'|                                                                          |
'+--------------------------------------------------------------------------+

#COMPILE EXE "mini.exe"

'-----------------------------------------------------------------
' Equates:
'-----------------------------------------------------------------
%WINAPI                                         = 1
%TRUE                                           = 1
%FALSE                                          = 0
%NULL                                           = 0
%ANSI_VAR_FONT                                  = 12
%SW_RESTORE                                     = 9
%WM_CREATE                                      = &H1
%WM_DESTROY                                     = &H2
%WM_PAINT                                       = &HF
%WM_CLOSE                                       = &H10
%WM_COMMAND                                     = &H111
%WS_OVERLAPPED                                  = &H0
%WS_CHILD                                       = &H40000000
%WS_VISIBLE                                     = &H10000000
%WS_CLIPSIBLINGS                                = &H04000000
%WS_CLIPCHILDREN                                = &H02000000
%WS_CAPTION                                     = &H00C00000  ' WS_BORDER OR WS_DLGFRAME
%WS_SYSMENU                                     = &H00080000
%WS_THICKFRAME                                  = &H00040000
%WS_TABSTOP                                     = &H00010000
%WS_MINIMIZEBOX                                 = &H00020000
%WS_MAXIMIZEBOX                                 = &H00010000
%WS_OVERLAPPEDWINDOW                            = %WS_OVERLAPPED OR %WS_CAPTION OR %WS_SYSMENU OR %WS_THICKFRAME OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX
%WS_EX_WINDOWEDGE                               = &H00000100
%WS_EX_APPWINDOW                                = &H00040000
%CS_VREDRAW                                     = &H1
%CS_HREDRAW                                     = &H2
%PM_REMOVE                                      = &H0001
%SM_CXSCREEN                                    = 0
%SM_CYSCREEN                                    = 1
%IDC_ARROW                                      = 32512&

'-----------------------------------------------------------------
' TYPE and UNION structures:
'-----------------------------------------------------------------
TYPE RECT
    nLeft AS LONG
    nTop AS LONG
    nRight AS LONG
    nBottom AS LONG
END TYPE

TYPE POINTAPI
    x AS LONG
    y AS LONG
END TYPE

TYPE tagMSG
    hwnd AS DWORD
    message AS DWORD
    wParam AS LONG
    lParam AS LONG
    time AS DWORD
    pt AS POINTAPI
END TYPE

TYPE WNDCLASSEX
    cbSize AS DWORD
    style AS DWORD
    lpfnWndProc AS LONG
    cbClsExtra AS LONG
    cbWndExtra AS LONG
    hInstance AS DWORD
    hIcon AS DWORD
    hCursor AS DWORD
    hbrBackground AS DWORD
    lpszMenuName AS ASCIIZ PTR
    lpszClassName AS ASCIIZ PTR
    hIconSm AS DWORD
END TYPE

TYPE PAINTSTRUCT
    hDC AS DWORD
    fErase AS LONG
    rcPaint AS RECT
    fRestore AS LONG
    fIncUpdate AS LONG
    rgbReserved(0 TO 31) AS BYTE
END TYPE

'-----------------------------------------------------------------
' Declared Functions:
'-----------------------------------------------------------------
DECLARE FUNCTION AdjustWindowRectEx LIB "USER32.DLL" ALIAS "AdjustWindowRectEx" (lpRect AS RECT, BYVAL dsStyle AS LONG, BYVAL bMenu AS LONG, BYVAL dwEsStyle AS DWORD) AS LONG
DECLARE FUNCTION CreateWindowEx LIB "USER32.DLL" ALIAS "CreateWindowExA" (BYVAL dwExStyle AS DWORD, lpClassName AS ASCIIZ, lpWindowName AS ASCIIZ, BYVAL dwStyle AS DWORD, BYVAL x AS LONG, BYVAL y AS LONG, _
    BYVAL nWidth AS LONG, BYVAL nHeight AS LONG, BYVAL hWndParent AS DWORD, BYVAL hMenu AS DWORD, BYVAL hInstance AS DWORD, lpParam AS ANY) AS DWORD
DECLARE FUNCTION DefWindowProc LIB "USER32.DLL" ALIAS "DefWindowProcA" (BYVAL hWnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
DECLARE FUNCTION DispatchMessage LIB "USER32.DLL" ALIAS "DispatchMessageA" (lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION GetClassInfoEx LIB "USER32.DLL" ALIAS "GetClassInfoExA" (BYVAL hInst AS DWORD, lpszClass AS ASCIIZ, lpWndClass AS WNDCLASSEX) AS LONG
DECLARE FUNCTION GetClientRect LIB "USER32.DLL" ALIAS "GetClientRect" (BYVAL hwnd AS DWORD, lpRect AS RECT) AS LONG
DECLARE FUNCTION GetMessage LIB "USER32.DLL" ALIAS "GetMessageA" (lpMsg AS tagMSG, BYVAL hWnd AS DWORD, BYVAL uMsgFilterMin AS DWORD, BYVAL uMsgFilterMax AS DWORD) AS LONG
DECLARE FUNCTION GetStockObject LIB "GDI32.DLL" ALIAS "GetStockObject" (BYVAL nIndex AS LONG) AS DWORD
DECLARE FUNCTION GetSystemMetrics LIB "USER32.DLL" ALIAS "GetSystemMetrics" (BYVAL nIndex AS LONG) AS LONG
DECLARE FUNCTION IsDialogMessage LIB "USER32.DLL" ALIAS "IsDialogMessageA" (BYVAL hDlg AS DWORD, lpMsg AS tagMSG) AS LONG
DECLARE FUNCTION LoadCursor LIB "USER32.DLL" ALIAS "LoadCursorA" (BYVAL hInstance AS DWORD, lpCursorName AS ASCIIZ) AS DWORD
DECLARE FUNCTION LoadIcon LIB "USER32.DLL" ALIAS "LoadIconA" (BYVAL hInstance AS DWORD, lpIconName AS ASCIIZ) AS DWORD
DECLARE FUNCTION PeekMessage LIB "USER32.DLL" ALIAS "PeekMessageA" (lpMsg AS tagMSG, BYVAL hWnd AS DWORD, BYVAL dwMsgFilterMin AS DWORD, BYVAL dwMsgFilterMax AS DWORD, BYVAL dwRemoveMsg AS DWORD) AS LONG
DECLARE FUNCTION RegisterClassEx LIB "USER32.DLL" ALIAS "RegisterClassExA" (pcWndClassEx AS WNDCLASSEX) AS WORD
DECLARE FUNCTION SetForegroundWindow LIB "USER32.DLL" ALIAS "SetForegroundWindow" (BYVAL hWnd AS DWORD) AS LONG
DECLARE FUNCTION SetRect LIB "USER32.DLL" ALIAS "SetRect" (lpRect AS RECT, BYVAL X1 AS LONG, BYVAL Y1 AS LONG, BYVAL X2 AS LONG, BYVAL Y2 AS LONG) AS LONG
DECLARE FUNCTION ShowWindow LIB "USER32.DLL" ALIAS "ShowWindow" (BYVAL hWnd AS DWORD, BYVAL nCmdShow AS LONG) AS LONG
DECLARE FUNCTION TranslateMessage LIB "USER32.DLL" ALIAS "TranslateMessage" (lpMsg AS tagMSG) AS LONG

'-----------------------------------------------------------------
' Declared Subs:
'-----------------------------------------------------------------
DECLARE SUB InitCommonControls LIB "COMCTL32.DLL" ALIAS "InitCommonControls" ()
DECLARE SUB PostQuitMessage LIB "USER32.DLL" ALIAS "PostQuitMessage" (BYVAL nExitCode AS LONG)

FUNCTION WinMain (BYVAL hInstance     AS LONG, _
                  BYVAL hPrevInstance AS LONG, _
                  BYVAL lpCmdLine     AS ASCIIZ PTR, _
                  BYVAL iCmdShow      AS LONG) AS LONG

    LOCAL rc          AS RECT
    LOCAL Msg         AS tagMsg
    LOCAL wc          AS WndClassEx
    LOCAL zClass      AS ASCIIZ * 80
    LOCAL IsInitialized, x, y AS LONG, dwExStyle, dwStyle, hMain  AS DWORD
'
    zClass = "ZMINI"
'
    IsInitialized = GetClassInfoEx(hInstance, zClass, wc)
    IF IsInitialized&   = 0 THEN
       wc.cbSize        = SIZEOF(wc)
       wc.style         = %CS_HREDRAW OR %CS_VREDRAW
       wc.lpfnWndProc   = CODEPTR(WndProc)
       wc.cbClsExtra    = 0
       wc.cbWndExtra    = 0
       wc.hInstance     = hInstance
       wc.hIcon         = LoadIcon(wc.hInstance, "PROGRAM")
       wc.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)
       wc.hbrBackground = %NULL ' GetStockObject(%BLACK_BRUSH)
       wc.lpszMenuName  = %NULL
       wc.lpszClassName = VARPTR(zClass)
       wc.hIconSm       = wc.hIcon
       IF RegisterClassEx(wc) THEN IsInitialized = %TRUE
    END IF
'
    IF IsInitialized THEN
'
      CALL InitCommonControls()
'
     ' Window Extended Style
       dwExStyle = %WS_EX_APPWINDOW OR %WS_EX_WINDOWEDGE
     ' Windows Style
       dwStyle = %WS_OVERLAPPEDWINDOW
'
       CALL SetRect(rc, 0, 0, 562, 350)
       CALL AdjustWindowRectEx(rc, dwStyle, %FALSE, dwExStyle)  ' Adjust Window To True Requested Size
'
       x = MAX&((GetSystemMetrics(%SM_CXSCREEN) - rc.nRight - rc.nLeft) \ 2, 0)
       y = MAX&((GetSystemMetrics(%SM_CYSCREEN) - rc.nBottom - rc.nTop) \ 2, 0)
'
     ' Create The Window
       MyTitle$ = "Mini"
       hMain = CreateWindowEx(dwExStyle, _            ' Extended Style For The Window
                             zClass, _                ' Class Name
                             (MyTitle$), _            ' Window Title
                             dwStyle OR _             ' Defined Window Style
                             %WS_CLIPSIBLINGS OR _    ' Required Window Style
                             %WS_CLIPCHILDREN, _      ' Required Window Style
                             x, y, _                  ' Window Position
                             rc.nRight - rc.nLeft, _  ' Calculate Window Width
                             rc.nBottom - rc.nTop, _  ' Calculate Window Height
                             %NULL, _                 ' No Parent Window
                             %NULL, _                 ' No Menu
                             wc.hInstance, _          ' Instance
                             BYVAL %NULL)             ' Dont Pass Anything To WM_CREATE
'
       IF hMain THEN
'
        ' Show the main window
          CALL ShowWindow(hMain, iCmdShow)
          CALL SetForegroundWindow(hMain)                  ' Slightly Higher Priority

          WHILE GetMessage(Msg, %NULL, 0, 0)
              IF IsDialogMessage(hMain, Msg) = %FALSE THEN
                 CALL TranslateMessage(msg)                ' Translate The Message
                 CALL DispatchMessage(msg)                 ' Dispatch The Message
              END IF
          WEND
          FUNCTION = msg.wParam
       END IF

    END IF

END FUNCTION

FUNCTION WndProc(BYVAL hWin AS LONG, BYVAL Msg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
    LOCAL ps AS PAINTSTRUCT
    LOCAL rc AS RECT

    SELECT CASE LONG Msg

    CASE %WM_CREATE
    CASE %WM_COMMAND
         SELECT CASE LONG LOWRD(wParam)

         END SELECT

    CASE %WM_PAINT
         FUNCTION = 0: EXIT FUNCTION
    CASE %WM_CLOSE
    CASE %WM_DESTROY
         CALL PostQuitMessage(0)
         FUNCTION = 0: EXIT FUNCTION
    END SELECT

    FUNCTION = DefWindowProc(hWin, Msg, wParam, lParam)

END FUNCTION


And the resulting EXE size is:
7680 octets (with PBWin 8.04)
8192 octets (with PBWin 9.00)
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Dominic Mitchell

Quote
ok but the FUNCTION Form1_InitWindow is not a event function?
In this case, it is not a true event function.  It is a function generated by the Phoenix Visual Designer that gives the programmer access to the command line or an application-defined value just before a top-level window is shown.
It also guarantees that all controls(embedded or otherwise) have been created when this pseudo event is received.

The OnCreate event, a true event that is generated in response to the WM_CREATE message, does a similar job.  It does not, however, give immediate access to the command line, and all controls on a form are not guaranteed to have been created if the window is not top-level.

Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com

Paul Squires

Hi Fabio,

Looks like an email you sent me a couple of days ago ended up in my spam folder. You asked about "Tutorial #2". It is an old tutorial but I have attached it to this post.

In FireFly, you can initialize controls in the WM_CREATE event handler for your Form.

I also come from a Visual Basic background. PB is lot more low level so you need to unlearn some VB tendencies. There is not a one to one translation from VB to PB. You will need to be patient and learn as you go. It will take some time so start off slowly and ask a lot of questions.

Using OCX's in PB is certainly not as easy as in VB. Jose and Dominic have done great jobs explaining a lot of the ways to do it in PB. FireFly uses code that Jose created in order to allow (most) OCX's in FireFly (it is based on using the ATL container DLL). Certain visual OCX's that were creating using VB itself will not be useable in FireFly.




Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com

Frederick J. Harris

#9
Hi Fabio!

     All isn't completely lost in your tramsition from VB To PB!  By programming in VB you have a good feel for the event driven nature of Windows programming.  And many if not most windows messages have a close or even exact translation to Visual Basic.  For example Form_Load() is the WM_CREATE message, and Form_Activate() is WM_ACTIVATE.  The way I write Windows programs was heavily influenced by Visual Basic, as I used that language all through the nineties, and even into 2000 and later.

          Last summer I spent a little time working on a program to convert Visual Basic source code to a PowerBASIC equivalent.  I started with very simple, even trivial Visual Basic programs.  I'll attach the VB and PB generated code written by my converter program.  It may be useful to you for comparison purposes in seeing the VB code from the frm file and what it would (could) look like in PowerBASIC.  The 'converter' generated code went into a file named 'PBSource.bas'.  Here is that file.  I have to emphasize - this isn't hand written code; it was generated by a converter program reading in a VB source.  However, its pretty close to how I'd write it by hand...

'PBSource.bas

#Compile Exe
#Include "Win32api.inc"
%frmName_lstMembers             =    1500
%frmName_txtPerson              =    1505
%frmName_btnExecute             =    1510
%frmName_txtAge                 =    1515
%frmName_txtLastName            =    1520
%frmName_txtFirstName           =    1525
%frmName_lblMembers             =    1530
%frmName_lblAge                 =    1535
%frmName_lblLastName            =    1540
%frmName_lblFirstName           =    1545

Type WndEventArgs
  wParam As Long
  lParam As Long
  hWnd   As Dword
  hInst  As Dword
End Type
Declare Function FnPtr(wea As WndEventArgs) As Long


Type MessageHandler
  wMessage As Long
  dwFnPtr As Dword
End Type
Global frmName_MsgHdlr() As MessageHandler


Function strGetWindowText(hParent As Dword, iCtrlId As Long) As String
  Local pszStr As Asciiz Ptr
  Local hCtrl As Dword
  Local iLen As Long

  hCtrl=GetDlgItem(hParent,iCtrlId)           'Retrieve handle of control with GetDlgItem()
  iLen=GetWindowTextLength(hCtrl)             'Retrieve length of text in control
  Incr iLen                                   'add extra byte for null terminator
  pszStr=GlobalAlloc(%GPTR,iLen)              'allocate buffer from global memory
  Call GetWindowText(hCtrl,ByVal pszStr,iLen) 'bring text into buffer (pass address of buffer)
  strGetWindowText=@pszStr                    'assignment brings PB OLE String Engine into picture
  Call GlobalFree(pszStr)                     'release string buffer for GetWindowText()
End Function


Sub SendListBoxMessage(hParent As Dword, iCtrlId As Long, iMsg As Long, wParam As Dword, strText As String)
  Local hCtrl As Dword                                  'Get Control ID of ListBox (from CreateWindowEx())

  hCtrl=GetDlgItem(hParent,iCtrlId)                     'Retrieve handle of control with GetDlgItem()
  Call SendMessage(hCtrl,iMsg,wParam,Strptr(strText))   'Api SendMessage Function
End Sub


Sub frmName_Load(Wea As WndEventArgs)
  Call SendListBoxMessage(Wea.hWnd,%frmName_lstMembers,%LB_INSERTSTRING, 0,"Stan Helton")
  Call SendListBoxMessage(Wea.hWnd,%frmName_lstMembers,%LB_INSERTSTRING, 1,"Fred Harris")
  Call SendListBoxMessage(Wea.hWnd,%frmName_lstMembers,%LB_INSERTSTRING, 2,"Rodney Hicks")
  Call SendListBoxMessage(Wea.hWnd,%frmName_lstMembers,%LB_INSERTSTRING, 3,"Chris Holbrook")
End Sub


Function frmName_OnCreate(wea As WndEventArgs) As Long   'Here Is Your Form_Load()
  Local pCreateStruct As CREATESTRUCT Ptr
  Local hCtrl As Dword

  pCreateStruct=wea.lParam
  wea.hInst=@pCreateStruct.hInstance
  hCtrl=CreateWindowEx(512,"listbox","",1344274497,12,34,171,108,wea.hWnd,%frmName_lstMembers,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(512,"edit","",1342177280,208,122,379,25,wea.hWnd,%frmName_txtPerson,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(0,"button","Execute",1342193664,454,28,103,57,wea.hWnd,%frmName_btnExecute,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(512,"edit","",1342177280,300,82,127,23,wea.hWnd,%frmName_txtAge,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(512,"edit","",1342177280,300,45,127,23,wea.hWnd,%frmName_txtLastName,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(512,"edit","",1342177280,300,10,127,23,wea.hWnd,%frmName_txtFirstName,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(0,"static","VB Converter Members",1342177280,14,12,169,21,wea.hWnd,%frmName_lblMembers,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(0,"static","Age",1342177280,210,82,73,25,wea.hWnd,%frmName_lblAge,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(0,"static","Last Name",1342177280,210,44,71,23,wea.hWnd,%frmName_lblLastName,wea.hInst,ByVal 0)
  hCtrl=CreateWindowEx(0,"static","First Name",1342177280,210,10,73,21,wea.hWnd,%frmName_lblFirstName,wea.hInst,ByVal 0)
  Call frmName_Load(Wea)

  frmName_OnCreate=0
End Function


Sub frmName_btnExecute_Click(Wea As WndEventArgs)
  Local strtxtPersonText As String
  strtxtPersonText= _
  "Your Name Is " & _
  strGetWindowText(Wea.hWnd,%frmName_txtFirstName) & _
  " " & _
  strGetWindowText(Wea.hWnd,%frmName_txtLastName) & _
  " And You Are " & _
  strGetWindowText(Wea.hWnd,%frmName_txtAge) & _
  " Years Old."
  Call SetWindowText(GetDlgItem(Wea.hWnd,%frmName_txtPerson),Byval StrPtr(strtxtPersonText))
End Sub


Function frmName_OnCommand(wea As WndEventArgs) As Long
  Select Case As Long LoWrd(wea.wParam)
    Case %frmName_btnExecute
      Select Case As Long HiWrd(wea.wParam)
        Case %BN_CLICKED
          Call frmName_btnExecute_Click(wea)
      End Select
  End Select

  frmName_OnCommand=0
End Function


Function frmName_OnClose(wea As WndEventArgs) As Long
  Call PostQuitMessage(0)
  frmName_OnClose=0
End Function


Function frmName_WndProc(ByVal hWnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As Long) As Long
  Local wea As WndEventArgs
  Register iReturn As Long
  Register i As Long

  For i=0 To 2
    If wMsg=frmName_MsgHdlr(i).wMessage Then
       wea.hWnd=hWnd: wea.wParam=wParam: wea.lParam=lParam
       Call Dword frmName_MsgHdlr(i).dwFnPtr Using FnPtr(wea) To iReturn
       frmName_WndProc=iReturn
       Exit Function
    End If
  Next i

  frmName_WndProc=DefWindowProc(hWnd,wMsg,wParam,lParam)
End Function


Sub Attach_frmName_MsgHdlrs()
  Redim frmName_MsgHdlr(2) As MessageHandler  'Associate Windows Message With Message Handlers

  frmName_MsgHdlr(0).wMessage=%WM_CREATE                  : frmName_MsgHdlr(0).dwFnPtr=CodePtr(frmName_OnCreate)
  frmName_MsgHdlr(1).wMessage=%WM_COMMAND                 : frmName_MsgHdlr(1).dwFnPtr=CodePtr(frmName_OnCommand)
  frmName_MsgHdlr(2).wMessage=%WM_CLOSE                   : frmName_MsgHdlr(2).dwFnPtr=CodePtr(frmName_OnClose)
End Sub


Function WinMain(ByVal hIns As Long,ByVal hPrev As Long,ByVal lpCL As Asciiz Ptr,ByVal iShow As Long) As Long
  Local szAppName As Asciiz * 16
  Local winclass As WndClassEx
  Local hWnd As Dword
  Local Msg As tagMsg

  szAppName="frmName"
  Call Attach_frmName_MsgHdlrs()
  winclass.cbSize=SizeOf(winclass)
  winclass.style=%CS_HREDRAW Or %CS_VREDRAW
  winclass.lpfnWndProc=CodePtr(frmName_WndProc)
  winclass.cbClsExtra=0
  winclass.cbWndExtra=0
  winclass.hInstance=hIns
  winclass.hIcon=LoadIcon(%NULL, ByVal %IDI_APPLICATION)
  winclass.hCursor=LoadCursor(%NULL, ByVal %IDC_ARROW)
  winclass.hbrBackground=%COLOR_BTNFACE+1
  winclass.lpszMenuName=%NULL
  winclass.lpszClassName=VarPtr(szAppName)
  RegisterClassEx winclass
  hWnd=CreateWindowEx(0,szAppName,"Enter Your Name",%WS_OVERLAPPEDWINDOW,400,300,606,191,0,0,hIns,ByVal 0)
  Call ShowWindow(hWnd,iShow)
  While GetMessage(Msg,%NULL,0,0)
    TranslateMessage Msg
    DispatchMessage Msg
  Wend

  Function=msg.wParam
End Function


     The program has a main window (form) with a listbox on it and several labels, textboxes, and a command button.  When you fill in the text boxes and click the command button the text in the text boxes is concatenated together and written to another text box.

     Here are the contents of the vbp, vbw, and frm files that my converter program read to create the PBSource...

'prj004.vbw

frmName = 110, 110, 834, 744, C, 22, 22, 835, 656, C


'prj004.vbp

Type=Exe
Form=vb004.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\WINDOWS\system32\stdole2.tlb#OLE Automation
IconForm="frmName"
Startup="frmName"
HelpFile=""
ExeName32="prjName.exe"
Path32="..\prj003"
Command32=""
Name="prjName"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="PA Bureau of Forestry"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1



'prj004.frm

VERSION 5.00
Begin VB.Form frmName
   Caption         =   "Enter Your Name"
   ClientHeight    =   2460
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8970
   LinkTopic       =   "Form1"
   ScaleHeight     =   2460
   ScaleWidth      =   8970
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox lstMembers
      Height          =   1620
      Left            =   180
      TabIndex        =   8
      Top             =   510
      Width           =   2565
   End
   Begin VB.TextBox txtPerson
      Height          =   375
      Left            =   3120
      TabIndex        =   7
      Top             =   1830
      Width           =   5685
   End
   Begin VB.CommandButton btnExecute
      Caption         =   "Execute"
      Height          =   855
      Left            =   6810
      TabIndex        =   6
      Top             =   420
      Width           =   1545
   End
   Begin VB.TextBox txtAge
      Height          =   345
      Left            =   4500
      TabIndex        =   5
      Top             =   1230
      Width           =   1905
   End
   Begin VB.TextBox txtLastName
      Height          =   345
      Left            =   4500
      TabIndex        =   4
      Top             =   675
      Width           =   1905
   End
   Begin VB.TextBox txtFirstName
      Height          =   345
      Left            =   4500
      TabIndex        =   3
      Top             =   150
      Width           =   1905
   End
   Begin VB.Label lblMembers
      Caption         =   "VB Converter Members"
      Height          =   315
      Left            =   210
      TabIndex        =   9
      Top             =   180
      Width           =   2535
   End
   Begin VB.Label lblAge
      Caption         =   "Age"
      Height          =   375
      Left            =   3150
      TabIndex        =   2
      Top             =   1230
      Width           =   1095
   End
   Begin VB.Label lblLastName
      Caption         =   "Last Name"
      Height          =   345
      Left            =   3150
      TabIndex        =   1
      Top             =   660
      Width           =   1065
   End
   Begin VB.Label lblFirstName
      Caption         =   "First Name"
      Height          =   315
      Left            =   3150
      TabIndex        =   0
      Top             =   150
      Width           =   1095
   End
End
Attribute VB_Name = "frmName"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim iNum As Long
Private Sub Form_Load()
  lstMembers.AddItem "Stan Helton", 0
  lstMembers.AddItem "Fred Harris", 1
  lstMembers.AddItem "Rodney Hicks", 2
  lstMembers.AddItem "Chris Holbrook", 3
End Sub
Private Sub btnExecute_Click()
  txtPerson.Text = "Your Name Is " & txtFirstName.Text & " " & txtLastName.Text & " And You Are " & txtAge.Text & " Years Old."
End Sub


     The only comment I might make is I hadn't coded the tab order like as is automatically handled by Visual Basic, otherwise the functionality and look is exactly the same.

     I'll also attach the four files; however, you'll have to rename the VB files as the forum software doesn't allow frm, vbp and vbw files.  Perhaps this example will help.  Additionally, I've written a bunch of tutorials that are here in Jose's forum down on my board.

Fred

José Roca

Quote
I'll also attach the four files; however, you'll have to rename the VB files as the forum software doesn't allow frm, vbp and vbw files.

It is usually advisable to zip the files, because many kind of files downloaded from the web trigger a Windows warning when you try to open them.

Fabio Stranieri

Hi Frederick,

thanks a lot for your  kind answer. Your tutorial is the  only and the only valid tutorial existent on the net. And this , second my modest opinion, is the very limit of power basic. In this moment i'm study your Tutorial n° 2. It's hard for me........we will see!!!

In the first your tutorial i have understand that power basic use very and very often windows api. For understand windows api i must to know C language. So, this is no my position, how say Josè Roca i know very little VB6. So here born my question (i hope that it is not fool): why i ,or another, would learn power basic if i know C?
Second my modest opinion, this is the second and the last limit of power basic.....for now.

Best of all

Fabio


Patrice Terrier

#12
It is not a matter of learning C, but learning how to use the core Windows API.
We all have to do this, sooner or later, believe me ;)

Look at José translation of Charles Petzold's examples.
Also try to put your hand on "Programming Windows 5th edition" from Mister Petzold.

The other alternative is to move to a L5G language like WinDev.

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

José Roca

 
I don't know how to program with C, yet I'm using the Windows API all the time. What it is important is to know what pointers are and how to work with them, and parameter passing conventions.

Frederick J. Harris

Fabio,

   You don't need to know c to use the Windows api - you just need to understand how to translate the Windows documentation written in c to the PowerBASIC equivalent.  For example, if you see somethinbg like this in a function parameter...

UINT

then in PB that would be a Dword, that is, an unsigned 32 bit integer number.  Also critically important is the whole Byref/Byval thing with passing function parameters.  The whole thing would be incomprehensible without fully and perfectly understanding that.  Unfortunately, I have to admit that these are issues that don't come up as often if you restrain yourself to the confines of some one particular language such as Visual Basic or QuickBasic.  A full understanding of some of these issues becomes important when you venture into the area of calling third party Dlls perhaps written in other languages from within some different language.

    Many very experienced C/C++ and Asm coders prefer doing app development work in PowerBASIC for some of the following reasons:

1)  PowerBASIC is not case sensitive which helps with rapid coding;
2)  With PowerBASIC one is not constantly confronted with variable casting issues which can really slow down ones coding in C/C++;
3)  PowerBASIC has a very good native string engine for dealing with strings.  There simply are no major programs that don't use strings in a major way.  C assembly language strings are very awkward to use in application development;  Various C++ application frameworks have various string classes, but many folks don't like to use/learn OOP class frameworks;
4) PowerBASIC programs are very small and fast.  There is no code bloat.  The compiler is also as close to being bug free as compilers get;
5) The PowerBASIC forums (and here) offer excellent peer support.

    There are probably other reasons, but just quick those are a few good ones.

    If you haven't been programming for a good while (pretty heavily for 6 months to a year), then things will go slow I expect.  There is a lot to learn.  If Sdk style seems too hard, perhaps the visual designers such as Dominic's or Paul's FireFly would help.  Also, don't be afraid to ask specific questions about lines of code you don't understand fully.