Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Newbie Template Suggestions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie Template Suggestions

    I just put a post in the PBWin forum, talking about the benefits of templates. I'm putting some suggested templates here.

    These are the three templates I have in my PB IDE. I'm sure as I get more experience with PowerBASIC, that I'll find myself using templates with more and more code.

    1. Modal dialog - nothing more
    Code:
    1
    .bas
    .Code Test - Modal Dialog, Empty
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    Global hDlg As Dword
    Function PBMain () As Long
       Dialog New Pixels, 0, "Test",300,300,200,200, %WS_OverlappedWindow To hDlg
       '... test code goes here
       Dialog Show Modal hdlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
        '... test code goes here
    End Function
    2. Test code with a button press
    Code:
    1
    .bas
    .Code Test - Modal Dialog, Press Button
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    Global hDlg As Dword
    Function PBMain() As Long
        Dialog New Pixels, 0, "Button Test",300,300,200,200, %WS_OverlappedWindow To hDlg
        Control Add Button, hDlg, 100,"Push", 50,10,100,20
        Control Add Label, hDlg, 101,"results", 50,40,100,20, %WS_Border
        Control Add Label, hDlg, 102,"results", 50,70,100,20, %WS_Border
        Dialog Show Modal hDlg Call DlgProc
    End Function
    
    CallBack Function DlgProc() As Long
       Select Case Cb.Msg
          Case %WM_Command
             Select Case Cb.Ctl
                Case 100
                   If Cb.CtlMsg = %BN_Clicked Then
                      Local iResult1&, iResult2&
                      '... test code here - place results in labels 100 & 101
                      Control Set Text hDlg, 101, Str$(iResult1&)
                      Control Set Text hDlg, 102, Str$(iResult2&)
                   End If
                End Select
        End Select
    End Function
    3. Test code within a Doevents loop
    Code:
    1
    .bas
    .Code Test - Modeless Dialog, Doevents Loop
    #Compile Exe
    #Dim All
    #Include "win32api.inc"
    Global hDlg As Dword
    Function PBMain() As Long
       Local Count& 
       Dialog New Pixels, 0, "Test",300,300,200,200, %WS_OverlappedWindow To hDlg
       Control Add Label, hDlg, 100,"results", 50,50,100,20, %WS_Border
       Control Add Label, hDlg, 101,"results", 50,80,100,20, %WS_Border
       Dialog Show Modeless hDlg
       Do
          Dialog DoEvents 0 To Count&
          MySub
       Loop While Count&
    End Function
    
    Sub MySub
       Local iResult1&, iResult2&
       '... test code here - place results in labels 100 & 101
       Control Set Text hDlg, 100, Str$(iResult1&)
       Control Set Text hDlg, 101, Str$(iResult2&)
    End Sub
    These can also be found and downloaded on my website at
    http://www.garybeene.com/power/pb-tutor-templates.htm.

  • #2
    Code:
      'Gary, I hope you don't mind this note on DOEVENTS 0
      DIALOG DOEVENTS 0 TO Count 'uses 50% of CPU
      DIALOG DOEVENTS 1 TO Count 'uses 1%  of CPU
      DIALOG DOEVENTS TO Count   'default, 1 to Count
    How long is an idea? Write it down.

    Comment

    Working...
    X