Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - How to load a single .png?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to load a single .png?

 Post Reply Post Reply
Author
Message
Michl View Drop Down
Senior Member
Senior Member


Joined: 14 September 2007
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Michl Quote  Post ReplyReply Direct Link To This Post Topic: How to load a single .png?
    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.
 

UINT commands[] = { ID_SERVER_SYNCHRONIZE };

pButton->GetImageManager()->SetIcons( IDR_SYNCHRONIZE_ICON32, commands, _countof(commands), CSize(32, 32) );

 
But it is annoying to declare an additional array with various names.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 17 October 2007 at 10:17am
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
Back to Top
Michl View Drop Down
Senior Member
Senior Member


Joined: 14 September 2007
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Michl Quote  Post ReplyReply Direct Link To This Post Posted: 17 October 2007 at 10:27am
That's right
 
(thought too complicated )
 
But is there a reason why SetIcon doesn't support png ressources?
Back to Top
Jayonas View Drop Down
Newbie
Newbie


Joined: 28 September 2007
Location: United States
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jayonas Quote  Post ReplyReply Direct Link To This Post Posted: 17 October 2007 at 2:42pm
ImageManager includes a SetIcon method that I've been using to successfully load single images (including PNGs).


BOOL Alpha;
this->GetCommandBars()->GetImageManager()->SetIcon(CXTPImageManagerIcon::LoadBitmapFromResource(MAKEINTRESOURCE(ResourceID), &Alpha), CommandID, Size, State);


You can also load them from files by using LoadBitmapFromFile instead of LoadBitmapFromResource.
Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 4:55am
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.
Back to Top
Michl View Drop Down
Senior Member
Senior Member


Joined: 14 September 2007
Status: Offline
Points: 138
Post Options Post Options   Thanks (0) Thanks(0)   Quote Michl Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 5:07am
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)
Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 5:51am
Originally posted by oleg oleg wrote:

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


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
Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 10:34am
Originally posted by Jayonas Jayonas wrote:

ImageManager includes a SetIcon method that I've been using to successfully load single images (including PNGs).


BOOL Alpha;
this->GetCommandBars()->GetImageManager()->SetIcon(CXTPImageManagerIcon::LoadBitmapFromResource(MAKEINTRESOURCE(ResourceID), Α), CommandID, Size, State);


You can also load them from files by using LoadBitmapFromFile instead of LoadBitmapFromResource.


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?


UINT command2;
command2 = ID_2;
BOOL A;
m_wndTaskPanel.GetImageManager()->SetIcon(CXTPImageManagerIcon::LoadBitmapFromResource(MAKEINTRESOURCE(IDP_DEVICE_PRINT), &A), command2, CSize(16,16), xtpImageNormal);
CXTPTaskPanelGroupItem* pItem3 = pGroup->AddLinkItem(3, ID_2);


IDP_DEVICE_PRINT is defined in the .rc as follows:

IDP_DEVICE_PRINT    PNG   MOVEABLE   PURE     "C:\\Dev\\print.png"


p.s.: all suggestions are welcome!

Back to Top
Jayonas View Drop Down
Newbie
Newbie


Joined: 28 September 2007
Location: United States
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jayonas Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 10:50am
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. :)
Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 11:08am
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.

Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 11:37am
I loaded a 32x32 .bmp and it didn't work.

I don't know what to try now!
Back to Top
Jayonas View Drop Down
Newbie
Newbie


Joined: 28 September 2007
Location: United States
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote Jayonas Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 11:40am
I'm out of ideas too.. sorry. :( Maybe oleg or someone else will come along with something to try.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2007 at 2:55pm
poiser,  attach your project. Obviously you do something wrong.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2007 at 10:31am
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
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2007 at 3:15pm
Hi,
also attach IDB_DEVICE_ICON16 bitmap file
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
poiser View Drop Down
Newbie
Newbie
Avatar

Joined: 23 October 2007
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote poiser Quote  Post ReplyReply Direct Link To This Post Posted: 29 October 2007 at 5:23am
Here is the bitmap file:


uploads/20071029_052255_paste2.zip

I look forward to hearing from you.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 29 October 2007 at 6:32am
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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.187 seconds.