1. Open BMP Dialog
- Posted by Kenneth E. Bernhardt <klmax at nnex.net>
Mar 06, 2007
-
Last edited Mar 07, 2007
Hi,
I am Very new to Euphoria. In the IDE,I am trying a simple test window with
one button and a BMP control. The button opens a 'OPEN Dialog'. How do I use
the Dialog to open the selected BMP and see it in the BMP control?
I really need all the code because I do not understand how these Dialogs are
to be used.
Thank You,
2. Re: Open BMP Dialog
- Posted by c.k.lester <euphoric at cklester.com>
Mar 06, 2007
-
Last edited Mar 07, 2007
Kenneth E. Bernhardt wrote:
>
> How do I use the Dialog to open the selected BMP and
> see it in the BMP control?
Kenneth, have a look at the Win32Lib\Demo folder. It has a few files in there
that show how to load and display and manipulate bitmaps.
If you have any specific questions, ask again. :)
3. Re: Open BMP Dialog
Kenneth E. Bernhardt wrote:
>
>
> Hi,
> I am Very new to Euphoria. In the IDE,I am trying a simple test window with
>
> one button and a BMP control. The button opens a 'OPEN Dialog'. How do I use
>
> the Dialog to open the selected BMP and see it in the BMP control?
>
> I really need all the code because I do not understand how these Dialogs are
>
> to be used.
>
> Thank You,
Ken,
Here's something that may be the start of what you want; it invokes the open
dialog, & then puts the resultant file name into a label. Then what you'd
want to do is to put the bitmap into a window. An example of how you might
do that follows after this first example. (ps. I found both of these by
using "RunDemos.exw", which can be found in the Demos folder for Win32Lib.)
Dan Moyer
include win32lib.ew
without warning
constant
Main = create( Window, "Main", 0, Default, Default, 500, 500, 0),
Name = create( LText, "", Main, 5,5, 470, 35, SS_NOPREFIX)
procedure main_open(integer void1, integer void2, sequence null)
object x
x = getOpenFileName(Main,"",{})
if sequence(x) then
setText(Name, x)
end if
end procedure
setHandler(Main,{w32HActivate, w32HClick},routine_id("main_open"))
WinMain(Main,Normal)
And this following example, as it states, shows some bitmaps in a window.
It does more than you need, & seems complex, so maybe I'll look for easier
examples. But at least it gives you some idea of how to proceed.
Dan
-- example16.exw
-- Display Bitmaps In Window
include win32lib.ew
without warning
without trace
VOID = setSearchPaths("..\\demoresources\\")
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-- controls
integer MyWindow
integer MyButton
integer btnStyle
integer vImgBuffer
atom vBitmapHandle
integer vNextBitmap
sequence vBitmapNames
integer vTiling
vTiling = w32True
with trace
-----------------------------------------------------------------------
procedure onPaint_MyWindow(integer self, integer event, sequence parms)
-----------------------------------------------------------------------
sequence lExtent
sequence lBitmapSize
if vBitmapHandle = 0 then
return
end if
-- get the window size
lExtent = getClientSize( MyWindow )
lExtent = lExtent[3..4]
lBitmapSize = getCtlSize(vBitmapHandle)
if vTiling then
-- Adjust size of off-screen buffer
setCtlSize(vImgBuffer,lExtent[1], lExtent[2])
-- fill the off-screen buffer with the bitmap
for i = 0 to lExtent[1] by lBitmapSize[1] do
for j = 0 to lExtent[2] by lBitmapSize[2] do
drawBitmap( vImgBuffer, vBitmapHandle, i, j )
end for
end for
-- Copy the off-screen buffer to the real screen.
copyBlt(MyWindow, 0, 0, vImgBuffer)
else
-- Adjust size of off-screen buffer
setCtlSize(vImgBuffer,lBitmapSize[1], lBitmapSize[2])
drawBitmap(vImgBuffer, vBitmapHandle, 0, 0 )
stretchBlt(MyWindow,0,0, lExtent[1], lExtent[2],
vImgBuffer,0, 0,lBitmapSize[1], lBitmapSize[2],
SRCCOPY)
end if
end procedure
-----------------------------------------------------------------------
procedure btnClick(integer self, integer event, sequence parms)
-----------------------------------------------------------------------
vNextBitmap += 1
if vNextBitmap > length(vBitmapNames) then
vNextBitmap = 1
end if
if vBitmapHandle then
-- delete the old bitmap
deleteObject(vBitmapHandle)
end if
vBitmapHandle = loadBitmapFromFile(vBitmapNames[vNextBitmap])
repaintFG(MyWindow)
end procedure
-----------------------------------------------------------------------
procedure btnStyleClick(integer self, integer event, sequence parms)
-----------------------------------------------------------------------
if equal(getCaption(self), "&Tile") then
setText(self, "&Stretch")
vTiling = w32True
else
setText(self, "&Tile")
vTiling = w32False
end if
repaintFG(MyWindow)
end procedure
-----------------------------------------------------------------------
procedure resizing(integer self, integer event, sequence parms)
-----------------------------------------------------------------------
if not vTiling then
repaintFG(MyWindow)
end if
end procedure
-----------------------------------------------------------------------
procedure main()
-----------------------------------------------------------------------
sequence lTextDim
object lFileList
vNextBitmap = 0
vBitmapHandle = 0
vBitmapNames = {}
MyWindow =
create( Window, "Tiled Bitmap Test", 0, Default, Default, 320, 200, 0 )
MyButton =
create( PushButton, "&Change Background", MyWindow, 10, 10, 160, 30, 0 )
btnStyle =
create( PushButton, "&Stretch", MyWindow, 180, 10, 100, 30, 0 )
vImgBuffer = create(Pixmap, "", 0, 0, 0, 1, 1, 0)
-- Get a list of the bitmaps in the current folder
lFileList= dir("..\\demoresources\\*.bmp")
if sequence (lFileList) then
for i = 1 to length(lFileList) do
vBitmapNames = append(vBitmapNames, lFileList[i][D_NAME])
end for
end if
if length(vBitmapNames) = 0 then
setText(MyButton, "No Bitmaps")
setEnable({MyButton, btnStyle}, 0)
else
setHandler(MyButton, w32HClick, routine_id("btnClick"))
end if
setHandler(btnStyle, w32HClick, routine_id("btnStyleClick"))
-- Establish the handlers.
setHandler(MyWindow, w32HPaint, routine_id("onPaint_MyWindow"))
setHandler(MyWindow, w32HResize, routine_id("resizing"))
-- hand control over to Windows
WinMain( MyWindow, Normal )
end procedure
main()
4. Re: Open BMP Dialog
Ken,
Here's an easier example of putting a bitmap into a window, just use the
return from the open file dialog as the file name, I think:
-- ex16.exw
--
-- Display Bitmaps In Window
-- Change Control's Font
include win32lib.ew
without warning
-----------------------------------------------------------------------------
VOID = setSearchPaths("..\\demoresources\\")
-----------------------------------------------------------------------------
-- controls
createForm({
"Test Window, width=50%, height=50%",
"Button,OK, left=10, top=10, width=80, height=40," &
"font=(Times New Roman,10),tag=1"
})
-- load the bitmap
constant hBitmap = loadBitmapFromFile("java.bmp")-- <-- PUT OPEN DIALOG RETURN
HERE
-----------------------------------------------------------------------------
global procedure Paint_TestWindow( integer self, integer event, sequence parms)
sequence extent
sequence bmsize
-- get the window size
extent = getCtlSize( self )
bmsize = getCtlSize( hBitmap )
-- fill with the bitmap
for i = 0 to extent[1] by bmsize[1] do
for j = 0 to extent[2] by bmsize[2] do
drawBitmap( self, hBitmap, i, j )
end for
end for
end procedure
registerRoutine("Paint_TestWindow", routine_id("Paint_TestWindow"))
-----------------------------------------------------------------------------
global procedure Click_OK(integer self, integer event, sequence parms)
-- change the font
sequence lTag
lTag = getUserProperty(self, "Tag")
if lTag[1] then
setFont( self, "Times New Roman", 18, Bold+Italic )
else
setFont( self, "Times New Roman", 10, Normal )
end if
setUserProperty(self, "Tag", not lTag[1])
end procedure
registerRoutine("Click_OK", routine_id("Click_OK"))
include w32Start.ew
5. Re: Open BMP Dialog
Kenneth E. Bernhardt wrote:
>
>
> Hi,
> I am Very new to Euphoria. In the IDE,I am trying a simple test window with
>
> one button and a BMP control. The button opens a 'OPEN Dialog'. How do I use
>
> the Dialog to open the selected BMP and see it in the BMP control?
>
> I really need all the code because I do not understand how these Dialogs are
>
> to be used.
>
> Thank You,
Kenneth,
Here's a "quick" and dirty example that worked for me; I cut snippets from
various demos, including "Generic" from the demos folder.
The "OFN_ALLOWMULTISELECT" flag is not necessary & might be a problem,
and you could probably change the sizing portion to suit your needs:
Dan Moyer
-- code generated by Win32Lib IDE v0.20.1
include Win32Lib.ew
without warning
--------------------------------------------------------------------------------
-- Window Window1
constant Window1 = createEx( Window, "Window1", 0, Default, Default, 400, 300,
0, 0 )
constant PushButton2 = createEx( PushButton, "PushButton2", Window1, 72, 72, 88,
28, 0, 0 )
---------------------------------------------------------
--------------------------------------------------------------------------------
-- default file types the app recognizes
constant FileTypes = {
"dialog flags", {OFN_ALLOWMULTISELECT},
"bitmaps", "*.bmp"}
atom hBitmap
--------------------------------------------------------------------------------
procedure PushButton2_onClick (integer self, integer event, sequence
params)--params is ()
sequence extent
sequence bmsize
integer handle
sequence fName, buffer
object data
-- get the file name
fName = getOpenFileName( Window1, "", FileTypes )
-- entered a file name?
if length( fName ) = 0 then
return
end if
if sequence(fName[1]) then
fName = fName[1] & fName[2]
end if
-- open the file
-- handle = open( fName, "r" )
-- load the bitmap
hBitmap = loadBitmapFromFile(fName)
-- get the window size
extent = getCtlSize( Window1 )
bmsize = getCtlSize( hBitmap )
-- fill with the bitmap
for i = 0 to extent[1] by bmsize[1] do
for j = 0 to extent[2] by bmsize[2] do
drawBitmap( Window1, hBitmap, i, j )
end for
end for
end procedure
setHandler( PushButton2, w32HClick, routine_id("PushButton2_onClick"))
WinMain( Window1,Normal )