CFanatic

Go Back   CFanatic > Programming > Win32 Programming

Join CFanatic Forum Now

Displaying Icons in Static controls topic posted under Win32 Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2008, 02:35 PM
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
Question Displaying Icons in Static controls

Hi,
I'm new at Win32 Programming and I'm trying to write my first program with a GUI.
I have create the main window and some Buttons and Static controls.

The problem is when I try to display an Icon from the resource in a Static.
I looked at the MSDN Library for the functions I should use and I came up with this code (I created a new class for the window for ease):

WinMain.Cpp
Code:
//create the control
//HWND hMain is defined in WinMain.h
//HWND hImgClip is defined in WinMain.h
hImgClip = CreateWindow(L"STATIC", TEXT(""), (SS_ICON | WS_VISIBLE | WS_CHILD | SS_BLACKFRAME | SS_REALSIZEIMAGE), 121, 60, 16, 16, hMain, NULL, (HINSTANCE)GetWindowLong(hMain, GWL_HINSTANCE), NULL);
//send the SetImage message
if (SendMessage(hImgClip, STM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_STATUS_INACTIVE /* Resource ID: 404 */)))==0)
{
  LPVOID lpMsgBuf;
  FormatMessage((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS), NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
  MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK);
  LocalFree(lpMsgBuf);
}
When I run the program I get an error message (Unable to find item).

Can anybody help me?
Reply With Quote
  #2  
Old 06-24-2008, 11:03 PM
shabbir's Avatar
Administrator
 
Join Date: Sep 2006
Posts: 1,164
Thanks: 57
Thanked 63 Times in 44 Posts
shabbir has a spectacular aura aboutshabbir has a spectacular aura about
| More
Re: Displaying Icons in Static controls

Moved to Win32 forum
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
Need Help Displaying the largest Number Travis876 C# Programming 5 07-20-2009 02:23 AM
Controls in a GroupBox Spogliani Win32 Programming 1 07-12-2008 12:23 AM
Displaying Sequential Record cherries C Programming 1 12-20-2007 04:55 AM
linking errors with DLL linked to static libraries mijal C++ Programming 3 08-23-2007 10:22 PM
Tutorial for creating dialog controls dynamically? ajcrm125 Win32 Programming 0 09-30-2006 06:46 PM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:50 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