/* * geticon.cpp * * # 他ファイルのアイコンを取得 */ #include #include const char szClassName[]="GetIcon"; HMODULE hAppModule=NULL; LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { hAppModule=(HMODULE)hInstance; WNDCLASSEX wc; wc.cbClsExtra = 0; wc.cbSize = sizeof(WNDCLASSEX); wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.hCursor = ::LoadCursor(NULL,MAKEINTRESOURCE(IDC_ARROW)); wc.hIcon = NULL; wc.hIconSm = NULL; wc.hInstance = hInstance; wc.lpfnWndProc = (WNDPROC)WndProc; wc.lpszClassName = szClassName; wc.lpszMenuName = NULL; wc.style = CS_HREDRAW | CS_VREDRAW; ::RegisterClassEx(&wc); HWND hWnd=::CreateWindow(szClassName,szClassName, WS_OVERLAPPED|WS_SYSMENU, CW_USEDEFAULT,CW_USEDEFAULT,100,100, NULL,NULL,hInstance,0); if ( hWnd==NULL ) return 0; ::ShowWindow(hWnd,nCmdShow); MSG msg; while ( ::GetMessage(&msg,NULL,0,0) ) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } return 0; } LRESULT CALLBACK WndProc(HWND in_hWnd, UINT in_Message, WPARAM in_wParam, LPARAM in_lParam) { switch ( in_Message ) { case WM_PAINT: PAINTSTRUCT ps; HDC hDC; hDC=::BeginPaint(in_hWnd,&ps); SHFILEINFO sfi; ::SHGetFileInfo("c:\\windows\\notepad.exe", 0,&sfi,sizeof(SHFILEINFO),SHGFI_ICON); ::DrawIcon(hDC,10,10,sfi.hIcon); ::DestroyIcon(sfi.hIcon); ::EndPaint(in_hWnd,&ps); break; case WM_DESTROY: ::PostQuitMessage(0); break; default: return ::DefWindowProc(in_hWnd, in_Message,in_wParam,in_lParam); } return 0; }