Author Topic: Convert PB DDT dialogs to O2 dialogs  (Read 152 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Convert PB DDT dialogs to O2 dialogs
« on: September 16, 2018, 05:17:23 AM »
Hello All

I have a direct method to convert PB DDT dialogs to O2 dialogs , thanxx to Roland of O2 forum
for his contribution of dialogs.inc file

for example a simple PB DDT program with 2 textboxes and 2 buttons and a label coded as below :
Code: [Select]
' Simple DDT.bas


 #COMPILE EXE
 #DIM ALL
 #INCLUDE "WIN32API.INC"


 ' Equates
 %IDC_TEXTBOX1        = 1001
 %IDC_TEXTBOX2        = 1002
 %IDC_LABEL1          = 1003
 %IDC_BUTTON1         = 1006
 %IDC_ExitBtn         = 1008


 GLOBAL hDlg  AS DWORD


'====================================
FUNCTION PBMAIN()


    DIALOG NEW 0, "Simple DDT ", 151, 118, 201, 133,_
                  %WS_OVERLAPPEDWINDOW TO hDlg


    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "TextBox 1", 10, 5, 55, 30
    CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX2, "TextBox 2", 10, 45, 55, 30


    CONTROL ADD LABEL,   hDlg, %IDC_LABEL1, "Label 1", 95, 5, 65, 30

    CONTROL ADD BUTTON,  hDlg, %IDC_BUTTON1, "Button1", 125, 45, 50, 20

    CONTROL ADD BUTTON,  hDlg, %IDC_ExitBtn, "Exit", 10, 95, 35, 20

    DIALOG SHOW MODAL hDlg, CALL DlgProc


END FUNCTION





'============================================
CALLBACK FUNCTION DlgProc()

    SELECT CASE AS LONG CBMSG

       CASE %WM_INITDIALOG


       CASE %WM_COMMAND
         SELECT CASE AS LONG CB.CTL
            CASE %IDC_BUTTON1
               IF CB.CTLMSG = %BN_CLICKED THEN
                  ? " Button 1 is clicked "
               END IF

           CASE %IDC_ExitBtn
               IF CB.CTLMSG = %BN_CLICKED THEN
                '  exit the program
                   DIALOG END CBHNDL
               END IF

         END SELECT

    END SELECT
END FUNCTION



 we can easily translate it to O2  directly using  Dialogs.inc
Code: [Select]
'====================================================================
' Simple DDT style dialogs in OxygenBasic
' Thanxx to Roland and Charles

$ filename "SimpleDDT.exe"

 uses rtl64
 uses dialogs
 #lookahead   


' Equates
 % IDC_TEXTBOX1     = 1001
 % IDC_TEXTBOX2     = 1002
 % IDC_LABEL1          = 1003
 % IDC_BUTTON1      = 1006
 %  IDC_ExitBtn         = 1008   

  sys  hDlg




'=====================================
sub winmain()


  Dialog( 151, 118, 201, 133, "DDT style in OxygenBasic",
          WS_OVERLAPPEDWINDOW  or DS_SETFONT,
          8, "MS Sans Serif" )

  EDITTEXT("TextBox 1", IDC_TEXTBOX1, 10, 5, 55, 30 )

  EDITTEXT("TextBox 2", IDC_TEXTBOX2, 10, 45, 55, 30 )


  LText( "Label 1 ", IDC_LABEL1, 95, 5, 65, 30)

  PushButton( "Button1" , IDC_Button1, 125, 45, 50, 20)

  PushButton( "Exit" , IDC_ExitBtn, 10, 95, 35, 20)

  CreateModalDialog( null, @DlgProc, 0) 

end sub




=============================================
 function DlgProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback

  select case uMsg
 
    case WM_INITDIALOG
     

    case WM_COMMAND
      select case loword(wParam)

       case IDC_Button1
                    mbox " Button 1 is clicked"

        case IDC_ExitBtn
                EndDialog( hDlg, null )

      end select

     
    case WM_CLOSE
         EndDialog( hDlg, null )
               
  end select

  return 0
end function




==============================================
'MAIN CODE start
winmain()






Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #1 on: September 16, 2018, 05:20:12 AM »
image of simple DDT done by PB



image of simple DDT done by O2

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #2 on: September 16, 2018, 05:25:06 AM »
hence the  translation method is as below

use the attached Dialogs.inc  file   (created by Roland)


The steps are as below:
  To convert  PB  DDT dialogs to O2 dialogs 


      1.   you need to have  at the start of the program ,
             place  these statements to get the includes files
              of  corewin.inc ,  dislogs.inc and user.inc

              uses corewin
              uses dialogs
              uses user
       
     
        2.   so in PB,  we have the following declarations

                %IDC_Button = 500
                 %IDC_LABEL1 = 508
                 %IDC_TxtBox  = 510
                GLOBAL hDlg, hToolTip, hButton, hTxtBox AS DWORD


              in O2, we declare their equivalent as follows

                 %   IDC_BUTTON = 500
                 %   IDC_LABEL1  = 508
                  %   IDC_TxtBox   = 510
                 sys  hDlg, hToolTip, hButton, hTxtBox




         3.   in the PBMain() for example they have the dialog declaration

                  DIALOG NEW PIXELS, 0, "Test Code",300,300,200,200,  _
                        %WS_OVERLAPPEDWINDOW TO hDlg



               in O2,  the dialog declaration can be

               '  Note that 0.7 and 0.6 are pixels factors for  Horizontal and Vertical
               '  with respect to the dialog units
                  init_common_controls()   
                 Dialog( 300*0.7, 300*0.6, 200*0.7, 200*0.6, "Test Code",
                            WS_OVERLAPPEDWINDOW or DS_SETFONT,
                            10, "Arial" )



          4.   in the PB dialog, they have a button

                  CONTROL ADD BUTTON, hDlg, %IDC_Button,"Button1", 50,10,65,15 


                 in O2,  the button is effected by

                     PushButton("Button1", ID_Button, 50,10,65,15)



           5.   in PB dialog, they have a label

                     CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Project Title 1 ",   20,160,  50,  9


                  in O2, the label can be effected as

                   LText( "Project Title 1 ", IDC_LABEL1, 20,160, 50,9)




          6.   in PB dialog , they have a text box
                     CONTROL ADD TEXTBOX, hDlg, %IDC_TxtBox, "",55, 120, 60, 15



                in O2, the equivalent code is
                    '  for text box data entry
                    EDITTEXT("", IDC_TxtBox, 55, 120, 60, 15)



         7.   in PB they have a modal dialog code
                  where DialogProc is the call back function
                       DIALOG SHOW MODAL hDlg, CALL DialogProc


                 in O2  place in at the end of the dialog code
                  CreateModalDialog( null, @DialogProc, 0)
                 


          8.  in PB their call back function is
                   CALLBACK FUNCTION DialogProc() AS LONG



                 in O2, the corresponding function is
             function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback






           9.  in PB call back function they have an exit button to end and destroy the dialog
                    using the statement   DIALOG END CBHNDL   

                     CASE %WM_COMMAND
                            ' Process control notifications
                              SELECT CASE AS LONG CBCTL

                                CASE %IDCANCEL   
                                      ' ESC key  or close button to exit
                                        DIALOG END CBHNDL         




                        in O2,  we use the equivalent  EndDialog()  as below

                                  select case uMsg

                                   case WM_COMMAND
                                            select case loword(wParam)
                                                   case IDCANCEL, IDC_BUTTON
                                                          EndDialog( hDlg, null )
                                              end select

Offline Brian Alvarez

  • Jr. Member
  • **
  • Posts: 55
    • PluriBASIC
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #3 on: September 24, 2018, 01:37:20 AM »
I would like to see more examples like this one.

One question, in the example code, i see:

Code: [Select]
function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback
 Why is it that lParam has no data type descriptor? or is it a typo?

Added:
 How do you change the control styles and extended styles?
« Last Edit: September 24, 2018, 01:39:22 AM by Brian Alvarez »

Offline Mike Lobanovsky

  • Jr. Member
  • **
  • Posts: 80
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #4 on: September 24, 2018, 04:39:39 AM »
Brian,

The rightmost sys covers everything that's to the right of it in between the parentheses unless superseded with some other data type next to another argument which, in its turn, would cover everything that's to the right of it, and so on so forth.
Mike
(3.6GHz Intel Core i5 w/ 16GB RAM, 2 x GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #5 on: September 25, 2018, 06:35:10 AM »
Hello Brian

you can add extended styles in the Dialog() routine
for example
before adding extended styles into SimpleDDT.o2bas
Code: [Select]
Dialog( 151, 118, 201, 133, "DDT style in OxygenBasic",
          WS_OVERLAPPEDWINDOW  or DS_SETFONT,
          8, "MS Sans Serif" )


after adding extended styles of  WS_EX_DLGMODALFRAME OR WS_EX_TOPMOST

Code: [Select]
Dialog( 151, 118, 201, 133, "DDT style in OxygenBasic",
          WS_VISIBLE or DS_SETFONT,
          8, "MS Sans Serif" ,  WS_EX_DLGMODALFRAME OR WS_EX_TOPMOST)


then the before and after screen displays are
where you can see that after modification the dialog appears on the topmost and you cannot
resize the dialog











Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #6 on: September 25, 2018, 06:37:38 AM »
after modification  with the extended styles the SimpleDDt.o2bas is
Code: [Select]
'====================================================================
' Simple DDT style dialogs in OxygenBasic
' Thanxx to Roland and Charles

$ filename "SimpleDDT.exe"

 uses rtl64
 uses dialogs
 #lookahead   


' Equates
 % IDC_TEXTBOX1     = 1001
 % IDC_TEXTBOX2     = 1002
 % IDC_LABEL1          = 1003
 % IDC_BUTTON1      = 1006
 %  IDC_ExitBtn         = 1008   

  sys  hDlg




'=====================================
sub winmain()


  Dialog( 151, 118, 201, 133, "DDT style in OxygenBasic",
          WS_VISIBLE or DS_SETFONT,
          8, "MS Sans Serif" ,  WS_EX_DLGMODALFRAME OR WS_EX_TOPMOST)

  EDITTEXT("TextBox 1", IDC_TEXTBOX1, 10, 5, 55, 30 )

  EDITTEXT("TextBox 2", IDC_TEXTBOX2, 10, 45, 55, 30 )


  LText( "Label 1 ", IDC_LABEL1, 95, 5, 65, 30)

  PushButton( "Button1" , IDC_Button1, 125, 45, 50, 20)

  PushButton( "Exit" , IDC_ExitBtn, 10, 95, 35, 20)

  CreateModalDialog( null, @DlgProc, 0) 

end sub




=============================================
 function DlgProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback

  select case uMsg
 
    case WM_INITDIALOG
     

    case WM_COMMAND
      select case loword(wParam)

       case IDC_Button1
                    mbox " Button 1 is clicked"

        case IDC_ExitBtn
                EndDialog( hDlg, null )

      end select

     
    case WM_CLOSE
         EndDialog( hDlg, null )
               
  end select

  return 0
end function




==============================================
'MAIN CODE start
winmain()






Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #7 on: September 25, 2018, 06:44:13 AM »
Brian,
what Mike said is correct as this is O2 style and very flexible to define

so
Code: [Select]
function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback

is also equivalent to
Code: [Select]
function DialogProc( sys hDlg, uint uMsg, sys wParam, sys lParam ) as sys callback


Offline Chris Chancellor

  • Full Member
  • ***
  • Posts: 126
Re: Convert PB DDT dialogs to O2 dialogs
« Reply #8 on: September 25, 2018, 07:01:38 AM »
yes

 more example programs for the amazing O2
  O2  can do wonders

 Thanxx a lot to Roland , Charles and Mike and Aurel

 good for 64bits and fewer virus threats than 32bits
 see the article attached