PDA

View Full Version : use bmps in labels



sandyrepope
06-08-2007, 05:56
I've been trying to understand how to use bmps in labels in my scripts. I'm just not getting it. Here is what I'm trying:


uses "UI"

dim hDlg AS long
dim Msg AS LONG
dim wParam AS LONG
dim lParam AS LONG
dim Width as long '---width
dim Height as long '---height
dim hImg1 AS DWORD
dim hImg2 AS DWORD
dim hImg3 AS DWORD
dim hImg4 AS DWORD

%Label_01 = 400
%Label_02 = 401
%Label_03 = 402
%Label_04 = 404
%IMAGE_BITMAP = 0
%LR_LOADFROMFILE = &H0010
%STM_SETIMAGE = &H172


dim BITMAP1 as string = App_SourcePath + "NEW.bmp"
dim BITMAP2 as string = App_SourcePath + "OPEN.bmp"
dim BITMAP3 as string = App_SourcePath + "SAVE.bmp"
dim BITMAP4 as string = App_SourcePath + "COPY.bmp"

DECLARE FUNCTION LoadImage LIB "USER32.DLL" ALIAS "LoadImageA" (BYVAL hInst AS DWORD, lpsz AS ASCIIZ, BYVAL uType AS DWORD, BYVAL cxDesired AS LONG, BYVAL cyDesired AS LONG, BYVAL fuLoad AS DWORD) AS DWORD

Width = 150
Height = 135

DIALOG NEW 0, "Toolbar example", -1, -1, Width, Height, _
%WS_DLGFRAME _
OR %DS_CENTER _
OR %WS_CAPTION _
OR %WS_SYSMENU _
OR %WS_OVERLAPPEDWINDOW _
OR 0 TO hDlg

