static void test_OleCreatePictureIndirect(void) { OLE_HANDLE handle; IPicture *pict; HRESULT hr; short type; if (0) { /* crashes on native */ OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, NULL); } hr = OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (void**)&pict); ok(hr == S_OK, "hr %08x\n", hr); type = PICTYPE_NONE; hr = IPicture_get_Type(pict, &type); ok(hr == S_OK, "hr %08x\n", hr); ok(type == PICTYPE_UNINITIALIZED, "type %d\n", type); handle = 0xdeadbeef; hr = IPicture_get_Handle(pict, &handle); ok(hr == S_OK, "hr %08x\n", hr); ok(handle == 0, "handle %08x\n", handle); IPicture_Release(pict); }
static IPictureDisp *QPixmapToIPicture(const QPixmap &pixmap) { #if defined(Q_OS_WINCE) Q_UNUSED(pixmap); return 0; #else IPictureDisp *pic = 0; PICTDESC desc; desc.cbSizeofstruct = sizeof(PICTDESC); desc.picType = PICTYPE_BITMAP; desc.bmp.hbitmap = 0; desc.bmp.hpal = QColormap::hPal(); if (!pixmap.isNull()) { desc.bmp.hbitmap = pixmap.toWinHBITMAP(); Q_ASSERT(desc.bmp.hbitmap); } HRESULT res = OleCreatePictureIndirect(&desc, IID_IPictureDisp, true, (void**)&pic); if (res != S_OK) { if (pic) pic->Release(); pic = 0; #if defined(QT_CHECK_STATE) qWarning("QPixmapToIPicture: Failed to create IPicture"); #endif } return pic; #endif }
/*static */ bool display_t::save_bitmap(const char *szFileName, HBITMAP bmp, HPALETTE pal /*= NULL*/) { START_FUNCTION_BOOL(); PICTDESC pdPictDesc; pdPictDesc.cbSizeofstruct = sizeof(PICTDESC); pdPictDesc.picType = PICTYPE_BITMAP; pdPictDesc.bmp.hbitmap = bmp; pdPictDesc.bmp.hpal = pal; LPPICTURE plPicture = NULL; HRESULT hResult = OleCreatePictureIndirect(&pdPictDesc, IID_IPicture, false, reinterpret_cast<void**>(&plPicture)); if (!SUCCEEDED(hResult)) { break; } LPSTREAM lpStream = NULL; hResult = CreateStreamOnHGlobal(0, true, &lpStream); if (!SUCCEEDED(hResult)) { plPicture->Release(); return false; } LONG lBytesStreamed = 0; hResult = plPicture->SaveAsFile(lpStream, true, &lBytesStreamed); HANDLE hFile = CreateFileA(szFileName, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (!SUCCEEDED(hResult) || !hFile) { lpStream->Release(); plPicture->Release(); break; } HGLOBAL hgMemory = 0; GetHGlobalFromStream(lpStream, &hgMemory); LPVOID lpData = GlobalLock(hgMemory); DWORD dwBytesWritten = 0; bool bResult = !!WriteFile(hFile, lpData, lBytesStreamed, &dwBytesWritten, 0); bResult &= (dwBytesWritten == static_cast<DWORD>(lBytesStreamed)); GlobalUnlock(hgMemory); CloseHandle(hFile); lpStream->Release(); plPicture->Release(); END_FUNCTION_BOOL(); }
///////////////////////////////////////////////////////////////////////////////////////// // Utility to save a bitmap to file for later examination. Used for debugging only. // Based on an article by "gelbert" on www.experts-exchange.com at // http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20193761.html // // This version is a member function and instead of taking an HBITMAP as the 2nd // parameter, it take a reference to a CBitmap. Otherwise, it is identical. ///////////////////////////////////////////////////////////////////////////////////////// BOOL CSliderCtrlEx::SaveBitmap(LPCSTR lpFileName, CBitmap &hBitmap, HPALETTE hPal) { BOOL bResult = FALSE; PICTDESC stPictDesc; stPictDesc.cbSizeofstruct = sizeof(PICTDESC); stPictDesc.picType = PICTYPE_BITMAP; stPictDesc.bmp.hbitmap = hBitmap; stPictDesc.bmp.hpal = hPal; LPPICTURE pPicture; HRESULT hr = OleCreatePictureIndirect( &stPictDesc, IID_IPicture, FALSE, reinterpret_cast<void**>(&pPicture) ); if ( SUCCEEDED(hr) ) { LPSTREAM pStream; hr = CreateStreamOnHGlobal( NULL, TRUE, &pStream ); if ( SUCCEEDED(hr) ) { long lBytesStreamed = 0; hr = pPicture->SaveAsFile( pStream, TRUE, &lBytesStreamed ); if ( SUCCEEDED(hr) ) { HANDLE hFile = CreateFile(_T(lpFileName), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if ( hFile ) { HGLOBAL hMem = NULL; GetHGlobalFromStream( pStream, &hMem ); LPVOID lpData = GlobalLock( hMem ); DWORD dwBytesWritten; bResult = WriteFile( hFile, lpData, lBytesStreamed, &dwBytesWritten, NULL ); bResult &= ( dwBytesWritten == (DWORD)lBytesStreamed ); // clean up GlobalUnlock(hMem); CloseHandle(hFile); } } // clean up pStream->Release(); } // clean up pPicture->Release(); } return bResult; }
static void test_get_Type(void) { IPicture *pic; HRESULT hres; OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic); hres = IPicture_get_Type(pic, NULL); ole_expect(hres, E_POINTER); IPicture_Release(pic); }
static void test_load_save_bmp(void) { IPicture *pic; PICTDESC desc; short type; OLE_HANDLE handle; HGLOBAL hmem; DWORD *mem; IPersistStream *src_stream; IStream *dst_stream; HRESULT hr; desc.cbSizeofstruct = sizeof(desc); desc.picType = PICTYPE_BITMAP; desc.u.bmp.hpal = 0; desc.u.bmp.hbitmap = CreateBitmap(1, 1, 1, 1, NULL); hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic); ok(hr == S_OK, "OleCreatePictureIndirect error %#x\n", hr); type = -1; hr = IPicture_get_Type(pic, &type); ok(hr == S_OK,"get_Type error %#8x\n", hr); ok(type == PICTYPE_BITMAP,"expected picture type PICTYPE_BITMAP, got %d\n", type); hr = IPicture_get_Handle(pic, &handle); ok(hr == S_OK,"get_Handle error %#8x\n", hr); ok(IntToPtr(handle) == desc.u.bmp.hbitmap, "get_Handle returned wrong handle %#x\n", handle); hmem = GlobalAlloc(GMEM_ZEROINIT, 4096); hr = CreateStreamOnHGlobal(hmem, FALSE, &dst_stream); ok(hr == S_OK, "createstreamonhglobal error %#x\n", hr); hr = IPicture_QueryInterface(pic, &IID_IPersistStream, (void **)&src_stream); ok(hr == S_OK, "QueryInterface error %#x\n", hr); hr = IPersistStream_Save(src_stream, dst_stream, TRUE); ok(hr == S_OK, "Save error %#x\n", hr); IPersistStream_Release(src_stream); IStream_Release(dst_stream); mem = GlobalLock(hmem); ok(!memcmp(mem, "lt\0\0", 4), "got wrong stream header %04x\n", mem[0]); ok(mem[1] == 66, "expected stream size 66, got %u\n", mem[1]); ok(!memcmp(&mem[2], "BM", 2), "got wrong bmp header %04x\n", mem[2]); GlobalUnlock(hmem); GlobalFree(hmem); DeleteObject(desc.u.bmp.hbitmap); IPicture_Release(pic); }
static void test_load_save_icon(void) { IPicture *pic; PICTDESC desc; short type; OLE_HANDLE handle; HGLOBAL hmem; DWORD *mem; IPersistStream *src_stream; IStream *dst_stream; HRESULT hr; desc.cbSizeofstruct = sizeof(desc); desc.picType = PICTYPE_ICON; desc.u.icon.hicon = LoadIcon(0, IDI_APPLICATION); hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic); ok(hr == S_OK, "OleCreatePictureIndirect error %#x\n", hr); type = -1; hr = IPicture_get_Type(pic, &type); ok(hr == S_OK,"get_Type error %#8x\n", hr); ok(type == PICTYPE_ICON,"expected picture type PICTYPE_ICON, got %d\n", type); hr = IPicture_get_Handle(pic, &handle); ok(hr == S_OK,"get_Handle error %#8x\n", hr); ok(IntToPtr(handle) == desc.u.icon.hicon, "get_Handle returned wrong handle %#x\n", handle); hmem = GlobalAlloc(GMEM_ZEROINIT, 8192); hr = CreateStreamOnHGlobal(hmem, FALSE, &dst_stream); ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr); hr = IPicture_QueryInterface(pic, &IID_IPersistStream, (void **)&src_stream); ok(hr == S_OK, "QueryInterface error %#x\n", hr); hr = IPersistStream_Save(src_stream, dst_stream, TRUE); ok(hr == S_OK, "Saveerror %#x\n", hr); IPersistStream_Release(src_stream); IStream_Release(dst_stream); mem = GlobalLock(hmem); ok(!memcmp(mem, "lt\0\0", 4), "got wrong stream header %04x\n", mem[0]); todo_wine ok(mem[1] == 766, "expected stream size 766, got %u\n", mem[1]); ok(mem[2] == 0x00010000, "got wrong icon header %04x\n", mem[2]); GlobalUnlock(hmem); GlobalFree(hmem); DestroyIcon(desc.u.icon.hicon); IPicture_Release(pic); }
CLIB_API IPicture * GetIPictureFromBitmap(HBITMAP hBitmap) { PICTDESC pd; pd.cbSizeofstruct=sizeof(PICTDESC); pd.picType=PICTYPE_BITMAP; pd.bmp.hbitmap=hBitmap; pd.bmp.hpal=NULL; IPicture* iPicture = NULL; if (SUCCEEDED(OleCreatePictureIndirect(&pd,IID_IPicture,TRUE,(LPVOID*)&iPicture))) return iPicture; // failed DeleteObject((HGDIOBJ)hBitmap); return NULL; }
LPUNKNOWN AFXAPI _AfxCreateObjectFromStreamedPropset(LPSTREAM lpStream, REFGUID iid) { LPUNKNOWN pUnk = NULL; CLSID clsid; if (_AfxGetClassIDFromStreamedPropset(&clsid, lpStream)) { // Special case: we know how to create font objects if (IsEqualCLSID(clsid, CLSID_StdFont) || IsEqualCLSID(clsid, CLSID_StdFont_V1)) { if (FAILED(OleCreateFontIndirect((LPFONTDESC)&_fdDefault, iid, (LPVOID*)&pUnk))) { pUnk = NULL; } } // Special case: we know how to create picture objects else if (IsEqualCLSID(clsid, CLSID_StdPicture) || IsEqualCLSID(clsid, CLSID_StdPicture_V1)) { if (FAILED(OleCreatePictureIndirect(NULL, iid, FALSE, (LPVOID*)&pUnk))) { pUnk = NULL; } } // General case: create the object else if (FAILED(CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, (LPVOID*)&pUnk))) { pUnk = NULL; } if (pUnk != NULL) { if (!_AfxLoadObjectFromStreamedPropset(pUnk, lpStream)) { RELEASE(pUnk); pUnk = NULL; } } } return pUnk; }
static void test_get_Attributes(void) { IPicture *pic; HRESULT hres; short type; DWORD attr; OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic); hres = IPicture_get_Type(pic, &type); ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres); ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type); hres = IPicture_get_Attributes(pic, NULL); ole_expect(hres, E_POINTER); attr = 0xdeadbeef; hres = IPicture_get_Attributes(pic, &attr); ole_expect(hres, S_OK); ok(attr == 0, "IPicture_get_Attributes does not reset attr to zero, got %d\n", attr); IPicture_Release(pic); }
STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture) { if( NULL == picture ) return E_POINTER; libvlc_media_player_t *p_md; HRESULT hr = getMD(&p_md); if( SUCCEEDED(hr) ) { static int uniqueId = 0; TCHAR path[MAX_PATH+1]; int pathlen = GetTempPath(MAX_PATH-24, path); if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) ) return E_FAIL; /* check temp directory path by openning it */ { HANDLE dirHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if( INVALID_HANDLE_VALUE == dirHandle ) { Instance()->setErrorInfo(IID_IVLCVideo, "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars."); return E_FAIL; } else { BY_HANDLE_FILE_INFORMATION bhfi; BOOL res = GetFileInformationByHandle(dirHandle, &bhfi); CloseHandle(dirHandle); if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) { Instance()->setErrorInfo(IID_IVLCVideo, "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars."); return E_FAIL; } } } TCHAR filepath[MAX_PATH+1]; _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"), path, GetCurrentProcessId(), ++uniqueId); #ifdef _UNICODE /* reuse path storage for UTF8 string */ char *psz_filepath = (char *)path; WCHAR* wpath = filepath; #else char *psz_filepath = path; /* first convert to unicode using current code page */ WCHAR wpath[MAX_PATH+1]; if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) ) return E_FAIL; #endif /* convert to UTF8 */ pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL); // fail if path is 0 or too short (i.e pathlen is the same as // storage size) if( (0 == pathlen) || (sizeof(path) == pathlen) ) return E_FAIL; /* take snapshot into file */ if( libvlc_video_take_snapshot(p_md, 0, psz_filepath, 0, 0) == 0 ) { /* open snapshot file */ HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE); if( snapPic ) { PICTDESC snapDesc; snapDesc.cbSizeofstruct = sizeof(PICTDESC); snapDesc.picType = PICTYPE_BITMAP; snapDesc.bmp.hbitmap = (HBITMAP)snapPic; snapDesc.bmp.hpal = NULL; hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture); if( FAILED(hr) ) { *picture = NULL; DeleteObject(snapPic); } } DeleteFile(filepath); } } return hr; };
static void test_Render(void) { IPicture *pic; HRESULT hres; short type; PICTDESC desc; HDC hdc = GetDC(0); /* test IPicture::Render return code on uninitialized picture */ OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic); hres = IPicture_get_Type(pic, &type); ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres); ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type); /* zero dimensions */ hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); /* nonzero dimensions, PICTYPE_UNINITIALIZED */ hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 10, NULL); ole_expect(hres, S_OK); IPicture_Release(pic); desc.cbSizeofstruct = sizeof(PICTDESC); desc.picType = PICTYPE_ICON; desc.u.icon.hicon = LoadIcon(NULL, IDI_APPLICATION); if(!desc.u.icon.hicon){ win_skip("LoadIcon failed. Skipping...\n"); ReleaseDC(NULL, hdc); return; } OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE, (VOID**)&pic); /* zero dimensions, PICTYPE_ICON */ hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); IPicture_Release(pic); ReleaseDC(NULL, hdc); }
static void test_Render(void) { IPicture *pic; HRESULT hres; short type; PICTDESC desc; OLE_XSIZE_HIMETRIC pWidth; OLE_YSIZE_HIMETRIC pHeight; COLORREF result, expected; HDC hdc = GetDC(0); /* test IPicture::Render return code on uninitialized picture */ OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic); hres = IPicture_get_Type(pic, &type); ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres); ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type); /* zero dimensions */ hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); /* nonzero dimensions, PICTYPE_UNINITIALIZED */ hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 10, NULL); ole_expect(hres, S_OK); IPicture_Release(pic); desc.cbSizeofstruct = sizeof(PICTDESC); desc.picType = PICTYPE_ICON; desc.u.icon.hicon = LoadIcon(NULL, IDI_APPLICATION); if(!desc.u.icon.hicon){ win_skip("LoadIcon failed. Skipping...\n"); ReleaseDC(NULL, hdc); return; } OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE, (VOID**)&pic); /* zero dimensions, PICTYPE_ICON */ hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); /* Check if target size and position is respected */ IPicture_get_Width(pic, &pWidth); IPicture_get_Height(pic, &pHeight); SetPixelV(hdc, 0, 0, 0x00F0F0F0); SetPixelV(hdc, 5, 5, 0x00F0F0F0); SetPixelV(hdc, 10, 10, 0x00F0F0F0); expected = GetPixel(hdc, 0, 0); hres = IPicture_Render(pic, hdc, 1, 1, 9, 9, 0, 0, pWidth, -pHeight, NULL); ole_expect(hres, S_OK); if(hres != S_OK) { IPicture_Release(pic); ReleaseDC(NULL, hdc); return; } /* Evaluate the rendered Icon */ result = GetPixel(hdc, 0, 0); ok(result == expected, "Color at 0,0 should be unchanged 0x%06X, but was 0x%06X\n", expected, result); result = GetPixel(hdc, 5, 5); ok(result != expected || broken(result == expected), /* WinNT 4.0 and older may claim they drew */ /* the icon, even if they didn't. */ "Color at 5,5 should have changed, but still was 0x%06X\n", expected); result = GetPixel(hdc, 10, 10); ok(result == expected, "Color at 10,10 should be unchanged 0x%06X, but was 0x%06X\n", expected, result); IPicture_Release(pic); ReleaseDC(NULL, hdc); }
static void test_himetric(void) { static const BYTE bmp_bits[1024]; OLE_XSIZE_HIMETRIC cx; OLE_YSIZE_HIMETRIC cy; IPicture *pic; PICTDESC desc; HBITMAP bmp; HRESULT hr; HICON icon; HDC hdc; INT d; desc.cbSizeofstruct = sizeof(desc); desc.picType = PICTYPE_BITMAP; desc.u.bmp.hpal = NULL; hdc = CreateCompatibleDC(0); bmp = CreateBitmap(1.9 * GetDeviceCaps(hdc, LOGPIXELSX), 1.9 * GetDeviceCaps(hdc, LOGPIXELSY), 1, 1, NULL); desc.u.bmp.hbitmap = bmp; /* size in himetric units reported rounded up to next integer value */ hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic); ok(hr == S_OK, "got 0x%08x\n", hr); cx = 0; d = MulDiv((INT)(1.9 * GetDeviceCaps(hdc, LOGPIXELSX)), 2540, GetDeviceCaps(hdc, LOGPIXELSX)); hr = IPicture_get_Width(pic, &cx); ok(hr == S_OK, "got 0x%08x\n", hr); ok(cx == d, "got %d, expected %d\n", cx, d); cy = 0; d = MulDiv((INT)(1.9 * GetDeviceCaps(hdc, LOGPIXELSY)), 2540, GetDeviceCaps(hdc, LOGPIXELSY)); hr = IPicture_get_Height(pic, &cy); ok(hr == S_OK, "got 0x%08x\n", hr); ok(cy == d, "got %d, expected %d\n", cy, d); DeleteObject(bmp); IPicture_Release(pic); /* same thing with icon */ icon = CreateIcon(NULL, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 1, 1, bmp_bits, bmp_bits); ok(icon != NULL, "failed to create icon\n"); desc.picType = PICTYPE_ICON; desc.u.icon.hicon = icon; hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic); ok(hr == S_OK, "got 0x%08x\n", hr); cx = 0; d = MulDiv(GetSystemMetrics(SM_CXICON), 2540, GetDeviceCaps(hdc, LOGPIXELSX)); hr = IPicture_get_Width(pic, &cx); ok(hr == S_OK, "got 0x%08x\n", hr); ok(cx == d, "got %d, expected %d\n", cx, d); cy = 0; d = MulDiv(GetSystemMetrics(SM_CYICON), 2540, GetDeviceCaps(hdc, LOGPIXELSY)); hr = IPicture_get_Height(pic, &cy); ok(hr == S_OK, "got 0x%08x\n", hr); ok(cy == d, "got %d, expected %d\n", cy, d); IPicture_Release(pic); DestroyIcon(icon); DeleteDC(hdc); }