Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++ Picture!

Status
Not open for further replies.

michaelkrauklis

Programmer
Dec 5, 2001
226
US
Ok, I stated this in another thread but it wasn't the question, so I'll pose it again:
I have three bitmap resources loaded;IDB_BITMAP_RED, IDB_BITMAP_GREEN, and IDB_BITMAP_YELLOW.
I have a dialog based application. I create a 'Picture' by using the Picture tool on the Controls palette. In the Picture Properties I set the type to Bitmap, and then select the correct Bitmap Resource from the Image Pulldown.

This part works fine. It displays the IDB_BITMAP_RED bitmap just as I want it to. Now my problem is this:

Later on in my program execution I would like to be able to change which bitmap this particular 'Picture' is displaying. I've tried things like getting the main window and calling LoadImage, but there are type problems.
Code:
AfxGetMainWnd()->GetDlgItem(IDC_STATIC0);//stuff like that
Now this part works fine, but the problem is it returns a CWind*. I need to at least know what type the 'Picture' is or I won't be able to cast it correctly nor call the correct member functions. Microsoft's documentation on this is very bad. I have a bunch of books but none of them address this. Is it even possible? Any help will be greatly appreciated. Thanks

MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Thanks, but that didn't really help me at all. This is starting to piss me off. It should be unbelievably easy, just to change a simple bitmap! But alas, it is not. Thanks for trying. MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Ok, this kind of helped. At least my program is doing something now(printing a random windows icno). I think my problem is I'm using my resource ID instead of a HBITMAP. How do you get a handle from a resource ID? I bet this is something pretty important huh:) Thanks! MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Well with this code:
Code:
CStatic *button=(CStatic*)(AfxGetMainWnd()->GetDlgItem(IDC_STATIC1));
HWND handle = AfxGetMainWnd()->GetDlgItem(IDB_BITMAP_GREEN)->GetSafeHwnd();
button->SetBitmap((HBITMAP)handle);
button->RedrawWindow();
**************************************************************************************
I can get my bitmap to dissapear!:) I assume it's not finding IDB_BITMAP_GREEN because it's not a Dialog Item. I'm getting so confused right now. I have MA's. Microsoft Angers... grrr! MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
So nobody knows how to get a handle from a resource ID?? MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Here's the code I have so far:
Code:
	CStatic *bitmap=(CStatic*)(AfxGetMainWnd()->GetDlgItem(IDC_STATIC1));
	HRSRC tmp_handle = FindResourceEx(NULL,"RT_BITMAP","IDB_BITMAP_GREEN", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
	HBITMAP handle = (HBITMAP)LoadResource(NULL,tmp_handle);
	bitmap->SetBitmap((HBITMAP)handle);
	bitmap->RedrawWindow();
But when I execute this my bitmap just dissapears completely. This would really be horrible if it wasn't the closest I've gotten to updating this. If anyone could even help me out in seeing if I correctly loaded the bitmap resource that would be great. MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Just a little update... the handle returned is NULL, therefore I must conclude that it is not loading the resource correctly. Any ideas? MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Ok, it's faq time. I found some code deeply nested in a CodeGuru forum. This is basically it:
Code:
	CStatic *bitmap=(CStatic*)(AfxGetMainWnd()->GetDlgItem(nIDResourceItem));
	bitmap->SetBitmap(LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(nIDResourceBitmap)));
	bitmap->RedrawWindow();

this has caused me many angers... MYenigmaSELF:-9
myenigmaself@yahoo.com
"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top