Cómo usar íconos personalizados en VS++2010
Hola lz
Los pasos específicos son los siguientes:
(1) Haga clic derecho en "Archivo de recursos" -> "Agregar" -> "Nuevo elemento "
(2) Seleccione "Recurso"->"Resource File.rc"->Nómbrelo "recurso"
(3) Seleccione "Ver"->"Vista de recursos" en la barra de menú, haga clic derecho en "resource.rc"->"Agregar recurso"
(4) Seleccione "Icono"->"Importar" ¿Seleccione el ícono que desea agregar
?(5) Haga clic derecho para agregar el ícono, seleccione "Propiedades", modifique ID
(6) Modifique el código fuente, de la siguiente manera: //IconDemo.c
#include
#include "resource.h"//Agregar archivo de encabezado de recursos
LRESULT?CALLBACK?WndProc(HWND,?UINT,?WPARAM,? LPARAM);
int?WINAPI ?WinMain(HINSTANCE?hInstance,
HINSTANCE?hPrevInstance,
PSTR?szCmdLine,
int ?iCmdShow)
{ p>
static TCHAR szAppName[]?=?TEXT("IconDemo");
HWND hwnd;
Mensaje MSG;
WNDCLASS wndclass;
int cxScreen,?cyScreen;
wndclass.style =?CS_HREDRAW?|?CS_VREDRAW;
wndclass.lpfnWndProc =?WndProc;
wndclass.cbClsExtra =?0;
wndclass.cbWndExtra =?0;
wndclass.hInstance =?hInstance;
wndclass.hIcon =?LoadIcon (hInstance,?MAKEINTRESOURCE(IDI_ICON));//Cargar icono
wndclass.hCursor =?LoadCursor(NULL,?IDC_ARROW);
wndclass.hbrBackground =?(HBRUSH)GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName =?NULL;
wndclass.lpszClassName =?szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,?TEXT("¿Este?programa?requiere?Windows?NT!"),
szAppName,?MB_ICONERROR);
return?0;
}
cxScreen?=?GetSystemMetrics(SM_CXSCREEN);
cyScreen?=?GetSystemMetrics(SM_CYSCREEN);
hwnd?=?CreateWindow(szAppNam
e,
TEXT("IconDemo"),
WS_OVERLAPPEDWINDOW,
cxScreen?*?7?/?20,
cyScreen ?/?4,
cxScreen?*?3?/?10,
cyScreen?/?2,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,?iCmdShow);
while(GetMessage(&msg, ?NULL,?0,?0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return?msg.wParam;
}
LRESULT?CALLBACK?WndProc(HWND?hwnd,?UINT?message,?WPARAM?wParam,?LPARAM ?lParam)
{
switch(mensaje)
{
caso?WM_DESTROY:
PostQuitMessage( 0);
return?0;
}
return?DefWindowProc(hwnd,?message,?wParam,?lParam);
}
(7) El efecto de la operación es el siguiente:
Espero que pueda ayudarte