INT_PTR CALLBACK DlgSkinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { if (hPreviewBitmap) ske_UnloadGlyphImage(hPreviewBitmap); break; } case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); SetDlgItemText(hwndDlg, IDC_SKINFOLDERLABEL, SkinsFolder); HTREEITEM it = FillAvailableSkinList(hwndDlg); HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1); TreeView_SelectItem(wnd, it); } return 0; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_COLOUR_MENUNORMAL: case IDC_COLOUR_MENUSELECTED: case IDC_COLOUR_FRAMES: case IDC_COLOUR_STATUSBAR: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_BUTTON_INFO: { TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000]; SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1)); if (hti == 0) return 0; { TVITEM tvi = { 0 }; tvi.hItem = hti; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi); sd = (SkinListData*)(tvi.lParam); } if (!sd) return 0; if (sd->File && !_tcschr(sd->File, _T('%'))) { GetPrivateProfileString(_T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF(Author), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF(URL), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF(Contact), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF(Description), sd->File); mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s):\t %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), sd->Name, Description, Author, Contact, URL, sd->File); } else { mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s): %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"), TranslateT("reVista for Modern v0.5"), TranslateT("This is second default Modern Contact list skin in Vista Aero style"), TranslateT("Angeli-Ka (graphics), FYR (template)"), _T("JID: [email protected]"), _T("fyr.mirandaim.ru"), TranslateT("Inside library")); } MessageBox(hwndDlg, text, TranslateT("Skin information"), MB_OK | MB_ICONINFORMATION); } break; case IDC_BUTTON_APPLY_SKIN: if (HIWORD(wParam) == BN_CLICKED) { SkinListData *sd = NULL; HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1)); if (hti == 0) return 0; { TVITEM tvi = { 0 }; tvi.hItem = hti; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi); sd = (SkinListData*)(tvi.lParam); } if (!sd) return 0; ske_LoadSkinFromIniFile(sd->File, FALSE); ske_LoadSkinFromDB(); pcli->pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0); Sync(CLUIFrames_OnClistResize_mod, 0, 0); ske_RedrawCompleteWindow(); Sync(CLUIFrames_OnClistResize_mod, 0, 0); { HWND hwnd = pcli->hwndContactList; RECT rc = { 0 }; GetWindowRect(hwnd, &rc); Sync(CLUIFrames_OnMoving, hwnd, &rc); } if (g_hCLUIOptionsWnd) { SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_LEFTMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "LeftClientMargin", SETTING_LEFTCLIENTMARIGN_DEFAULT)); SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_RIGHTMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "RightClientMargin", SETTING_RIGHTCLIENTMARIGN_DEFAULT)); SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_TOPMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "TopClientMargin", SETTING_TOPCLIENTMARIGN_DEFAULT)); SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_BOTTOMMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "BottomClientMargin", SETTING_BOTTOMCLIENTMARIGN_DEFAULT)); } } break; case IDC_BUTTON_RESCAN: if (HIWORD(wParam) == BN_CLICKED) { HTREEITEM it = FillAvailableSkinList(hwndDlg); HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1); TreeView_SelectItem(wnd, it); } } break; } case WM_DRAWITEM: if (wParam == IDC_PREVIEW) { //TODO:Draw hPreviewBitmap here int mWidth, mHeight; HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; mWidth = dis->rcItem.right - dis->rcItem.left; mHeight = dis->rcItem.bottom - dis->rcItem.top; HDC memDC = CreateCompatibleDC(dis->hDC); HBITMAP hbmp = ske_CreateDIB32(mWidth, mHeight); HBITMAP holdbmp = (HBITMAP)SelectObject(memDC, hbmp); RECT workRect = dis->rcItem; OffsetRect(&workRect, -workRect.left, -workRect.top); FillRect(memDC, &workRect, hbr); DeleteObject(hbr); if (hPreviewBitmap) { //variables BITMAP bmp = { 0 }; POINT imgPos = { 0 }; float xScale = 1, yScale = 1; //GetSize GetObject(hPreviewBitmap, sizeof(BITMAP), &bmp); int wWidth = workRect.right - workRect.left; int wHeight = workRect.bottom - workRect.top; if (wWidth < bmp.bmWidth) xScale = (float)wWidth / bmp.bmWidth; if (wHeight < bmp.bmHeight) yScale = (float)wHeight / bmp.bmHeight; xScale = min(xScale, yScale); yScale = xScale; int dWidth = (int)(xScale*bmp.bmWidth); int dHeight = (int)(yScale*bmp.bmHeight); //CalcPosition imgPos.x = workRect.left + ((wWidth - dWidth) >> 1); imgPos.y = workRect.top + ((wHeight - dHeight) >> 1); //DrawImage DrawAvatarImageWithGDIp(memDC, imgPos.x, imgPos.y, dWidth, dHeight, hPreviewBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, 8, 255); } BitBlt(dis->hDC, dis->rcItem.left, dis->rcItem.top, mWidth, mHeight, memDC, 0, 0, SRCCOPY); SelectObject(memDC, holdbmp); DeleteObject(hbmp); DeleteDC(memDC); } break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->idFrom) { case IDC_TREE1: { NMTREEVIEW * nmtv = (NMTREEVIEW *)lParam; if (nmtv == NULL) return 0; if (nmtv->hdr.code == TVN_SELCHANGEDA || nmtv->hdr.code == TVN_SELCHANGEDW) { SkinListData * sd = NULL; if (hPreviewBitmap) { ske_UnloadGlyphImage(hPreviewBitmap); hPreviewBitmap = NULL; } if (nmtv->itemNew.lParam) { sd = (SkinListData*)nmtv->itemNew.lParam; TCHAR buf[MAX_PATH]; PathToRelativeT(sd->File, buf); SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, buf); TCHAR prfn[MAX_PATH] = { 0 }, imfn[MAX_PATH] = { 0 }, skinfolder[MAX_PATH] = { 0 }; GetPrivateProfileString(_T("Skin_Description_Section"), _T("Preview"), _T(""), imfn, SIZEOF(imfn), sd->File); IniParser::GetSkinFolder(sd->File, skinfolder); mir_sntprintf(prfn, SIZEOF(prfn), _T("%s\\%s"), skinfolder, imfn); PathToAbsoluteT(prfn, imfn); hPreviewBitmap = ske_LoadGlyphImage(imfn); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_APPLY_SKIN), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_INFO), TRUE); if (hPreviewBitmap) InvalidateRect(GetDlgItem(hwndDlg, IDC_PREVIEW), NULL, TRUE); else { //prepare text TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000]; SkinListData* sd = NULL; HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1)); if (hti == 0) return 0; { TVITEM tvi = { 0 }; tvi.hItem = hti; tvi.mask = TVIF_HANDLE | TVIF_PARAM; TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi); sd = (SkinListData*)(tvi.lParam); } if (!sd) return 0; if (sd->File && !_tcschr(sd->File, _T('%'))) { GetPrivateProfileString(_T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF(Author), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF(URL), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF(Contact), sd->File); GetPrivateProfileString(_T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF(Description), sd->File); mir_sntprintf(text, SIZEOF(text), TranslateT("Preview is not available\n\n%s\n----------------------\n\n%s\n\nAUTHOR(S):\n%s\n\nCONTACT:\n%s\n\nHOMEPAGE:\n%s"), sd->Name, Description, Author, Contact, URL); } else { mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAUTHORS:\n%s\n\nCONTACT:\n%s\n\nWEB:\n%s\n\n\n"), TranslateT("reVista for Modern v0.5"), TranslateT("This is second default Modern Contact list skin in Vista Aero style"), TranslateT("graphics by Angeli-Ka\ntemplate by FYR"), _T("JID: [email protected]"), _T("fyr.mirandaim.ru")); } ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_INFO), SW_SHOW); SetDlgItemText(hwndDlg, IDC_STATIC_INFO, text); } } else { //no selected SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, TranslateT("Select skin from list")); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_APPLY_SKIN), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_INFO), FALSE); SetDlgItemText(hwndDlg, IDC_STATIC_INFO, TranslateT("Please select skin to apply")); ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), SW_HIDE); } ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), hPreviewBitmap ? SW_SHOW : SW_HIDE); return 0; } else if (nmtv->hdr.code == TVN_DELETEITEMA || nmtv->hdr.code == TVN_DELETEITEMW) { mir_free_and_nil(nmtv->itemOld.lParam); return 0; } } break; case 0: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: pcli->pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0); NotifyEventHooks(g_CluiData.hEventBkgrChanged, 0, 0); pcli->pfnClcBroadcast(INTM_INVALIDATE, 0, 0); RedrawWindow(GetParent(pcli->hwndContactTree), NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); } break; } }
static void test_palette_brush(void) { char buffer[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD) + 16 * 16]; BITMAPINFO *info = (BITMAPINFO *)buffer; WORD *indices = (WORD *)info->bmiColors; char pal_buffer[sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY)]; LOGPALETTE *pal = (LOGPALETTE *)pal_buffer; HDC hdc = CreateCompatibleDC( 0 ); DWORD *dib_bits; HBITMAP dib; HBRUSH brush; int i; HPALETTE palette, palette2; memset( info, 0, sizeof(*info) ); info->bmiHeader.biSize = sizeof(info->bmiHeader); info->bmiHeader.biWidth = 16; info->bmiHeader.biHeight = 16; info->bmiHeader.biPlanes = 1; info->bmiHeader.biBitCount = 32; info->bmiHeader.biCompression = BI_RGB; dib = CreateDIBSection( NULL, info, DIB_RGB_COLORS, (void**)&dib_bits, NULL, 0 ); ok( dib != NULL, "CreateDIBSection failed\n" ); info->bmiHeader.biBitCount = 8; for (i = 0; i < 256; i++) indices[i] = 255 - i; for (i = 0; i < 256; i++) ((BYTE *)(indices + 256))[i] = i; brush = CreateDIBPatternBrushPt( info, DIB_PAL_COLORS ); ok( brush != NULL, "CreateDIBPatternBrushPt failed\n" ); pal->palVersion = 0x300; pal->palNumEntries = 256; for (i = 0; i < 256; i++) { pal->palPalEntry[i].peRed = i * 2; pal->palPalEntry[i].peGreen = i * 2; pal->palPalEntry[i].peBlue = i * 2; pal->palPalEntry[i].peFlags = 0; } palette = CreatePalette( pal ); ok( SelectObject( hdc, dib ) != NULL, "SelectObject failed\n" ); ok( SelectPalette( hdc, palette, 0 ) != NULL, "SelectPalette failed\n" ); ok( SelectObject( hdc, brush ) != NULL, "SelectObject failed\n" ); memset( dib_bits, 0xaa, 16 * 16 * 4 ); PatBlt( hdc, 0, 0, 16, 16, PATCOPY ); for (i = 0; i < 256; i++) { DWORD expect = (pal->palPalEntry[255 - i].peRed << 16 | pal->palPalEntry[255 - i].peGreen << 8 | pal->palPalEntry[255 - i].peBlue); ok( dib_bits[i] == expect, "wrong bits %x/%x at %u,%u\n", dib_bits[i], expect, i % 16, i / 16 ); } for (i = 0; i < 256; i++) pal->palPalEntry[i].peRed = i * 3; palette2 = CreatePalette( pal ); ok( SelectPalette( hdc, palette2, 0 ) != NULL, "SelectPalette failed\n" ); memset( dib_bits, 0xaa, 16 * 16 * 4 ); PatBlt( hdc, 0, 0, 16, 16, PATCOPY ); for (i = 0; i < 256; i++) { DWORD expect = (pal->palPalEntry[255 - i].peRed << 16 | pal->palPalEntry[255 - i].peGreen << 8 | pal->palPalEntry[255 - i].peBlue); ok( dib_bits[i] == expect, "wrong bits %x/%x at %u,%u\n", dib_bits[i], expect, i % 16, i / 16 ); } DeleteDC( hdc ); DeleteObject( dib ); DeleteObject( brush ); DeleteObject( palette ); DeleteObject( palette2 ); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT lpPaint; switch(iMessage) { case WM_CLOSE: case WM_DESTROY: exit(0); if(MessageBox(hWnd, "Do you really want to quit?", "Message", MB_YESNO) == IDYES) PostQuitMessage(0); break; case WM_ERASEBKGND: return 1; // Done case WM_PAINT: GdiFlush(); hDC = BeginPaint( hWnd, &lpPaint); // Assume hPaintDC is a variable of type HDC, and the dc we're rendering to HDC hBitmapDC = CreateCompatibleDC(hDC); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, screenBitmap); //HPALETTE hOldPalette = SelectPalette(hPaintDC, hPalette, FALSE); GdiFlush(); if( !BitBlt(hDC, 0, 0, VSCREEN_WIDTH, VSCREEN_HEIGHT, hBitmapDC, 0, 0, SRCCOPY) ) { DWORD err = GetLastError(); //FormatMessage(); printf("Win error %d", (int)err); LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); printf("WinErr: %s\n", (const char *)lpMsgBuf ); } GdiFlush(); //SelectPalette(hPaintDC, hOldPalette, TRUE); SelectObject(hBitmapDC, hOldBitmap); DeleteDC(hBitmapDC); /*if(eline) { MoveToEx(hDC, 60, 20, NULL); LineTo(hDC, 264, 122); }*/ // TODO: paint OS mouse cursor EndPaint( hWnd, &lpPaint); break; #if HOVER case WM_MOUSEHOVER: { int xPos = (short)(0x0FFFF & lParam);//GET_X_LPARAM(lParam); int yPos = VSCREEN_HEIGHT - (short)(0x0FFFF & (lParam>>16));//GET_Y_LPARAM(lParam); printf("%d,%d\n", xPos, yPos ); TrackMouseEvent(&eventTrack); } break; #endif //case WM_KEYDOWN: //case WM_KEYUP: TranslateMessage( __in const MSG *lpMsg ); case WM_CHAR: { printf("-%x-", (int)lParam ); } break; case WM_MOUSEMOVE: { int xPos = (short)(0x0FFFF & lParam);//GET_X_LPARAM(lParam); int yPos = VSCREEN_HEIGHT - (short)(0x0FFFF & (lParam>>16));//GET_Y_LPARAM(lParam); // printf("%d,%d\n", xPos, yPos ); drv_video_win32.mouse_x = xPos; drv_video_win32.mouse_y = yPos; drv_video_win32.mouse_flags = wParam; drv_video_win32.mouse(); #if 1 struct ui_event e; e.type = UI_EVENT_TYPE_MOUSE; e.time = fast_time(); e.focus= 0; e.m.buttons = wParam; e.abs_x = xPos; e.abs_y = VSCREEN_HEIGHT - yPos - 1; ev_q_put_any( &e ); //printf("-ms-"); printf("%d,%d\n", xPos, yPos ); #endif } break; default: return DefWindowProc(hWnd, iMessage, wParam, lParam); } return 0; }
void CDlgScraperOutput::DoBitblt(HBITMAP bitmap, RMapCI r_iter) { CDC *pDC = m_ScraperBitmap.GetDC(); HDC hdcControl = *pDC; HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); HDC hdcCompat1 = CreateCompatibleDC(hdcScreen); HDC hdcCompat2 = CreateCompatibleDC(hdcScreen); HBITMAP hbm2 = NULL, old_bitmap1 = NULL, old_bitmap2 = NULL; int w = 0, h = 0, zoom = 0; RECT rect = {0}; CBrush gray_brush, *pTempBrush = NULL, oldbrush; CPen null_pen, *pTempPen = NULL, oldpen; CString res = ""; CTransform trans; if (in_startup) { DeleteDC(hdcCompat1); DeleteDC(hdcCompat2); DeleteDC(hdcScreen); ReleaseDC(pDC); return; } m_ScraperBitmap.GetWindowRect(&rect); // Erase control area gray_brush.CreateSolidBrush(COLOR_GRAY); pTempBrush = (CBrush*)pDC->SelectObject(&gray_brush); oldbrush.FromHandle((HBRUSH)pTempBrush); // Save old brush null_pen.CreatePen(PS_NULL, 0, COLOR_BLACK); pTempPen = (CPen*)pDC->SelectObject(&null_pen); oldpen.FromHandle((HPEN)pTempPen); // Save old pen pDC->Rectangle(1, 1, rect.right-rect.left, rect.bottom-rect.top); pDC->SelectObject(oldbrush); pDC->SelectObject(oldpen); // return if all we needed to do was erase display if (bitmap == NULL) { DeleteDC(hdcCompat1); DeleteDC(hdcCompat2); DeleteDC(hdcScreen); ReleaseDC(pDC); return; } // load bitmap into 1st DC and stretchblt to 2nd DC old_bitmap1 = (HBITMAP) SelectObject(hdcCompat1, bitmap); zoom = m_Zoom.GetCurSel()==0 ? 1 : m_Zoom.GetCurSel()==1 ? 2 : m_Zoom.GetCurSel()==2 ? 4 : m_Zoom.GetCurSel()==3 ? 8 : m_Zoom.GetCurSel()==4 ? 16 : 1; w = (r_iter->second.right - r_iter->second.left) * zoom; h = (r_iter->second.bottom - r_iter->second.top) * zoom; hbm2 = CreateCompatibleBitmap(hdcScreen, w, h); old_bitmap2 = (HBITMAP) SelectObject(hdcCompat2, hbm2); StretchBlt( hdcCompat2, 0, 0, w, h, hdcCompat1, 0, 0, r_iter->second.right - r_iter->second.left, r_iter->second.bottom - r_iter->second.top, SRCCOPY ); // Copy 2nd DC to control BitBlt( hdcControl, 1, 1, rect.right-rect.left-2, rect.bottom-rect.top-2, hdcCompat2, 0, 0, SRCCOPY ); // Output result trans.DoTransform(r_iter, hdcCompat1, &res); m_ScraperResult.SetWindowText(res); // Clean up SelectObject(hdcCompat1, old_bitmap1); SelectObject(hdcCompat2, old_bitmap2); DeleteObject(hbm2); DeleteDC(hdcCompat1); DeleteDC(hdcCompat2); DeleteDC(hdcScreen); ReleaseDC(pDC); }
void _DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, short xStart, short yStart, COLORREF cTransparentColor) { BITMAP bm; COLORREF cColor; HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave; POINT ptSize; hdcTemp = CreateCompatibleDC(hdc); SelectObject(hdcTemp, hBitmap); // Select the bitmap GetObject(hBitmap, sizeof(BITMAP), &bm); ptSize.x = bm.bmWidth; // Get width of bitmap ptSize.y = bm.bmHeight; // Get height of bitmap DPtoLP(hdcTemp, &ptSize, 1); // Convert from device // to logical points // Create some DCs to hold temporary data. hdcBack = CreateCompatibleDC(hdc); hdcObject = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc); hdcSave = CreateCompatibleDC(hdc); // Create a bitmap for each DC. DCs are required for a number of // GDI functions. // Monochrome DC bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); // Monochrome DC bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); // Each DC must select a bitmap object to store pixel data. bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack); bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject); bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem); bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave); // Set proper mapping mode. SetMapMode(hdcTemp, GetMapMode(hdc)); // Save the bitmap sent here, because it will be overwritten. BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC to the color. // contained in the parts of the bitmap that should be transparent cColor = SetBkColor(hdcTemp, cTransparentColor); // Create the object mask for the bitmap by performing a BitBlt // from the source bitmap to a monochrome bitmap. BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC back to the original // color. SetBkColor(hdcTemp, cColor); // Create the inverse of the object mask. BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY); // Copy the background of the main DC to the destination. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY); // Mask out the places where the bitmap will be placed. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND); // Mask out the transparent colored pixels on the bitmap. BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND); // XOR the bitmap with the background on the destination DC. BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT); // Copy the destination to the screen. BitBlt(hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY); // Place the original bitmap back into the bitmap sent here. BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY); // Delete the memory bitmaps. DeleteObject(SelectObject(hdcBack, bmBackOld)); DeleteObject(SelectObject(hdcObject, bmObjectOld)); DeleteObject(SelectObject(hdcMem, bmMemOld)); DeleteObject(SelectObject(hdcSave, bmSaveOld)); // Delete the memory DCs. DeleteDC(hdcMem); DeleteDC(hdcBack); DeleteDC(hdcObject); DeleteDC(hdcSave); DeleteDC(hdcTemp); }
void drawsplash(HWND hDlg, char* str){ m_Blend.BlendOp = AC_SRC_OVER; //theonlyBlendOpdefinedinWindows2000 m_Blend.BlendFlags = 0; //nothingelseisspecial... m_Blend.AlphaFormat = AC_SRC_ALPHA; //... m_Blend.SourceConstantAlpha = 255;//AC_SRC_ALPHA static Image *m_pImageBack; if(!m_pImageBack) ImageFromIDResource(IDB_PNG1, L"PNG", m_pImageBack); //----绘制 PAINTSTRUCT ps; HDC hdcTemp = BeginPaint(hDlg, &ps); HDC hMemDC = CreateCompatibleDC(hdcTemp); RECT rct; GetWindowRect(hDlg, &rct); HBITMAP hBitMap = CreateCompatibleBitmap(hdcTemp, rct.right - rct.left, rct.bottom - rct.top); HBITMAP hBmpOld = (HBITMAP)SelectObject(hMemDC, hBitMap); HDC hdcScreen = GetDC(hDlg); POINT ptWinPos = { rct.left, rct.top }; Graphics imageGraphics(hMemDC); Point points[] = { Point(0, 0), Point(400, 0), Point(0, 255) }; Point points2[] = { Point(50, 50), Point(450, 50), Point(50, 305) }; // 设置层次窗口 DWORD dwExStyle = GetWindowLong(hDlg, GWL_EXSTYLE); if ((dwExStyle & 0x80000) != 0x80000){ SetWindowLong(hDlg, GWL_EXSTYLE, dwExStyle ^ 0x80000); } POINT ptSrc = { 0, 0 }; SIZE sizeWindow = { rct.right - rct.left, rct.bottom - rct.top }; // 完成透明不规则窗口的绘制 imageGraphics.DrawImage(m_pImageBack, points, 3); WCHAR* drawString = (WCHAR*)calloc(256, sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, str, (int)strlen(str), drawString, 255); // Create font and brush. Font* drawFont = new Font(L"Tahoma", 8); SolidBrush* drawBrush = new SolidBrush(Color::White); // Create point for upper-left corner of drawing. PointF drawPoint = PointF(210.0F, 240.0F); // Draw string to screen. imageGraphics.DrawString(drawString, -1, drawFont, drawPoint, drawBrush); delete drawFont; delete drawBrush; UpdateLayeredWindow(hDlg, hdcScreen, &ptWinPos, &sizeWindow, hMemDC, &ptSrc, 255, &m_Blend, ULW_ALPHA); // 释放空间 EndPaint(hDlg, &ps); }
DWORD CmdDrawZoom::CmdDrawAjustZooming::SetPoint(DWORD MouseAction, CPoint pt) { CmdDrawZoom *p = dynamic_cast<CmdDrawZoom*>(m_pOwner); if (enCmdMouseNone == MouseAction) { LP_MATERIALINFO pTempInfo = p->m_pReceiver->getComicStripData()->getSelectedInfo(); if (NULL == pTempInfo) { return FALSE; } CSize size = CSize(pt.x - pTempInfo->GetLTPoint().x, pt.y - pTempInfo->GetLTPoint().y); size.cx = max(size.cx, 24); size.cy = max(size.cy, 24); pTempInfo->SetFinalSize(size); if (pTempInfo->isPenDraw) { int width = pTempInfo->m_image.GetWidth(); int height = pTempInfo->m_image.GetHeight(); if (width<size.cx || height<size.cy) { int newWidth = max(width, size.cx); int newHeight = max(height, size.cy); CxImage tempImage = pTempInfo->m_image; pTempInfo->m_image.Create(newWidth, newHeight, 24, CXIMAGE_FORMAT_PNG); RGBQUAD rgb = pTempInfo->m_image.GetPixelColor(1,1); pTempInfo->m_image.SetTransIndex(0); pTempInfo->m_image.SetTransColor(rgb); HDC memdcOrg = CreateCompatibleDC(NULL); HBITMAP hbitmapOrg = tempImage.MakeBitmap(); HGDIOBJ pOldGDIOBJOrg = SelectObject(memdcOrg, hbitmapOrg); HDC memdc = CreateCompatibleDC(NULL); HBITMAP hbitmap = pTempInfo->m_image.MakeBitmap(); HGDIOBJ pOldGDIOBJ = SelectObject(memdc, hbitmap); BitBlt(memdc, 0, 0, width, height, memdcOrg, 0, 0, SRCCOPY); pTempInfo->m_image.CreateFromHBITMAP(hbitmap); SelectObject(memdc, pOldGDIOBJ); DeleteObject(hbitmap); DeleteDC(memdc); SelectObject(memdcOrg, pOldGDIOBJOrg); DeleteObject(hbitmapOrg); DeleteDC(memdcOrg); } } p->m_pReceiver->UpdateComicStrip(pTempInfo->nIDOwner); } else if (enCmdMouseLUp == MouseAction) { LP_MATERIALINFO pTempInfo = p->m_pReceiver->getComicStripData()->getSelectedInfo(); if (NULL == pTempInfo) { return FALSE; } CSize size = CSize(pt.x - pTempInfo->GetLTPoint().x, pt.y - pTempInfo->GetLTPoint().y); size.cx = max(size.cx, 24); size.cy = max(size.cy, 24); pTempInfo->SetFinalSize(size); if (pTempInfo->isPenDraw) { int width = pTempInfo->m_image.GetWidth(); int height = pTempInfo->m_image.GetHeight(); if (width<size.cx || height<size.cy) { CxImage tempImage = pTempInfo->m_image; pTempInfo->m_image.Create(size.cx, size.cy, 24, CXIMAGE_FORMAT_PNG); RGBQUAD rgb = pTempInfo->m_image.GetPixelColor(1,1); pTempInfo->m_image.SetTransIndex(0); pTempInfo->m_image.SetTransColor(rgb); HDC memdcOrg = CreateCompatibleDC(NULL); HBITMAP hbitmapOrg = tempImage.MakeBitmap(); HGDIOBJ pOldGDIOBJOrg = SelectObject(memdcOrg, hbitmapOrg); HDC memdc = CreateCompatibleDC(NULL); HBITMAP hbitmap = pTempInfo->m_image.MakeBitmap(); HGDIOBJ pOldGDIOBJ = SelectObject(memdc, hbitmap); BitBlt(memdc, 0, 0, width, height, memdcOrg, 0, 0, SRCCOPY); pTempInfo->m_image.CreateFromHBITMAP(hbitmap); SelectObject(memdc, pOldGDIOBJ); DeleteObject(hbitmap); DeleteDC(memdc); SelectObject(memdcOrg, pOldGDIOBJOrg); DeleteObject(hbitmapOrg); DeleteDC(memdcOrg); } } p->m_pReceiver->SaveFile(); p->m_pReceiver->UpdateComicStrip(pTempInfo->nIDOwner); p->m_pDsState = &p->m_dsZoomBgn; p->m_pReceiver->SetCursor(); p->m_nDrawState = enDrawIdle; } return TRUE; }
JNIEXPORT jlong JNICALL Java_sun_font_FileFontStrike__1getGlyphImageFromWindows (JNIEnv *env, jobject unused, jstring fontFamily, jint style, jint size, jint glyphCode, jboolean fm) { GLYPHMETRICS glyphMetrics; LOGFONTW lf; BITMAPINFO bmi; TEXTMETRIC textMetric; RECT rect; int bytesWidth, dibBytesWidth, extra, imageSize, dibImageSize; unsigned char* dibImage = NULL, *rowPtr, *pixelPtr, *dibPixPtr, *dibRowPtr; unsigned char r,g,b; unsigned char* igTable; GlyphInfo* glyphInfo = NULL; int nameLen; LPWSTR name; HFONT oldFont, hFont; MAT2 mat2; unsigned short width; unsigned short height; short advanceX; short advanceY; int topLeftX; int topLeftY; int err; int bmWidth, bmHeight; int x, y; HBITMAP hBitmap = NULL, hOrigBM; int gamma, orient; HWND hWnd = NULL; HDC hDesktopDC = NULL; HDC hMemoryDC = NULL; hWnd = GetDesktopWindow(); hDesktopDC = GetWindowDC(hWnd); if (hDesktopDC == NULL) { return (jlong)0; } if (GetDeviceCaps(hDesktopDC, BITSPIXEL) < 15) { FREE_AND_RETURN; } hMemoryDC = CreateCompatibleDC(hDesktopDC); if (hMemoryDC == NULL || fontFamily == NULL) { FREE_AND_RETURN; } err = SetMapMode(hMemoryDC, MM_TEXT); if (err == 0) { FREE_AND_RETURN; } memset(&lf, 0, sizeof(LOGFONTW)); lf.lfHeight = -size; lf.lfWeight = (style & 1) ? FW_BOLD : FW_NORMAL; lf.lfItalic = (style & 2) ? 0xff : 0; lf.lfCharSet = DEFAULT_CHARSET; lf.lfQuality = CLEARTYPE_QUALITY; lf.lfOutPrecision = OUT_TT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfPitchAndFamily = DEFAULT_PITCH; nameLen = (*env)->GetStringLength(env, fontFamily); name = (LPWSTR)alloca((nameLen+1)*2); if (name == NULL) { FREE_AND_RETURN; } (*env)->GetStringRegion(env, fontFamily, 0, nameLen, name); name[nameLen] = '\0'; if (nameLen < (sizeof(lf.lfFaceName) / sizeof(lf.lfFaceName[0]))) { wcscpy(lf.lfFaceName, name); } else { FREE_AND_RETURN; } hFont = CreateFontIndirectW(&lf); if (hFont == NULL) { FREE_AND_RETURN; } oldFont = SelectObject(hMemoryDC, hFont); memset(&textMetric, 0, sizeof(TEXTMETRIC)); err = GetTextMetrics(hMemoryDC, &textMetric); if (err == 0) { FREE_AND_RETURN; } memset(&glyphMetrics, 0, sizeof(GLYPHMETRICS)); memset(&mat2, 0, sizeof(MAT2)); mat2.eM11.value = 1; mat2.eM22.value = 1; err = GetGlyphOutline(hMemoryDC, glyphCode, GGO_METRICS|GGO_GLYPH_INDEX, &glyphMetrics, 0, NULL, &mat2); if (err == GDI_ERROR) { /* Probably no such glyph - ie the font wasn't the one we expected. */ FREE_AND_RETURN; } width = (unsigned short)glyphMetrics.gmBlackBoxX; height = (unsigned short)glyphMetrics.gmBlackBoxY; /* Don't handle "invisible" glyphs in this code */ if (width <= 0 || height == 0) { FREE_AND_RETURN; } advanceX = glyphMetrics.gmCellIncX; advanceY = glyphMetrics.gmCellIncY; topLeftX = glyphMetrics.gmptGlyphOrigin.x; topLeftY = glyphMetrics.gmptGlyphOrigin.y; /* GetGlyphOutline pre-dates cleartype and I'm not sure that it will * account for all pixels touched by the rendering. Need to widen, * and also adjust by one the x position at which it is rendered. * The extra pixels of width are used as follows : * One extra pixel at the left and the right will be needed to absorb * the pixels that will be touched by filtering by GDI to compensate * for colour fringing. * However there seem to be some cases where GDI renders two extra * pixels to the right, so we add one additional pixel to the right, * and in the code that copies this to the image cache we test for * the (rare) cases when this is touched, and if its not reduce the * stated image width for the blitting loops. * For fractional metrics : * One extra pixel at each end to account for sub-pixel positioning used * when fractional metrics is on in LCD mode. * The pixel at the left is needed so the blitting loop can index into * that a byte at a time to more accurately position the glyph. * The pixel at the right is needed so that when such indexing happens, * the blitting still can use the same width. * Consequently the width that is specified for the glyph is one less * than that of the actual image. * Note that in the FM case as a consequence we need to adjust the * position at which GDI renders, and the declared width of the glyph * See the if (fm) {} cases in the code. * For the non-FM case, we not only save 3 bytes per row, but this * prevents apparent glyph overlapping which affects the rendering * performance of accelerated pipelines since it adds additional * read-back requirements. */ width+=3; if (fm) { width+=1; } /* DIB scanline must end on a DWORD boundary. We specify 3 bytes per pixel, * so must round up as needed to a multiple of 4 bytes. */ dibBytesWidth = bytesWidth = width*3; extra = dibBytesWidth % 4; if (extra != 0) { dibBytesWidth += (4-extra); } /* The glyph cache image must be a multiple of 3 bytes wide. */ extra = bytesWidth % 3; if (extra != 0) { bytesWidth += (3-extra); } bmWidth = width; bmHeight = height; /* Must use desktop DC to create a bitmap of that depth */ hBitmap = CreateCompatibleBitmap(hDesktopDC, bmWidth, bmHeight); if (hBitmap == NULL) { FREE_AND_RETURN; } hOrigBM = (HBITMAP)SelectObject(hMemoryDC, hBitmap); /* Fill in black */ rect.left = 0; rect.top = 0; rect.right = bmWidth; rect.bottom = bmHeight; FillRect(hMemoryDC, (LPRECT)&rect, GetStockObject(BLACK_BRUSH)); /* Set text color to white, background to black. */ SetBkColor(hMemoryDC, RGB(0,0,0)); SetTextColor(hMemoryDC, RGB(255,255,255)); /* adjust rendering position */ x = -topLeftX+1; if (fm) { x += 1; } y = topLeftY - textMetric.tmAscent; err = ExtTextOutW(hMemoryDC, x, y, ETO_GLYPH_INDEX|ETO_OPAQUE, (LPRECT)&rect, (LPCWSTR)&glyphCode, 1, NULL); if (err == 0) { FREE_AND_RETURN; } /* Now get the image into a DIB. * MS docs for GetDIBits says the compatible bitmap must not be * selected into a DC, so restore the original first. */ SelectObject(hMemoryDC, hOrigBM); SelectObject(hMemoryDC, oldFont); DeleteObject(hFont); memset(&bmi, 0, sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); bmi.bmiHeader.biWidth = width; bmi.bmiHeader.biHeight = -height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; dibImageSize = dibBytesWidth*height; dibImage = malloc(dibImageSize); if (dibImage == NULL) { FREE_AND_RETURN; } memset(dibImage, 0, dibImageSize); err = GetDIBits(hMemoryDC, hBitmap, 0, height, dibImage, &bmi, DIB_RGB_COLORS); if (err == 0) { /* GetDIBits failed. */ FREE_AND_RETURN; } err = SystemParametersInfo(SPI_GETFONTSMOOTHINGORIENTATION, 0, &orient, 0); if (err == 0) { FREE_AND_RETURN; } err = SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0, &gamma, 0); if (err == 0) { FREE_AND_RETURN; } igTable = getIGTable(gamma/10); if (igTable == NULL) { FREE_AND_RETURN; } /* Now copy glyph image into a GlyphInfo structure and return it. * NB the xadvance calculated here may be overwritten by the caller. * 1 is subtracted from the bitmap width to get the glyph width, since * that extra "1" was added as padding, so the sub-pixel positioning of * fractional metrics could index into it. */ imageSize = bytesWidth*height; glyphInfo = (GlyphInfo*)malloc(sizeof(GlyphInfo)+imageSize); if (malloc == NULL) { FREE_AND_RETURN; } glyphInfo->cellInfo = NULL; glyphInfo->rowBytes = bytesWidth; glyphInfo->width = width; if (fm) { glyphInfo->width -= 1; // must subtract 1 } glyphInfo->height = height; glyphInfo->advanceX = advanceX; glyphInfo->advanceY = advanceY; glyphInfo->topLeftX = (float)(topLeftX-1); if (fm) { glyphInfo->topLeftX -= 1; } glyphInfo->topLeftY = (float)-topLeftY; glyphInfo->image = (unsigned char*)glyphInfo+sizeof(GlyphInfo); memset(glyphInfo->image, 0, imageSize); /* DIB 24bpp data is always stored in BGR order, but we usually * need this in RGB, so we can't just memcpy and need to swap B and R. * Also need to apply inverse gamma adjustment here. * We re-use the variable "extra" to see if the last pixel is touched * at all. If its not we can reduce the glyph image width. This comes * into play in some cases where GDI touches more pixels than accounted * for by increasing width by two pixels over the B&W image. Whilst * the bytes are in the cache, it doesn't affect rendering performance * of the hardware pipelines. */ extra = 0; if (fm) { extra = 1; // always need it. } dibRowPtr = dibImage; rowPtr = glyphInfo->image; for (y=0;y<height;y++) { pixelPtr = rowPtr; dibPixPtr = dibRowPtr; for (x=0;x<width;x++) { if (orient == FE_FONTSMOOTHINGORIENTATIONRGB) { b = *dibPixPtr++; g = *dibPixPtr++; r = *dibPixPtr++; } else { r = *dibPixPtr++; g = *dibPixPtr++; b = *dibPixPtr++; } *pixelPtr++ = igTable[r]; *pixelPtr++ = igTable[g]; *pixelPtr++ = igTable[b]; if (!fm && (x==(width-1)) && (r|g|b)) { extra = 1; } } dibRowPtr += dibBytesWidth; rowPtr += bytesWidth; } if (!extra) { glyphInfo->width -= 1; } free(dibImage); ReleaseDC(hWnd, hDesktopDC); DeleteObject(hMemoryDC); DeleteObject(hBitmap); return ptr_to_jlong(glyphInfo); }
int CWinApp::CaptureAnImage(HWND hWnd) { HDC hdcScreen; HDC hdcWindow; HDC hdcMemDC = NULL; HBITMAP hbmScreen = NULL; BITMAP bmpScreen; // Retrieve the handle to a display device context for the client // area of the window. hdcScreen = GetDC(NULL); hdcWindow = GetDC(hWnd); // Create a compatible DC which is used in a BitBlt from the window DC hdcMemDC = CreateCompatibleDC(hdcWindow); if(!hdcMemDC) { MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK); goto done; } // Get the client area for size calculation RECT rcClient; GetClientRect(hWnd, &rcClient); DrawText(hdcWindow,L"客户区字画",_countof(L"客户区字画"),&rcClient,DT_LEFT); //This is the best stretch mode SetStretchBltMode(hdcWindow,HALFTONE); //The source DC is the entire screen and the destination DC is the current window (HWND) if(!StretchBlt(hdcWindow, 0,0, rcClient.right, rcClient.bottom, hdcScreen, 0,0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), SRCCOPY)) { MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK); goto done; } // Create a compatible bitmap from the Window DC hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top); if(!hbmScreen) { MessageBox(hWnd, L"CreateCompatibleBitmap Failed",L"Failed", MB_OK); goto done; } // Select the compatible bitmap into the compatible memory DC. SelectObject(hdcMemDC,hbmScreen); // Bit block transfer into our compatible memory DC. if(!BitBlt(hdcMemDC, 0,0, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, hdcWindow, 0,0, SRCCOPY)) { MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK); goto done; } // Get the BITMAP from the HBITMAP GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen); BITMAPFILEHEADER bmfHeader; BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = bmpScreen.bmWidth; bi.biHeight = bmpScreen.bmHeight; bi.biPlanes = 1; bi.biBitCount = 32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight; // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc // have greater overhead than HeapAlloc. HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); char *lpbitmap = (char *)GlobalLock(hDIB); // Gets the "bits" from the bitmap and copies them into a buffer // which is pointed to by lpbitmap. GetDIBits(hdcWindow, hbmScreen, 0, (UINT)bmpScreen.bmHeight, lpbitmap, (BITMAPINFO *)&bi, DIB_RGB_COLORS); // A file is created, this is where we will save the screen capture. HANDLE hFile = CreateFile(L"d:\\captureqwsx.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // Add the size of the headers to the size of the bitmap to get the total file size DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); //Offset to where the actual bitmap bits start. bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER); //Size of the file bmfHeader.bfSize = dwSizeofDIB; //bfType must always be BM for Bitmaps bmfHeader.bfType = 0x4D42; //BM DWORD dwBytesWritten = 0; WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL); WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL); //Unlock and Free the DIB from the heap GlobalUnlock(hDIB); GlobalFree(hDIB); //Close the handle for the file that was created CloseHandle(hFile); //Clean up done: DeleteObject(hbmScreen); ReleaseDC(hWnd, hdcMemDC); ReleaseDC(NULL,hdcScreen); ReleaseDC(hWnd,hdcWindow); return 0; }
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { PAINTSTRUCT ps; HDC hdc = BeginPaint( &ps ); HDC hdcMem, hdcBB; HBITMAP hbmOld, hbmOldBB; BLENDFUNCTION func = { AC_SRC_OVER, 0, 0, 0 }; ps.rcPaint.right -= ps.rcPaint.left; ps.rcPaint.bottom -= ps.rcPaint.top; if (frame < 400) { hdcMem = CreateCompatibleDC( hdc ); hbmOld = (HBITMAP) SelectObject( hdcMem, frames[0] ); BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcMem, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); SelectObject( hdcMem, hbmOld ); DeleteDC( hdcMem ); } else if (frame < 500) { hdcBB = CreateCompatibleDC( hdc ); hbmOldBB = (HBITMAP) SelectObject( hdcBB, backbuffer ); hdcMem = CreateCompatibleDC( hdc ); hbmOld = (HBITMAP) SelectObject( hdcMem, frames[0] ); BitBlt( hdcBB, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcMem, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); SelectObject( hdcMem, frames[1] ); func.SourceConstantAlpha = (frame - 400) * 255 / 100; AlphaBlend( hdcBB, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcMem, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, func); SelectObject( hdcMem, hbmOld ); DeleteDC( hdcMem ); BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcBB, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); SelectObject( hdcBB, hbmOldBB ); DeleteDC( hdcBB ); } else if (frame < 900) { hdcMem = CreateCompatibleDC( hdc ); hbmOld = (HBITMAP) SelectObject( hdcMem, frames[1] ); BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcMem, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); SelectObject( hdcMem, hbmOld ); DeleteDC( hdcMem ); } else if (frame < 1000) { hdcBB = CreateCompatibleDC( hdc ); hbmOldBB = (HBITMAP) SelectObject( hdcBB, backbuffer ); hdcMem = CreateCompatibleDC( hdc ); hbmOld = (HBITMAP) SelectObject( hdcMem, frames[1] ); BitBlt( hdcBB, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcMem, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); SelectObject( hdcMem, frames[0] ); func.SourceConstantAlpha = (frame - 900) * 255 / 100; AlphaBlend( hdcBB, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcMem, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, func); SelectObject( hdcMem, hbmOld ); DeleteDC( hdcMem ); BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom, hdcBB, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY); SelectObject( hdcBB, hbmOldBB ); DeleteDC( hdcBB ); } EndPaint( &ps ); return 0; }
void IcoSave(const std::wstring &fileName, HICON hicon) { std::ofstream store(fileName.c_str(), std::ios_base::binary); if (!store.is_open()) return; ICONINFO ii; if (!GetIconInfo(hicon, &ii)) { store.close(); return; } HBITMAP hbmMask = ii.hbmMask; HBITMAP hbmColor = ii.hbmColor; BITMAP bmiMask; BITMAP bmiColor; if (GetObject(hbmColor, sizeof(bmiColor), &bmiColor) && GetObject(hbmMask, sizeof(bmiMask), &bmiMask) && (bmiColor.bmWidth == bmiMask.bmWidth) && (bmiColor.bmHeight == bmiMask.bmHeight) && (bmiMask.bmHeight) > 0 && (bmiMask.bmWidth) > 0) { BITMAPINFOHEADER icobmi = { 0 }; MYBITMAPINFO info1 = { 0 }; MYBITMAPINFO info2 = { 0 }; HDC hDC = CreateCompatibleDC(nullptr); info1.bmiHeader.biSize = sizeof(info1.bmiHeader); info1.bmiHeader.biWidth = bmiColor.bmWidth; info1.bmiHeader.biHeight = bmiColor.bmHeight; info1.bmiHeader.biPlanes = 1; info1.bmiHeader.biBitCount = bmiColor.bmBitsPixel; unsigned int size = GetDIBits(hDC, hbmColor, 0, info1.bmiHeader.biHeight, nullptr, (BITMAPINFO*)&info1, DIB_RGB_COLORS); char* bits1 = new char[info1.bmiHeader.biSizeImage]; size = GetDIBits(hDC, hbmColor, 0, info1.bmiHeader.biHeight, bits1, (BITMAPINFO*)&info1, DIB_RGB_COLORS); info2.bmiHeader.biSize = sizeof(info2.bmiHeader); info2.bmiHeader.biWidth = bmiMask.bmWidth; info2.bmiHeader.biHeight = bmiMask.bmHeight; info2.bmiHeader.biPlanes = 1; info2.bmiHeader.biBitCount = bmiMask.bmBitsPixel; size = GetDIBits(hDC, hbmColor, 0, info1.bmiHeader.biHeight, nullptr, (BITMAPINFO*)&info2, DIB_RGB_COLORS); char* bits2 = new char[info2.bmiHeader.biSizeImage]; size = GetDIBits(hDC, hbmMask, 0, info2.bmiHeader.biHeight, bits2, (BITMAPINFO*)&info2, DIB_RGB_COLORS); ICONDIR icodir; ICONDIRENTRY icoent; icodir.idReserved = 0; icodir.idType = 1; icodir.idCount = 1; icoent.bWidth = (unsigned char)bmiColor.bmWidth; icoent.bHeight = (unsigned char)bmiColor.bmHeight; icoent.bColorCount = 8 <= bmiColor.bmBitsPixel ? 0 : 1 << bmiColor.bmBitsPixel; icoent.bReserved = 0; icoent.wPlanes = bmiColor.bmPlanes; icoent.wBitCount = bmiColor.bmBitsPixel; icoent.dwBytesInRes = sizeof(BITMAPINFOHEADER) + info1.bmiHeader.biSizeImage + info2.bmiHeader.biSizeImage; icoent.dwImageOffset = sizeof(icodir) + sizeof(icoent); store.write((char*)&icodir, sizeof(icodir)); store.write((char*)&icoent, sizeof(icoent)); icobmi.biSize = sizeof(icobmi); icobmi.biWidth = bmiColor.bmWidth; icobmi.biHeight = bmiColor.bmHeight + bmiMask.bmHeight; icobmi.biPlanes = info1.bmiHeader.biPlanes; icobmi.biBitCount = bmiColor.bmBitsPixel; icobmi.biSizeImage = 0; store.write((char*)&icobmi, sizeof(icobmi)); store.write(bits1, info1.bmiHeader.biSizeImage); store.write(bits2, info2.bmiHeader.biSizeImage); DeleteDC(hDC); delete[] bits1; delete[] bits2; } store.close(); if (ii.hbmColor) DeleteObject(ii.hbmColor); if (ii.hbmMask) DeleteObject(ii.hbmMask); }
/*********************************************************************\ * * * BOOL DoAlphaBlend() * * * * Purpose: * * Captures a copy of the source and destination areas and * * alpha blends them into a memory surface that it displays * * into the destination area. * * * * Notes: * * Takes the same parameters as the AlphaBlend function except * * that the last parameter is a source weighting value rather * * than a BLENDFUNCTION structure. * * * \*********************************************************************/ BOOL DoAlphaBlend_internal( HDC hdcDest, // Handle to destination DC. int nXOriginDest, // X-coord of upper-left corner. int nYOriginDest, // Y-coord of upper-left corner. int nWidthDest, // Destination width. int nHeightDest, // Destination height. HDC hdcSrc, // Handle to source DC. int nXOriginSrc, // X-coord of upper-left corner. int nYOriginSrc, // Y-coord of upper-left corner. int nWidthSrc, // Source width. int nHeightSrc, // Source height. DWORD dwSourceWeight) // Source weighting (between 0 and 255). { if(pfnSetStretchBltMode) { #ifdef PNA pfnSetStretchBltMode = (pfnSetStretchBltMode_t) GetProcAddress(GetModuleHandle(TEXT("coredll.dll")), TEXT("SetStretchBltMode")); #else pfnSetStretchBltMode = SetStretchBltMode; #endif } HDC hdcSrc1 = NULL; HDC hdcSrc2 = NULL; HDC hdcDst = NULL; HBITMAP hbmSrc1 = NULL; HBITMAP hbmSrc2 = NULL; HBITMAP hbmDst = NULL; BOOL bReturn; // Create surfaces for sources and destination images. hbmSrc1 = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest); if (!hbmSrc1) goto HANDLEERROR; hbmSrc2 = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest); if (!hbmSrc2) goto HANDLEERROR; hbmDst = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest); if (!hbmDst) goto HANDLEERROR; // Create HDCs to hold our surfaces. hdcSrc1 = CreateCompatibleDC(hdcDest); if (!hdcSrc1) goto HANDLEERROR; hdcSrc2 = CreateCompatibleDC(hdcDest); if (!hdcSrc2) goto HANDLEERROR; hdcDst = CreateCompatibleDC(hdcDest); if (!hdcDst) goto HANDLEERROR; // Prepare the surfaces for drawing. SelectObject(hdcSrc1, hbmSrc1); SelectObject(hdcSrc2, hbmSrc2); SelectObject(hdcDst, hbmDst); if(pfnSetStretchBltMode) { pfnSetStretchBltMode(hdcSrc1, COLORONCOLOR); pfnSetStretchBltMode(hdcSrc2, COLORONCOLOR); } // Capture a copy of the source area. if (!StretchBlt(hdcSrc1, 0,0,nWidthDest,nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY)) goto HANDLEERROR; // Capture a copy of the destination area. if (!StretchBlt(hdcSrc2, 0,0,nWidthDest,nHeightDest, hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, SRCCOPY)) goto HANDLEERROR; // Blend the two source areas to create the destination image. bReturn = BlendImages(hbmSrc1, hbmSrc2, hbmDst, dwSourceWeight); // Clean up objects you do not need any longer. // You cannot delete an object that's selected into an // HDC so delete the HDC first. DeleteDC(hdcSrc1); DeleteDC(hdcSrc2); DeleteObject(hbmSrc1); DeleteObject(hbmSrc2); // Display the blended (destination) image to the target HDC. if (bReturn) { BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hdcDst, 0,0, SRCCOPY); } // Clean up the rest of the objects you created. DeleteDC(hdcDst); DeleteObject(hbmDst); return bReturn; HANDLEERROR: if (hdcSrc1) DeleteDC(hdcSrc1); if (hdcSrc2) DeleteDC(hdcSrc2); if (hdcDst) DeleteDC(hdcDst); if (hbmSrc1) DeleteObject(hbmSrc1); if (hbmSrc2) DeleteObject(hbmSrc2); if (hbmDst) DeleteObject(hbmDst); return FALSE; }
HRESULT BlendApplicationImage(HWND hwndApp) { LONG cx, cy; HRESULT hr; // Read the default video size hr = pWC->GetNativeVideoSize(&cx, &cy, NULL, NULL); if (FAILED(hr)) { Msg(TEXT("GetNativeVideoSize FAILED! hr=0x%x\r\n"), hr); return hr; } // Load the bitmap to alpha blend from the resource file HBITMAP hbm = LoadBitmap(ghInst, MAKEINTRESOURCE(IDR_TICKER)); // Create a device context compatible with the current window HDC hdc = GetDC(hwndApp); HDC hdcBmp = CreateCompatibleDC(hdc); ReleaseDC(hwndApp, hdc); // Select our bitmap into the device context and save the old one BITMAP bm; HBITMAP hbmOld; GetObject(hbm, sizeof(bm), &bm); hbmOld = (HBITMAP)SelectObject(hdcBmp, hbm); // Configure the VMR's bitmap structure VMR9AlphaBitmap bmpInfo; ZeroMemory(&bmpInfo, sizeof(bmpInfo) ); bmpInfo.dwFlags = VMRBITMAP_HDC; bmpInfo.hdc = hdcBmp; // Remember the width of this new bitmap g_nImageWidth = bm.bmWidth; // Save the ratio of the bitmap's width to the width of the video file. // This value is used to reposition the bitmap in composition space. g_fBitmapCompWidth = (float)g_nImageWidth / (float)cx; // Display the bitmap in the bottom right corner. // rSrc specifies the source rectangle in the GDI device context // rDest specifies the destination rectangle in composition space (0.0f to 1.0f) SetRect(&bmpInfo.rSrc, 0, 0, g_nImageWidth, bm.bmHeight); bmpInfo.rDest.left = 1.0f; bmpInfo.rDest.right = 1.0f + g_fBitmapCompWidth; bmpInfo.rDest.top = (float)(cy - bm.bmHeight) / (float)cy - EDGE_BUFFER; bmpInfo.rDest.bottom = 1.0f - EDGE_BUFFER; // Copy initial settings to global memory for later modification g_rDest = bmpInfo.rDest; // Transparency value 1.0 is opaque, 0.0 is transparent. bmpInfo.fAlpha = TRANSPARENCY_VALUE; // Set the COLORREF so that the bitmap outline will be transparent SetColorRef(bmpInfo); // Give the bitmap to the VMR for display hr = pBMP->SetAlphaBitmap(&bmpInfo); if (FAILED(hr)) { Msg(TEXT("SetAlphaBitmap FAILED! hr=0x%x\r\n\r\n%s\0"), hr, STR_VMR_DISPLAY_WARNING); } // Select the initial object back into our device context DeleteObject(SelectObject(hdcBmp, hbmOld)); // Clean up resources DeleteObject(hbm); DeleteDC(hdcBmp); return hr; }
HRESULT BlendApplicationText(HWND hwndApp, TCHAR *szNewText) { LONG cx, cy; HRESULT hr; // Read the default video size hr = pWC->GetNativeVideoSize(&cx, &cy, NULL, NULL); if (FAILED(hr)) return hr; // Create a device context compatible with the current window HDC hdc = GetDC(hwndApp); HDC hdcBmp = CreateCompatibleDC(hdc); // Write with a known font by selecting it into our HDC HFONT hOldFont = (HFONT) SelectObject(hdcBmp, g_hFont); // Determine the length of the string, then determine the // dimensions (in pixels) of the character string using the // currently selected font. These dimensions are used to create // a bitmap below. int nLength, nTextBmpWidth, nTextBmpHeight; SIZE sz={0}; nLength = (int) _tcslen(szNewText); GetTextExtentPoint32(hdcBmp, szNewText, nLength, &sz); nTextBmpHeight = sz.cy; nTextBmpWidth = sz.cx; // Create a new bitmap that is compatible with the current window HBITMAP hbm = CreateCompatibleBitmap(hdc, nTextBmpWidth, nTextBmpHeight); ReleaseDC(hwndApp, hdc); // Select our bitmap into the device context and save the old one BITMAP bm; HBITMAP hbmOld; GetObject(hbm, sizeof(bm), &bm); hbmOld = (HBITMAP)SelectObject(hdcBmp, hbm); // Set initial bitmap settings RECT rcText; SetRect(&rcText, 0, 0, nTextBmpWidth, nTextBmpHeight); SetBkColor(hdcBmp, RGB(255, 255, 255)); // Pure white background SetTextColor(hdcBmp, g_rgbColors); // Write text with requested color // Draw the requested text string onto the bitmap TextOut(hdcBmp, 0, 0, szNewText, nLength); // Configure the VMR's bitmap structure VMR9AlphaBitmap bmpInfo; ZeroMemory(&bmpInfo, sizeof(bmpInfo) ); bmpInfo.dwFlags = VMRBITMAP_HDC; bmpInfo.hdc = hdcBmp; // DC which has selected our bitmap // Remember the width of this new bitmap g_nImageWidth = bm.bmWidth; // Save the ratio of the bitmap's width to the width of the video file. // This value is used to reposition the bitmap in composition space. g_fBitmapCompWidth = (float)g_nImageWidth / (float)cx; // Display the bitmap in the bottom right corner. // rSrc specifies the source rectangle in the GDI device context // rDest specifies the destination rectangle in composition space (0.0f to 1.0f) bmpInfo.rDest.left = 1.0f; bmpInfo.rDest.right = 1.0f + g_fBitmapCompWidth; bmpInfo.rDest.top = (float)(cy - bm.bmHeight) / (float)cy - EDGE_BUFFER; bmpInfo.rDest.bottom = 1.0f - EDGE_BUFFER; bmpInfo.rSrc = rcText; // Copy initial settings to global memory for later modification g_rDest = bmpInfo.rDest; // Transparency value 1.0 is opaque, 0.0 is transparent. bmpInfo.fAlpha = TRANSPARENCY_VALUE; // Set the COLORREF so that the bitmap outline will be transparent SetColorRef(bmpInfo); // Give the bitmap to the VMR for display hr = pBMP->SetAlphaBitmap(&bmpInfo); if (FAILED(hr)) Msg(TEXT("SetAlphaBitmap FAILED! hr=0x%x\r\n\r\n%s\0"), hr, STR_VMR_DISPLAY_WARNING); // Select the initial objects back into our device context DeleteObject(SelectObject(hdcBmp, hbmOld)); SelectObject(hdc, hOldFont); // Clean up resources DeleteObject(hbm); DeleteDC(hdcBmp); return hr; }
void *wxGetClipboardData(wxDataFormat dataFormat, long *len) { void *retval = NULL; switch ( dataFormat ) { #ifndef __WXWINCE__ case wxDF_BITMAP: { BITMAP bm; HBITMAP hBitmap = (HBITMAP) GetClipboardData(CF_BITMAP); if (!hBitmap) break; HDC hdcMem = CreateCompatibleDC((HDC) NULL); HDC hdcSrc = CreateCompatibleDC((HDC) NULL); HBITMAP old = (HBITMAP) ::SelectObject(hdcSrc, hBitmap); GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); HBITMAP hNewBitmap = CreateBitmapIndirect(&bm); if (!hNewBitmap) { SelectObject(hdcSrc, old); DeleteDC(hdcMem); DeleteDC(hdcSrc); break; } HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hNewBitmap); BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY); // Select new bitmap out of memory DC SelectObject(hdcMem, old1); // Clean up SelectObject(hdcSrc, old); DeleteDC(hdcSrc); DeleteDC(hdcMem); // Create and return a new wxBitmap wxBitmap *wxBM = new wxBitmap; wxBM->SetHBITMAP((WXHBITMAP) hNewBitmap); wxBM->SetWidth(bm.bmWidth); wxBM->SetHeight(bm.bmHeight); wxBM->SetDepth(bm.bmPlanes); retval = wxBM; break; } #endif case wxDF_METAFILE: case CF_SYLK: case CF_DIF: case CF_TIFF: case CF_PALETTE: case wxDF_DIB: wxLogError(_("Unsupported clipboard format.")); return NULL; case wxDF_OEMTEXT: dataFormat = wxDF_TEXT; // fall through case wxDF_TEXT: { HANDLE hGlobalMemory = ::GetClipboardData(dataFormat); if (!hGlobalMemory) break; DWORD hsize = ::GlobalSize(hGlobalMemory); if (len) *len = hsize; char *s = new char[hsize]; if (!s) break; LPSTR lpGlobalMemory = (LPSTR) GlobalLock(hGlobalMemory); memcpy(s, lpGlobalMemory, hsize); GlobalUnlock(hGlobalMemory); retval = s; break; } default: { HANDLE hGlobalMemory = ::GetClipboardData(dataFormat); if ( !hGlobalMemory ) break; DWORD size = ::GlobalSize(hGlobalMemory); if ( len ) *len = size; void *buf = malloc(size); if ( !buf ) break; LPSTR lpGlobalMemory = (LPSTR) GlobalLock(hGlobalMemory); memcpy(buf, lpGlobalMemory, size); GlobalUnlock(hGlobalMemory); retval = buf; break; } } if ( !retval ) { wxLogSysError(_("Failed to retrieve data from the clipboard.")); } return retval; }
void Test_Rectangle(void) { HDC hdc; HBITMAP hBmp; BOOL ret; HBRUSH hBrush; HPEN hPen; COLORREF color; hdc = CreateCompatibleDC(NULL); ok(hdc != NULL, "Failed to create the DC!\n"); hBmp = CreateCompatibleBitmap(hdc, 4, 4); ok(hBmp != NULL, "Failed to create the Bitmap!\n"); hBmp = SelectObject(hdc, hBmp); ok(hBmp != NULL, "Failed to select the Bitmap!\n"); hBrush = CreateSolidBrush(RGB(0, 0, 0)); ok(hBrush != NULL, "Failed to create a solid brush!\n"); hBrush = SelectObject(hdc, hBrush); ok(hBrush != NULL, "Failed to select the brush!\n"); /* Blank the bitmap */ ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS); ok(ret, "BitBlt failed to blank the bitmap!\n"); /* Try inverted rectangle coordinates */ ret = Rectangle(hdc, 0, 2, 2, 0); ok(ret, "Rectangle failed!"); color = GetPixel(hdc, 0, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 2); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 0, 2); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 0); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 1, 1); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS); ok(ret, "BitBlt failed to blank the bitmap!\n"); /* Try well ordered rectangle coordinates */ ret = Rectangle(hdc, 0, 0, 2, 2); ok(ret, "Rectangle failed!"); color = GetPixel(hdc, 0, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 2); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 0, 2); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 0); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 1, 1); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); /* tests with NULL pen */ hPen = SelectObject(hdc, GetStockObject(NULL_PEN)); /* Blank the bitmap */ ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS); ok(ret, "BitBlt failed to blank the bitmap!\n"); ret = Rectangle(hdc, 0, 0, 3, 3); ok(ret, "Rectangle failed!"); color = GetPixel(hdc, 0, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 2); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 0, 2); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 0); ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 1, 1); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); SelectObject(hdc, hPen); /* Same tests with GM_ADVANCED */ ok(SetGraphicsMode(hdc, GM_ADVANCED) == GM_COMPATIBLE, "Default mode for the DC is not GM_COMPATIBLE.\n"); /* Blank the bitmap */ ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS); ok(ret, "BitBlt failed to blank the bitmap!\n"); /* Try inverted rectangle coordinates */ ret = Rectangle(hdc, 0, 2, 2, 0); ok(ret, "Rectangle failed!"); color = GetPixel(hdc, 0, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 2); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 0, 2); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 1, 1); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS); ok(ret, "BitBlt failed to blank the bitmap!\n"); /* Try well ordered rectangle coordinates */ ret = Rectangle(hdc, 0, 0, 2, 2); ok(ret, "Rectangle failed!"); color = GetPixel(hdc, 0, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 2); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 0, 2); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 2, 0); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); color = GetPixel(hdc, 1, 1); ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color); hBmp = SelectObject(hdc, hBmp); hBrush = SelectObject(hdc, hBrush); DeleteObject(hBmp); DeleteObject(hBrush); DeleteDC(hdc); }
/*********************************************************************** * D3DXCreateFontIndirectW (D3DX9_36.@) */ HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_DESCW *desc, ID3DXFont **font) { D3DDEVICE_CREATION_PARAMETERS cpars; D3DDISPLAYMODE mode; struct d3dx_font *object; IDirect3D9 *d3d; HRESULT hr; TRACE("(%p, %p, %p)\n", device, desc, font); if (!device || !desc || !font) return D3DERR_INVALIDCALL; TRACE("desc: %d %d %d %d %d %d %d %d %d %s\n", desc->Height, desc->Width, desc->Weight, desc->MipLevels, desc->Italic, desc->CharSet, desc->OutputPrecision, desc->Quality, desc->PitchAndFamily, debugstr_w(desc->FaceName)); /* The device MUST support D3DFMT_A8R8G8B8 */ IDirect3DDevice9_GetDirect3D(device, &d3d); IDirect3DDevice9_GetCreationParameters(device, &cpars); IDirect3DDevice9_GetDisplayMode(device, 0, &mode); hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); if (FAILED(hr)) { IDirect3D9_Release(d3d); return D3DXERR_INVALIDDATA; } IDirect3D9_Release(d3d); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct d3dx_font)); if (!object) { *font = NULL; return E_OUTOFMEMORY; } object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl; object->ref = 1; object->device = device; object->desc = *desc; object->hdc = CreateCompatibleDC(NULL); if (!object->hdc) { HeapFree(GetProcessHeap(), 0, object); return D3DXERR_INVALIDDATA; } object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet, desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName); if (!object->hfont) { DeleteDC(object->hdc); HeapFree(GetProcessHeap(), 0, object); return D3DXERR_INVALIDDATA; } SelectObject(object->hdc, object->hfont); SetTextColor(object->hdc, 0x00ffffff); SetBkColor(object->hdc, 0x00000000); IDirect3DDevice9_AddRef(device); *font = &object->ID3DXFont_iface; return D3D_OK; }
LRESULT CALLBACK PropsTabWndWndProc(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { static int selected, sizingbottom; static HIMAGELIST tabIml; static int ilProps, ilToolbox; RECT r; TC_ITEM tie; NMHDR *h; DRAWITEMSTRUCT *dr; HFONT font; HBITMAP hbmp; HDC hMemDC; PAINTSTRUCT paint; HDC dc; switch (iMessage) { case WM_SYSCOMMAND: if (wParam == SC_CLOSE) { PostMessage(hwnd, WM_CLOSE, 0, 0); return 0; } break; case WM_NOTIFY: h = (NMHDR*)lParam; switch (h->code) { case TCN_SELCHANGE: switch (selected = TabCtrl_GetCurSel(hwndPropsTabCtrl)) { case 0: ShowWindow(hwndToolbox, SW_HIDE) ; ShowWindow(hwndProps, SW_SHOW) ; break; case 1: ShowWindow(hwndProps, SW_HIDE) ; ShowWindow(hwndToolbox, SW_SHOW) ; break; } } break; case WM_SETTEXT: return SendMessage(hwndPropsTabCtrl, iMessage, wParam, lParam); case WM_DRAWITEM: dr = (DRAWITEMSTRUCT*)lParam; hMemDC = CreateCompatibleDC(dr->hDC); hbmp = SelectObject(hMemDC, *bitmaps[dr->itemID]); BitBlt(dr->hDC, dr->rcItem.left + 2, dr->rcItem.bottom - 18, 16, 16, hMemDC, 0, 0, SRCCOPY); font = SelectObject(dr->hDC, font); TextOut(dr->hDC, dr->rcItem.left + 18, dr->rcItem.bottom - 16, nameTags[dr->itemID], strlen(nameTags[dr->itemID])); font = SelectObject(dr->hDC, font); SelectObject(dr->hDC, hbmp); DeleteDC(hMemDC); break; case WM_CREATE: hwndPropsTab = hwnd; GetClientRect(hwnd, &r); hwndPropsTabCtrl = CreateWindow(WC_TABCONTROL, 0, WS_CHILD + WS_CLIPSIBLINGS + WS_VISIBLE + TCS_FLATBUTTONS /*+ TCS_OWNERDRAWFIXED */ + TCS_FOCUSNEVER /*+ TCS_FIXEDWIDTH*/ + TCS_BOTTOM, r.left, r.top, r.right - r.left, r.bottom - r.top, hwnd, 0, hInstance, 0); ApplyDialogFont(hwndPropsTabCtrl); propsBitMap = LoadImage(hInstance, "ID_PROPSBMP", IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADMAP3DCOLORS); toolsBitMap = LoadImage(hInstance, "ID_TOOLBOXBMP", IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADMAP3DCOLORS); tabIml = ImageList_Create(16, 16, ILC_COLOR32, 1, 0); ilProps = ImageList_Add(tabIml, propsBitMap, 0); ilToolbox = ImageList_Add(tabIml, toolsBitMap, 0); TabCtrl_SetImageList(hwndPropsTabCtrl, tabIml); CreatePropsWindow(); CreateCtlTbWindow(); tie.mask = TCIF_TEXT | TCIF_IMAGE; tie.iImage = ilProps; tie.pszText = nameTags[0]; TabCtrl_InsertItem(hwndPropsTabCtrl, 0, &tie); tie.mask = TCIF_TEXT | TCIF_IMAGE ; tie.iImage = ilToolbox ; tie.pszText = nameTags[1] ; TabCtrl_InsertItem(hwndPropsTabCtrl,1, &tie) ; ShowWindow(hwndToolbox,SW_HIDE) ; return 0; case WM_COMMAND: break; case WM_SELERRWINDOW: { NMHDR xx; memset(&xx, 0, sizeof(xx)); xx.code = TCN_SELCHANGE; TabCtrl_SetCurSel(hwndPropsTabCtrl, lParam); SendMessage(hwnd, WM_NOTIFY, 0, (LPARAM)&xx); } break; case WM_PAINT: dc = BeginPaint(hwnd, &paint); EndPaint(hwnd, &paint); break; case WM_DESTROY: DestroyWindow(hwndToolbox) ; DestroyWindow(hwndProps); DestroyWindow(hwndPropsTabCtrl); DeleteObject(propsBitMap); DeleteObject(toolsBitMap); hwndPropsTab = 0; break; case WM_SIZE: r.right = LOWORD(lParam); r.bottom = HIWORD(lParam); r.left = r.top = 0; MoveWindow(hwndPropsTabCtrl, r.left, r.top, r.right - r.left, r.bottom - r.top, 1); GetPropsTabRect(&r); MoveWindow(hwndProps, r.left, r.top, r.right - r.left, r.bottom - r.top, 1); MoveWindow( hwndToolbox,r.left,r.top,r.right-r.left,r.bottom-r.top,TRUE) ; break; case WM_CLOSE: break; } return DefWindowProc(hwnd, iMessage, wParam, lParam); }
void debugview_info::draw_contents(HDC windc) { debug_view_char const *viewdata = m_view->viewdata(); debug_view_xy const visarea = m_view->visible_size(); // get the client rect RECT client; GetClientRect(m_wnd, &client); // create a compatible DC and an offscreen bitmap HDC const dc = CreateCompatibleDC(windc); if (dc == NULL) return; HBITMAP const bitmap = CreateCompatibleBitmap(windc, client.right, client.bottom); if (bitmap == NULL) { DeleteDC(dc); return; } HGDIOBJ const oldbitmap = SelectObject(dc, bitmap); // set the font HGDIOBJ const oldfont = SelectObject(dc, metrics().debug_font()); COLORREF const oldfgcolor = GetTextColor(dc); int const oldbkmode = GetBkMode(dc); SetBkMode(dc, TRANSPARENT); // iterate over rows and columns for (UINT32 row = 0; row < visarea.y; row++) { // loop twice; once to fill the background and once to draw the text for (int iter = 0; iter < 2; iter++) { COLORREF fgcolor; COLORREF bgcolor = RGB(0xff,0xff,0xff); HBRUSH bgbrush = NULL; int last_attrib = -1; TCHAR buffer[256]; int count = 0; RECT bounds; // initialize the text bounds bounds.left = bounds.right = 0; bounds.top = row * metrics().debug_font_height(); bounds.bottom = bounds.top + metrics().debug_font_height(); // start with a brush on iteration #0 if (iter == 0) bgbrush = CreateSolidBrush(bgcolor); // iterate over columns for (UINT32 col = 0; col < visarea.x; col++) { // if the attribute changed, adjust the colors if (viewdata[col].attrib != last_attrib) { COLORREF oldbg = bgcolor; // reset to standard colors fgcolor = RGB(0x00,0x00,0x00); bgcolor = RGB(0xff,0xff,0xff); // pick new fg/bg colors if (viewdata[col].attrib & DCA_VISITED) bgcolor = RGB(0xc6, 0xe2, 0xff); if (viewdata[col].attrib & DCA_ANCILLARY) bgcolor = RGB(0xe0,0xe0,0xe0); if (viewdata[col].attrib & DCA_SELECTED) bgcolor = RGB(0xff,0x80,0x80); if (viewdata[col].attrib & DCA_CURRENT) bgcolor = RGB(0xff,0xff,0x00); if ((viewdata[col].attrib & DCA_SELECTED) && (viewdata[col].attrib & DCA_CURRENT)) bgcolor = RGB(0xff,0xc0,0x80); if (viewdata[col].attrib & DCA_CHANGED) fgcolor = RGB(0xff,0x00,0x00); if (viewdata[col].attrib & DCA_INVALID) fgcolor = RGB(0x00,0x00,0xff); if (viewdata[col].attrib & DCA_DISABLED) fgcolor = RGB((GetRValue(fgcolor) + GetRValue(bgcolor)) / 2, (GetGValue(fgcolor) + GetGValue(bgcolor)) / 2, (GetBValue(fgcolor) + GetBValue(bgcolor)) / 2); if (viewdata[col].attrib & DCA_COMMENT) fgcolor = RGB(0x00,0x80,0x00); // flush any pending drawing if (count > 0) { bounds.right = bounds.left + (count * metrics().debug_font_width()); if (iter == 0) FillRect(dc, &bounds, bgbrush); else ExtTextOut(dc, bounds.left, bounds.top, 0, NULL, buffer, count, NULL); bounds.left = bounds.right; count = 0; } // set the new colors if (iter == 0 && oldbg != bgcolor) { DeleteObject(bgbrush); bgbrush = CreateSolidBrush(bgcolor); } else if (iter == 1) SetTextColor(dc, fgcolor); last_attrib = viewdata[col].attrib; } // add this character to the buffer buffer[count++] = viewdata[col].byte; } // flush any remaining stuff if (count > 0) { bounds.right = bounds.left + (count * metrics().debug_font_width()); if (iter == 0) FillRect(dc, &bounds, bgbrush); else ExtTextOut(dc, bounds.left, bounds.top, 0, NULL, buffer, count, NULL); } // erase to the end of the line if (iter == 0) { bounds.left = bounds.right; bounds.right = client.right; FillRect(dc, &bounds, bgbrush); DeleteObject(bgbrush); } } // advance viewdata viewdata += visarea.x; } // erase anything beyond the bottom with white GetClientRect(m_wnd, &client); client.top = visarea.y * metrics().debug_font_height(); FillRect(dc, &client, (HBRUSH)GetStockObject(WHITE_BRUSH)); // reset the font SetBkMode(dc, oldbkmode); SetTextColor(dc, oldfgcolor); SelectObject(dc, oldfont); // blit the final results BitBlt(windc, 0, 0, client.right, client.bottom, dc, 0, 0, SRCCOPY); // undo the offscreen stuff SelectObject(dc, oldbitmap); DeleteObject(bitmap); DeleteDC(dc); }
BOOL CDIB::SetBitmap(HBITMAP hBitmap, HPALETTE hPal /*= NULL*/) { // DeleteObject(); if (!hBitmap) return FALSE; // Get dimensions of bitmap BITMAP bm; if (!::GetObject(hBitmap, sizeof(bm),(LPVOID)&bm)) return FALSE; bm.bmHeight = abs(bm.bmHeight); HDC hDC = GetWindowDC(NULL); HPALETTE hOldPal = NULL; m_iColorTableSize = NumColorEntries(bm.bmBitsPixel, BI_RGB); // Initialize the BITMAPINFOHEADER in m_DIBinfo BITMAPINFOHEADER& bih = m_DIBinfo.bmiHeader; bih.biSize = sizeof(BITMAPINFOHEADER); bih.biWidth = bm.bmWidth; bih.biHeight = bm.bmHeight; bih.biPlanes = 1; // Must always be 1 according to docs bih.biBitCount = bm.bmBitsPixel; bih.biCompression = BI_RGB; bih.biSizeImage = BytesPerLine(bm.bmWidth, bm.bmBitsPixel) * bm.bmHeight; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; bih.biClrUsed = 0; bih.biClrImportant = 0; GetColorTableEntries(hDC, hBitmap); // If we have a palette supplied, then set the palette (and hance DIB color // table) using this palette if (hPal) SetPalette(hPal); if (hPal) { hOldPal = SelectPalette(hDC, m_hPal, FALSE); RealizePalette(hDC); } // Create it! m_hBitmap = CreateDIBSection(hDC, (const BITMAPINFO*) m_DIBinfo, m_iColorDataType, &m_ppvBits, NULL, 0); if (hOldPal) SelectPalette(hDC, hOldPal, FALSE); hOldPal = NULL; if (! m_hBitmap) { TRACE0("Unable to CreateDIBSection\n"); return FALSE; } // If palette was supplied then create a palette using the entries in the DIB // color table. if (! hPal) CreatePalette(); // Need to copy the supplied bitmap onto the newly created DIBsection HDC hMemDC = CreateCompatibleDC(hDC); HDC hCopyDC = CreateCompatibleDC(hDC); if (! hMemDC || ! hCopyDC) { TRACE0("Unable to create compatible DC's\n"); //AfxThrowResourceException(); } if (m_hPal) { SelectPalette(hMemDC, m_hPal, FALSE); RealizePalette(hMemDC); SelectPalette(hCopyDC, m_hPal, FALSE); RealizePalette(hCopyDC); } HBITMAP hOldMemBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap); HBITMAP hOldCopyBitmap = (HBITMAP) SelectObject(hCopyDC, m_hBitmap); BitBlt(hCopyDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY); SelectObject(hMemDC, hOldMemBitmap); SelectObject(hCopyDC, hOldCopyBitmap); if (m_hPal) { HGDIOBJ hObj = ::GetStockObject(DEFAULT_PALETTE); SelectObject(hMemDC, hObj); SelectObject(hCopyDC, hObj); } ReleaseDC(NULL, hDC); return TRUE; }
void draw_button( int button_id, DRAWITEMSTRUCT FAR * draw ) { HBITMAP bmp; HBITMAP oldbmp; HPEN blackpen, shadowpen, brightpen, facepen; HPEN oldpen; BITMAP bitmap; HDC memdc; HINSTANCE inst; int shift; inst = GET_HINSTANCE( draw->hwndItem ); bmp = LoadBitmap( inst, MAKEINTRESOURCE( button_id ) ); if( !bmp ) return; GetObject( bmp, sizeof(BITMAP), &bitmap ); memdc = CreateCompatibleDC( draw->hDC ); oldbmp = SelectObject( memdc, bmp ); if( draw->itemState & ODS_SELECTED ) { shift = 4; } else { shift = 2; } BitBlt( draw->hDC, draw->rcItem.left + shift, draw->rcItem.top + shift, bitmap.bmWidth, bitmap.bmHeight, memdc, 0, 0, SRCCOPY ); SelectObject( memdc, oldbmp ); DeleteDC( memdc ); DeleteObject( bmp ); // Draw four sides of the button except one pixel in each corner blackpen = CreatePen( PS_SOLID, 0, RGB(0,0,0) ); brightpen = CreatePen( PS_SOLID, 0, RGB(255,255,255) ); shadowpen = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) ); facepen = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNFACE ) ); oldpen = SelectObject( draw->hDC, blackpen ); horizontal( draw, draw->rcItem.top ); horizontal( draw, draw->rcItem.bottom - 1 ); vertical( draw, draw->rcItem.left ); vertical( draw, draw->rcItem.right - 1 ); // Now the shading SelectObject( draw->hDC, shadowpen ); if( draw->itemState & ODS_SELECTED ) { horizontal( draw, draw->rcItem.top + 1 ); vertical( draw, draw->rcItem.left + 1 ); SelectObject( draw->hDC, facepen ); horizontal( draw, draw->rcItem.top + 2 ); vertical( draw, draw->rcItem.left + 2 ); horizontal( draw, draw->rcItem.top + 3 ); vertical( draw, draw->rcItem.left + 3 ); } else { horizontal( draw, draw->rcItem.bottom - 2 ); horizontal( draw, draw->rcItem.bottom - 3 ); vertical( draw, draw->rcItem.right - 2 ); vertical( draw, draw->rcItem.right - 3 ); SelectObject( draw->hDC, brightpen ); horizontal( draw, draw->rcItem.top + 1 ); vertical( draw, draw->rcItem.left + 1 ); } SelectObject( draw->hDC, oldpen ); DeleteObject( blackpen ); DeleteObject( brightpen ); DeleteObject( shadowpen ); DeleteObject( facepen ); }
BOOL CDIB::CreatePalette() { //m_hPal DeleteObject(); if (!m_hBitmap) return FALSE; // Create a 256 color halftone palette if there is no color table in the DIBSection if (m_iColorTableSize == 0) return CreateHalftonePalette(m_hPal, 256); // Get space for the color entries RGBQUAD *pRGB = new RGBQUAD[m_iColorTableSize]; if (!pRGB) return CreateHalftonePalette(m_hPal, m_iColorTableSize); HDC hDC = ::GetDC(NULL); if (!hDC) { delete [] pRGB; return FALSE; } // Create a memory DC compatible with the current DC HDC hMemDC = CreateCompatibleDC(hDC); if (!hMemDC) { delete [] pRGB; ReleaseDC(NULL, hDC); return CreateHalftonePalette(m_hPal, m_iColorTableSize); } ReleaseDC(NULL, hDC); HBITMAP hOldBitmap = (HBITMAP) SelectObject(hMemDC, m_hBitmap); if (!hOldBitmap) { delete [] pRGB; return CreateHalftonePalette(m_hPal, m_iColorTableSize); } // Get the colors used. WinCE does not support GetDIBColorTable so if you // are using this on a CE device with palettes, then you need to replace // the call with code that manually gets the color table from the m_DIBinfo structure. int nColors = CEGetDIBColorTable(hDC, 0, m_iColorTableSize, pRGB); // Clean up SelectObject(hMemDC, hOldBitmap); if (!nColors) // No colors retrieved => the bitmap in the DC is not a DIB section { delete [] pRGB; return CreateHalftonePalette(m_hPal, m_iColorTableSize); } // Create and fill a LOGPALETTE structure with the colors used. PALETTEINFO PaletteInfo; PaletteInfo.palNumEntries = m_iColorTableSize; for (int ii = 0; ii < nColors; ii++) { PaletteInfo.palPalEntry[ii].peRed = pRGB[ii].rgbRed; PaletteInfo.palPalEntry[ii].peGreen = pRGB[ii].rgbGreen; PaletteInfo.palPalEntry[ii].peBlue = pRGB[ii].rgbBlue; PaletteInfo.palPalEntry[ii].peFlags = 0; } delete [] pRGB; // Create Palette! m_hPal = ::CreatePalette( &PaletteInfo ); return (NULL != m_hPal); }
HBITMAP CSplashScreen::CopyScreenToBitmap(CRect& rect/*lpRect 代表选定区域*/) { HDC hScrDC; // 屏幕设备描述表 HDC hMemDC; // 内存设备描述表 HBITMAP hBitmap, hOldBitmap; // 位图句柄 int nX, nY, nX2, nY2; // 选定区域坐标 int nWidth, nHeight; // 位图宽度和高度 int xScrn, yScrn; // 屏幕分辨率 // 确保选定区域不为空矩形 //if (IsRectEmpty(lpRect)) //{ // return NULL; //} //为屏幕创建设备描述表 hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL); //为屏幕设备描述表创建兼容的内存设备描述表 hMemDC = CreateCompatibleDC(hScrDC); // 获得选定区域坐标 //nX = lpRect -> left; //nY = lpRect -> top; //nX2 = lpRect -> right; //nY2 = lpRect -> bottom; nX = rect.left; nY = rect.top; nX2 = rect.right; nY2 = rect.bottom; // 获得屏幕分辨率 xScrn = GetDeviceCaps(hScrDC, HORZRES); yScrn = GetDeviceCaps(hScrDC, VERTRES); //nX = (xScrn - rect.Width())/2; //nY = (yScrn - rect.Height())/2; //nX2 = xScrn - nX + rect.Width(); //nY2 = yScrn - nY + rect.Height(); //确保选定区域是可见的 if (nX<0) nX = 0; if (nY<0) nY = 0; if (nX2 > xScrn) nX2 = xScrn; if (nY2 > yScrn) nY2 = yScrn; nWidth = nX2 - nX; nHeight = nY2 - nY; // 创建一个与屏幕设备描述表兼容的位图 hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight); // 把新位图选到内存设备描述表中 hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap); // 把屏幕设备描述表拷贝到内存设备描述表中 BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY); //得到屏幕位图的句柄 hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap); //清除 DeleteDC(hScrDC); DeleteDC(hMemDC); //返回位图句柄 return hBitmap; }
/***************************************************************************** * SIC_OverlayShortcutImage [internal] * * NOTES * Creates a new icon as a copy of the passed-in icon, overlayed with a * shortcut image. */ static HICON SIC_OverlayShortcutImage(HICON SourceIcon, BOOL large) { ICONINFO SourceIconInfo, ShortcutIconInfo, TargetIconInfo; HICON ShortcutIcon, TargetIcon; BITMAP SourceBitmapInfo, ShortcutBitmapInfo; HDC SourceDC = NULL, ShortcutDC = NULL, TargetDC = NULL, ScreenDC = NULL; HBITMAP OldSourceBitmap = NULL, OldShortcutBitmap = NULL, OldTargetBitmap = NULL; static int s_imgListIdx = -1; /* Get information about the source icon and shortcut overlay */ if (! GetIconInfo(SourceIcon, &SourceIconInfo) || 0 == GetObjectW(SourceIconInfo.hbmColor, sizeof(BITMAP), &SourceBitmapInfo)) { return NULL; } /* search for the shortcut icon only once */ if (s_imgListIdx == -1) s_imgListIdx = SIC_LoadOverlayIcon(- IDI_SHELL_SHORTCUT); /* FIXME should use icon index 29 instead of the resource id, but not all icons are present yet so we can't use icon indices */ if (s_imgListIdx != -1) { if (large) ShortcutIcon = ImageList_GetIcon(ShellBigIconList, s_imgListIdx, ILD_TRANSPARENT); else ShortcutIcon = ImageList_GetIcon(ShellSmallIconList, s_imgListIdx, ILD_TRANSPARENT); } else ShortcutIcon = NULL; if (NULL == ShortcutIcon || ! GetIconInfo(ShortcutIcon, &ShortcutIconInfo) || 0 == GetObjectW(ShortcutIconInfo.hbmColor, sizeof(BITMAP), &ShortcutBitmapInfo)) { return NULL; } TargetIconInfo = SourceIconInfo; TargetIconInfo.hbmMask = NULL; TargetIconInfo.hbmColor = NULL; /* Setup the source, shortcut and target masks */ SourceDC = CreateCompatibleDC(NULL); if (NULL == SourceDC) goto fail; OldSourceBitmap = SelectObject(SourceDC, SourceIconInfo.hbmMask); if (NULL == OldSourceBitmap) goto fail; ShortcutDC = CreateCompatibleDC(NULL); if (NULL == ShortcutDC) goto fail; OldShortcutBitmap = SelectObject(ShortcutDC, ShortcutIconInfo.hbmMask); if (NULL == OldShortcutBitmap) goto fail; TargetDC = CreateCompatibleDC(NULL); if (NULL == TargetDC) goto fail; TargetIconInfo.hbmMask = CreateCompatibleBitmap(TargetDC, SourceBitmapInfo.bmWidth, SourceBitmapInfo.bmHeight); if (NULL == TargetIconInfo.hbmMask) goto fail; ScreenDC = GetDC(NULL); if (NULL == ScreenDC) goto fail; TargetIconInfo.hbmColor = CreateCompatibleBitmap(ScreenDC, SourceBitmapInfo.bmWidth, SourceBitmapInfo.bmHeight); ReleaseDC(NULL, ScreenDC); if (NULL == TargetIconInfo.hbmColor) goto fail; OldTargetBitmap = SelectObject(TargetDC, TargetIconInfo.hbmMask); if (NULL == OldTargetBitmap) goto fail; /* Create the target mask by ANDing the source and shortcut masks */ if (! BitBlt(TargetDC, 0, 0, SourceBitmapInfo.bmWidth, SourceBitmapInfo.bmHeight, SourceDC, 0, 0, SRCCOPY) || ! BitBlt(TargetDC, 0, SourceBitmapInfo.bmHeight - ShortcutBitmapInfo.bmHeight, ShortcutBitmapInfo.bmWidth, ShortcutBitmapInfo.bmHeight, ShortcutDC, 0, 0, SRCAND)) { goto fail; } /* Setup the source and target xor bitmap */ if (NULL == SelectObject(SourceDC, SourceIconInfo.hbmColor) || NULL == SelectObject(TargetDC, TargetIconInfo.hbmColor)) { goto fail; } /* Copy the source xor bitmap to the target and clear out part of it by using the shortcut mask */ if (! BitBlt(TargetDC, 0, 0, SourceBitmapInfo.bmWidth, SourceBitmapInfo.bmHeight, SourceDC, 0, 0, SRCCOPY) || ! BitBlt(TargetDC, 0, SourceBitmapInfo.bmHeight - ShortcutBitmapInfo.bmHeight, ShortcutBitmapInfo.bmWidth, ShortcutBitmapInfo.bmHeight, ShortcutDC, 0, 0, SRCAND)) { goto fail; } if (NULL == SelectObject(ShortcutDC, ShortcutIconInfo.hbmColor)) goto fail; /* Now put in the shortcut xor mask */ if (! BitBlt(TargetDC, 0, SourceBitmapInfo.bmHeight - ShortcutBitmapInfo.bmHeight, ShortcutBitmapInfo.bmWidth, ShortcutBitmapInfo.bmHeight, ShortcutDC, 0, 0, SRCINVERT)) { goto fail; } /* Clean up, we're not goto'ing to 'fail' after this so we can be lazy and not set handles to NULL */ SelectObject(TargetDC, OldTargetBitmap); DeleteObject(TargetDC); SelectObject(ShortcutDC, OldShortcutBitmap); DeleteObject(ShortcutDC); SelectObject(SourceDC, OldSourceBitmap); DeleteObject(SourceDC); /* Create the icon using the bitmaps prepared earlier */ TargetIcon = CreateIconIndirect(&TargetIconInfo); /* CreateIconIndirect copies the bitmaps, so we can release our bitmaps now */ DeleteObject(TargetIconInfo.hbmColor); DeleteObject(TargetIconInfo.hbmMask); return TargetIcon; fail: /* Clean up scratch resources we created */ if (NULL != OldTargetBitmap) SelectObject(TargetDC, OldTargetBitmap); if (NULL != TargetIconInfo.hbmColor) DeleteObject(TargetIconInfo.hbmColor); if (NULL != TargetIconInfo.hbmMask) DeleteObject(TargetIconInfo.hbmMask); if (NULL != TargetDC) DeleteObject(TargetDC); if (NULL != OldShortcutBitmap) SelectObject(ShortcutDC, OldShortcutBitmap); if (NULL != ShortcutDC) DeleteObject(ShortcutDC); if (NULL != OldSourceBitmap) SelectObject(SourceDC, OldSourceBitmap); if (NULL != SourceDC) DeleteObject(SourceDC); return NULL; }
void GDisplay::SaveAsJpeg(LPCTSTR pszFileName) { const int req_comps = 3; // request RGB image HDC hdcClient = GetDC(m_hWnd); HDC hdcCompatible = CreateCompatibleDC(hdcClient); HBITMAP hBmp = CreateCompatibleBitmap(hdcClient, m_nClientWidth, m_nClientHeight); HGDIOBJ hOldBmp = SelectObject(hdcCompatible, hBmp); BitBlt(hdcCompatible, 0,0, m_nClientWidth, m_nClientHeight, hdcClient, 0,0, SRCCOPY); BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = m_nClientWidth; bi.biHeight = m_nClientHeight; bi.biPlanes = 1; bi.biBitCount = 24; // RGB mode is 24 bits bi.biCompression = BI_RGB; bi.biSizeImage = 0; // can be 0 for 24 bit images bi.biXPelsPerMeter = 0x0ec4; // paint and PSP use this values bi.biYPelsPerMeter = 0x0ec4; bi.biClrUsed = 0; // we are in RGB mode and have no palette bi.biClrImportant = 0; // all colors are important SIZE_T dwBmpSize = ((m_nClientWidth*bi.biBitCount + 31)/24)*4*m_nClientHeight; HANDLE hDIB = GlobalAlloc(GHND, dwBmpSize); if (hDIB) { PUCHAR lpBits = (PUCHAR)GlobalLock(hDIB); if (!GetDIBits(hdcClient, hBmp, 0, (WORD)bi.biHeight, lpBits, (LPBITMAPINFO)&bi, DIB_RGB_COLORS)) { // error handler here... } // MUST be free later !!! PUCHAR pRGBBits = ConvertBMPToRGBBuffer(lpBits, m_nClientWidth, m_nClientHeight); // Fill in the compression parameter structure. jpge::params params; params.m_quality = 80; params.m_subsampling = jpge::H2V2; params.m_two_pass_flag = false; CHAR szAnsiFileName[MAX_PATH]; #ifndef _UNICODE StringCbCopy(szAnsiFileName, MAX_PATH, pszFileName); #else _wcstombsz(szAnsiFileName, pszFileName, MAX_PATH); #endif if (!jpge::compress_image_to_jpeg_file(szAnsiFileName, m_nClientWidth, m_nClientHeight, req_comps, pRGBBits, params)) { // error handler here... } //Unlock and Free the DIB from the heap GlobalUnlock(hDIB); // DON'T forget free this !!! delete pRGBBits; } GlobalFree(hDIB); SelectObject(hdcCompatible, hOldBmp); DeleteDC(hdcCompatible); DeleteObject(hBmp); }
// TODO code: optimise airspace drawing (same as DrawAirSpace()) // draw airspace using alpha blending //static void MapWindow::DrawTptAirSpace(HDC hdc, const RECT rc) { // since standard GDI functions (brushes, pens...) ignore alpha octet in ARGB // color value and don't set it in the resulting bitmap, we cannot use // perpixel alpha blending, instead we use global opacity for alpha blend // (same opacity for all pixels); for fully "transparent" areas (without // airspace) we must copy destination bitmap into source bitmap first so that // alpha blending of such areas results in the same pixels as origin pixels // in destination CAirspaceList::const_iterator it; CAirspaceList::const_reverse_iterator itr; const CAirspaceList& airspaces_to_draw = CAirspaceManager::Instance().GetNearAirspacesRef(); int airspace_type; bool found = false; bool borders_only = (GetAirSpaceFillType() == asp_fill_ablend_borders); HDC hdcbuffer = NULL; HBITMAP hbbufferold = NULL, hbbuffer = NULL; if (borders_only) { // Prepare layers hdcbuffer = CreateCompatibleDC(hdc); hbbuffer = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top); hbbufferold = (HBITMAP)SelectObject(hdcbuffer, hbbuffer); BitBlt(hdcbuffer, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, rc.left, rc.top, BLACKNESS ); SelectObject(hdcbuffer, GetStockObject(NULL_PEN)); BitBlt(hDCMask, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, rc.left, rc.top, BLACKNESS ); SelectObject(hDCMask, hAirspaceBorderPen); SelectObject(hDCMask, GetStockObject(HOLLOW_BRUSH)); } // Draw airspace area if (1) { CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef()); if (borders_only) { // Draw in reverse order! // The idea behind this, is lower top level airspaces are smaller. (statistically) // They have to be draw later, because inside border area have to be in correct color, // not the color of the bigger airspace above this small one. for (itr=airspaces_to_draw.rbegin(); itr != airspaces_to_draw.rend(); ++itr) { if ((*itr)->DrawStyle() == adsFilled) { airspace_type = (*itr)->Type(); if (!found) { found = true; ClearTptAirSpace(hdc, rc); } // set filling brush SelectObject(hdcbuffer, GetAirSpaceSldBrushByClass(airspace_type)); (*itr)->Draw(hdcbuffer, rc, true); (*itr)->Draw(hDCMask, rc, false); } }//for } else { // Draw in direct order! for (it=airspaces_to_draw.begin(); it != airspaces_to_draw.end(); ++it) { if ((*it)->DrawStyle() == adsFilled) { airspace_type = (*it)->Type(); if (!found) { found = true; ClearTptAirSpace(hdc, rc); } // set filling brush SelectObject(hDCTemp, GetAirSpaceSldBrushByClass(airspace_type)); (*it)->Draw(hDCTemp, rc, true); } }//for }//else borders_only }//mutex release // alpha blending if (found) { if (borders_only) { #if (WINDOWSPC<1) TransparentImage(hdcbuffer, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, hDCMask, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, RGB_WHITE ); TransparentImage(hDCTemp, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, hdcbuffer, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, RGB_BLACK ); #else TransparentBlt(hdcbuffer, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, hDCMask, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, RGB_WHITE ); TransparentBlt(hDCTemp, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, hdcbuffer, rc.left,rc.top, rc.right-rc.left,rc.bottom-rc.top, RGB_BLACK ); #endif } DoAlphaBlend(hdc, rc, hDCTemp, rc, (255 * GetAirSpaceOpacity()) / 100); } // draw it again, just the outlines // we will be drawing directly into given hdc, so store original PEN object HPEN hOrigPen = (HPEN) SelectObject(hdc, GetStockObject(WHITE_PEN)); if (1) { CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef()); for (it=airspaces_to_draw.begin(); it != airspaces_to_draw.end(); ++it) { if ((*it)->DrawStyle()) { airspace_type = (*it)->Type(); if (bAirspaceBlackOutline) { SelectObject(hdc, GetStockObject(BLACK_PEN)); } else { SelectObject(hdc, hAirspacePens[airspace_type]); } (*it)->Draw(hdc, rc, false); } }//for } if (borders_only) { // Free up GDI resources SelectObject(hdcbuffer, hbbufferold); DeleteObject(hbbuffer); DeleteDC(hdcbuffer); } // restore original PEN SelectObject(hdc, hOrigPen); } // DrawTptAirSpace()
LRESULT CALLBACK WindowProc(HWND _hwnd, UINT _msg, WPARAM _wparam, LPARAM _lparam) { // This is the main message handler of the system. PAINTSTRUCT ps; // Used in WM_PAINT. HDC hdc; // Handle to a device context. // What is the message? switch (_msg) { case WM_CREATE: { _iNumThreads = std::thread::hardware_concurrency(); // Do initialization stuff here. // Return Success. return (0); } break; case WM_PAINT: { // Simply validate the window. hdc = BeginPaint(_hwnd, &ps); if (!bitmapsToDraw.empty()) { //Starting coordinates int x = 0; int y = 0; //Used to nicely arrange the images int _iNum = int(ceil(sqrt(bitmapsToDraw.size()))); int _iWidth = (1000 / _iNum); int _iHeight = _iWidth; //Drawing the images for (unsigned int i = 0; i < bitmapsToDraw.size(); i++) { BITMAP bitmap; GetObject(bitmapsToDraw[i], sizeof(BITMAP), &bitmap); HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP oldBitmap = static_cast<HBITMAP>(SelectObject(hdcMem, bitmapsToDraw[i])); SetStretchBltMode(hdc, _iStretchColor); StretchBlt(hdc, x, y, _iWidth, _iHeight, hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY); SelectObject(hdcMem, oldBitmap); DeleteDC(hdcMem); x += _iWidth; //Adding new row if (x >= 1000) { y += _iWidth; x = 0; } } } EndPaint(_hwnd, &ps); // Return Success. return (0); } break; case WM_COMMAND: { switch (LOWORD(_wparam)) { case ID_FILE_LOADIMAGES: { LoadBitmaps(); InvalidateRect(_hwnd, NULL, TRUE); break; } case ID_FILE_LOADSOUNDS: { LoadSounds(); break; } case ID_COLORTYPE_HALFTONE: { _iStretchColor = HALFTONE; InvalidateRect(_hwnd, NULL, TRUE); break; } case ID_COLORTYPE_BLACKONWHITE: { _iStretchColor = BLACKONWHITE; InvalidateRect(_hwnd, NULL, TRUE); break; } case ID_COLORTYPE_COLORONCOLOR: { _iStretchColor = COLORONCOLOR; InvalidateRect(_hwnd, NULL, TRUE); break; } case ID_COLORTYPE_WHITEONBLACK: { _iStretchColor = STRETCH_ORSCANS; InvalidateRect(_hwnd, NULL, TRUE); break; } case ID_EXIT: { //Deleting bitmaps upon exiting for (unsigned int i = 0; i < bitmapsToDraw.size(); i++) { DeleteObject(bitmapsToDraw[i]); } PostQuitMessage(0); // Return success. return (0); break; } default: break; } return(0); } case WM_DESTROY: { //Delete all bitmaps here // Kill the application, this sends a WM_QUIT message. for (unsigned int i = 0; i < bitmapsToDraw.size(); i++) { DeleteObject(bitmapsToDraw[i]); } PostQuitMessage(0); // Return success. return (0); } break; default:break; } // End switch. // Process any messages that we did not take care of... return (DefWindowProc(_hwnd, _msg, _wparam, _lparam)); }
bool wxSetClipboardData(wxDataFormat dataFormat, const void *data, int width, int height) { HANDLE handle = 0; // return value of SetClipboardData switch (dataFormat) { case wxDF_BITMAP: { wxBitmap *bitmap = (wxBitmap *)data; HDC hdcMem = CreateCompatibleDC((HDC) NULL); HDC hdcSrc = CreateCompatibleDC((HDC) NULL); HBITMAP old = (HBITMAP) ::SelectObject(hdcSrc, (HBITMAP)bitmap->GetHBITMAP()); HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc, bitmap->GetWidth(), bitmap->GetHeight()); if (!hBitmap) { SelectObject(hdcSrc, old); DeleteDC(hdcMem); DeleteDC(hdcSrc); return false; } HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hBitmap); BitBlt(hdcMem, 0, 0, bitmap->GetWidth(), bitmap->GetHeight(), hdcSrc, 0, 0, SRCCOPY); // Select new bitmap out of memory DC SelectObject(hdcMem, old1); // Set the data handle = ::SetClipboardData(CF_BITMAP, hBitmap); // Clean up SelectObject(hdcSrc, old); DeleteDC(hdcSrc); DeleteDC(hdcMem); break; } #if wxUSE_WXDIB case wxDF_DIB: { wxBitmap *bitmap = (wxBitmap *)data; if ( bitmap && bitmap->Ok() ) { wxDIB dib(*bitmap); if ( dib.IsOk() ) { handle = ::SetClipboardData(CF_DIB, dib.Detach()); } } break; } #endif // VZ: I'm told that this code works, but it doesn't seem to work for me // and, anyhow, I'd be highly surprised if it did. So I leave it here // but IMNSHO it is completely broken. #if wxUSE_METAFILE && !defined(wxMETAFILE_IS_ENH) && !defined(__WXWINCE__) case wxDF_METAFILE: { wxMetafile *wxMF = (wxMetafile *)data; HANDLE data = GlobalAlloc(GHND, sizeof(METAFILEPICT) + 1); METAFILEPICT *mf = (METAFILEPICT *)GlobalLock(data); mf->mm = wxMF->GetWindowsMappingMode(); mf->xExt = width; mf->yExt = height; mf->hMF = (HMETAFILE) wxMF->GetHMETAFILE(); GlobalUnlock(data); wxMF->SetHMETAFILE((WXHANDLE) NULL); handle = SetClipboardData(CF_METAFILEPICT, data); break; } #endif // wxUSE_METAFILE #if wxUSE_ENH_METAFILE && !defined(__WXWINCE__) case wxDF_ENHMETAFILE: { wxEnhMetaFile *emf = (wxEnhMetaFile *)data; wxEnhMetaFile emfCopy = *emf; handle = SetClipboardData(CF_ENHMETAFILE, (void *)emfCopy.GetHENHMETAFILE()); } break; #endif // wxUSE_ENH_METAFILE case CF_SYLK: case CF_DIF: case CF_TIFF: case CF_PALETTE: default: { wxLogError(_("Unsupported clipboard format.")); return false; } case wxDF_OEMTEXT: dataFormat = wxDF_TEXT; // fall through case wxDF_TEXT: { char *s = (char *)data; width = strlen(s) + 1; height = 1; DWORD l = (width * height); HANDLE hGlobalMemory = GlobalAlloc(GHND, l); if ( hGlobalMemory ) { LPSTR lpGlobalMemory = (LPSTR)GlobalLock(hGlobalMemory); memcpy(lpGlobalMemory, s, l); GlobalUnlock(hGlobalMemory); } handle = SetClipboardData(dataFormat, hGlobalMemory); break; } // Only tested with Visual C++ 6.0 so far #if defined(__VISUALC__) case wxDF_HTML: { char* html = (char *)data; // Create temporary buffer for HTML header... char *buf = new char [400 + strlen(html)]; if(!buf) return false; // Get clipboard id for HTML format... static int cfid = 0; if(!cfid) cfid = RegisterClipboardFormat(wxT("HTML Format")); // Create a template string for the HTML header... strcpy(buf, "Version:0.9\r\n" "StartHTML:00000000\r\n" "EndHTML:00000000\r\n" "StartFragment:00000000\r\n" "EndFragment:00000000\r\n" "<html><body>\r\n" "<!--StartFragment -->\r\n"); // Append the HTML... strcat(buf, html); strcat(buf, "\r\n"); // Finish up the HTML format... strcat(buf, "<!--EndFragment-->\r\n" "</body>\r\n" "</html>"); // Now go back, calculate all the lengths, and write out the // necessary header information. Note, wsprintf() truncates the // string when you overwrite it so you follow up with code to replace // the 0 appended at the end with a '\r'... char *ptr = strstr(buf, "StartHTML"); sprintf(ptr+10, "%08u", strstr(buf, "<html>") - buf); *(ptr+10+8) = '\r'; ptr = strstr(buf, "EndHTML"); sprintf(ptr+8, "%08u", strlen(buf)); *(ptr+8+8) = '\r'; ptr = strstr(buf, "StartFragment"); sprintf(ptr+14, "%08u", strstr(buf, "<!--StartFrag") - buf); *(ptr+14+8) = '\r'; ptr = strstr(buf, "EndFragment"); sprintf(ptr+12, "%08u", strstr(buf, "<!--EndFrag") - buf); *(ptr+12+8) = '\r'; // Now you have everything in place ready to put on the // clipboard. // Allocate global memory for transfer... HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(buf)+4); // Put your string in the global memory... ptr = (char *)GlobalLock(hText); strcpy(ptr, buf); GlobalUnlock(hText); handle = ::SetClipboardData(cfid, hText); // Free memory... GlobalFree(hText); // Clean up... delete [] buf; break; } #endif } if ( handle == 0 ) { wxLogSysError(_("Failed to set clipboard data.")); return false; } return true; }
////////////////////////////////////// // CompileSprite Function ////////////////////////////////////// void CompileSprite(HWND hwnd, HDC origBkgHdc, LPLEVEL level) { HDC bkgHdc = GetDC(hwnd); UINT j = 0; /* check for collision COLSPRITE cSprite; HBITMAP blackBit = CreateCompatibleBitmap(origBkgHdc, XMAX, YMAX); HDC blackHdc = CreateCompatibleDC(origBkgHdc); HGDIOBJ Old_blackHdc = SelectObject(blackHdc, blackBit); BitBlt(blackHdc, 0, 0, XMAX, YMAX, origBkgHdc, 0, 0, BLACKNESS); spriteA[0]->cSprite.hdcBkg = blackHdc; for(i = 0; ; i++) { SelectObject(hdcM, spriteA[i]->spriteM); CheckCollision(spriteA[i]->cSprite.hdcBkg , hdcM, spriteA, i); } */ /* // clean up from old sprite while(level->lSpriteA[j].oldSprite != (POLDSPRITE)0xcdcdcdcd) { if(level->lSpriteA[j].zOrder == j) { if(((level->lSpriteA[j].oldSprite->rt.x != level->lSpriteA[j].rt.x) || (level->lSpriteA[j].oldSprite->rt.y != level->lSpriteA[j].rt.y)) && (level->lSpriteA[j].oldSprite != (POLDSPRITE)0xcdcdcdcd) ) { BitBlt(bkgHdc, level->lSpriteA[j].oldSprite->rt.x, level->lSpriteA[j].oldSprite->rt.y, level->lSpriteA[j].oldSprite->rt.w, level->lSpriteA[j].oldSprite->rt.h, level->lSpriteA[j].oldSprite->spriteHdc, 0, 0, SRCCOPY); } j++; } else zOrderSort(level); } // copy screen from new to old sprite for clean up j = 0; while(level->spriteNum > j) { if(level->lSpriteA[j].oldSprite != (POLDSPRITE)0xcdcdcdcd) { HBITMAP bitM = CreateCompatibleBitmap(origBkgHdc, level->lSpriteA[j].rt.w, level->lSpriteA[j].rt.h); level->lSpriteA[j].oldSprite->spriteHdc = CreateCompatibleDC(origBkgHdc); HGDIOBJ Old_hdcM = SelectObject(level->lSpriteA[j].oldSprite->spriteHdc, bitM); level->lSpriteA[j].oldSprite->rt.x = level->lSpriteA[j].rt.x; level->lSpriteA[j].oldSprite->rt.y = level->lSpriteA[j].rt.y; level->lSpriteA[j].oldSprite->rt.w = level->lSpriteA[j].rt.w; level->lSpriteA[j].oldSprite->rt.h = level->lSpriteA[j].rt.h; BitBlt(level->lSpriteA[j].oldSprite->spriteHdc, 0, 0, level->lSpriteA[j].rt.w, level->lSpriteA[j].rt.h, origBkgHdc, level->lSpriteA[j].rt.x, level->lSpriteA[j].rt.y, SRCCOPY); SelectObject(hdcM, level->lSpriteA[j].spriteM); BitBlt(level->lSpriteA[j].oldSprite->spriteHdc, 0, 0, level->lSpriteA[j].rt.w, level->lSpriteA[j].rt.h, hdcM, 0, 0, SRCPAINT); j++; } else { level->lSpriteA[j].oldSprite = (POLDSPRITE)malloc(sizeof(OLDSPRITE)); level->lSpriteA[j].oldSprite->spriteHdc = (HDC)malloc(sizeof(HDC)); } } */ // main graphics loop level->lBitmapA[0].rt.w HBITMAP BkgTemp = CreateCompatibleBitmap(origBkgHdc, level->lZoneA[level->lBitmapA[0].zNum].w, level->lZoneA[level->lBitmapA[0].zNum].h); HDC BkgTempHdc = CreateCompatibleDC(origBkgHdc); HGDIOBJ Old_BkgTempHdc = SelectObject(BkgTempHdc, BkgTemp); BitBlt(BkgTempHdc, 0, 0, level->lZoneA[level->lBitmapA[0].zNum].w, level->lZoneA[level->lBitmapA[0].zNum].h, origBkgHdc, 0, 0, SRCCOPY); j = 0; while(level->spriteNum > j) { int SpXPos = (level->lZoneA[level->lSpriteA[j].zNum].w)*(level->lSpriteA[j].cel), SpYPos = 0; int x = level->lZoneA[level->lSpriteA[j].zNum].x1, y = level->lZoneA[level->lSpriteA[j].zNum].y1, w = level->lZoneA[level->lSpriteA[j].zNum].w, h = level->lZoneA[level->lSpriteA[j].zNum].h; // out side view area test and resolve /* if(x <= 0) { w += x; SpXPos += (-1)*x; x = 0; } else if((x+w) >= XMAX) w = XMAX - x; if(y <= 0) { h += y; SpYPos += (-1)*y; y = 0; } else if((y+h) >= YMAX) h = YMAX - y; */ // out side view area test and resolve //////////////////////////////////// // Store zOrder displaying ///////////////////////////////////// if(level->lSpriteA[j].zOrder == j) { // create SpTemp HBITMAP SpTemp = CreateCompatibleBitmap(bkgHdc, w, h); HDC SpTempHdc = CreateCompatibleDC(bkgHdc); HGDIOBJ Old_SpTempHdc = SelectObject(bkgHdc, SpTemp); // create bkgtemp /* HBITMAP BkgTemp = CreateCompatibleBitmap(bkgHdc, w, h); HDC BkgTempHdc = CreateCompatibleDC(bkgHdc); HGDIOBJ Old_BkgTempHdc = SelectObject(BkgTempHdc, BkgTemp); // copy background to bkgtemp BitBlt(BkgTempHdc, 0, 0, w, h, bkgHdc, x, y, SRCCOPY); */ // bitmap mask ANDcopy to bkgtemp SelectObject(SpTempHdc, level->lSpriteA[j].spriteM); BitBlt(BkgTempHdc, x, y, w, h, SpTempHdc, SpXPos, SpYPos, SRCAND); // bitmap ORcopy to bkgtemp SelectObject(SpTempHdc, level->lSpriteA[j].sprite); BitBlt(BkgTempHdc, x, y, w, h, SpTempHdc, SpXPos, SpYPos, SRCPAINT); // copy bkgtemp to background /* BitBlt(bkgHdc, x, y, w, h, BkgTempHdc, 0, 0, SRCCOPY); */ // mem cleanup SelectObject(SpTempHdc, Old_SpTempHdc); DeleteObject(SpTemp); DeleteDC(SpTempHdc); j++; } else zOrderSort(level); } ///////////////////////////////////// // Display zOrder displaying ///////////////////////////////////// j = 0; while(level->spriteNum > j) { int x, y, w = (level->lZoneA[level->lSpriteA[j].zNum].w + level->lSpriteA[j].xDelta), h = (level->lZoneA[level->lSpriteA[j].zNum].h + level->lSpriteA[j].yDelta); if(level->lSpriteA[j].xDelta >= 0) x = (level->lZoneA[level->lSpriteA[j].zNum].x1 - level->lSpriteA[j].xDelta); else if(level->lSpriteA[j].xDelta < 0) { x = level->lZoneA[level->lSpriteA[j].zNum].x1; w = (level->lZoneA[level->lSpriteA[j].zNum].w - level->lSpriteA[j].xDelta); } if(level->lSpriteA[j].yDelta >= 0) y = (level->lZoneA[level->lSpriteA[j].zNum].y1 - level->lSpriteA[j].yDelta); else if(level->lSpriteA[j].yDelta < 0) { y = level->lZoneA[level->lSpriteA[j].zNum].y1; h = (level->lZoneA[level->lSpriteA[j].zNum].h - level->lSpriteA[j].yDelta); } // out side view area test and resolve /* if(x <= 0) { w += x; x = 0; } else if((x+w) >= XMAX) w = (XMAX - x); if(y <= 0) { h += y; y = 0; } else if((y+h) >= YMAX) h = (YMAX - y); */ // out side view area test and resolve BitBlt(bkgHdc, x, y, w, h, BkgTempHdc, x, y, SRCCOPY); j++; } SelectObject(BkgTempHdc, Old_BkgTempHdc); DeleteObject(BkgTemp); DeleteDC(BkgTempHdc); /* SelectObject(blackHdc, Old_blackHdc); DeleteObject(blackBit); DeleteDC(blackHdc); DeleteDC(hdcM); */ ReleaseDC(hwnd, bkgHdc); }
static void test_font_transform(void) { static const WCHAR string[] = { 'A',0 }; GpStatus status; HDC hdc; LOGFONTA lf; GpFont *font; GpGraphics *graphics; GpMatrix *matrix; GpStringFormat *format, *typographic; PointF pos[1] = { { 0,0 } }; REAL height, margin_y; RectF bounds, rect; hdc = CreateCompatibleDC(0); status = GdipCreateFromHDC(hdc, &graphics); expect(Ok, status); status = GdipSetPageUnit(graphics, UnitPixel); expect(Ok, status); status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format); expect(Ok, status); status = GdipStringFormatGetGenericTypographic(&typographic); expect(Ok, status); memset(&lf, 0, sizeof(lf)); lstrcpyA(lf.lfFaceName, "Tahoma"); lf.lfHeight = -100; lf.lfWidth = 100; status = GdipCreateFontFromLogfontA(hdc, &lf, &font); expect(Ok, status); margin_y = 100.0 / 8.0; /* identity matrix */ status = GdipCreateMatrix(&matrix); expect(Ok, status); status = GdipSetWorldTransform(graphics, matrix); expect(Ok, status); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); expect(-100, lf.lfHeight); expect(0, lf.lfWidth); expect(0, lf.lfEscapement); expect(0, lf.lfOrientation); status = GdipGetFontHeight(font, graphics, &height); expect(Ok, status); expectf(120.703125, height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); todo_wine expectf(height + margin_y, bounds.Height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); expectf_(height, bounds.Height, 1.0); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, NULL, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf_(-100.0, bounds.Y, 0.05); expectf_(height, bounds.Height, 0.5); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, matrix, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf_(-100.0, bounds.Y, 0.05); expectf_(height, bounds.Height, 0.5); /* scale matrix */ status = GdipScaleMatrix(matrix, 2.0, 3.0, MatrixOrderAppend); expect(Ok, status); status = GdipSetWorldTransform(graphics, matrix); expect(Ok, status); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); expect(-300, lf.lfHeight); expect(0, lf.lfWidth); expect(0, lf.lfEscapement); expect(0, lf.lfOrientation); status = GdipGetFontHeight(font, graphics, &height); expect(Ok, status); expectf(120.703125, height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); todo_wine expectf(height + margin_y, bounds.Height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); expectf_(height, bounds.Height, 0.05); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, NULL, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf_(-100.0, bounds.Y, 0.05); expectf_(height, bounds.Height, 0.2); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, matrix, &bounds); expect(Ok, status); expectf(0.0, bounds.X); todo_wine expectf_(-300.0, bounds.Y, 0.15); todo_wine expectf(height * 3.0, bounds.Height); /* scale + ratate matrix */ status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend); expect(Ok, status); status = GdipSetWorldTransform(graphics, matrix); expect(Ok, status); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); expect(-300, lf.lfHeight); expect(0, lf.lfWidth); expect_(3151, lf.lfEscapement, 1); expect_(3151, lf.lfOrientation, 1); status = GdipGetFontHeight(font, graphics, &height); expect(Ok, status); expectf(120.703125, height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); todo_wine expectf(height + margin_y, bounds.Height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); expectf_(height, bounds.Height, 0.05); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, NULL, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf_(-100.0, bounds.Y, 0.05); expectf_(height, bounds.Height, 0.2); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, matrix, &bounds); expect(Ok, status); todo_wine expectf_(-43.814377, bounds.X, 0.05); todo_wine expectf_(-212.235611, bounds.Y, 0.05); todo_wine expectf_(340.847534, bounds.Height, 0.05); /* scale + ratate + shear matrix */ status = GdipShearMatrix(matrix, 4.0, 5.0, MatrixOrderAppend); expect(Ok, status); status = GdipSetWorldTransform(graphics, matrix); expect(Ok, status); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); todo_wine expect(1032, lf.lfHeight); expect(0, lf.lfWidth); expect_(3099, lf.lfEscapement, 1); expect_(3099, lf.lfOrientation, 1); status = GdipGetFontHeight(font, graphics, &height); expect(Ok, status); expectf(120.703125, height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); todo_wine expectf(height + margin_y, bounds.Height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); expectf_(height, bounds.Height, 0.2); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, NULL, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf_(-100.0, bounds.Y, 0.2); expectf_(height, bounds.Height, 0.2); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, matrix, &bounds); expect(Ok, status); todo_wine expectf_(-636.706848, bounds.X, 0.05); todo_wine expectf_(-175.257523, bounds.Y, 0.05); todo_wine expectf_(1532.984985, bounds.Height, 0.05); /* scale + ratate + shear + translate matrix */ status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend); expect(Ok, status); status = GdipSetWorldTransform(graphics, matrix); expect(Ok, status); status = GdipGetLogFontA(font, graphics, &lf); expect(Ok, status); todo_wine expect(1032, lf.lfHeight); expect(0, lf.lfWidth); expect_(3099, lf.lfEscapement, 1); expect_(3099, lf.lfOrientation, 1); status = GdipGetFontHeight(font, graphics, &height); expect(Ok, status); expectf(120.703125, height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); todo_wine expectf(height + margin_y, bounds.Height); set_rect_empty(&rect); set_rect_empty(&bounds); status = GdipMeasureString(graphics, string, -1, font, &rect, typographic, &bounds, NULL, NULL); expect(Ok, status); expectf(0.0, bounds.X); expectf(0.0, bounds.Y); expectf_(height, bounds.Height, 0.1); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, NULL, &bounds); expect(Ok, status); expectf(0.0, bounds.X); expectf_(-100.0, bounds.Y, 0.2); expectf_(height, bounds.Height, 0.2); set_rect_empty(&bounds); status = GdipMeasureDriverString(graphics, (const UINT16 *)string, -1, font, pos, DriverStringOptionsCmapLookup, matrix, &bounds); expect(Ok, status); todo_wine expectf_(-626.706848, bounds.X, 0.05); todo_wine expectf_(-155.257523, bounds.Y, 0.05); todo_wine expectf_(1532.984985, bounds.Height, 0.05); GdipDeleteMatrix(matrix); GdipDeleteFont(font); GdipDeleteGraphics(graphics); GdipDeleteStringFormat(typographic); GdipDeleteStringFormat(format); DeleteDC(hdc); }