ap0909629 发表于 2012-4-12 16:08:59

vc6 自己手动建rc文件 自定义图标不能加载

file:///c:/2.jpgfile:///c:/3.jpg
//window_eg.cpp - a complete window program
//includes///////////////////////////////////////////////////////////////////////////////////////////////////////
# include <windows.h>         //all window include
# include <windowsx.h>      //useful macros
# include <stdio.h>
# include <math.h>
# include "resource.h"
//define////////////////////////////////////////////////////////////////////////////////////////////////////////
//define for window
# define WINDOW_CLASS_NAME "WINCLASS1"
//functions////////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
       UINT msg, WPARAM wparam,
         LPARAM lparam)
{
//this is main message handler of the system
PAINTSTRUCT ps; //used in WM_PAINT
HDC         hdc; //handle to a device context
HINSTANCE   hinstance;
//char load_string;
switch(msg)
{
case WM_CREATE:
{
   //do initialization stuff here
   //LoadString(hinstance, IDS_STRING_LOAD_GAME, load_string, 80);
   //return success
   return 0;
}
break;
case WM_PAINT:
{
   //simply validate the window
   hdc = BeginPaint(hwnd, &ps);
   //you would do all your painting here
   EndPaint(hwnd, &ps);
   //return success
   return 0;
}
break;
case WM_DESTROY:
{
   //kill the application this send a WM_QUIT message
   PostQuitMessage(0);
   //return success
   return 0;
}
break;
default:
break;
}//end switch
return(DefWindowProc(hwnd, msg, wparam, lparam));
}//end winproc

//winmain////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance,
       HINSTANCE hprevinstance,
       LPSTR lpcmdline,
       int ncmdshow)
{
WNDCLASSEX winclass;//this will hold the class we create
HWND hwnd;          //generic window handle
MSGmsg;         //generic messgae
//first fill int the window class structure
winclass.cbSize = sizeof(WNDCLASSEX);//size of this structure
winclass.style = CS_DBLCLKS | CS_OWNDC | //style flage
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;    //function pointer to handler
winclass.cbClsExtra= 0;   //extra class info
winclass.cbWndExtra= 0;   //extra window info
winclass.hInstance= hinstance; //the instance of the application
winclass.hIcon   = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1)); //the main icon
winclass.hCursor   = LoadCursor(hinstance, MAKEINTRESOURCE(IDC_CURSOR1));//the cursor for the window
winclass.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH); //the cursor for the window
winclass.lpszMenuName   = NULL;         //the background brush to paint the window
winclass.lpszClassName= WINDOW_CLASS_NAME;   //the name of the menu to attach
winclass.hIconSm= LoadIcon(NULL, IDI_APPLICATION);//the handle of the small icon

//register the window class
if(!RegisterClassEx(&winclass))
return 0;
//create the window
if(!(hwnd = CreateWindowEx(NULL,
      WINDOW_CLASS_NAME,
      "My basic window",
      WS_OVERLAPPEDWINDOW | WS_VISIBLE,
      0,0,
      400,400,
      NULL,
      NULL,
      hinstance,
      NULL)))
return 0;
//enter main event loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);

DispatchMessage(&msg);
}
return(msg.wParam);
}
//error
//libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main .(.g.d){j.
//libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main .*.+oJ.(e.

//Windows项目要使用Windows子系统, 而不是Console, 可以这样设置
// --> --> 选择"Link"属性页
//在Project Options中将/subsystem:console改成/subsystem:windows
// winclass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);   type to change

ap0909629 发表于 2012-4-12 19:54:41

搞了一天 原来是hiconsm结构成员。。。搞了hicon

fishc1008 发表于 2017-1-21 13:34:54

学习学习
页: [1]
查看完整版本: vc6 自己手动建rc文件 自定义图标不能加载