How to load a single .png? |
Post Reply |
Author | ||||
Michl
Senior Member Joined: 14 September 2007 Status: Offline Points: 138 |
Post Options
Thanks(0)
Posted: 17 October 2007 at 8:58am |
|||
Hello,
sample applications using SetIcons to load a set of .png icons.
But how to load only one icon?
Is it possible that SetIcon doesn't support ressources with name "png"?
My actual "workaround" ist to use SetIcons and set an array with one element.
But it is annoying to declare an additional array with various names.
|
||||
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
|||
Hi, yes this right code.
You don't need additional array - just modify command:
UINT command ;
command = ID_1; pButton->GetImageManager()->SetIcons( IDR_SYNCHRONIZE_ICON32, &command, 1, CSize(32, 32) );
command = ID_2; pButton->GetImageManager()->SetIcons( IDR_SYNCHRONIZE_ICON32, &command, 1, CSize(32, 32) );
etc |
||||
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
||||
Michl
Senior Member Joined: 14 September 2007 Status: Offline Points: 138 |
Post Options
Thanks(0)
|
|||
That's right
(thought too complicated )
But is there a reason why SetIcon doesn't support png ressources?
|
||||
Jayonas
Newbie Joined: 28 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
|
|||
ImageManager includes a SetIcon method that I've been using to successfully load single images (including PNGs).
You can also load them from files by using LoadBitmapFromFile instead of LoadBitmapFromResource. |
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
Hi,
I am new to Codejock so apologies for newbie type questions in advance. I tried the code you posted however the compiler had issues with the command variable and the value you assign to it ID_1, ID_2. Where is ID_1 defined? what is its value and what is its signifficance?.... Same goes for ID_2 Thanks. |
||||
Michl
Senior Member Joined: 14 September 2007 Status: Offline Points: 138 |
Post Options
Thanks(0)
|
|||
ID_? is a placeholder for the ID of your control (see SetID()). Typically you set all your available IDs with your resource editor (->resource.h)
You can set this value directly for dynamic controls or it will be loaded from resources automatically (e.g. menu items)
|
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
Thank Michl for your reply. I have now managed to load a single .png icon onto an AddLinkItem link on the CXTPTaskPanel using he quoted code above. However the .png is not displaying properly i.e. I can only see the top left 25% of the image. How can I resize the AddLinkItem so that it displays the image as whole? Cheers |
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
I tried the following code above but modified to suit my needs (code below). It compiles and runs fine but the image/icon is not displayed. When i checked the value of A at runtime it was false meaning that loading the .png failed. Can somebody tell me why?
IDP_DEVICE_PRINT is defined in the .rc as follows:
p.s.: all suggestions are welcome! |
||||
Jayonas
Newbie Joined: 28 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
|
|||
Ugh, there was a slight error in my code, although it doesn't explain your problem. The variable "A" being passed to the function should have been "&Alpha". The HTML thought that the & symbol meant something else. I've corrected my original post. As best as I understand, that boolean is not an indication of success or failure, but of whether or not the loaded PNG uses an alpha channel.
As far as why the image doesn't display.. I'm not sure. I know that code has been working for me. Is the PNG in question actually 16x16? I'm not sure what it would do if the size you give it doesn't match the size of the image. You could check the return value of both LoadBitmapFromResource and SetIcon to see if either returns an error value. If one of them does, you could step into the loading code in the debugger to find out where and why it's failing. If they return successful values, I'd guess there was something wrong with how the image is used in the TaskPanel, but I'm completely unfamiliar with TaskPanels, so I have no idea what that problem might be. My only wild guess would be that the TaskPanel might be looking for a 32x32 or some other sized icon to display and the ImageManager only has the 16x16 one loaded. Good luck. :) |
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
Cheers Jahonas,
I just tried out ur suggestions. LoadBitmapFromResource does return something and SetIcon return true. I will try and investigate further by loading exactly a 32x32 image and see if that yield s any results. |
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
I loaded a 32x32 .bmp and it didn't work.
I don't know what to try now! |
||||
Jayonas
Newbie Joined: 28 September 2007 Location: United States Status: Offline Points: 12 |
Post Options
Thanks(0)
|
|||
I'm out of ideas too.. sorry. :( Maybe oleg or someone else will come along with something to try.
|
||||
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
|||
poiser, attach your project. Obviously you do something wrong.
|
||||
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
Unfortunately the project is too large to attach, even when zipped.
However I attach the file the most relevant files so you can at least see what's happening. Your suggestion that I am doing something wrong is probably right because I only started using codejock this week! The file that contains the code which loads the images is MainFrm.cpp, line 255 where it says "Test 3". Cheers uploads/20071024_111058_Files.zip Bitmap/PNG files are located in this directory, including IDB_DEVICE_ICON16 bitmap file: uploads/20071025_043213_res.zip |
||||
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
|||
Hi,
also attach IDB_DEVICE_ICON16 bitmap file
|
||||
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
||||
poiser
Newbie Joined: 23 October 2007 Status: Offline Points: 8 |
Post Options
Thanks(0)
|
|||
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
|||
Hi,
LoadBitmapFromResource was added for loading alpha bitmaps.
use this way instead
UINT command = ID_2;
m_wndTaskPanel.GetImageManager()->SetIcons( IDB_DEVICE_ICON16, &command, 1, CSize(16, 16) ); |
||||
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
||||
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |