Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Showing bitmaps or Icons
Showing bitmaps or Icons [message #117] |
Sat, 26 November 2005 08:55  |
gprentice
Messages: 260 Registered: November 2005 Location: New Zealand
|
Experienced Member |
|
|
Where would I look for info on how to load and show a .bmp bitmap file or an icon (given an icon handle HICON on Win32) and then get mouse events (mouse move, mouse click) for this image?
Second question : if there's a short answer, any hints on how to do this?
e.g. suppose I want a customised checkbox - I create two bitmaps (checked and unchecked) that I want to switch when the image is clicked.
Last question : I recall mention of a grid component created by Daniel. Is this part of UPP? If not, it's ok. Just wondering.
Graeme
|
|
|
|
|
|
Re: Showing bitmaps or Icons [message #1803 is a reply to message #127] |
Mon, 20 March 2006 07:45   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
Why this doesn't work?
#include <CtrlLib/CtrlLib.h>
GUI_APP_MAIN
{ TopWindow w;
Label l;
Image img;
w.Add(l);
l.SetPos(l.PosLeft(0, 100), l.PosTop(0, 30));
img = BmpEncoder::NewBmp()->LoadImage("testImg.bmp");
//img.Exclamation(); //at least this should work?
l.SetImage(img);
w.Run();
}
And how to check if image was loaded?
[Updated on: Mon, 20 March 2006 07:45] Report message to a moderator
|
|
|
|
Re: Showing bitmaps or Icons [message #1813 is a reply to message #1806] |
Mon, 20 March 2006 14:27   |
 |
fudadmin
Messages: 1321 Registered: November 2005 Location: Kaunas, Lithuania
|
Ultimate Contributor Administrator |
|
|
luzr wrote on Mon, 20 March 2006 08:12 |
fudadmin wrote on Mon, 20 March 2006 01:45 | Why this doesn't work?
#include <CtrlLib/CtrlLib.h>
GUI_APP_MAIN
{ TopWindow w;
Label l;
Image img;
w.Add(l);
l.SetPos(l.PosLeft(0, 100), l.PosTop(0, 30));
img = BmpEncoder::NewBmp()->LoadImage("testImg.bmp");
//img.Exclamation(); //at least this should work?
l.SetImage(img);
w.Run();
}
And how to check if image was loaded?
|
Are you sure that path is correct? (Well, there is no path, so it likely is not).
If it was not loaded, result will be empty (e.g. GetSize() == Size(0, 0))
Mirek
|
Are you sure that you know Ultimate++?... 
The image loading works this way:
GUI_APP_MAIN
{
TopWindow w;
Label l1,l2;
Image img1,img2;
w.Add(l1);
l1.SetPos(l1.PosLeft(10, 100), l1.PosTop(10, 30));
img1= PngEncoder::New()->LoadImageFile("testImg.png");
l1.SetImage(img1);
w.Add(l2);
img2 = BmpEncoder::NewBmp()->LoadImageFile("testImg.bmp");
l2.SetImage(img2);
l2.SetPos(l2.PosLeft(150, 100), l2.PosTop(10, 30));
w.Run();
}
[Updated on: Mon, 20 March 2006 14:28] Report message to a moderator
|
|
|
|
Re: Showing bitmaps or Icons [message #2502 is a reply to message #117] |
Sat, 15 April 2006 13:20   |
gprentice
Messages: 260 Registered: November 2005 Location: New Zealand
|
Experienced Member |
|
|
Is the code below valid - it seems to work?
gp1 is the name of a bitmap in an .iml file, just like Smiley() in the reference/iml example. What does img1 = gp1() do - does img1 store a copy of the bitmap?
GUI_APP_MAIN
{
App w;
Label l1;
Image img1;
w.Add(l1);
l1.SetPos(l1.PosLeft(10, 100), l1.PosTop(10, 30));
img1= gp1();
l1.SetImage(img1);
w.Run();
}
In the iml example there is
w.DrawImage((sz.cx - isz.cx) / 2, (sz.cy - isz.cy) / 2, Smiley());
What does "Smiley()" do here - does it get the "address" of the Smiley bitmap that has been embedded in the app due to the iml file being part of the project?
Graeme
BTW - in the reference/events example, the Log("Paint") in the Paint function causes continuous events ... I can't remember if this was originally a commented line and I uncommented it myself or not.
[Updated on: Sun, 16 April 2006 11:35] Report message to a moderator
|
|
|
Re: Showing bitmaps or Icons [message #2550 is a reply to message #2502] |
Mon, 17 April 2006 18:52  |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
Quote: |
gp1 is the name of a bitmap in an .iml file, just like Smiley() in the reference/iml example. What does img1 = gp1() do - does img1 store a copy of the bitmap?
|
Think about Image as of any other "value" type like "int", "Date" or "String". Copies are full and cheap (internally there is reference counting mechanism, but that is nothing you should bother you).
Now "Smiley()" is the Image you have designed and stored in .iml - it is Image constant. In fact, in ideal world, its definition would be (in header)
extern Image Smiley;
However, there are two problems with this:
- first, certain platforms (namely Win32) do not support global variables in .dll (not that we are using .dlls all that often, but it is better to be ready).
- second, global variables in C++ has unpleasant problem of "initialization" order. In practice, in constructor of global variable you are never sure which other global variables are already constructed (unless they are in the same .cpp file).
Therefore, instead of global variable, we are (quite often) using "functional constants". E.g.
const Image& Smiley();
This solves both problems.
Mirek
|
|
|
Goto Forum:
Current Time: Fri May 09 08:49:23 CEST 2025
Total time taken to generate the page: 0.00582 seconds
|