control add label, hDlg, %Label_01, "1", 0, 0, 16, 16, %ss_notify or %SS_ETCHEDFRAME OR %SS_CENTERIMAGE
hImg1 = LoadImage ( %NULL, BITMAP1, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
CONTROL SEND hDlg, %Label_01, %STM_SETIMAGE, %IMAGE_BITMAP, hImg1
control redraw hDlg, %Label_01


control add label, hDlg, %Label_02, "2", 16, 0, 16, 16, %ss_notify or %SS_ETCHEDFRAME OR %SS_CENTERIMAGE
hImg2 = LoadImage ( %NULL, BITMAP2, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
CONTROL SEND hDlg, %Label_02, %STM_SETIMAGE, %IMAGE_BITMAP, hImg2
control redraw hDlg, %Label_02


control add label, hDlg, %Label_03, "3", 32, 0, 16, 16, %ss_notify or %SS_ETCHEDFRAME OR %SS_CENTERIMAGE
hImg3 = LoadImage ( %NULL, BITMAP3, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
CONTROL SEND hDlg, %Label_03, %STM_SETIMAGE, %IMAGE_BITMAP, hImg3
control redraw hDlg, %Label_03


control add label, hDlg, %Label_04, "4", 48, 0, 16, 16, %ss_notify or %SS_ETCHEDFRAME OR %SS_CENTERIMAGE
hImg4 = LoadImage ( %NULL, BITMAP4, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
CONTROL SEND hDlg, %Label_04, %STM_SETIMAGE, %IMAGE_BITMAP, hImg4
control redraw hDlg, %Label_04


' ** Display the dialog
DIALOG SHOW modeless hDlg

WHILE IsWindow(hDlg)
'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)


'---Now test the message
SELECT CASE Msg

case %WM_COMMAND
'---Test which control has been clicked
SELECT CASE lowrd(wParam)

case %Label_01
select case HIwrd(wParam)
case %CBN_SELCHANGE
msgbox 0, "You clicked the NEW button"
end select
'---Something has happened with %Combo02
case %Label_02
select case HIwrd(wParam)
case %CBN_SELCHANGE
msgbox 0, "You clicked the OPEN button"
end select
CASE %Label_03
SELECT CASE HIWRD(wParam)
case %CBN_SELCHANGE
msgbox 0, "You clicked the SAVE button"
end select
CASE %Label_04
SELECT CASE HIWRD(wParam)
case %CBN_SELCHANGE
msgbox 0, "You clicked the COPY button"
end select
end select
CASE %WM_SYSCOMMAND
select case wParam
CASE %SC_CLOSE
EXIT WHILE
end select
end select
wend

DIALOG END hDlg


Everything works except for the bmps. They just won't show in the labels. There are a few things that I don't understand in the script.

Can someone help me with this?

Thanks
Sandy

Petr Schreiber
06-08-2007, 09:08
Hi,

I am little bit confused how it should be done so here is my approach.
Still a bit problematic ( control is sometimes not drawn properly ). It seems important is to use %SS_BITMAP style.

But it contains few important modifications - using %STN_CLICKED to capture click on control and deleting the resources on the end.

But there must be better and more reliable way...



uses "UI"

dim hDlg AS long
dim Msg AS LONG
dim wParam AS LONG
dim lParam AS LONG
dim Width as long '---width
dim Height as long '---height
dim hImg1 AS DWORD
dim hImg2 AS DWORD
dim hImg3 AS DWORD
dim hImg4 AS DWORD

%Label_01 = 400
%Label_02 = 401
%Label_03 = 402
%Label_04 = 404
%IMAGE_BITMAP = 0
%LR_LOADFROMFILE = &H0010
%STM_SETIMAGE = &H172

dim BITMAP1 as string = App_SourcePath + "NEW.bmp"
dim BITMAP2 as string = App_SourcePath + "OPEN.bmp"
dim BITMAP3 as string = App_SourcePath + "SAVE.bmp"
dim BITMAP4 as string = App_SourcePath + "COPY.bmp"

DECLARE FUNCTION LoadImage LIB "USER32.DLL" ALIAS "LoadImageA" (BYVAL hInst AS DWORD, lpsz AS ASCIIZ, BYVAL uType AS DWORD, BYVAL cxDesired AS LONG, BYVAL cyDesired AS LONG, BYVAL fuLoad AS DWORD) AS DWORD

Width = 150
Height = 135

DIALOG NEW 0, "Toolbar example", -1, -1, Width, Height, _
%WS_DLGFRAME _
OR %DS_CENTER _
OR %WS_CAPTION _
OR %WS_SYSMENU _
OR %WS_OVERLAPPEDWINDOW _
OR 0 TO hDlg

control add label, hDlg, %Label_01, "", 0, 0, 16, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP OR %SS_SUNKEN or %SS_NOTIFY
hImg1 = LoadImage ( %NULL, BITMAP1, %IMAGE_BITMAP, 16, 16, %LR_LOADFROMFILE)


control add label, hDlg, %Label_02, "2", 16, 0, 16, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP OR %SS_SUNKEN or %SS_NOTIFY
hImg2 = LoadImage ( %NULL, BITMAP2, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)


control add label, hDlg, %Label_03, "3", 32, 0, 16, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP OR %SS_SUNKEN or %SS_NOTIFY
hImg3 = LoadImage ( %NULL, BITMAP3, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)


control add label, hDlg, %Label_04, "4", 48, 0, 16, 16, %WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP OR %SS_SUNKEN or %SS_NOTIFY
hImg4 = LoadImage ( %NULL, BITMAP4, %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)

' ** Display the dialog
DIALOG SHOW modeless hDlg
%STN_CLICKED = 0
WHILE IsWindow(hDlg)
'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)


'---Now test the message
SELECT CASE Msg
case %WM_INITDIALOG
CONTROL send hDlg, %Label_01, %STM_SETIMAGE, %IMAGE_BITMAP, hImg1
control redraw hDlg, %Label_01

CONTROL send hDlg, %Label_02, %STM_SETIMAGE, %IMAGE_BITMAP, hImg2
control redraw hDlg, %Label_02

CONTROL send hDlg, %Label_03, %STM_SETIMAGE, %IMAGE_BITMAP, hImg3
control redraw hDlg, %Label_03

CONTROL send hDlg, %Label_04, %STM_SETIMAGE, %IMAGE_BITMAP, hImg4
control redraw hDlg, %Label_04


case %WM_COMMAND
'---Test which control has been clicked
SELECT CASE lowrd(wParam)

case %Label_01
select case HIwrd(wParam)
case %STN_CLICKED
msgbox 0, "You clicked the NEW button"
end select
'---Something has happened with %Combo02
case %Label_02
select case HIwrd(wParam)
case %STN_CLICKED
msgbox 0, "You clicked the OPEN button"
end select
CASE %Label_03
SELECT CASE HIWRD(wParam)
case %STN_CLICKED
msgbox 0, "You clicked the SAVE button"
end select
CASE %Label_04
SELECT CASE HIWRD(wParam)
case %STN_CLICKED
msgbox 0, "You clicked the COPY button"
end select
end select

CASE %WM_SYSCOMMAND
select case wParam
CASE %SC_CLOSE
EXIT WHILE
end select
end select
wend

DIALOG END hDlg

' -- Release resources
DeleteObject(hImg1)
DeleteObject(hImg2)
DeleteObject(hImg3)
DeleteObject(hImg4)

kryton9
06-08-2007, 11:28
A good question and nice answer Petr. That was a tough one.

sandyrepope
06-08-2007, 15:50
Thanks, Petr, your changes are a real improvement. It works better than mine did. I'll keep trying to find out why it doesn't always draw all the controls. I wouldn't have gotten so far without your help.

Thanks
Sandy

ErosOlmi
06-08-2007, 18:30
Hi Sandy,

do not struggle too much with toolbar because I think I've found a way to use standard windows toolbar.
I think to be able to post source code and changed dll by tomorrow.

Ciao
Eros

PS: I've tried to fix your and Petr code but seems the only way is to go too deeper into windows message pump and this will consume a lot of time of script just for redrawing the label. In any case I will investigate more.

ErosOlmi
06-08-2007, 19:21
Hi Sandy,

I had some spare time to create and pack a zip file with a Toolbar example that should be easy to update following your needs.
For the moment do not care about the 2 include files, just keep with the main code. I'm implementing some standard declaration files for future thinBasic releases.

Please move thinBasic_UI.dll into \thinBasic\Lib\ directory replacing the one you have.

Let me know.
Eros

PS: I'm still finalize some aspects and understand how to simply add new features. So expect new posts on this.
For example: how to change images (current one are taken from standard window common controls), how to use litle icons, how to group commands, activate, deactivate icons, ...


ADDED: attachement removed due to solution already present in thinBasic preview release 1.4.0.1 under \thinBasic\Samplescripts\UI\Toolbar\ directory after instalaltion.

kryton9
06-08-2007, 22:57
That is nice Eros and will be really cool when you add the features you mention. Thanks!