Author Topic: theForger's Win32 Api tutorial in Oxygenbasic  (Read 5072 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
theForger's Win32 Api tutorial in Oxygenbasic
« on: April 02, 2014, 07:47:05 AM »

After having studied many of the examples supplied with Oxygenbasic I finally started an own project (learning by doing). My intention was to run the examples of the theForger's Win32 Api tutorial in Oxygenbasic.

To my surprise it turned out that porting the examples from C to Oxygenbasic was not too difficult. So maybe there is some interest in reading the tutorial and experiment with the examples. Please pay attention to the readme.txt

If the zip file is unzippeded correctly there will be a directory "theForger_o2h" with several subdirectories. The structure of the subfolders reflect the structure of the tutorial. There are the following distinctions:

DirName      file.o2bas runs directly with gxo2.exe
DirName_d   file.o2bas runs with gxo2 but needs a resource.dll to work correctly
DirName_e   file.o2bas must be compiled and linked with a resource file to an executable

Each subdirectory contains batch files to build and run the correspondent example file. If the path for Oxygenbasic is not c:\Oxygenbasic, then this must be corrected in _util/getpath.bat.

Although the programs run as expected on my system, perhaps the more experienced users of Oxygenbasic could help a little bit with checking the examples. I would like to create some templates for further projects.

Are there logical errors in the structure of the examples?
Are there places where I could use built-in functions of Oxygenbasic?
For some examples I used $/inc/FileDialog.inc. Maybe there are other include files which could also be used?

Roland

.

Aurel

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #1 on: April 02, 2014, 09:10:48 AM »
Quote
Maybe there are other include files which could also be used?
If you whish you can try mine awinh.inc include file which is mostly oriented to
win32 GUI functions.
Here is minimum code for GUI program in Oxygen Basic with awinh.inc .

Code: [Select]
$ Filename "skeleton.exe" ' Oxygen Basic
include "RTL32.inc"
include "awinh.inc"
INT win,x=0,y=0,w=400,h=300,wstyle = WS_MINMAXSIZE
win=SetWindow("Skeleton GUI App...",x,y,w,h,0,wstyle)
Wait()  'message loop
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback
SELECT hwnd
CASE win
Select wmsg
CASE WM_CLOSE
CloseWindow(win)
EndProgram
End Select
END SELECT
RETURN Default
END FUNCTION

.
« Last Edit: April 02, 2014, 09:18:45 AM by Aurel »

Arnold

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #2 on: April 04, 2014, 05:51:03 PM »
Hi Aurel,

sorry for the delayed answer. I had to take care for some other duties.

I already use a libray in another language. I can do a lot of nice things with it, but at some time there is a limit. Therefore I want to start it at a lower level, and Oxygenbasic seems to be the right tool for this purpose.

As the aspect of using resource dlls is new for me too, I sat down and started a little project. What is your code for this little (nonsense) app. This is mine:

Code: [Select]

$ filename "controls.exe"

includepath "$/inc/"

'#include "RTL32.inc"
'#include "RTL64.inc"

#include "MinWin.inc"

includepath ""
#include "res/resource.h"

s = error()

if s then
  print s
  end
end if


'=======================
'MAIN CODE
'=======================
 
dim nCmdline as asciiz ptr, hInstance as sys
&nCmdline = GetCommandLine
hInstance = GetModuleHandle(0)

'========================================'

% IMAGE_BITMAP = 0
% PBM_SETPOS = 1026
% SB_SETPARTS = 1028
% SB_SETTEXT = 1025
% SBARS_SIZEGRIP = 256
% TB_ADDBITMAP = 1043
% TB_ADDBUTTONS = 1044
% TB_BUTTONSTRUCTSIZE = 1054
% TBSTATE_ENABLED = 4
% TBSTYLE_BUTTON = 0
% STATUSCLASSNAME = "msctls_statusbar32"
% TOOLBARCLASSNAME = "ToolbarWindow32"

type TBADDBITMAP
  sys     hInst
  sys     nID
end type

type TBBUTTON
  int       iBitmap
  int       idCommand
  BYTE      fsState
  BYTE      fsStyle
  BYTE      bReserved[2]
  dword     dwData
  int       iString
