📄 drawicon.c
字号:
/*---------------------------------------------------
DrawIcon.c
---------------------------------------------------*/
#include <windows.h>
#include "resource.h"
HINSTANCE hInst;
HCURSOR hIcon;
LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("DrawIcon") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
hInst=hInstance;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = MainWndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon =LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MYICON));
wndclass.hCursor =LoadCursorFromFile (TEXT("MyCursor.cur")) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("Draw Icon"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int cxIcon, cyIcon, cxClient, cyClient ;
HDC hdc ;
PAINTSTRUCT ps ;
static HICON hIcon; // icon handle
HINSTANCE hExe; // handle to loaded .EXE file
HRSRC hResource; // handle for FindResource
HRSRC hMem; // handle for LoadResource
BYTE *lpResource; // pointer to resource data
int nID; // ID of resource that best fits current screen
int x, y ;
switch (message)
{
case WM_CREATE:
cxIcon = GetSystemMetrics (SM_CXICON) ;
cyIcon = GetSystemMetrics (SM_CYICON) ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
// Load the file from which to copy the icon.
hExe = LoadLibrary("DrawIcon.exe");
// Find the icon directory whose identifier is 440.
hResource = FindResource(hExe,MAKEINTRESOURCE(IDI_MYICON), RT_GROUP_ICON);
// Load and lock the icon directory.
hMem = LoadResource(hExe, hResource);
lpResource = LockResource(hMem);
// Get the identifier of the icon that is most appropriate
// for the video display.
nID = LookupIconIdFromDirectoryEx((PBYTE) lpResource, TRUE,
SM_CXICON , SM_CYICON , LR_DEFAULTCOLOR);
// Find the bits for the nID icon.
hResource = FindResource(hExe, MAKEINTRESOURCE(nID),MAKEINTRESOURCE(RT_ICON));
// Load and lock the icon.
hMem = LoadResource(hExe, hResource);
lpResource = LockResource(hMem);
// Create a handle to the icon.
hIcon = CreateIconFromResourceEx((PBYTE) lpResource, SizeofResource(hExe, hResource), TRUE, 0x00030000, SM_CXICON , SM_CYICON , LR_DEFAULTCOLOR);
// Draw the icon in the client area.
for (y = 0 ; y < cyClient ; y += cyIcon)
for (x = 0 ; x < cxClient ; x += cxIcon)
DrawIcon (hdc, x, y, hIcon) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
DestroyIcon(hIcon);
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -