1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Displaying Icons in Static controls

Discussion in 'Win32' started by Spogliani, Jun 24, 2008.

  1. Spogliani

    Spogliani New Member

    Joined:
    Jun 24, 2008
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Milano, Italy
    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:
    [COLOR=seagreen]//create the control[/COLOR]
    [COLOR=#2e8b57]//HWND hMain is defined in WinMain.h[/COLOR]
    [COLOR=#2e8b57]//HWND hImgClip is defined in WinMain.h[/COLOR]
    [SIZE=2]hImgClip = CreateWindow(L[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"STATIC"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], TEXT([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]), (SS_ICON | WS_VISIBLE | WS_CHILD | SS_BLACKFRAME | SS_REALSIZEIMAGE), 121, 60, 16, 16, hMain, NULL, (HINSTANCE)GetWindowLong(hMain, GWL_HINSTANCE), NULL);[/SIZE]
    [COLOR=seagreen]//send the SetImage message[/COLOR]
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (SendMessage(hImgClip, STM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_STATUS_INACTIVE [COLOR=seagreen]/* Resource ID: 404 */[/COLOR])))==0)[/SIZE]
    [SIZE=2]{[/SIZE]
    [SIZE=2]  LPVOID lpMsgBuf;[/SIZE]
    [SIZE=2]  FormatMessage((FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS), NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);[/SIZE]
    [SIZE=2]  MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Error"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]), MB_OK);[/SIZE]
    [SIZE=2]  LocalFree(lpMsgBuf);[/SIZE]
    [SIZE=2]}[/SIZE]
    
    When I run the program I get an error message (Unable to find item).

    Can anybody help me?
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    1
    Trophy Points:
    0
    Moved to Win32 forum
     

Share This Page