Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Chris Chancellor on September 16, 2018, 05:17:23 AM

Title: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor 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 :

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






Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor on September 16, 2018, 05:20:12 AM
image of simple DDT done by PB



image of simple DDT done by O2
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor 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
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez 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:

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?
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Mike Lobanovsky 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.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor 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

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










Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor on September 25, 2018, 06:37:38 AM
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()





Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor 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

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


Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor 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

Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on September 29, 2018, 12:46:13 AM
Hello,

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

Thanks. :)
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on September 29, 2018, 12:47:03 AM
(PluriBASIC is now generating perfect code for o2!)
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Mike Lobanovsky on September 29, 2018, 09:57:19 AM
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.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on September 29, 2018, 07:29:23 PM
thanks mike!
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Charles Pegge on September 30, 2018, 01:50:35 PM
Thanks, Mike.

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

uses rtl64
uses console

Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Mike Lobanovsky on September 30, 2018, 07:58:31 PM
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?
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Charles Pegge on September 30, 2018, 09:50:57 PM
If an includepath is not specified then o2 will first look in the current folder, then it will look in "$\inc\"
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Mike Lobanovsky on October 01, 2018, 04:32:12 PM
Got it, thanks a lot! :)
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 01, 2018, 08:05:04 PM
Hello Again, I was wondering if o2 is at the point that controls have a custom callback function.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 02, 2018, 12:03:27 AM
After a few successful compiles, i started getting a virus warning, is this sometihng with a known fix?
(see image attached)



Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor on October 02, 2018, 03:15:02 PM
Hello Brian

this looks like PB source codes?   Probably you need to know that 32bits executatble 
are always captured by Anti virus programs,  that's why we all need to compile in 64bits

32bits exe is a real threat in terms of virus infection

see this 
https://www.symantec.com/content/dam/symantec/docs/security-center/white-papers/32-bit-virus-threats-64-bit-windows-02-en.pdf (https://www.symantec.com/content/dam/symantec/docs/security-center/white-papers/32-bit-virus-threats-64-bit-windows-02-en.pdf)
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor on October 02, 2018, 03:24:47 PM
Hello Brian


looks like you are generating O2 codes
Always  add this into the code at the start to compile to 64bits


uses rtl64



and then set your Antivirus  to have exclusion on the output folder so that the AV won't capture the
resultant exe file

Avast ,  BTW is not a good antivirus software

i think we should not be compiling to 32bits as it is virus prone


Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 02, 2018, 08:55:22 PM
Chris, this is what i get when i use the 64Bit mode, this is what i wanted to change the includes path, can you help me?
Maybe i can send you a copy of PluriBASIC when this starts working a bit better, maybe you can add stock code if you want?

Basically what PluriBASIC does is that it includes different portions of code depending on the features of the compiled
application. For example, if a TEXTBOX control is used, it includes the code of CONTROL_TEXTBOX.bin, so, you can include
anything required to initialize text boxes there, and even put different codes in different sections of the generated code, or
even external files.

But since those are empty, it needs coding. Right now, since the DDT features are used, it needs to add the contents of your
dialogs.inc file in the DIALOG.bin file.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor on October 03, 2018, 12:35:39 AM
Hello Brian

i have attached the zip file for the Simple DDT
Please see how i did the batch file  Build_SimpleDDT.bat (as shown below)  to get it compile



::@echo off

::Set the Oxygenbasic compiler path
set o2dir=C:\OxygenBasicProgressSep4

::Compile
%o2dir%\gxo2.exe SimpleDDT.o2bas


echo done
pause


all the Charles's  OxygenProgressZip  are placed inside my computer 's  folder  C:\OxygenBasicProgressSep4

so you either place the Dialog.inc file inside this folder  C:\OxygenBasicProgressSep4
or  inside the folder that contains  SimpleDDT.o2bas

and then inside SimpleDDT.o2bas , you enter the following codes at the start


$ filename "SimpleDDT.exe"

uses rtl64
uses dialogs
#lookahead   