end type

! GetDlgItem lib "user32.dll" alias "GetDlgItem" (sys hDlg, nIDDlgItem) as sys
! InitCommonControls lib "comctl32.dll" alias "InitCommonControls" ()
! LoadMenu lib "user32.dll" alias "LoadMenuA"(sys hInstance, sys lpMenuName) as sys

function DialogBox(sys hInstance, lpTemplate, hWndParent, lpDialogFunc) as sys
    return DialogBoxParam(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0)
end function

InitCommonControls()

sys hResources = loadlibrary "controls.dll"
if not hResources then print "Error: controls.dll not found"


function DlgProc(sys hwnd, Message, wParam, lParam) as bool callback

switch Message

case WM_INITDIALOG
// This is where we set up the dialog box, and initialise any default values
           

            hMenu=LoadMenu(hResources, IDR_MAINMENU)
            SetMenu(hwnd, hMenu)
           
            TBADDBITMAP tbab
            TBBUTTON tbb[14]

            hToolBar = CreateWindowEx( 0, TOOLBARCLASSNAME,
            NULL,
            WS_CHILD or WS_VISIBLE, 0, 0, 0, 0,
            hWnd,
            IDC_TBR1,
            hResources, NULL )
           
if hToolBar = NULL then
MessageBox(hwnd, "Could not create tool bar.", "Error", MB_OK or MB_ICONERROR)
            end if

            sys hToolBitmap = LoadImage( hResources, ID_TBBmp, IMAGE_BITMAP, 0, 0, 0 )
            if not hToolBitmap then
                Messagebox(hWnd, "Load Bitmap Failed!","Error!",0 )
            end if 

            // Send the TB_BUTTONSTRUCTSIZE message, which is required for
            // backward compatibility.
            SendMessage( hToolBar, TB_BUTTONSTRUCTSIZE, sizeOf(TBBUTTON), 0 )

            tbab.hInst = NULL
            tbab.nID = hToolBitmap
         
            SendMessage(hToolBar, TB_ADDBITMAP, 14, &tbab)

            for x=1 to 14         
            tbb[x].iBitmap   = x-1
            tbb[x].fsState = TBSTATE_ENABLED
            tbb[x].fsStyle = TBSTYLE_BUTTON
            next x

            SendMessage( hToolBar, TB_ADDBUTTONS, spanof(tbb), &tbb )

// Create Status bar

    sys hStatus
int statwidths[] = {100, -1}           

hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
WS_CHILD or WS_VISIBLE or SBARS_SIZEGRIP, 0, 0, 0, 0,
hwnd, IDC_SBR1, GetModuleHandle(NULL), NULL)     

SendMessage(hStatus, SB_SETPARTS, 2, &statwidths)
SendMessage(hStatus, SB_SETTEXT, 0, "Hi there :)")           

           
case WM_COMMAND
switch loword(wParam)

                case IDC_StartButton
                    hProgress = GetDlgItem(hwnd, IDC_Progressbar)               
                    for x = 1 to 100
                        SendMessage(hProgress, PBM_SETPOS, x, 0)
                        Sleep(20)
                    next x       
                    Sleep(1000)
                    SendMessage(hProgress, PBM_SETPOS, 0, 0)                 

case IDM_Close
EndDialog(hwnd, 0)
               
                case IDC_CloseButton
                EndDialog(hwnd, 0)
               
                case IDM_About
                MessageBox(hwnd, "Tiny Application" + chr(13) + "Does nothing!",
                                    "About Tiny Application", MB_OK)

end switch

case WM_CLOSE
EndDialog(hwnd, 0)

case else
return FALSE

    end switch

    return TRUE
end function

function WinMain(sys nCmdShow) as sys

return DialogBox(hResources, IDD_DLG1, NULL, @DlgProc)
end function

'WINDOWS START
'=============
'
WinMain(SW_NORMAL)



This app does not much. It shows a Menu, a Toolbar, some controls. You can start a Progressbar, close the app via menu or button. I was not in the mood for handling the toolbar. And this should be enough for about 90 lines of code.

