• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Convert PB DDT dialogs to O2 dialogs

Started by Chris Chancellor, September 16, 2018, 05:17:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Chancellor

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 :

' 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

'====================================================================
' 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()







Chris Chancellor

image of simple DDT done by PB



image of simple DDT done by O2

Chris Chancellor

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.incdislogs.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

Brian Alvarez

#3
I would like to see more examples like this one.

One question, in the example code, i see:

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?

Mike Lobanovsky

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)

Chris Chancellor

Hello Brian

you can add extended styles in the Dialog() routine
for example
before adding extended styles into SimpleDDT.o2bas

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


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











Chris Chancellor

after modification  with the extended styles the SimpleDDt.o2bas is

'====================================================================
' 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()






Chris Chancellor

Brian,
what Mike said is correct as this is O2 style and very flexible to define

so

function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback


is also equivalent to

function DialogProc( sys hDlg, uint uMsg, sys wParam, sys lParam ) as sys callback



Chris Chancellor

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


Brian Alvarez

Hello,

How do i specify the paths for the includes when the source is in a different location?

Thanks. :)

Brian Alvarez

(PluriBASIC is now generating perfect code for o2!)

Mike Lobanovsky

Brian,

In

includepath "$\inc\"
include        "console.inc"

includepath defines a relative path to the folder that stores the include files specified with subsequent include statements. $ stands for the folder (usually the \OxygenBasic\ root folder) where the O2 binaries reside. An absolute path to the include folder is also acceptable.
Mike
(3.6GHz Intel Core i5 w/ 16GB RAM, 2 x GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)


Charles Pegge

#13
Thanks, Mike.

This can be shortened to uses without quotes, .inc extension by default:

uses rtl64
uses console


Mike Lobanovsky

Quote from: Charles Pegge on September 30, 2018, 01:50:35 PMThis can be shortened...

Thanks for the refinement, Charles.

I presume this refers to include only, leaving includepath as stated in my message?
Mike
(3.6GHz Intel Core i5 w/ 16GB RAM, 2 x GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)