i don't have any problem compiling using a batch file like this ?

maybe you need to modify your Pluribasic program so that it generate a batch file similar
to Build_SimpleDDT.bat
and then shell execute this batch file to obtain the compile file

in this way you can place your source file and inc files in any folder as you like.

Test compile using my batch file and see the results.






Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 03, 2018, 02:50:37 AM
I am using a custom DLL caller, im sure the problem resides there, as i recently modified it. Here is the code i am calling internally:


    CL = "#file """ & TRIM$(PATHNAME$(PATH, COMMAND$), ANY "/\") & "\" & PATHNAME$(NAME, COMMAND$) & ".exe""" & $CR & _
         FC

    SP = STRPTR(CL)

    CALL O2_MODE(9)

    O2_ASMO(SP)

    ER = O2_ERROR()   


I am using mode 9 to get strings like in PowerBASIC, then i call O2_ASMO() as advised... should i use something else??

Thanks.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 03, 2018, 02:53:32 AM
 Note that i had to do it this way to avoid getting popups from the compiler's dll and for
being able to capture the console output. I was also told this way i would not have to write BAT
files. I would prefer not write any BAT files. So, i have no option. This way used to work as intended.

I would like the internal structure of the DLL to remain intact so my caller
doesnt break in the future... So, if any changes are going to be made, i will appreciate if
i am told before calling my own "final".
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Chris Chancellor on October 03, 2018, 04:34:33 AM
Brian

If you don't wish to have batch file screen popup then make the Build_SimpleDDT.bat code as below


@echo off

::Set the Oxygenbasic compiler path
set o2dir=C:\OxygenBasicProgressSep4

::Compile
%o2dir%\gxo2.exe SimpleDDT.o2bas


While your PB code in DLL caller , maybe make it longer code
and not to have too complex


    LOCAL  pnam , filnam, givComm AS STRING
      givComm = COMMAND$
      pnam = TRIM$(PATHNAME$(PATH, givComm), ANY "/\")
      filnam = PATHNAME$(NAME, givComm) & ".exe"

     CL = "#file """ & pnam & "\" & filnam & "" & $CR &  FC

     SP = STRPTR(CL)       



As for CALL O2_MODE(9)  and   O2_ASMO(SP)
you would need to check with Charles as i have never use these commands before


Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 03, 2018, 06:06:20 AM

I would rather completely avoid bat files. I dont want my executable executing bat files at all.

Lets see what direction charles points us at. :)
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Charles Pegge on October 03, 2018, 11:03:07 AM
Hi Brian,

o2_asmo is now obsolete, use o2_basic instead. (they were identical)

You can also test for compiler errors by checking o2_errno:

if o2_errno() then
  er=o2_error()
  ...
else
  ...
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 03, 2018, 06:35:27 PM
Yes, doing that changed the error to:

ERROR: Problem with file: C:\Oxygen\projects\tests\inc\rtl64.inc
WORD: rtl64
LINE: 5
PASS: 2
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Anthon Com on October 03, 2018, 07:43:53 PM
This could be a problem in the rtl64.inc file, you ought to download the latest copy of
oxygenbasicprogress.zip and replace this inc file. Always use the latest copy.

Alternately, it could be something is blocking access to the rtl64.inc file possibly by the Avast program?
In this case,  before compiling, Brian should use a  command to copy the rtl64.inc file
into the same folder as the source code, get it ready for the Oxygen compiler gxo2.exe
to access it.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 03, 2018, 11:38:21 PM
It was a problem with rtl64.inc, with the last update now i get this:

ERROR: #file requires name.exe or name.dll
WORD: filename
LINE: 54
FILE: C:\Oxygen\inc\rtl64.inc
PASS: 2


Disregard. I forgot to add the $ filename "SimpleDDT.exe" statement.
Title: Re: Convert PB DDT dialogs to O2 dialogs
Post by: Brian Alvarez on October 04, 2018, 12:07:19 AM
Success... back on track.