Короче, я с этой проблемой разобрался - смотрите код ниже (Visual C++ 6.0) Но у меня возник еще вопрос - так же в коде описан. Помогите стоящим советом
| Код | #include "stdafx.h" #include <ShlObj.h> #include <ShellAPI.h> #include <CommCtrl.h>
const char cszEmptyWndClass[] = "EmptyWndClass";
LRESULT CALLBACK EmptyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: { RECT rt; GetClientRect(hWnd, &rt); PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); Rectangle(hdc, rt.left, rt.top, rt.right, rt.bottom);
//************Народ подскажите почему здесь нереальный шрифт наименований икон десктопа берется? НАЧАЛО //************И как взять реальный шрифт наименований икон десктопа? HWND DesktopHWND = FindWindowEx(FindWindowEx(FindWindow("Progman", 0), 0, 0, 0), 0, 0, 0); //Get desktop as SysListView32 HDC DesktopHDC = GetWindowDC(DesktopHWND); HFONT DesktopFont = (HFONT)GetCurrentObject(DesktopHDC, OBJ_FONT); LOGFONT DesktopLogFont; int NumBytes = GetObject(DesktopFont, sizeof DesktopLogFont, &DesktopLogFont); HFONT hThisFont = CreateFontIndirect(&DesktopLogFont); HFONT hOldFont = (HFONT)SelectObject(hdc, hThisFont); //************Народ подскажите почему здесь нереальный шрифт наименований икон десктопа берется? КОНЕЦ
//*********************Вот здесь мы и выцепляем иконы с десктопа:) НАЧАЛО IShellFolder* psfDesktop; IEnumIDList * pEnumIDList; ITEMIDLIST * pItemIDList; ULONG celtFetched; SHFILEINFO ShFileInfo; HIMAGELIST hImageList; int cx, cy, x = 10, y = 10, i = 0, ito = 5; RECT TextRect; InitCommonControls(); SHGetDesktopFolder(&psfDesktop); psfDesktop->EnumObjects(hWnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &pEnumIDList); while(pEnumIDList->Next(1, &pItemIDList, &celtFetched) == NOERROR) { hImageList = (HIMAGELIST)SHGetFileInfo((LPCTSTR)pItemIDList, 0, &ShFileInfo, sizeof ShFileInfo, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_TYPENAME); ImageList_GetIconSize(hImageList, &cx, &cy); ImageList_Draw(hImageList, ShFileInfo.iIcon, hdc, x, y, ILD_TRANSPARENT); SetRect(&TextRect, x + cx + 5, y, x + 200, y + cy); DrawText(hdc, ShFileInfo.szDisplayName, -1, &TextRect, DT_WORDBREAK); if(++i < ito) x += 210; else { i = 0; x = 10; y += cy + 10; } } pEnumIDList->Release(); psfDesktop->Release(); //*********************Вот здесь мы и выцепляем иконы с десктопа:) КОНЕЦ
SelectObject(hdc, hOldFont);
EndPaint(hWnd, &ps); return 0; } case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wcex; memset(&wcex, 0, sizeof wcex); wcex.cbSize = sizeof wcex; wcex.lpfnWndProc = EmptyWndProc; wcex.hInstance = hInstance; wcex.lpszClassName = cszEmptyWndClass; RegisterClassEx(&wcex);
HWND hWnd = CreateWindow(cszEmptyWndClass, 0, WS_OVERLAPPEDWINDOW, 0, 0, 1200, 950, 0, 0, hInstance, 0);
if(!hWnd) return 0; ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);
MSG msg; while(GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage (&msg); } return msg.wParam; }
| |