win32 应用程序更换icon图标
生活随笔
收集整理的這篇文章主要介紹了
win32 应用程序更换icon图标
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
按照文章《win32 application 添加一個icon 資源 resource》,
編譯之后,運行
HelloRes.exe
界面如下:
任務欄上面的圖標,如下:
修改后的hello.cpp中的代碼:
#include <windows.h> #include <stdlib.h> #include <string.h> #include <tchar.h> #include "resource.h" // 1LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) {static TCHAR szAppName[] = TEXT("HelloWin");HWND hwnd;MSG msg;WNDCLASS wndclass;wndclass.style = CS_HREDRAW | CS_VREDRAW;wndclass.lpfnWndProc = WndProc;wndclass.cbClsExtra = 0;wndclass.cbWndExtra = 0;wndclass.hInstance = hInstance;//wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // 2wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); // 3wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wndclass.lpszMenuName = NULL;wndclass.lpszClassName = szAppName;if (!RegisterClass(&wndclass)){MessageBox(NULL, TEXT("This program requires Windows NT!"),szAppName, MB_ICONERROR);return 0;}hwnd = CreateWindow(szAppName, // window class nameTEXT("The Hello Program"), // window captionWS_OVERLAPPEDWINDOW, // window styleCW_USEDEFAULT, // initial x positionCW_USEDEFAULT, // initial y positionCW_USEDEFAULT, // initial x sizeCW_USEDEFAULT, // initial y sizeNULL, // parent window handleNULL, // window menu handlehInstance, // program instance handleNULL); // creation parametersShowWindow(hwnd, iCmdShow);UpdateWindow(hwnd);while (GetMessage(&msg, NULL, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}return msg.wParam; }LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {HDC hdc;PAINTSTRUCT ps;RECT rect;TCHAR msg[] = _T("Hello, World!"); switch (message){case WM_CLOSE:DestroyWindow(hwnd);break;case WM_DESTROY:PostQuitMessage(0);break;case WM_PAINT: hdc = BeginPaint(hwnd, &ps); TextOut(hdc, 50, 5, msg, _tcslen(msg)); EndPaint(hwnd, &ps); break; default:return DefWindowProc(hwnd, message, wParam, lParam);}return 0; }共修改了3個地方 ,看代碼中的 //1 , //2 ,//3所在的語句。
編譯,運行之后的效果,如下:
主要修改的內容:
//wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // 2wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); // 3總結
以上是生活随笔為你收集整理的win32 应用程序更换icon图标的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sql 插入
- 下一篇: 米联ZYNQ7Z020系列的以太网网口芯