TWO DEMOS BY DAVID CONNER
lbdavid26@yahoo.com

Home

Liberty BASIC News
Safe Registry and Ini File Alternative
Deleting and Renaming Disk Files
Segments and Flushing
Flat Toolbar with Toolips
Translating 32-bit VB API Calls
Event-Driven Programming Concepts
Spotlight on the Community!
ODBC in Liberty BASIC
Hex Viewer
Listing Files Recursively
Registering Hot Keys
Preventing more than 1 instance
Multi-Coloured Text Input Boxes
Images on Buttons and Statictext
Two Demos by David Conner

Editor's note: These demos are not commented. If you have questions, please email the author at the address above. The first demo is a color previewer that allows the user to specify red, green and blue values. It then shows the resulting color in a preview box. Editor suggests that you trap errors if you implement this code in your own programs. If user doesn't enter values, the program crashes. Editor suggests that you fill the textboxes with a default value at the start of the program, and then check for valid values before attempting to fill the preview box. For instance, after opening the window:

print #1.t1, "255"

Then, when the preview button is clicked:

if val(red$)<0 the red$="0"
if val(red$)>255 then red$="255"

The second demo adds a cascading popup menu to an existing menu. For a full explanation of this method, please see newsletter #82, where such a menu was added to the Open Source Editor, with detailed instructions. The explanation is for LB2, which is 16-bit. Please look in the Open Source Editor, which is attached to this newsletter, for an update for LB3, 32-bit syntax.


' Custom Color Previewer
' ccp.bas
' -mailto: lbdavid26@yahoo.com

[init]
WindowWidth = 350 : WindowHeight = 200
UpperLeftX = int(DisplayWidth-WindowWidth)/2
UpperLeftY = int(DisplayHeight-WindowHeight)/2
nomainwin

[open]
graphicbox #1.g, 224,32,100,100
textbox #1.t1, 70,30,50,24
textbox #1.t2, 70,60,50,24
textbox #1.t3, 70,90,50,24
statictext #1.s1, "&Red (0-255)", 20,30,50,25
statictext #1.s2, "&Green (0-255)", 20,60,50,25
statictext #1.s3, "&Blue (0-255)", 20,90,50,25
button #1.b1, "Preview Color", [preview],LR,200,10
open "Custom Color Previewer" for window as #1
#1 "trapclose [quit]"

wait

[quit]
close #1: end

[preview]
#1.t1 "!contents? red$"
#1.t2 "!contents? green$"
#1.t3 "!contents? blue$"
#1.g "fill "; red$; " "; green$; " "; blue$
wait
'''''''''''''''''''''''''''''''''''''''''''''
'popupmenu2.bas

' A Cascading Popup Menu
' David Conner, Open Source

if val(Version$) < 3 then
notice "LB 3 or Higher"
end
end if

NoMainWin
WindowWidth = 300
WindowHeight = 150
UpperLeftX = int(DisplayWidth-WindowWidth)/2
UpperLeftY = int(DisplayHeight-WindowHeight)/2

open "user32" for dll as #user

menu #1, "&File",_
"&Exit", [quit],_
"Popup", [loop]

menu #1, "&Popup",_
"&Item 1", [1],_
"&Item 2", [2]

statictext #1.s, "Click on the File Menu to see", 10,30,250,24
statictext #1.s, "a Cascading Popup Menu", 10,50,250,24

open "Cascading Popup Example" for window_nf as #1

#1 "trapclose [quit]"
h = hwnd(#1)
calldll #user, "GetMenu", h as long, hMenu as long

calldll #user, "GetSubMenu",_
hMenu as long,_
0 as long,_
hFile as long

calldll #user, "GetSubMenu",_
hMenu as long,_
1 as long,_
hPopup as long

mFlags = _MF_BYPOSITION or _MF_POPUP or _MF_STRING

calldll #user, "ModifyMenuA",_
hFile as long,_
1 as long,_
mFlags as long,_
hPopup as long,_
"&Popup Menu" as ptr,_
result as long

calldll #user, "RemoveMenu",_
hMenu as long,_
1 as long,_
_MF_BYPOSITION as long,_
result as long

calldll #user, "DrawMenuBar",_
h as long,_
result as void

wait

[quit]
close #1:close #user:end

[loop]
wait

[1]
notice "You Selected Item 1"
wait

[2]
notice "You Selected Item 2"
wait
  

Home

Liberty BASIC News
Safe Registry and Ini File Alternative
Deleting and Renaming Disk Files
Segments and Flushing
Flat Toolbar with Toolips
Translating 32-bit VB API Calls
Event-Driven Programming Concepts
Spotlight on the Community!
ODBC in Liberty BASIC
Hex Viewer
Listing Files Recursively
Registering Hot Keys
Preventing more than 1 instance
Multi-Coloured Text Input Boxes
Images on Buttons and Statictext
Two Demos by David Conner