In my opinion the problem is not to create the many controls which exist, but the day after. If I should manage some of the many messages and notifications some day I would be happy. Maybe I should continue reading Petzold's book.

Roland



.

JRS

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #3 on: April 04, 2014, 08:02:32 PM »
Hi Roland,

Quote
As the aspect of using resource dlls is new for me too, I sat down and started a little project.

Is using standard control theming in your O2 resource plans?

Example



Mike Lobanovsky

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #4 on: April 04, 2014, 08:45:59 PM »
Hehe John,

I was about to ask the same question a few minutes before you published yours but then I deleted my message. :)

In Windows, a (theming) manifest can be either precompiled into the binary (dll or exe) directly or saved as a standalone file under the same name plus the .manifest extension (say, mybinary.dll.manifest) in the folder together with the binary to exactly the same effect.

I guess doing either of these manually for a small test-case library (unless the compiler does it for you automatically) would be just an extra PITA. :)

Aurel

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #5 on: April 04, 2014, 11:06:19 PM »
Hi Arnold

-What is your code for this little (nonsense) app. This is mine?

First of all ,i don't use DIALOG type of windows forms
because they have special purpose.
Second i don't use this way of application structure which
means put everything in functions.
I prefer to hold my GUI functions inside include file.
And if you look into ASciEdit2 source code you will see how i create controls. ;)
« Last Edit: April 04, 2014, 11:25:49 PM by Aurel »

Arnold

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #6 on: April 05, 2014, 01:45:20 AM »
Hi John,

your example looks very nice. Was it done with ScriptBasic?

BTW I do not want to compete with anyone or anything.  My capabilities would be too much limited. All I would like to do is learning a little bit more about doing some things in Windows using Oxygenbasic.

Roland

Aurel

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #7 on: April 05, 2014, 02:05:33 AM »
Arnold
This thing what John presented here is GUI program created with IUP gui framework.
And there is no competition between some thirdParty gui-s with native winApi
which is a full-powered GUI system for Windows.
Anyway you can create GUI programs in Oxygen on many ways using native winApi
or using some other alternatives like is iup,wx,..etc
Oxygen is a great tool to lern how things work on low-level .
In my include i use few methods for creating functions and some are modified versions
of VB functions and some not.
« Last Edit: April 05, 2014, 12:20:34 PM by Aurel »

JRS

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #8 on: April 05, 2014, 10:44:02 AM »
Charles,

I was going to point Roland to the ProjectB\IUP folder for examples of using IUP with O2. I get this error dialog with each example I try in that folder.



Would that Hex2Bin.sb example be toying with the idea of using SB as an assembler?
« Last Edit: April 05, 2014, 11:01:49 AM by John »

Charles Pegge

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #9 on: April 05, 2014, 08:48:18 PM »
Hi John,

This is bust  (in iup.h), and so is my brain!

typedef int (*Icallback)(Ihandle*);

But this works:

typedef sys Icallback

JRS

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #10 on: April 05, 2014, 08:56:15 PM »
Can this be handled with a #ifdef so the iup.h can be used with C or O2?

Charles Pegge

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #11 on: April 06, 2014, 12:57:59 AM »

It will be fixed on the next update.

JRS

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #12 on: April 06, 2014, 06:31:48 AM »
typedef int (*Icallback)(Ihandle*);

The biggest problem with C is its short circuit syntax rules that make it unparsable to anything other than the compilers that allow it.


Charles Pegge

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #13 on: April 06, 2014, 08:08:08 PM »
typedef int (*Icallback)(Ihandle*);

I think void* would be less problematic. Ther is no advantage in being so specific.

Also:  Int is not correct for 64 bit systems, since a function pointer is returned.

This would simplify the IUP headers:

typedef void *handle, *pCallback;

oxygen:

typedef sys handle, pCallback

JRS

  • Guest
Re: theForger's Win32 Api tutorial in Oxygenbasic
« Reply #14 on: April 06, 2014, 09:56:54 PM »
Quote
This would simplify the IUP headers:

typedef void *handle, *pCallback;

This worked for me.

Code: [Select]
// typedef int (*Icallback)(Ihandle*);
typedef void *Icallback, *Ihandle;