View Full Version : dialog background
sandyrepope
13-01-2008, 22:33
Is there a way to put a background picture (read .bmp) in a dialog so that the controls will always remain visible?
It's not really important. I'd just like to know. I'm not sure if my question is clear or not.
Thanks
Sandy
ErosOlmi
14-01-2008, 01:13
Sandy,
there is no a direct way already implemented but this request is a great "excuse" for me to think how to do.
Anyhow, Petr some times ago, did the following example. Mainly it creates a static control (LABEL) with the same size of the dialog client area. Than assign a bitmap to its background simulating to be the dialog background. Problem is that sometimes it fails to load. Anyhow, check by yourself.
Attached the code.
Ciao
Eros
sandyrepope
14-01-2008, 02:40
I've tried using that example but as you have said 'sometimes it fails to load'.
Lately I've been trying to use list view and it always loads the image. My problem is keeping all the controls on top of it.
A friend of mine wants to use my monthly calendar but he wants it to have a background picture. I told him that I would see if I could do it. Right now, some of the controls don't show up at the start because they are behind the list view. When the window is maximized the list view is put in front of everything and none of the controls show. It seems that labels especially tend to hide this way.
If I can solve this problem I'll post my solution.
Thanks
Sandy
ErosOlmi
14-01-2008, 03:51
Sandy,
I think I've got it but I need another 1/2 days to finish other ongoing new features I was adding for new preview version to be ready.
Just one line of code will be enough. New command will be:
DIALOG SET IMAGE hDlg, BMPFileName
Dialog will be resizable and background image will adjust automatically.
I will let you know.
Eros
catventure
14-01-2008, 12:07
DIALOG SET IMAGE hDlg, BMPFileName
Dialog will be resizable and background image will adjust automatically.
That sounds utterly brilliant. I hope can be done :)
catventure
ErosOlmi
14-01-2008, 12:38
Yes, it seems working fine thanks to the help of José Roca (as usual) in its forum: http://www.jose.it-berater.org
I asked there about setting background image in dialogs because my tests had too much flickering when dialog was resizing.
It seems that handling %WM_ERASEBKGND is the trick. I'm integrating it in thinBasic personalized message pump.
Ciao
Eros
ErosOlmi
14-01-2008, 13:20
Attention: working only with current online thinBasic version 1.6.0.x
Attached what I've been able to do so far.
Put thinBasic_UI.dll in \thinBasic\Lib directory and replace your current one.
Put thinBasic script and background image into a new directory and execute script.
I've still to test some aspects like resetting the background image to a new one on the fly clearing previous image and other aspects like that.
Tested also under Win9x OS.
Let me know.
Eros
Updates:
1. attached thinBasic_UI.dll updated. Client area not refreshed when dialog has no background image.
2. attached thinBasic_UI.dll updated, sample updated. Now UI module support multiple fire of DIALOG SET IMAGE. You can change background image on the fly. Previous allocated resources are released automatically
3. attached file updated: solved problem preventing background image repaint after some %WM_SIZE events fired
Updates 2008.01.15:
attached file updated: added Stretced or Tiled image mode
attached file updated: added WindowResize mode
Attached file removed. Functionality now present into thinBasic preview version 1.6.0.1
catventure
14-01-2008, 20:33
Very nice Eros!
Seems to work OK on mine (Vista)
Bmp disappears *sometimes* when resizing - I think when goes below dialog set minsize? Anyhow, a mouse click usually restores it...
Looking very promising indeed.
catventure
Michael Hartlef
14-01-2008, 21:09
Same here. Sometimes, during a resize (not even minimizing) the image dissapears complete or sometimes partially.
ErosOlmi
14-01-2008, 21:21
Thanks a lot. I'm working on it .
ErosOlmi
14-01-2008, 22:49
I think I've solved problems regarding stop repainting of the background image.
Please download module and example again from above post
Let me know.
Eros
catventure
14-01-2008, 23:28
Hi Eros,
I think I've solved problems regarding stop repainting of the background image.
I'm pleased to report it all seems to work fine now! :) :)
catventure
That is so cool. It is working perfectly... I tried to resize in crazy ways and it always worked. Very nice background images too, very cheerful!
Petr, when you are done with tough week at school, perhaps you can tap into what Eros has done and offer tbgl screen as background. Then we can develop tools in thinBasic using tbgl and windows controls. I did this playing around with Delphi I think or was it c++... so it is doable. For making tools it is more than adequate performance.
Let me know what you think.
ErosOlmi
14-01-2008, 23:47
Thanks a lot to all for testing.
Things are starting to go into the right place. I will double check again the code in next days before making an official release.
Ciao
Eros
Petr Schreiber
15-01-2008, 15:09
Hi,
I could not test as I was a bit busy, works great on my PC, except of little artifacts when resizing image to smaller one.
But it can be graphic driver problem. It does kind of edge detection :)
As nobody reported this, I think it is my PC only again :), and I will use only fixed size BMP dialogs, where no problem at all. When making dialog bigger, no artifacts. Generally the refresh of image is very good!
Kent, great idea, but cannot say now when it will become reality.
Catventure, nice avatar :)
Bye,
Petr
ErosOlmi
15-01-2008, 23:32
Petr,
I think it depends on the image used. In some cases StretchBlt (http://msdn2.microsoft.com/en-us/library/ms532355.aspx) function seems inserting black pixels. I do not know if there is a solution but I will check.
In the meantime I've changed DIALOG SET IMAGE sintax. Now you can decide if image has to be Stretced or Tiled.
Download again example from http://community.thinbasic.com/index.php?topic=1449.msg10326#msg10326 and see.
Ciao
Eros
Petr Schreiber
15-01-2008, 23:48
Hi Eros,
good great idea!
I think the default stretch mode will be good for not resizable dialogs, and tileable for the rest. I can imagine with some well repeating texture it will look very very nice!
Thanks a lot,
Petr
P.S. Where did you get the testing images :) ?
ErosOlmi
15-01-2008, 23:54
Google images! What else? ;D
http://images.google.com/images?hl=en&q=background
http://www.kantor.com/blog/2006/01/wallpaper/
I'm trying to do also the following modes: CenterImage, WindowSizeToImageSize, StretchedProportional.
But it takes to much time. Maybe in future releases.
Ciao
Eros
ErosOlmi
16-01-2008, 01:39
I've changed DIALOG SET IMAGE again. Added WinResize mode. In this mode dialog client area will be automatically resized to the image size
Download again example from http://community.thinbasic.com/index.php?topic=1449.msg10326#msg10326
Ciao
Eros
sandyrepope
16-01-2008, 02:57
I've been playing around with the example script and I've noticed that once in a while a bmp won't display very well. I think I've tracked down the reason. It has something to do with the dpi of the bmp. I don't know what a dpi is but I've noticed that the higher the dpi of a bit map image the better it diaplays.
What is a dpi?
Thanks
Sandy
catventure
16-01-2008, 05:04
Hi Eros,
Works OK on mine.
catventure
Petr Schreiber
16-01-2008, 10:06
Hi Eros,
works ok here too!
Sandy, dpi is "dots per inch". I think it is how many pixels of the image will fit in one inch ( 2.54 cm ).
Thanks,
Petr
ErosOlmi
16-01-2008, 11:46
Sandy,
for those kind of info I've found that WikiPedia is great.
Here Wikipedia info about DPI.
In any case, when background images are stretched into the client area, if resolution is not enought, some weird approximation will take place. It is very similar about enlarging a digital image taken from a digital camera having very low Pixel resolution. When enlarged, it will be distorted and single pixels errors will be magnified. While if image is at high resolution, it will not suffer too much when enlarged but it will suffer a bit when reduced non proportionally (like when stretched in client dialog).
If you plan to have background images in your window, best solution is to have an image at least with the same width/height of the window size in order to show it at 1:1 size.
Ciao
Eros