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:
$ 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
.