/** * genopt_window_close(): Close the General Options window. */ void genopt_window_close(void) { if (!genopt_window) return; // Destroy the window. DestroyWindow(genopt_window); genopt_window = NULL; // Delete OSD color brushes and pens. for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { DeleteBrush(brushOSD[i][j]); DeletePen(penOSD[i][j]); } } // Delete intro effect color brushes and pens. for (int i = 0; i < 8; i++) { for (int j = 0; j < 2; j++) { DeleteBrush(brushIntroEffect[i][j]); DeletePen(penIntroEffect[i][j]); } } }
LRESULT CALLBACK Announcements::AnnounceWndMainProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { //LRESULT lResult; //BOOL bHandled; RECT rect; HDC hdc; PAINTSTRUCT ps; //TABCOLORINFO ci = {0}; HBRUSH hbr; //wyWChar* text; //wyInt32 len; //HFONT hfont; //int i; //Announcements* ann = (Announcements*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if(message == WM_PAINT) { hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rect); SetBkMode(hdc, TRANSPARENT); //hbr = CreateSolidBrush(RGB(240, 0, 0)); hbr = CreateSolidBrush(RGB(240, 240, 240)); FillRect(hdc, &rect, hbr); DeleteBrush(hbr); EndPaint(hwnd, &ps); return 1; } return DefWindowProc(hwnd, message, wParam, lParam); }
/* This function draws one item in the out-basket list. */ void FASTCALL OutBasket_OnDrawItem( HWND hwnd, const DRAWITEMSTRUCT FAR * lpDrawItem ) { if( lpDrawItem->itemID != -1 ) if( lpDrawItem->itemAction == ODA_FOCUS ) DrawFocusRect( lpDrawItem->hDC, (LPRECT)&lpDrawItem->rcItem ); else { HFONT hOldFont; HWND hwndList; OBINFO obinfo; TEXTMETRIC tm; COLORREF tmpT; COLORREF tmpB; COLORREF T; COLORREF B; HBRUSH hbr; LPOB lpob; RECT rc; hwndList = GetDlgItem( hwnd, IDD_LIST ); lpob = (LPOB)ListBox_GetItemData( hwndList, lpDrawItem->itemID ); Amob_GetObInfo( lpob, &obinfo ); rc = lpDrawItem->rcItem; hOldFont = SelectFont( lpDrawItem->hDC, hOutBasketFont ); if( lpDrawItem->itemState & ODS_SELECTED ) { T = crHighlightText; B = crHighlight; } else { T = (obinfo.obHdr.wFlags & OBF_OPEN) ? crIgnoredTopic : crOutBaskText; B = crOutBaskWnd; } hbr = CreateSolidBrush( B ); tmpT = SetTextColor( lpDrawItem->hDC, T ); tmpB = SetBkColor( lpDrawItem->hDC, B ); rc.left = 0; rc.right = 32; FillRect( lpDrawItem->hDC, &rc, hbr ); if( obinfo.obHdr.wFlags & OBF_KEEP ) Amuser_DrawBitmap( lpDrawItem->hDC, rc.left, rc.top, 16, 16, hbmpOutBasket, 1 ); if( obinfo.obHdr.wFlags & OBF_HOLD ) Amuser_DrawBitmap( lpDrawItem->hDC, rc.left + 16, rc.top, 16, 16, hbmpOutBasket, 0 ); if( obinfo.obHdr.wFlags & OBF_ACTIVE ) Amuser_DrawBitmap( lpDrawItem->hDC, rc.left + 16, rc.top, 16, 16, hbmpOutBasket, 2 ); if( obinfo.obHdr.wFlags & OBF_SCRIPT ) Amuser_DrawBitmap( lpDrawItem->hDC, rc.left + 16, rc.top, 16, 16, hbmpOutBasket, 4 ); if( obinfo.obHdr.wFlags & OBF_ERROR ) Amuser_DrawBitmap( lpDrawItem->hDC, rc.left + 16, rc.top, 16, 16, hbmpOutBasket, 3 ); rc.left = rc.right; rc.right = lpDrawItem->rcItem.right; Amob_Describe( lpob, lpTmpBuf ); GetTextMetrics( lpDrawItem->hDC, &tm ); ExtTextOut( lpDrawItem->hDC, rc.left, rc.top, ETO_OPAQUE, &rc, lpTmpBuf, strlen( lpTmpBuf ), NULL ); SelectFont( lpDrawItem->hDC, hOldFont ); SetTextColor( lpDrawItem->hDC, tmpT ); SetBkColor( lpDrawItem->hDC, tmpB ); DeleteBrush( hbr ); } }
void DrawFigure() //Draw next figure { HDC dc = GetDC(g_hFigure); RECT rectWndFigure; HBRUSH hOldBrach; HBRUSH hBrash = CreateSolidBrush(RGB(100, 100, 100)); HBRUSH hBlackBrash = GetStockBrush(BLACK_BRUSH); GetWindowRect(g_hFigure, &rectWndFigure); int x = (rectWndFigure.right - rectWndFigure.left) / 4; int y = (rectWndFigure.bottom - rectWndFigure.top) / 4; for (int i = 0; i<4; i++) for (int j = 0; j<4; j++) { if (g_bNextFigur[i][j]) { hOldBrach = SelectBrush(dc, hBrash); Rectangle(dc, i*x, j*y, ((i + 1)*x) + x, (j*y) + y); hBrash = SelectBrush(dc, hOldBrach); } else { hOldBrach = SelectBrush(dc, hBlackBrash); Rectangle(dc, i*x, j*y, ((i + 1)*x) + x, (j*y) + y); SelectBrush(dc, hOldBrach); } } DeleteBrush(SelectBrush(dc, hOldBrach)); ReleaseDC(g_hFigure, dc); ValidateRect(g_hFigure, &rectWndFigure); }
void static OnDestroy (HWND hWnd) { PILINE pILine ; pILine = ILData (hWnd) ; IntrLineFocus = FALSE ; DeleteBrush (pILine->hBrushBk) ; MemoryFree (pILine) ; }
/* This function handles the WM_DRAWITEM message */ void FASTCALL Comms_Blink_OnDrawItem( HWND hwnd, const DRAWITEMSTRUCT FAR * lpDrawItem ) { COLORREF tmpT, tmpB; HBITMAP hbmpFont; char sz[ 100 ]; COLORREF T, B; HFONT hFont; HBRUSH hbr; SIZE size; RECT rc; int y; /* Get the text we're drawing. */ ListBox_GetText( lpDrawItem->hwndItem, lpDrawItem->itemID, sz ); rc = lpDrawItem->rcItem; /* Set the drawing colours. */ GetOwnerDrawListItemColours( lpDrawItem, &T, &B ); /* Blank out the line we're drawing. */ hbr = CreateSolidBrush( GetSysColor( COLOR_WINDOW ) ); FillRect( lpDrawItem->hDC, &rc, hbr ); /* Draw the standard bitmap for this entry. */ hbmpFont = LoadBitmap( hRscLib, MAKEINTRESOURCE(IDB_BLINKMAN) ); Amuser_DrawBitmap( lpDrawItem->hDC, rc.left, rc.top, 16, 16, hbmpFont, 0 ); DeleteBitmap( hbmpFont ); /* Draw the label. */ tmpT = SetTextColor( lpDrawItem->hDC, T ); tmpB = SetBkColor( lpDrawItem->hDC, B ); hFont = SelectFont( lpDrawItem->hDC, hHelvB8Font ); GetTextExtentPoint( lpDrawItem->hDC, sz, strlen(sz), &size ); rc.left += 16; rc.right = rc.left + size.cx + 6; y = rc.top + ( ( rc.bottom - rc.top ) - size.cy ) / 2; ExtTextOut( lpDrawItem->hDC, rc.left + 2, y, ETO_OPAQUE, &rc, sz, strlen(sz), NULL ); SelectFont( lpDrawItem->hDC, hFont ); /* Draw a focus if needed. */ if( lpDrawItem->itemState & ODS_FOCUS ) DrawFocusRect( lpDrawItem->hDC, &rc ); /* Clean up before we go home. */ SetTextColor( lpDrawItem->hDC, tmpT ); SetBkColor( lpDrawItem->hDC, tmpB ); DeleteBrush( hbr ); }
void ScreenDown(HDC hdc, HDC hdc_src, int width, int height, int split_width, int delay, double accelerate, COLORREF background_color) { HBITMAP hbm_buffer = CreateCompatibleBitmap(hdc, width, height); HDC hdc_buffer = CreateCompatibleDC(hdc); HBRUSH hbr_backgound = CreateSolidBrush(background_color); int *arr, arr_count = width / split_width + (width % split_width == 0 ? 0 : 1); int i, t = 0; SelectBitmap(hdc_buffer, hbm_buffer); arr = (int *)malloc(sizeof(*arr) * arr_count); if (!arr) { return; } for (i = 0; i < arr_count; i++) { arr[i] = -i * delay; } BitBlt(hdc_buffer, 0, 0, width, height, hdc_src, 0, 0, SRCCOPY); while (t < arr_count) { t = DrawScreenBitmap1(hdc_src, hdc, hdc_buffer, arr, arr_count, split_width, width, height, accelerate, hbr_backgound); for (i = 0; i < arr_count; i++) { arr[i]++; } } for (i = 0; i < arr_count; i++) { arr[i] = -i * delay; } t = 0; while (t < arr_count) { t = DrawScreenBitmap2(hdc_src, hdc, hdc_buffer, arr, arr_count, split_width, width, height, accelerate, hbr_backgound); for (i = 0; i < arr_count; i++) { arr[i]++; } } DeleteBrush(hbr_backgound); DeleteDC(hdc_buffer); DeleteBitmap(hbm_buffer); free(arr); }
void CDC::Brush(int iObjectID) { HBRUSH hOldBrush = SelectBrush(m_hDC, GetStockBrush(iObjectID)); // Delete the old one? if (m_bDelOldBrush) DeleteBrush(hOldBrush); // This object doesn't need deleting. m_bDelOldBrush = FALSE; }
static void OnInvertTracker(HWND hWnd, const RECT *rect) { HDC hDC = GetDC(hWnd); HBRUSH hBrush = CreateSolidBrush(RGB(0xFF, 0xFF, 0xFF)); HBRUSH hOldBrush = 0; if (hBrush != 0) hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); PatBlt(hDC, rect->left, rect->top, rect->right - rect->left, rect->bottom - rect->top, DSTINVERT); if (hOldBrush != 0) SelectObject(hDC, hOldBrush); ReleaseDC(hWnd, hDC); DeleteBrush(hBrush); }
void Globals::ClearGrabhandle() { EnterCriticalSection(&m_csGlobals); BOOL bResult; for (int nIndex = 0; nIndex < GrabStyleCount; nIndex++) { if (m_hBrushGrab[nIndex]) { bResult = DeleteBrush(m_hBrushGrab[nIndex]); assert(bResult); m_hBrushGrab[nIndex] = NULL; } } LeaveCriticalSection(&m_csGlobals); }
/*! ウインドウを閉じるときに発生。デバイスコンテキストとか確保した画面構造のメモリとかも終了。 @param[in] hWnd 親ウインドウのハンドル @return 無し */ VOID Cls_OnDestroy( HWND hWnd ) { UnregisterHotKey( hWnd, IDHK_CLIPSTEAL_FILECHANGE ); ChangeClipboardChain( hWnd , ghNextViewer ); // クリップボードチェインから離脱 gstNtfyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO; Shell_NotifyIcon( NIM_DELETE, &gstNtfyIcon ); // トレイアイコン破壊 DeleteBrush( ghBrush ); PostQuitMessage( 0 ); return; }
void CDC::Cleanup(void) { // Currently selected pen needs deleting? if (m_bDelOldPen) { HPEN hOldPen = SelectPen(m_hDC, GetStockPen(BLACK_PEN)); DeletePen(hOldPen); } // Currently selected brush needs deleting? if (m_bDelOldBrush) { HBRUSH hOldBrush = SelectBrush(m_hDC, GetStockBrush(WHITE_BRUSH)); DeleteBrush(hOldBrush); } }
/* This function handles the WM_CLOSE message. */ void FASTCALL OutBasket_OnClose( HWND hwnd ) { /* Unregister to receive some events. */ Amuser_UnregisterEvent( AE_INSERTED_OUTBASKET_OBJECT, OutBasketEvents ); Amuser_UnregisterEvent( AE_DELETING_OUTBASKET_OBJECT, OutBasketEvents ); Amuser_UnregisterEvent( AE_EDITING_OUTBASKET_OBJECT, OutBasketEvents ); Amuser_UnregisterEvent( AE_EDITED_OUTBASKET_OBJECT, OutBasketEvents ); /* Clean up */ Adm_DestroyMDIWindow( hwnd ); DeleteBitmap( hbmpOutBasket ); DeleteBrush( hbrOutBaskWnd ); hwndOutBasket = NULL; }
void CDC::Brush(COLORREF crColour) { // Create the new brush and select it HBRUSH hNewBrush = CreateSolidBrush(crColour); ASSERT(hNewBrush); HBRUSH hOldBrush = SelectBrush(m_hDC, hNewBrush); // Delete the old one? if (m_bDelOldBrush) DeleteBrush(hOldBrush); // The new one needs deleting. m_bDelOldBrush = TRUE; }
//WM_DRAWITEM void PBSettings_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem) { //Get the PBSDP PenBrushSettingsDlgParam * pbsdp=(PenBrushSettingsDlgParam *)(LONG_PTR)GetWindowLongPtr(hwnd,GWLP_USERDATA); switch(lpDrawItem->CtlID) //Controls switch { case IDC_PB_PREVIEW: //Preview pane { RECT fillRct=lpDrawItem->rcItem; HRGN fillRgn=CreateRectRgnIndirect(&fillRct); ArrowSettings tas=UITC->GetTool<UIArrowline>(IDC_TB_ARROWLINE)->GetArrowSettings(); //Paint the background with a white brush FillRgn(lpDrawItem->hDC,fillRgn,(HBRUSH)GetStockObject(WHITE_BRUSH)); //Select the pen and the brush and set the appropriate settigns BEGIN_SELOBJ(lpDrawItem->hDC,pbsdp->GetPreviewPaneFGCU().GetPen(),hDC_pen); BEGIN_SELOBJ(lpDrawItem->hDC,pbsdp->GetPreviewPaneBGCU().GetBrush(),hDC_brush); pbsdp->GetPreviewPaneFGCU().ApplyACUPs(lpDrawItem->hDC); //Draw a filled rectangle in the left part of the rectangle Rectangle(lpDrawItem->hDC,fillRct.left+5,fillRct.top+5,(fillRct.right-fillRct.left)/2-5,fillRct.bottom-5); //Draw a filled arrow in the top right part of the rectangle MoveToEx(lpDrawItem->hDC,(fillRct.right-fillRct.left)/2+5,fillRct.top+5,NULL); tas.drawSecondArrow=true; ArrowTo(lpDrawItem->hDC,fillRct.right-5,fillRct.bottom-25,&tas); //Draw a line in the bottom right part of the rectangle MoveToEx(lpDrawItem->hDC,(fillRct.right-fillRct.left)/2+5,fillRct.bottom-15,NULL); LineTo(lpDrawItem->hDC,fillRct.right-5,fillRct.bottom-5); //Deselect the pen and the brush END_SELOBJ(lpDrawItem->hDC,hDC_brush); END_SELOBJ(lpDrawItem->hDC,hDC_pen); DeleteRgn(fillRgn); break; } //End IDC_PB_PREVIEW case IDC_PB_B_COLOR: //Color panes case IDC_PB_H_COLORP: { HBRUSH hbr=CreateSolidBrush((lpDrawItem->CtlID==IDC_PB_B_COLOR?pbsdp->GetCurrentCU().GetColor():pbsdp->GetCurrentCU().GetACUPs().bgColor)); FillRect(lpDrawItem->hDC,&lpDrawItem->rcItem,hbr); DeleteBrush(hbr); break; } //End IDC_PB_B_COLOR } }
static void initHistogram(HWND hwnd) { HDC hdc; HBITMAP hist; RECT rect; HBRUSH brush; long w, h; GetClientRect(hwnd, &rect); w = rect.right - rect.left; h = rect.bottom - rect.top; /* create the memory DC */ hdc = GetDC(hwnd); hist = CreateCompatibleBitmap(hdc, w, h); hdcHist = CreateCompatibleDC(hdc); SelectBitmap(hdcHist, hist); ReleaseDC(hwnd, hdc); /* fill with black */ brush = CreateSolidBrush(RGB(0,0,0)); FillRect(hdcHist, &rect, brush); DeleteBrush(brush); }
/*! MAA窓の背景色選択ダイヤログの面倒見る @param[in] hWnd オーナーウインドウハンドル @return HRESULT 終了状態コード */ HRESULT MaaBackColourChoose( HWND hWnd ) { BOOL bRslt; COLORREF adColourTemp[16], dColour; CHOOSECOLOR stChColour; ZeroMemory( adColourTemp, sizeof(adColourTemp) ); dColour = (COLORREF)InitParamValue( INIT_LOAD, VL_MAA_BKCOLOUR, 0x00FFFFFF ); adColourTemp[0] = dColour; ZeroMemory( &stChColour, sizeof(CHOOSECOLOR) ); stChColour.lStructSize = sizeof(CHOOSECOLOR); stChColour.hwndOwner = hWnd; // stChColour.hInstance = GetModuleHandle( NULL ); stChColour.rgbResult = dColour; stChColour.lpCustColors = adColourTemp; stChColour.Flags = CC_RGBINIT; bRslt = ChooseColor( &stChColour ); // 色ダイヤログ使う if( bRslt ) { dColour = stChColour.rgbResult; InitParamValue( INIT_SAVE, VL_MAA_BKCOLOUR, (INT)dColour ); DeleteBrush( ghBkBrush ); // ブラシ作り直し ghBkBrush = CreateSolidBrush( dColour ); InvalidateRect( ghItemsWnd, NULL, TRUE ); return S_OK; } return E_ABORT; }
/*! 全ツリーやお気にリストの内容を表示するスタティックとか作る @param[in] hWnd 親ウインドウハンドル・NULLなら破壊 @param[in] hInst アプリの実存 @param[in] ptRect クライアント領域のサイズ @return HRESULT 終了状態コード */ HRESULT AaItemsInitialise( HWND hWnd, HINSTANCE hInst, LPRECT ptRect ) { #ifdef MAA_TOOLTIP INT ttSize; TTTOOLINFO stToolInfo; #endif SCROLLINFO stScrollInfo; RECT rect; LOGFONT stFont; COLORREF dBkColour; if( !(hWnd) ) { free( gptTipBuffer ); SetWindowFont( ghItemsWnd, GetStockFont(DEFAULT_GUI_FONT), FALSE ); #ifdef MAA_TOOLTIP SetWindowFont( ghToolTipWnd, GetStockFont(DEFAULT_GUI_FONT), FALSE ); DeleteFont( ghTipFont ); #endif DeleteFont( ghAaFont ); DeletePen( ghSepPen ); DeleteBrush( ghBkBrush ); return S_FALSE; } //ウインドウのサイズは、あとで変更が飛んでくるので、ここでは固定値で作っておk ghSepPen = CreatePen( PS_SOLID, 1, RGB(0xAA,0xAA,0xAA) ); // 1なら区切り線スタイル gbLineSep = InitParamValue( INIT_LOAD, VL_MAASEP_STYLE, 0 ); dBkColour = (COLORREF)InitParamValue( INIT_LOAD, VL_MAA_BKCOLOUR, 0x00FFFFFF ); ghBkBrush = CreateSolidBrush( dBkColour ); #ifndef _ORRVW // 選択したらフォーカスを編集窓に戻す? gbMaaRetFocus = InitParamValue( INIT_LOAD, VL_MAA_RETFCS, 0 ); #endif gptTipBuffer = NULL; gixTopItem = 0; gixNowSel = -1; #ifdef USE_HOVERTIP gixNowToolTip = -1; #endif #ifdef MAA_TEXT_FIND ZeroMemory( gatFindText, sizeof(gatFindText) ); #endif #ifdef MAA_TOOLTIP // ツールチップ作る ghToolTipWnd = CreateWindowEx( WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, NULL, hInst, NULL ); #endif // 見出しコンボックス ghComboxWnd = CreateWindowEx( 0, WC_COMBOBOX, TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_NOINTEGRALHEIGHT, TREE_WIDTH + SPLITBAR_WIDTH, 0, ptRect->right - TREE_WIDTH - LSSCL_WIDTH, TITLECBX_HEI, hWnd, (HMENU)IDCB_AAITEMTITLE, hInst, NULL ); GetClientRect( ghComboxWnd, &rect ); // サブクラス化 gpfOrgAaTitleCbxProc = SubclassWindow( ghComboxWnd, gpfAaTitleCbxProc ); // AA一覧のスタティックつくる・オーナードローで描画 ghItemsWnd = CreateWindowEx( WS_EX_CLIENTEDGE | WS_EX_ACCEPTFILES, WC_STATIC, TEXT(""), WS_VISIBLE | WS_CHILD | SS_OWNERDRAW | SS_NOTIFY, TREE_WIDTH + SPLITBAR_WIDTH, rect.bottom, ptRect->right - TREE_WIDTH - LSSCL_WIDTH, ptRect->bottom - rect.bottom, hWnd, (HMENU)IDSO_AAITEMS, hInst, NULL ); //DragAcceptFiles( ghItemsWnd, TRUE ); WS_EX_ACCEPTFILESでおk // サブクラス化 gpfOrgAaItemsProc = SubclassWindow( ghItemsWnd, gpfAaItemsProc ); // 一覧のスクロールバー ghScrollWnd = CreateWindowEx( 0, WC_SCROLLBAR, TEXT("scroll"), WS_VISIBLE | WS_CHILD | SBS_VERT, ptRect->right - LSSCL_WIDTH, rect.bottom, LSSCL_WIDTH, ptRect->bottom - rect.bottom, hWnd, (HMENU)IDSB_LISTSCROLL, hInst, NULL ); ZeroMemory( &stScrollInfo, sizeof(SCROLLINFO) ); stScrollInfo.cbSize = sizeof(SCROLLINFO); stScrollInfo.fMask = SIF_DISABLENOSCROLL; SetScrollInfo( ghScrollWnd, SB_CTL, &stScrollInfo, TRUE ); // 表示用メインフォント ViewingFontGet( &stFont ); ghAaFont = CreateFontIndirect( &stFont ); // gstBaseFont SetWindowFont( ghItemsWnd, ghAaFont, TRUE ); #ifdef MAA_TOOLTIP // ポッパップチップ用・12/9pt兼用 ttSize = InitParamValue( INIT_LOAD, VL_MAATIP_SIZE, FONTSZ_REDUCE ); // サイズ確認 stFont.lfHeight = (FONTSZ_REDUCE == ttSize) ? FONTSZ_REDUCE : FONTSZ_NORMAL; ghTipFont = CreateFontIndirect( &stFont ); SetWindowFont( ghToolTipWnd, ghTipFont, TRUE ); // ツールチップをコールバックで割り付け ZeroMemory( &stToolInfo, sizeof(TTTOOLINFO) ); stToolInfo.cbSize = sizeof(TTTOOLINFO); stToolInfo.uFlags = TTF_SUBCLASS; stToolInfo.hinst = NULL; // stToolInfo.hwnd = ghItemsWnd; stToolInfo.uId = IDSO_AAITEMS; GetClientRect( ghItemsWnd, &stToolInfo.rect ); stToolInfo.lpszText = LPSTR_TEXTCALLBACK; // コレを指定するとコールバックになる SendMessage( ghToolTipWnd, TTM_ADDTOOL, 0, (LPARAM)&stToolInfo ); SendMessage( ghToolTipWnd, TTM_SETMAXTIPWIDTH, 0, 0 ); // チップの幅。0設定でいい。これしとかないと改行されない #endif return S_OK; }
STDMETHODIMP CShellExt::Extract(LPCTSTR /*pszFile*/, UINT /*nIconIndex*/, HICON * phiconLarge, HICON * phiconSmall, UINT nIconSize) { WORD sizeSmall = HIWORD(nIconSize); WORD sizeLarge = LOWORD(nIconSize); ICONINFO iconinfo; BOOL res; HRESULT hrSmall = S_OK, hrLarge = S_OK; if (phiconSmall) hrSmall = LoadShellIcon(sizeSmall, sizeSmall, phiconSmall); if (phiconLarge) hrLarge = LoadShellIcon(sizeLarge, sizeLarge, phiconLarge); if (FAILED(hrSmall) || FAILED(hrLarge)) { InvalidateIcon(phiconSmall, phiconLarge); return S_FALSE; } if (!m_isDynamic || !phiconLarge || sizeLarge < 32) //No modifications required return S_OK; HDC dcEditColor, dcEditMask, dcEditTemp; HFONT font; HBRUSH brush; HPEN pen; BITMAPINFO bmi; HBITMAP hbm; LPDWORD pPix; res = GetIconInfo(*phiconLarge, &iconinfo); if (!res) return S_OK; //abort, the icon is still valid res = DestroyIcon(*phiconLarge); if (!res) return S_OK; else *phiconLarge = NULL; dcEditColor = CreateCompatibleDC(GetDC(0)); dcEditMask = CreateCompatibleDC(GetDC(0)); dcEditTemp = CreateCompatibleDC(GetDC(0)); // Create temp bitmap to render rectangle to ZeroMemory(&bmi, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = sizeLarge; bmi.bmiHeader.biHeight = sizeLarge; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; hbm = CreateDIBSection(dcEditTemp, &bmi, DIB_RGB_COLORS, (VOID**)&pPix, NULL, 0); memset(pPix, 0x00FFFFFF, sizeof(DWORD)*sizeLarge*sizeLarge); //initialize to white pixels, no alpha SelectObject(dcEditColor, iconinfo.hbmColor); SelectObject(dcEditMask, iconinfo.hbmMask); SelectObject(dcEditTemp, hbm); LONG calSize = (LONG)(sizeLarge*2/5); LOGFONT lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0}}; lf.lfHeight = calSize; lf.lfWeight = FW_NORMAL; lf.lfCharSet = DEFAULT_CHARSET; lstrcpyn(lf.lfFaceName, TEXT("Courier New"), LF_FACESIZE); RECT rectText = {0, 0, 0, 0}; RECT rectBox = {0, 0, 0, 0}; COLORREF backGround = RGB(1, 1, 60); COLORREF textColor = RGB(250,250,250); font = CreateFontIndirect(&lf); brush = CreateSolidBrush(backGround); pen = CreatePen(PS_NULL, 0, backGround); SelectObject(dcEditTemp, font); SelectObject(dcEditTemp, brush); SelectObject(dcEditTemp, pen); SetBkMode(dcEditTemp, TRANSPARENT); //dont clear background when drawing text SetBkColor(dcEditTemp, backGround); SetTextColor(dcEditTemp, textColor); //Calculate size of the displayed string SIZE stringSize; GetTextExtentPoint32(dcEditTemp, m_szFilePath, m_nameLength, &stringSize); stringSize.cx = std::min(stringSize.cx, (LONG)sizeLarge-2); stringSize.cy = std::min(stringSize.cy, (LONG)sizeLarge-2); rectText.top = sizeLarge - stringSize.cy - 1; rectText.left = sizeLarge - stringSize.cx - 1; rectText.bottom = sizeLarge - 1; rectText.right = sizeLarge - 1; rectBox.top = sizeLarge - stringSize.cy - 2; rectBox.left = sizeLarge - stringSize.cx - 2; rectBox.bottom = sizeLarge; rectBox.right = sizeLarge; //Draw the background (rounded) rectangle int elipsSize = calSize/3; RoundRect(dcEditTemp, rectBox.left, rectBox.top, rectBox.right, rectBox.bottom, elipsSize, elipsSize); //Draw text in the rectangle DrawText(dcEditTemp, m_szFilePath, m_nameLength, &rectText, DT_BOTTOM|DT_SINGLELINE|DT_LEFT); //set alpha of non white pixels back to 255 //premultiply alpha //Fill in the mask bitmap (anything not 100% alpha is transparent) int red, green, blue, alpha; for(int y = 0; y < sizeLarge; y++) { for(int x = 0; x < sizeLarge; x++) { DWORD * pix = pPix+(y*sizeLarge+x); red = *pix & 0xFF; green = *pix >> 8 & 0xFF; blue = *pix >> 16 & 0xFF; alpha = *pix >> 24 & 0xFF; if ((*pix << 8) == 0xFFFFFF00) alpha = 0x00; else alpha = 0xFF; red = (red*alpha)/0xFF; green = (green*alpha)/0xFF; blue = (blue*alpha)/0xFF; *pix = RGBA(red, green, blue, alpha); } } BLENDFUNCTION ftn = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA }; int width = rectBox.right - rectBox.left; int height = rectBox.bottom - rectBox.top; AlphaBlend(dcEditColor, rectBox.left, rectBox.top, stringSize.cx, stringSize.cy, dcEditTemp, rectBox.left, rectBox.top, width, height, ftn); //Adjust the mask image: simply draw the rectangle to it backGround = RGB(0, 0, 0); DeleteBrush(brush); DeletePen(pen); brush = CreateSolidBrush(backGround); pen = CreatePen(PS_NULL, 0, backGround); SelectObject(dcEditMask, brush); SelectObject(dcEditMask, pen); RoundRect(dcEditMask, rectBox.left, rectBox.top, rectBox.right, rectBox.bottom, elipsSize, elipsSize); DeleteDC(dcEditColor); DeleteDC(dcEditMask); DeleteDC(dcEditTemp); DeleteBrush(brush); DeletePen(pen); DeleteFont(font); DeleteBitmap(hbm); *phiconLarge = CreateIconIndirect(&iconinfo); DeleteBitmap(iconinfo.hbmColor); DeleteBitmap(iconinfo.hbmMask); if (*phiconLarge == NULL) { InvalidateIcon(phiconSmall, phiconLarge); return S_FALSE; } return S_OK; }
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); { HBRUSH brush = CreateSolidBrush(RGB(0, 255, 0)); HBRUSH oldBrush = SelectBrush(hdc, brush); Rectangle(hdc, 100, 100, 500, 400); SelectBrush(hdc, oldBrush); DeleteBrush(brush); } // TODO: 在此添加任意绘图代码... { HDC comDC = CreateCompatibleDC(hdc); RECT rect; GetClientRect(hWnd, &rect); HBITMAP bitmap = CreateCompatibleBitmap(comDC, 400, 300); HBITMAP oldBitmap = SelectBitmap(comDC, bitmap); SetTextColor(comDC, RGB(255, 0, 0)); TCHAR* szText = L"wwwwww.....aaa"; BOOL ret = TextOut(comDC,300,200,szText,_tcslen(szText)); BLENDFUNCTION bfc = {0}; bfc.AlphaFormat = 0; bfc.BlendFlags = 0; bfc.BlendOp = AC_SRC_OVER; bfc.SourceConstantAlpha = 100; ret = AlphaBlend(hdc, 0, 0, 400, 300, comDC, 0, 0, 400, 300, bfc); SelectBitmap(comDC, oldBitmap); DeleteBitmap(bitmap); DeleteDC(comDC); } EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
void Picker_HandleDrawItem(HWND hWnd, LPDRAWITEMSTRUCT lpDrawItemStruct) { struct PickerInfo *pPickerInfo; HDC hDC = lpDrawItemStruct->hDC; RECT rcItem = lpDrawItemStruct->rcItem; UINT uiFlags = ILD_TRANSPARENT; HIMAGELIST hImageList; int nItem = lpDrawItemStruct->itemID; COLORREF clrTextSave = 0; COLORREF clrBkSave = 0; COLORREF clrImage = GetSysColor(COLOR_WINDOW); static TCHAR szBuff[MAX_PATH]; BOOL bFocus = (GetFocus() == hWnd); LPCTSTR pszText; UINT nStateImageMask = 0; BOOL bSelected = 0; LV_COLUMN lvc; LV_ITEM lvi; RECT rcAllLabels; RECT rcLabel; RECT rcIcon; int offset = 0; SIZE size; int i = 0, j = 0; int nColumn = 0; int nColumnMax = 0; int *order; BOOL bDrawAsChild = 0; int indent_space = 0; BOOL bColorChild = FALSE; BOOL bParentFound = FALSE; int nParent = 0; HBITMAP hBackground = GetBackgroundBitmap(); MYBITMAPINFO *pbmDesc = GetBackgroundInfo(); BOOL res = 0; pPickerInfo = GetPickerInfo(hWnd); order = (int*)malloc(pPickerInfo->nColumnCount * sizeof(*order)); if (!order) return; nColumnMax = Picker_GetNumColumns(hWnd); if (GetUseOldControl()) { pPickerInfo->pCallbacks->pfnGetColumnOrder(order); } else { /* Get the Column Order and save it */ res = ListView_GetColumnOrderArray(hWnd, nColumnMax, order); /* Disallow moving column 0 */ if (order[0] != 0) { for (i = 0; i < nColumnMax; i++) { if (order[i] == 0) { order[i] = order[0]; order[0] = 0; } } res = ListView_SetColumnOrderArray(hWnd, nColumnMax, order); } } /* Labels are offset by a certain amount */ /* This offset is related to the width of a space character */ GetTextExtentPoint32(hDC, TEXT(" "), 1, &size); offset = size.cx; lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_PARAM; lvi.iItem = nItem; lvi.iSubItem = order[0]; lvi.pszText = szBuff; lvi.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]); lvi.stateMask = 0xFFFF; /* get all state flags */ res = ListView_GetItem(hWnd, &lvi); bSelected = ((lvi.state & LVIS_DROPHILITED) || ( (lvi.state & LVIS_SELECTED) && ((bFocus) || (GetWindowLong(hWnd, GWL_STYLE) & LVS_SHOWSELALWAYS)))); /* figure out if we indent and draw grayed */ if (pPickerInfo->pCallbacks->pfnFindItemParent) nParent = pPickerInfo->pCallbacks->pfnFindItemParent(hWnd, lvi.lParam); else nParent = -1; bDrawAsChild = (pPickerInfo->pCallbacks->pfnGetViewMode() == VIEW_GROUPED && (nParent >= 0)); /* only indent if parent is also in this view */ if ((nParent >= 0) && bDrawAsChild) { for (i = 0; i < ListView_GetItemCount(hWnd); i++) { lvi.mask = LVIF_PARAM; lvi.iItem = i; res = ListView_GetItem(hWnd, &lvi); if (lvi.lParam == nParent) { bParentFound = TRUE; break; } } } if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren()) { if (!bParentFound && bDrawAsChild) { /*Reset it, as no Parent is there*/ bDrawAsChild = FALSE; bColorChild = TRUE; } else { nParent = -1; bParentFound = FALSE; } } res = ListView_GetItemRect_Modified(hWnd, nItem, &rcAllLabels, LVIR_BOUNDS); res = ListView_GetItemRect_Modified(hWnd, nItem, &rcLabel, LVIR_LABEL); rcAllLabels.left = rcLabel.left; if (hBackground != NULL) { RECT rcClient; HRGN rgnBitmap; RECT rcTmpBmp = rcItem; RECT rcFirstItem; HPALETTE hPAL; HDC htempDC; HBITMAP oldBitmap; htempDC = CreateCompatibleDC(hDC); oldBitmap = (HBITMAP)SelectObject(htempDC, hBackground); GetClientRect(hWnd, &rcClient); rcTmpBmp.right = rcClient.right; /* We also need to check whether it is the last item The update region has to be extended to the bottom if it is */ if (nItem == ListView_GetItemCount(hWnd) - 1) rcTmpBmp.bottom = rcClient.bottom; rgnBitmap = CreateRectRgnIndirect(&rcTmpBmp); SelectClipRgn(hDC, rgnBitmap); DeleteBitmap(rgnBitmap); hPAL = GetBackgroundPalette(); if (hPAL == NULL) hPAL = CreateHalftonePalette(hDC); if (GetDeviceCaps(htempDC, RASTERCAPS) & RC_PALETTE && hPAL != NULL) { SelectPalette(htempDC, hPAL, FALSE); RealizePalette(htempDC); } res = ListView_GetItemRect_Modified(hWnd, 0, &rcFirstItem, LVIR_BOUNDS); for (i = rcFirstItem.left; i < rcClient.right; i += pbmDesc->bmWidth) for (j = rcFirstItem.top; j < rcClient.bottom; j += pbmDesc->bmHeight) BitBlt(hDC, i, j, pbmDesc->bmWidth, pbmDesc->bmHeight, htempDC, 0, 0, SRCCOPY); SelectObject(htempDC, oldBitmap); DeleteDC(htempDC); if (GetBackgroundPalette() == NULL) { DeletePalette(hPAL); hPAL = NULL; } } indent_space = 0; if (bDrawAsChild) { RECT rect; res = ListView_GetItemRect_Modified(hWnd, nItem, &rect, LVIR_ICON); /* indent width of icon + the space between the icon and text * so left of clone icon starts at text of parent */ indent_space = rect.right - rect.left + offset; } rcAllLabels.left += indent_space; if (bSelected) { HBRUSH hBrush; HBRUSH hOldBrush; if (bFocus) { clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT)); hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT)); } else { clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT)); clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_BTNFACE)); hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); } hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); FillRect(hDC, &rcAllLabels, hBrush); SelectObject(hDC, hOldBrush); DeleteBrush(hBrush); } else { if (hBackground == NULL) { HBRUSH hBrush; hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW)); FillRect(hDC, &rcAllLabels, hBrush); DeleteBrush(hBrush); } if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren()) { if (bDrawAsChild || bColorChild) clrTextSave = SetTextColor(hDC, GetListCloneColor()); else clrTextSave = SetTextColor(hDC, GetListFontColor()); } else { if (bDrawAsChild) clrTextSave = SetTextColor(hDC, GetListCloneColor()); else clrTextSave = SetTextColor(hDC, GetListFontColor()); } clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_WINDOW)); } if (lvi.state & LVIS_CUT) { clrImage = GetSysColor(COLOR_WINDOW); uiFlags |= ILD_BLEND50; } else if (bSelected) { if (bFocus) clrImage = GetSysColor(COLOR_HIGHLIGHT); else clrImage = GetSysColor(COLOR_BTNFACE); uiFlags |= ILD_BLEND50; } nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK; if (nStateImageMask) { int nImage = (nStateImageMask >> 12) - 1; hImageList = ListView_GetImageList(hWnd, LVSIL_STATE); if (hImageList) ImageList_Draw(hImageList, nImage, hDC, rcItem.left, rcItem.top, ILD_TRANSPARENT); } res = ListView_GetItemRect_Modified(hWnd, nItem, &rcIcon, LVIR_ICON); rcIcon.left += indent_space; res = ListView_GetItemRect_Modified(hWnd, nItem, &rcItem, LVIR_LABEL); hImageList = ListView_GetImageList(hWnd, LVSIL_SMALL); if (hImageList) { UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK; if (rcIcon.left + 16 + indent_space < rcItem.right) { ImageList_DrawEx(hImageList, lvi.iImage, hDC, rcIcon.left, rcIcon.top, 16, 16, GetSysColor(COLOR_WINDOW), clrImage, uiFlags | nOvlImageMask); } } res = ListView_GetItemRect_Modified(hWnd, nItem, &rcItem, LVIR_LABEL); pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2*offset + indent_space); rcLabel = rcItem; rcLabel.left += offset + indent_space; rcLabel.right -= offset; DrawText(hDC, pszText, -1, &rcLabel, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); for (nColumn = 1; nColumn < nColumnMax; nColumn++) { int nRetLen; UINT nJustify; LV_ITEM lvItem; lvc.mask = LVCF_FMT | LVCF_WIDTH; res = ListView_GetColumn(hWnd, order[nColumn], &lvc); lvItem.mask = LVIF_TEXT; lvItem.iItem = nItem; lvItem.iSubItem = order[nColumn]; lvItem.pszText = szBuff; lvItem.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]); if (ListView_GetItem(hWnd, &lvItem) == FALSE) continue; rcItem.left = rcItem.right; rcItem.right += lvc.cx; nRetLen = _tcslen(szBuff); if (nRetLen == 0) continue; pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2 * offset); nJustify = DT_LEFT; if (pszText == szBuff) { switch (lvc.fmt & LVCFMT_JUSTIFYMASK) { case LVCFMT_RIGHT: nJustify = DT_RIGHT; break; case LVCFMT_CENTER: nJustify = DT_CENTER; break; default: break; } } rcLabel = rcItem; rcLabel.left += offset; rcLabel.right -= offset; DrawText(hDC, pszText, -1, &rcLabel, nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); } if (lvi.state & LVIS_FOCUSED && bFocus) DrawFocusRect(hDC, &rcAllLabels); SetTextColor(hDC, clrTextSave); SetBkColor(hDC, clrBkSave); free(order); res++; }
/* This function handles all messages for the out-basket window. */ LRESULT EXPORT CALLBACK OutBasketWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam ) { switch( message ) { HANDLE_MSG( hwnd, WM_CREATE, OutBasket_OnCreate ); HANDLE_MSG( hwnd, WM_CLOSE, OutBasket_OnClose ); HANDLE_MSG( hwnd, WM_SIZE, OutBasket_OnSize ); HANDLE_MSG( hwnd, WM_MOVE, OutBasket_OnMove ); HANDLE_MSG( hwnd, WM_ERASEBKGND, Common_OnEraseBkgnd ); HANDLE_MSG( hwnd, WM_COMMAND, OutBasket_OnCommand ); HANDLE_MSG( hwnd, WM_DRAWITEM, OutBasket_OnDrawItem ); HANDLE_MSG( hwnd, WM_MEASUREITEM, OutBasket_OnMeasureItem ); HANDLE_MSG( hwnd, WM_MDIACTIVATE, OutBasket_MDIActivate ); HANDLE_MSG( hwnd, WM_MENUSELECT, MainWnd_OnMenuSelect ); #ifdef WIN32 HANDLE_MSG( hwnd, WM_CTLCOLORLISTBOX, OutBasket_OnCtlColor ); #else HANDLE_MSG( hwnd, WM_CTLCOLOR, OutBasket_OnCtlColor ); #endif HANDLE_MSG( hwnd, WM_SETFOCUS, OutBasket_OnSetFocus ); HANDLE_MSG( hwnd, WM_ADJUSTWINDOWS, OutBasket_OnAdjustWindows ); case WM_CHANGEFONT: if( wParam == FONTYP_OUTBASKET || 0xFFFF == wParam ) { MEASUREITEMSTRUCT mis; HWND hwndList; hwndList = GetDlgItem( hwnd, IDD_LIST ); SendMessage( hwnd, WM_MEASUREITEM, IDD_LIST, (LPARAM)(LPSTR)&mis ); SendMessage( hwndList, LB_SETITEMHEIGHT, 0, MAKELPARAM( mis.itemHeight, 0) ); SetWindowFont( hwndList, hOutBasketFont, TRUE ); } return( 0L ); case WM_APPCOLOURCHANGE: if( wParam == WIN_OUTBASK ) { HWND hwndList; if( NULL != hbrOutBaskWnd ) DeleteBrush( hbrOutBaskWnd ); hbrOutBaskWnd = CreateSolidBrush( crOutBaskWnd ); hwndList = GetDlgItem( hwnd, IDD_LIST ); InvalidateRect( hwndList, NULL, TRUE ); UpdateWindow( hwndList ); } return( 0L ); case WM_GETMINMAXINFO: { MINMAXINFO FAR * lpMinMaxInfo; LRESULT lResult; /* Set the minimum tracking size so the client window can never * be resized below 24 lines. */ lResult = Adm_DefMDIDlgProc( hwnd, message, wParam, lParam ); lpMinMaxInfo = (MINMAXINFO FAR *)lParam; lpMinMaxInfo->ptMinTrackSize.x = 175; lpMinMaxInfo->ptMinTrackSize.y = 192; return( lResult ); } default: break; } return( Adm_DefMDIDlgProc( hwnd, message, wParam, lParam ) ); }
Globals::~Globals() { try { BOOL bResult; if (m_hHookAccelator) { bResult = UnhookWindowsHookEx(m_hHookAccelator); assert(bResult); } if (m_hBitmapExpandVert) { bResult = DeleteBitmap(m_hBitmapExpandVert); assert(bResult); } if (m_hBitmapExpandHorz) { bResult = DeleteBitmap(m_hBitmapExpandHorz); assert(bResult); } if (m_hBitmapMenuScroll) { bResult = DeleteBitmap(m_hBitmapMenuScroll); assert(bResult); } if (m_hBitmapEndMarker) { bResult = DeleteBitmap(m_hBitmapEndMarker); assert(bResult); } if (m_hBitmapSubMenu) { bResult = DeleteBitmap(m_hBitmapSubMenu); assert(bResult); } if (m_hBitmapSMCombo) { bResult = DeleteBitmap(m_hBitmapSMCombo); assert(bResult); } if (m_hBitmapMenuCheck) { bResult = DeleteBitmap(m_hBitmapMenuCheck); assert(bResult); } if (m_hBitmapMenuExpand) { bResult = DeleteBitmap(m_hBitmapMenuExpand); assert(bResult); } if (m_hBitmapMDIButtons) { bResult = DeleteBitmap(m_hBitmapMDIButtons); assert(bResult); } if (m_hHandCursor) { bResult = DestroyCursor(m_hHandCursor); assert(bResult); } if (m_hSmallCaption) { bResult = DeleteFont(m_hSmallCaption); assert(bResult); } if (m_ilSizer) { bResult = ImageList_Destroy(m_ilSizer); assert(bResult); } if (m_ilSlidingScrollImages) { bResult = ImageList_Destroy(m_ilSlidingScrollImages); assert(bResult); } for (int nIndex = 0; nIndex < GrabStyleCount; nIndex++) { if (m_hBrushGrab[nIndex]) { bResult = DeleteBrush(m_hBrushGrab[nIndex]); assert(bResult); } } if (m_hBrushDither) { bResult = DeleteBrush(m_hBrushDither); assert(bResult); } if (m_hBrushPattern) { bResult = DeleteBrush(m_hBrushPattern); assert(bResult); } if (m_pmapBar) { assert(0 == m_pmapBar->GetCount()); delete m_pmapBar; } if (m_pmapAccelator) { assert(0 == m_pmapAccelator->GetCount()); delete m_pmapAccelator; } if (m_hMMLibrary) FreeLibrary(m_hMMLibrary); if (m_hUser32Library) FreeLibrary(m_hUser32Library); delete m_pDragDropMgr; FDialog::CheckMap(); FDialog::CleanUp(); FWnd::CheckMap(); FWnd::CleanUp(); CDDPropertySheet::Cleanup(); delete m_pControls; delete m_pEventLog; _set_se_translator(m_seFunction); DeleteCriticalSection(&m_csGlobals); DeleteCriticalSection(&m_csPaintIcon); } CATCH { assert(FALSE); m_pEventLog = NULL; REPORTEXCEPTION(__FILE__, __LINE__) } }
void gui_mch_draw_string( int row, int col, char_u *text, int len, int flags) { #ifndef MSWIN16_FASTTEXT static int *padding = NULL; static int pad_size = 0; int i; #endif HPEN hpen, old_pen; int y; #ifndef MSWIN16_FASTTEXT /* * Italic and bold text seems to have an extra row of pixels at the bottom * (below where the bottom of the character should be). If we draw the * characters with a solid background, the top row of pixels in the * character below will be overwritten. We can fix this by filling in the * background ourselves, to the correct character proportions, and then * writing the character in transparent mode. Still have a problem when * the character is "_", which gets written on to the character below. * New fix: set gui.char_ascent to -1. This shifts all characters up one * pixel in their slots, which fixes the problem with the bottom row of * pixels. We still need this code because otherwise the top row of pixels * becomes a problem. - webb. */ HBRUSH hbr; RECT rc; if (!(flags & DRAW_TRANSP)) { /* * Clear background first. * Note: FillRect() excludes right and bottom of rectangle. */ rc.left = FILL_X(col); rc.top = FILL_Y(row); #ifdef FEAT_MBYTE if (has_mbyte) { /* Compute the length in display cells. */ rc.right = FILL_X(col + mb_string2cells(text, len)); } else #endif rc.right = FILL_X(col + len); rc.bottom = FILL_Y(row + 1); hbr = CreateSolidBrush(gui.currBgColor); FillRect(s_hdc, &rc, hbr); DeleteBrush(hbr); SetBkMode(s_hdc, TRANSPARENT); /* * When drawing block cursor, prevent inverted character spilling * over character cell (can happen with bold/italic) */ if (flags & DRAW_CURSOR) { pcliprect = &rc; foptions = ETO_CLIPPED; } } #else /* * Alternative: write the characters in opaque mode, since we have blocked * bold or italic fonts. */ /* The OPAQUE mode and backcolour have already been set */ #endif /* The forecolor and font have already been set */ #ifndef MSWIN16_FASTTEXT if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width) { vim_free(padding); pad_size = Columns; padding = (int *)alloc(pad_size * sizeof(int)); if (padding != NULL) for (i = 0; i < pad_size; i++) padding[i] = gui.char_width; } #endif /* * We have to provide the padding argument because italic and bold versions * of fixed-width fonts are often one pixel or so wider than their normal * versions. * No check for DRAW_BOLD, Windows will have done it already. */ #ifndef MSWIN16_FASTTEXT ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), 0, NULL, (char *)text, len, padding); #else TextOut(s_hdc, TEXT_X(col), TEXT_Y(row), (char *)text, len); #endif if (flags & DRAW_UNDERL) { hpen = CreatePen(PS_SOLID, 1, gui.currFgColor); old_pen = SelectObject(s_hdc, hpen); /* When p_linespace is 0, overwrite the bottom row of pixels. * Otherwise put the line just below the character. */ y = FILL_Y(row + 1) - 1; #ifndef MSWIN16_FASTTEXT if (p_linespace > 1) y -= p_linespace - 1; #endif MoveToEx(s_hdc, FILL_X(col), y, NULL); /* Note: LineTo() excludes the last pixel in the line. */ LineTo(s_hdc, FILL_X(col + len), y); DeleteObject(SelectObject(s_hdc, old_pen)); } }
/** * genopt_window_wndproc(): Window procedure. * @param hWnd hWnd of the window. * @param message Window message. * @param wParam * @param lParam * @return */ static LRESULT CALLBACK genopt_window_wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: genopt_window_create_child_windows(hWnd); break; case WM_DRAWITEM: genopt_window_callback_drawMsgRadioButton(LOWORD(wParam), (LPDRAWITEMSTRUCT)lParam); break; case WM_COMMAND: // Button press switch (LOWORD(wParam)) { case IDOK: genopt_window_save(); DestroyWindow(hWnd); break; case IDAPPLY: genopt_window_save(); break; case IDCANCEL: DestroyWindow(hWnd); break; default: if ((LOWORD(wParam) & 0xFF00) == 0xA000) { // Radio button selected. genopt_window_callback_selectRadioButton(LOWORD(wParam)); } } break; case WM_DESTROY: if (hWnd != genopt_window) break; genopt_window = NULL; // Delete OSD color brushes and pens. for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { DeleteBrush(brushOSD[i][j]); DeletePen(penOSD[i][j]); } } // Delete intro effect color brushes and pens. for (int i = 0; i < 8; i++) { for (int j = 0; j < 2; j++) { DeleteBrush(brushIntroEffect[i][j]); DeletePen(penIntroEffect[i][j]); } } break; } return DefWindowProc(hWnd, message, wParam, lParam); }
STDMETHODIMP CShellExt::Extract(LPCTSTR pszFile, UINT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIconSize) { WORD sizeSmall = HIWORD(nIconSize); WORD sizeLarge = LOWORD(nIconSize); ICONINFO iconinfo; BOOL res; HRESULT hrSmall = S_OK, hrLarge = S_OK; if (phiconSmall) hrSmall = LoadShellIcon(sizeSmall, sizeSmall, phiconSmall); if (phiconLarge) hrLarge = LoadShellIcon(sizeLarge, sizeLarge, phiconLarge); if (FAILED(hrSmall) || FAILED(hrLarge)) { InvalidateIcon(phiconSmall, phiconLarge); return S_FALSE; } if (!m_isDynamic || !phiconLarge) //No modifications required return S_OK; HDC dcEditColor, dcEditMask; HGDIOBJ oldBitmapColor, oldBitmapMask, oldFontColor; HFONT font; HBRUSH brush; res = GetIconInfo(*phiconLarge, &iconinfo); if (!res) return S_OK; //abort, the icon is still valid res = DestroyIcon(*phiconLarge); if (!res) return S_OK; else *phiconLarge = NULL; dcEditColor = CreateCompatibleDC(GetDC(0)); dcEditMask = CreateCompatibleDC(GetDC(0)); oldBitmapColor = SelectObject(dcEditColor, iconinfo.hbmColor); oldBitmapMask = SelectObject(dcEditMask, iconinfo.hbmMask); LONG calSize = (LONG)(sizeLarge*2/5); LOGFONT lf = {0}; lf.lfHeight = std::min(calSize, (LONG)15); //this is in pixels. Make no larger than 15 pixels (but smaller is allowed for small icons) lf.lfWeight = FW_NORMAL; lf.lfCharSet = DEFAULT_CHARSET; lstrcpyn(lf.lfFaceName, TEXT("Bitstream Vera Sans Mono"), LF_FACESIZE); LOGBRUSH lbrush; lbrush.lbStyle = BS_SOLID; lbrush.lbHatch = 0; RECT rect = {0}; COLORREF backGround = RGB(1, 1, 1); COLORREF textColor = RGB(255,255,255); //Grab the topleft pixel as the background color COLORREF maskBack = GetPixel(dcEditColor, 0, 0); if (backGround == maskBack) backGround++; //add one, shouldn't be very visible font = CreateFontIndirect(&lf); lbrush.lbColor = backGround; brush = CreateBrushIndirect(&lbrush); oldFontColor = SelectObject(dcEditColor, font); SetBkMode(dcEditColor, TRANSPARENT); //dont clear background when drawing text (doesnt change much, colors are the same) SetBkColor(dcEditColor, backGround); SetTextColor(dcEditColor, textColor); SIZE stringSize; GetTextExtentPoint32(dcEditColor, m_szFilePath, m_nameLength, &stringSize); stringSize.cx = std::min(stringSize.cx, (LONG)sizeLarge-2); stringSize.cy = std::min(stringSize.cy, (LONG)sizeLarge-2); rect.top = sizeLarge - stringSize.cy - 2; rect.left = sizeLarge - stringSize.cx - 1; rect.bottom = sizeLarge; rect.right = sizeLarge-1; FillRect(dcEditColor, &rect, brush); FillRect(dcEditMask, &rect, brush); rect.top += 1; rect.left -= 1; rect.bottom -= 1; rect.right += 1; FillRect(dcEditColor, &rect, brush); FillRect(dcEditMask, &rect, brush); rect.left += 1; DrawText(dcEditColor, m_szFilePath, m_nameLength, &rect, DT_BOTTOM|DT_SINGLELINE|DT_LEFT); SetBkColor(dcEditColor, maskBack); //BitBlt(dcEditMask, 0, 0, sizeLarge, sizeLarge, dcEditColor, 0, 0, SRCCOPY); SelectObject(dcEditColor, oldFontColor); SelectObject(dcEditColor, oldBitmapColor); SelectObject(dcEditMask, oldBitmapMask); DeleteDC(dcEditColor); DeleteDC(dcEditMask); DeleteBrush(brush); *phiconLarge = CreateIconIndirect(&iconinfo); res = DeleteBitmap(iconinfo.hbmColor); res = DeleteBitmap(iconinfo.hbmMask); if (*phiconLarge == NULL) { InvalidateIcon(phiconSmall, phiconLarge); return S_FALSE; } return S_OK; }
/* create and hdc of the trace graph so it can just be blitted over and we don't have to construct it every time */ static void initTracer(HWND hwnd) { HDC hdc; HBITMAP graph; HPEN pen; HBRUSH brush; RECT rect; long fw,fh,w,h; GetClientRect(hwnd, &rect); fw = rect.right - rect.left; fh = rect.bottom - rect.top; w = fw - (XHAIR_HALF*2|1); h = fh - (XHAIR_HALF*2|1); /* create the memoryDC for the graph */ hdc = GetDC(hwnd); graph = CreateCompatibleBitmap(hdc, fw, fh); hdcTracer = CreateCompatibleDC(hdc); ReleaseDC(hwnd, hdc); //we now longer need this, we now draw into hdcTracer SelectBitmap(hdcTracer, graph); /* fill with black */ brush = CreateSolidBrush(RGB(0,0,0)); FillRect(hdcTracer, &rect, brush); DeleteBrush(brush); /* draw reference grid */ pen = CreatePen(PS_SOLID, 1, RGB(0,255,255)); SelectPen(hdcTracer, pen); //Squares brush = CreateSolidBrush(RGB(0,64,64)); SelectBrush(hdcTracer, brush); //borderRect(hdcTracer, XHAIR_HALF, XHAIR_HALF, XHAIR_HALF+w+1, XHAIR_HALF+h+1, brush); borderRect(hdcTracer, XHAIR_HALF, XHAIR_HALF, XHAIR_HALF+w+1, XHAIR_HALF+w+1, brush); borderRect(hdcTracer, XHAIR_HALF + w/4, XHAIR_HALF + h/4, XHAIR_HALF + w/4*3+1, XHAIR_HALF + h/4*3+1, brush); DeleteBrush(brush); /*brush = CreateSolidBrush(RGB(0,16,16)); SelectBrush(hdcTracer, brush); borderRect(hdcTracer, XHAIR_HALF + w/8*3, XHAIR_HALF + h/8*3, XHAIR_HALF + w/8*5+1, XHAIR_HALF + h/8*5+1, brush); borderRect(hdcTracer, XHAIR_HALF + w/8, XHAIR_HALF + h/8, XHAIR_HALF + w/8*7+1, XHAIR_HALF + h/8*7+1, brush); DeleteBrush(brush);*/ //Main Axis centerLine(hdcTracer, fw/2, fh/2, w, LINE_XAXIS); centerLine(hdcTracer, fw/2, fh/2, h, LINE_YAXIS); //X half hashes centerLine(hdcTracer, XHAIR_HALF, h/2 + XHAIR_HALF, BIG_HASH, LINE_YAXIS); centerLine(hdcTracer, w/4 + XHAIR_HALF, h/2 + XHAIR_HALF, BIG_HASH, LINE_YAXIS); centerLine(hdcTracer, w/4*3 + XHAIR_HALF, h/2 + XHAIR_HALF, BIG_HASH, LINE_YAXIS); centerLine(hdcTracer, w + XHAIR_HALF, h/2 + XHAIR_HALF, BIG_HASH, LINE_YAXIS); //X quarter hashes centerLine(hdcTracer, w/8 + XHAIR_HALF, h/2 + XHAIR_HALF, SMALL_HASH, LINE_YAXIS); centerLine(hdcTracer, w/8*3 + XHAIR_HALF, h/2 + XHAIR_HALF, SMALL_HASH, LINE_YAXIS); centerLine(hdcTracer, w/8*5 + XHAIR_HALF, h/2 + XHAIR_HALF, SMALL_HASH, LINE_YAXIS); centerLine(hdcTracer, w/8*7 + XHAIR_HALF, h/2 + XHAIR_HALF, SMALL_HASH, LINE_YAXIS); //Y half hashes centerLine(hdcTracer, w/2 + XHAIR_HALF, XHAIR_HALF, BIG_HASH, LINE_XAXIS); centerLine(hdcTracer, w/2 + XHAIR_HALF, h/4 + XHAIR_HALF, BIG_HASH, LINE_XAXIS); centerLine(hdcTracer, w/2 + XHAIR_HALF, h/4*3 + XHAIR_HALF, BIG_HASH, LINE_XAXIS); centerLine(hdcTracer, w/2 + XHAIR_HALF, h + XHAIR_HALF, BIG_HASH, LINE_XAXIS); //Y quarter hashes centerLine(hdcTracer, w/2 + XHAIR_HALF, h/8 + XHAIR_HALF, SMALL_HASH, LINE_XAXIS); centerLine(hdcTracer, w/2 + XHAIR_HALF, h/8*3 + XHAIR_HALF, SMALL_HASH, LINE_XAXIS); centerLine(hdcTracer, w/2 + XHAIR_HALF, h/8*5 + XHAIR_HALF, SMALL_HASH, LINE_XAXIS); centerLine(hdcTracer, w/2 + XHAIR_HALF, h/8*7 + XHAIR_HALF, SMALL_HASH, LINE_XAXIS); DeletePen(pen); GdiFlush(); }
void MDIOSprite_UpdateWindow (MIOWinInfoPtr pmInfoPtr, BOOL pmCopyToOffscreen) { MYRECTLIST *myDirtyRect, *myNextDirtyRect; MYRECT myRect; SpriteInfo *mySpritePtr; BOOL mySpriteNotDrawn, myBackgroundNotDrawn; int myWidth, myHeight; //int gdiRes, userRes, gdiRes1, userRes1; //gdiRes = GetGuiResources (GetCurrentProcess(), GR_GDIOBJECTS); //userRes = GetGuiResources (GetCurrentProcess(), GR_USEROBJECTS); myDirtyRect = pmInfoPtr -> dirtyRectHead; // Set up the window. // TW // Now, if there are no items that are behind the offscreen window (i.e. // all sprites have positive height), then simply do a copy of the // offscreen window. However, if there are, then we start by filling // the entire area with the transparent colour of the offscreen window, // then drawing the non-postive height sprites in MERGE mode, then drawing // the offscreen window in MERGE mode, then drawing the rest of the // sprites in MERGE mode. while (myDirtyRect != NULL) { myRect = myDirtyRect -> rect; // Convert from Turing coordinates to Windows coordinates myWidth = myRect.right - myRect.left; myHeight = myRect.bottom - myRect.top; // Now draw each sprite mySpritePtr = (SpriteInfo *) (pmInfoPtr -> spriteQueueHead); mySpriteNotDrawn = TRUE; myBackgroundNotDrawn = TRUE; while (mySpritePtr != NULL) { // If the sprite is not visible or does not intersect with the // dirty rectangle, ignore it. if ((!mySpritePtr -> visible) || !MIO_RectanglesIntersect (&myDirtyRect -> rect, &mySpritePtr -> spriteRect)) { // Sprite not visible or doesn't intersect, don't draw it! mySpritePtr = mySpritePtr -> next; continue; } // If we haven't drawn a sprite before we either have to draw the // offscreen window (if the first sprite's height is positive, // or just fill the sprite space with the transparent colour). if (mySpriteNotDrawn) { if (mySpritePtr -> spriteHeight >= 0) { // The lowest sprite is above the background. Draw the // background using COPY BitBlt (pmInfoPtr -> spriteDeviceContext, myRect.left, myRect.top, myWidth, myHeight, pmInfoPtr -> offscreenDeviceContext, myRect.left, myRect.top, SRCCOPY); myBackgroundNotDrawn = FALSE; } else { // Fill the background with the offscreen window's // transparent color HPEN myNewPen, myOldPen; HBRUSH myNewBrush, myOldBrush; COLORREF myTransparentColour; myTransparentColour = (COLORREF) MIORGB_ConvertColour ( pmInfoPtr -> transparentColour); myNewPen = CreatePen (PS_SOLID, 1, myTransparentColour); myNewBrush = CreateSolidBrush (myTransparentColour); myOldPen = SelectPen (pmInfoPtr -> spriteDeviceContext, myNewPen); myOldBrush = SelectBrush (pmInfoPtr -> spriteDeviceContext, myNewBrush); Rectangle (pmInfoPtr -> spriteDeviceContext, myRect.left, myRect.top, myRect.right + 1, myRect.bottom + 1); SelectBrush (pmInfoPtr -> spriteDeviceContext, myOldBrush); DeleteBrush (myNewBrush); SelectPen (pmInfoPtr -> spriteDeviceContext, myOldPen); DeletePen (myNewPen); } mySpriteNotDrawn = FALSE; } else { // If we haven't drawn the background before, and this sprite // is above the background (height >= 0), then its time to // draw the background in MERGE mode if (myBackgroundNotDrawn && (mySpritePtr -> spriteHeight >= 0)) { MDIOPic_SpriteDraw (pmInfoPtr, NULL, myRect.left, myRect.top, myWidth, myHeight, pmInfoPtr -> transparentColour); myBackgroundNotDrawn = FALSE; } } // Draw Sprite MDIOPic_SpriteDraw (pmInfoPtr, mySpritePtr -> picMDPicInfo, mySpritePtr -> x, mySpritePtr -> y, mySpritePtr -> picWidth, mySpritePtr -> picHeight, mySpritePtr -> picTransparentColour); mySpritePtr = mySpritePtr -> next; } // If we still haven't drawn the background after having drawn all the // sprites, then it is time to draw the background. If we've drawn // any sprites above, then the background has already been drawn, and // we draw in MERGE mode. If we haven't drawn a sprite, then we draw // the background in copy mode. if (myBackgroundNotDrawn) { if (mySpriteNotDrawn) { BitBlt (pmInfoPtr -> spriteDeviceContext, myRect.left, myRect.top, myWidth, myHeight, pmInfoPtr -> offscreenDeviceContext, myRect.left, myRect.top, SRCCOPY); } else { MDIOPic_SpriteDraw (pmInfoPtr, NULL, myRect.left, myRect.top, myWidth, myHeight, pmInfoPtr -> transparentColour); } myBackgroundNotDrawn = FALSE; } // Finally, draw the completed sprite surface to the on-screen window. BitBlt (pmInfoPtr -> deviceContext, myRect.left, myRect.top, myWidth, myHeight, pmInfoPtr -> spriteDeviceContext, myRect.left, myRect.top, SRCCOPY); // Okay, if pmCopyToOffscreen is true, then copy all of this to the // offscreen bitmap as well. This is used when Turing is finished and // the sprites are about to be deallocated. if (pmCopyToOffscreen) { BitBlt (pmInfoPtr -> offscreenDeviceContext, myRect.left, myRect.top, myWidth, myHeight, pmInfoPtr -> spriteDeviceContext, myRect.left, myRect.top, SRCCOPY); } // Free the current dirty rect and get the next dirty rectangle. myNextDirtyRect = myDirtyRect -> next; free (myDirtyRect); myDirtyRect = myNextDirtyRect; } // while pmInfoPtr -> dirtyRectHead = NULL; //gdiRes1 = GetGuiResources (GetCurrentProcess(), GR_GDIOBJECTS); //userRes1 = GetGuiResources (GetCurrentProcess(), GR_USEROBJECTS); } // MDIOSprite_UpdateWindow
void Label::DrawBackground(HDC hDC) { if (mBackgroundImage) { int w = 0; int h = 0; // Fill background with an image HDC backgroundDC = CreateCompatibleDC(hDC); HBITMAP oldBackgroundBitmap = SelectBitmap(backgroundDC, mBackgroundImage); GetLSBitmapSize(mBackgroundImage, &w, &h); ScaleEdgeBlt(hDC, 0, 0, mWidth, mHeight, backgroundDC, 0, 0, w, h, mBackgroundImageBorderLeft, mBackgroundImageBorderTop, mBackgroundImageBorderRight, mBackgroundImageBorderBottom, mBackgroundImageTile, SRCCOPY); SelectBitmap(backgroundDC, oldBackgroundBitmap); DeleteDC(backgroundDC); } else { // Fill background with color HBRUSH brush = CreateSolidBrush(mBackgroundColor); HBRUSH oldBrush = SelectBrush(hDC, brush); PatBlt(hDC, 0, 0, mWidth, mHeight, PATCOPY); SelectBrush(hDC, oldBrush); DeleteBrush(brush); // Draw top border if (mBorderTop > 0) { HPEN pen = CreatePen(PS_SOLID, mBorderTop * 2, mBorderColorTop); HPEN oldPen = SelectPen(hDC, pen); MoveToEx(hDC, 0, 0, NULL); LineTo(hDC, mWidth, 0); SelectPen(hDC, oldPen); DeletePen(pen); } // Draw right border if (mBorderRight > 0) { HPEN pen = CreatePen(PS_SOLID, mBorderRight * 2, mBorderColorRight); HPEN oldPen = SelectPen(hDC, pen); MoveToEx(hDC, mWidth, 0, NULL); LineTo(hDC, mWidth, mHeight); SelectPen(hDC, oldPen); DeletePen(pen); } // Draw bottom border if (mBorderBottom > 0) { HPEN pen = CreatePen(PS_SOLID, mBorderBottom * 2, mBorderColorBottom); HPEN oldPen = SelectPen(hDC, pen); MoveToEx(hDC, mWidth, mHeight, NULL); LineTo(hDC, 0, mHeight); SelectPen(hDC, oldPen); DeletePen(pen); } // Draw left border if (mBorderLeft > 0) { HPEN pen = CreatePen(PS_SOLID, mBorderLeft * 2, mBorderColorLeft); HPEN oldPen = SelectPen(hDC, pen); MoveToEx(hDC, 0, mHeight, NULL); LineTo(hDC, 0, 0); SelectPen(hDC, oldPen); DeletePen(pen); } } }
void drawHistogram(HWND hwnd, long *values, int nValues, int maxval) { HDC hdc; RECT bounds; HBRUSH brush; HPEN pen; int w,h; int bars; float barw; long histidx; unsigned short histmax; //unsigned short phist[HIST_BARS], nhist[HIST_BARS]; unsigned short *phist = NULL, *nhist = NULL; int c; if (hdcHist == NULL) initHistogram(hwnd); if (maxval < MAX_BARS) bars = maxval; else bars = MAX_BARS; phist = malloc(sizeof(short) * bars); nhist = malloc(sizeof(short) * bars); if ((phist == NULL) || (nhist == NULL)) return; /* compute histogram data */ memset(phist, 0, sizeof(short) * bars); memset(nhist, 0, sizeof(short) * bars); for (c=0; c<nValues; c++) { histidx = (long)(((float)abs(values[c]) / maxval) * (bars - 0.001f)); if (values[c] > 0) phist[histidx]++; else if (values[c] < 0) nhist[histidx]++; } //find scale histmax = 0; for (c=0; c<bars; c++) { if (phist[c] > histmax) histmax = phist[c]; if (nhist[c] > histmax) histmax = nhist[c]; } /* get attributes */ GetClientRect(hwnd, &bounds); w = bounds.right - bounds.left; h = bounds.bottom - bounds.top; barw = (float) w / bars; /* fill with black */ brush = CreateSolidBrush(RGB(0,0,0)); FillRect(hdcHist, &bounds, brush); DeleteBrush(brush); GdiFlush(); /* draw histogram */ //positive values brush = CreateSolidBrush(RGB(0,255,0)); pen = CreatePen(PS_SOLID, 1, RGB(0,255,0)); SelectBrush(hdcHist, brush); SelectPen(hdcHist, pen); for (c=0; c<bars; c++) { Rectangle(hdcHist, bounds.left + (int)(c * barw), bounds.top + h/2 - (int)(((float)phist[c] / histmax) * (h / 2.0f)), bounds.left + (int)((c + 1) * barw), bounds.bottom - h/2); } DeleteBrush(brush); DeletePen(pen); GdiFlush(); //negative values brush = CreateSolidBrush(RGB(255,0,0)); pen = CreatePen(PS_SOLID, 1, RGB(255,0,0)); SelectBrush(hdcHist, brush); SelectPen(hdcHist, pen); for (c=0; c<bars; c++) { Rectangle(hdcHist, bounds.left + (int)(c * barw), bounds.top + h/2, bounds.left + (int)((c + 1) * barw), bounds.top + h/2 + (int)(((float)nhist[c] / histmax) * (h / 2.0f))); } DeleteBrush(brush); DeletePen(pen); GdiFlush(); /* draw a line through zero */ pen = CreatePen(PS_SOLID, 1, RGB(0,255,255)); SelectPen(hdcHist, pen); MoveToEx(hdcHist, 0, h/2, (LPPOINT) NULL); LineTo(hdcHist, w, h/2); DeletePen(pen); GdiFlush(); /* swap the buffer */ hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, w, h, hdcHist, 0, 0, SRCCOPY); GdiFlush(); ReleaseDC(hwnd, hdc); free(phist); free(nhist); }