CFanatic

Go Back   CFanatic > Programming > Win32 Programming

Join CFanatic Forum Now

Toolbar help: How to make buttons dynamic using images topic posted under Win32 Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2008, 05:26 PM
Junior Member
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Echelo is on a distinguished road
| More
Toolbar help: How to make buttons dynamic using images

I am trying to make a toolbar with dynamic buttons which change the image of the button when the user clicks on it. More specifically to change the index of the iBitmap in TBButton. So far I've been trying to use TB_SETBUTTONINFO but without much luck, so far the message fails with...here's the code so far:

I have the toolbar setup and buttons setup as follows:
Code:
//Globals:
	TBBUTTON tbb[2];
	HWND hTool = NULL;
	HIMAGELIST imagelist;

//WM_CREATE:

			// Create Toolbar
			hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
				hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);

			if(hTool == NULL)
				MessageBox(hwnd, TEXT("Could not create tool bar."), TEXT("Error"), MB_OK | MB_ICONERROR);

			// Send the TB_BUTTONSTRUCTSIZE message, which is required for
			// backward compatibility.
			SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
imagelist = ImageList_Create(32, 32, ILC_COLOR32, 3, 3);
			HBITMAP hToolIcons = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_TOOLBAR));
			ImageList_Add(imagelist, hToolIcons, NULL);

			SendMessage(hTool, TB_SETIMAGELIST, 0, (LPARAM)(HIMAGELIST)imagelist);

			ZeroMemory(tbb, sizeof(tbb));
			tbb[0].iBitmap = 0; 
			tbb[0].fsState = TBSTATE_ENABLED;
			tbb[0].fsStyle = TBSTYLE_BUTTON;
			tbb[0].idCommand = ID_FILE_CONNECT;

			tbb[1].iBitmap = 2;
			tbb[1].fsState = TBSTATE_ENABLED;
			tbb[1].fsStyle = TBSTYLE_BUTTON;
			tbb[1].idCommand = ID_FILE_SELECTSERVER;

			SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);


//and when the user clicks on the button I have the following code:
		case ID_FILE_CONNECT:
			{
				if(!g_CONNECTED)
				{	
					CreateNewMDIChild(g_hMDIClient);
					TBBUTTONINFO tbInfo;
					tbInfo.cbSize = sizeof(tbInfo);
					tbInfo.dwMask = TBIF_IMAGE;
					tbInfo.iImage = 1;
					//tbb[0].iBitmap = 1; 
					int i = SendMessage(hwnd, TB_SETBUTTONINFO,(WPARAM)ID_FILE_CONNECT, (LPARAM)&tbInfo);
					if(i == NULL)
						MessageBox(hwnd, TEXT("Could not update tool bar."), TEXT("Error"), MB_OK | MB_ICONERROR);
					
				}
			}
			break;
		}
		break;
Can anyone help? maybe Im doing something wrong.

Last edited by shabbir; 08-02-2008 at 12:29 AM. Reason: Code block
Reply With Quote
  #2  
Old 08-27-2008, 04:32 AM
Junior Member
 
Join Date: Jun 2008
Location: Milano, Italy
Posts: 12
Thanks: 0
Thanked 1 Time in 1 Post
Spogliani is on a distinguished road
| More
Re: Toolbar help: How to make buttons dynamic using images

Hi, I've never worked with toolbars but I had similar problems with other controls.
I think the problem is that you do not any value for "idCommand" in the tbInfo structure, while managing the message.

Try to add something like
Code:
tbInfo.idCommand = ID_FILE_CONNECT;
I think this may be the solution for your problem becouse of the info found at http://msdn.microsoft.com/en-us/libr...76(VS.85).aspx

I hope this can help you
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Images Zigioman C++ Programming 2 01-07-2009 04:23 AM
dynamic memory allocation vamsi1990 C++ Programming 2 12-31-2008 12:29 AM
how to make window transparent vidhya Win32 Programming 10 06-08-2007 04:31 PM
how to make window to not appear on taskbar vidhya Win32 Programming 4 06-06-2007 01:21 PM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 04:39 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board