Beispiel #1
0
void  ex_trace_scrn(int x, int y, char* _msg)
{
#ifdef _WIN32
		HDC hDC = GetDC(NULL);
		RECT  rtScreen;
		SetRectEmpty(&rtScreen);
		
		SetTextColor(hDC, 0x00ff0000);
		SetBkColor(hDC, 0x00FF00FF);

	
	#if defined(UNICODE) || defined(_UNICODE)
		wchar_t uni_msg[128];
		memset(uni_msg, 0, sizeof(uni_msg));
		ex_char2uni(_msg, uni_msg, Ex_MIDOF(uni_msg) );

		DrawTextW(hDC, uni_msg, wcslen(uni_msg) , &rtScreen, DT_CALCRECT );
		OffsetRect(&rtScreen, x, y );
		DrawTextW(hDC, uni_msg, wcslen(uni_msg) , &rtScreen, DT_LEFT|DT_TOP );	

	#else
		DrawTextA(hDC, _msg, strlen(_msg) , &rtScreen, DT_CALCRECT );
		OffsetRect(&rtScreen, x, y );
		DrawTextA(hDC, _msg, strlen(_msg) , &rtScreen, DT_LEFT|DT_TOP );	
	#endif

	ReleaseDC(NULL, hDC);
#endif
}
Beispiel #2
0
// *********************************************************************
// 					DrawLabel()										
// *********************************************************************
void GdiLabelDrawer::DrawLabel(CLabelOptions* options, CLabelInfo* lbl, CRect& rect, double angleRad, double piX, double piY)
{
	// ------------------------------------------------------
	//	GDI drawing w/o transparency, gradients, etc
	// ------------------------------------------------------
	XFORM xForm;
	xForm.eM11 = (FLOAT)cos(angleRad);
	xForm.eM12 = (FLOAT)sin(angleRad);
	xForm.eM21 = (FLOAT)-sin(angleRad);
	xForm.eM22 = (FLOAT)cos(angleRad);
	xForm.eDx = (FLOAT)piX;
	xForm.eDy = (FLOAT)piY;
	_dc->SetWorldTransform(&xForm);

	CPen* oldPen = NULL;

	// drawing frame
	if (options->frameVisible)
	{
		oldPen = _dc->SelectObject(&_penFrameOutline);
		DrawFrame(&rect, options);
		_dc->SelectObject(oldPen);
	}

	// drawing outlines
	if (options->shadowVisible)
	{
		_dc->SetWindowOrg(-options->shadowOffsetX, -options->shadowOffsetY);
		_dc->SetTextColor(options->shadowColor);
		DrawTextW(_dc->m_hDC, lbl->text, -1, rect, _alignment);
		_dc->SetTextColor(options->fontColor);
		_dc->SetWindowOrg(0, 0);
	}

	if (options->haloVisible)
	{
		_dc->BeginPath();
		DrawTextW(_dc->m_hDC, lbl->text, -1, rect, _alignment);
		_dc->EndPath();
		oldPen = _dc->SelectObject(&_penHalo);
		_dc->StrokePath();
		_dc->SelectObject(oldPen);
	}

	if (options->fontOutlineVisible)
	{
		_dc->BeginPath();
		DrawTextW(_dc->m_hDC, lbl->text, -1, rect, _alignment);
		_dc->EndPath();
		oldPen = _dc->SelectObject(&_penFontOutline);
		_dc->StrokePath();
		_dc->SelectObject(oldPen);
	}

	DrawTextW(_dc->m_hDC, lbl->text, -1, rect, _alignment);
}
Beispiel #3
0
static WINUSERAPI int WINAPI DrawTextUW(HDC hDC, LPCSTR lpchText, int nCount, LPRECT lpRect, UINT uFormat)
{
    if (!lpchText)
    {
        // String not specified. Don't bother converting anything.
        return DrawTextW(hDC, (LPCWSTR)lpchText, nCount, lpRect, uFormat);
    }

    // Convert lpchText from UTF-8 to UTF-16.
    wchar_t *lpchwText = w32u_UTF8toUTF16(lpchText);
    int ret = DrawTextW(hDC, lpchwText, nCount, lpRect, uFormat);
    free(lpchwText);
    return ret;
}
static void LLabel_OnPaint(HWND hwnd)
{
	PAINTSTRUCT		ps;
	RECT			rc;
	int				state;
	HFONT			hFont;
	int				style = DT_SINGLELINE | DT_VCENTER;

	BeginPaint(hwnd, &ps);
	GetClientRect(hwnd, &rc);
	state = SaveDC(ps.hdc);
	SetBkMode(ps.hdc, TRANSPARENT);
	hFont = CreateFontIndirectW((LPLOGFONTW)GetWindowLongPtrW(hwnd, 4));
	SelectFont(ps.hdc, hFont);
	SetTextColor(ps.hdc, RGB(0, 0, 255));
	if(IsWindowUnicode(hwnd)){
		if(GetPropW(hwnd, LL_ALIGNW))
			style |= DT_RIGHT;
		else
			style |= DT_LEFT;
		DrawTextW(ps.hdc, (wchar_t *)GetWindowLongPtrW(hwnd, 0), -1, &rc, style);
	}
	else{
		if(GetProp(hwnd, LL_ALIGN))
			style |= DT_RIGHT;
		else
			style |= DT_LEFT;
		DrawText(ps.hdc, (char *)GetWindowLongPtr(hwnd, 0), -1, &rc, style);
	}
	RestoreDC(ps.hdc, state);
	DeleteFont(hFont);
	EndPaint(hwnd, &ps);
}
void Lexem::calc(HDC hdc, double multiplier)
{
  if (width * height == 0)
  {
    HFONT hf = winWrap::setFont(hdc, FONT_SIZE * multiplier);
    RECT r;
    DrawTextW(hdc, name.data(), name.length(), &r, DT_CALCRECT);
    width = r.right - r.left;
    height = r.bottom - r.top;
    DeleteObject(hf);

    int scr_w = 0, h = 0;
    if (supscript != NULL)
    {
      supscript->calc(hdc, multiplier * SCRIPT_SIZE);
      scr_w = supscript->getWidth();
      h = height / 2;
    }

    if (subscript != NULL)
    {
      subscript->calc(hdc, multiplier * SCRIPT_SIZE);
      scr_w = max(scr_w, subscript->getWidth());
      h += height / 2;
    }
    width += scr_w;
    height += getSubScriptHeight() + getSuperScriptHeight() - h;
  }
}
Beispiel #6
0
void
dialog_paint_motd(HDC hDC)
{
    HANDLE hFont;
    CHAR date_line[64];
    RECT r = { 300, 90, 565, 330 };

    // invalid month
    if (motd.month < 1 || motd.month > 12)
        return;

    SetBkMode(hDC, TRANSPARENT);

    // title
    hFont = CreateFont(16, 0, 0, 0, FW_BOLD, FALSE, TRUE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
                CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Tahoma"));
    SelectObject(hDC, hFont);
    sprintf_s(date_line, sizeof(date_line), "%d %s %d", motd.day, month_names[motd.month-1], motd.year);
    DrawText(hDC, date_line, -1, &r, DT_WORDBREAK);

    r.top = 115;

    // text
    hFont = CreateFont(16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
                CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Tahoma"));
    SelectObject(hDC, hFont);
    DrawTextW(hDC, motd.text, -1, &r, DT_WORDBREAK);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC         hdc;
	PAINTSTRUCT ps;
	RECT        rect;

	switch (message)
	{
	case WM_CREATE:
		PlaySoundW(L"hellowin.wav", NULL, SND_FILENAME | SND_ASYNC);
		return 0;

	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);

		GetClientRect(hwnd, &rect);

		DrawTextW(hdc, L"Hello, Windows 98!汉字", -1, &rect,
			DT_SINGLELINE | DT_CENTER | DT_VCENTER);

		EndPaint(hwnd, &ps);
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
    SIZE sizeWithText(const wchar_t * pszText, int nLen, DWORD dwFmt, LONG nWidthLimit)
    {
        SIZE tRet = {0};
        do 
        {
            CC_BREAK_IF(! pszText || nLen <= 0);

            RECT rc = {0, 0, 0, 0};
            DWORD dwCalcFmt = DT_CALCRECT;

            if (nWidthLimit > 0)
            {
                rc.right = nWidthLimit;
                dwCalcFmt |= DT_WORDBREAK
                    | (dwFmt & DT_CENTER)
                    | (dwFmt & DT_RIGHT);
            }
            // use current font to measure text extent
            HGDIOBJ hOld = SelectObject(_DC, _font);

            // measure text size
            DrawTextW(_DC, pszText, nLen, &rc, dwCalcFmt);
            SelectObject(_DC, hOld);

            tRet.cx = rc.right;
            tRet.cy = rc.bottom;
        } while (0);

        return tRet;
    }
Beispiel #9
0
void OnPaint(HWND hWnd)
{
   HDC dialogDC;
   PAINTSTRUCT paint;
   RECT cRC, textRC;
   int i;
   HBRUSH hBrush;
   HPEN hPen;
   HFONT dcFont;
   COLORREF cr;
   int nch = GetWindowTextW(windowList[selectedWindow], windowText, 1023);

   dialogDC = BeginPaint(hWnd, &paint);
   {
      GetClientRect(hWnd, &cRC);
      FillRect(dialogDC, &cRC, GetSysColorBrush(COLOR_MENU));

      for(i=0; i< windowCount; i++)
      {
         HICON hIcon = iconList[i];
         
         int xpos = xOffset + 40 * (i % nCols);
         int ypos = yOffset + 40 * (i / nCols);

         if (selectedWindow == i)
         {
            hBrush = GetSysColorBrush(COLOR_HIGHLIGHT);
         }
         else
         {
            hBrush = GetSysColorBrush(COLOR_MENU);
         }
#if TRUE
         cr = GetSysColor(COLOR_BTNTEXT); // doesn't look right! >_<
         hPen = CreatePen(PS_DOT, 1, cr);
         SelectObject(dialogDC, hPen);
         SelectObject(dialogDC, hBrush);
         Rectangle(dialogDC, xpos-2, ypos-2, xpos+32+2, ypos+32+2);
         DeleteObject(hPen);
         // Must NOT destroy the system brush!
#else
         RECT rc = { xpos-2, ypos-2, xpos+32+2, ypos+32+2 };
         FillRect(dialogDC, &rc, hBrush);
#endif
         DrawIcon(dialogDC, xpos, ypos, hIcon);
      }

      dcFont = SelectObject(dialogDC, dialogFont);
      SetTextColor(dialogDC, GetSysColor(COLOR_BTNTEXT));
      SetBkColor(dialogDC, GetSysColor(COLOR_BTNFACE));

      textRC.top = itemsH;
      textRC.left = 8;
      textRC.right = totalW - 8;
      textRC.bottom = totalH - 8;
      DrawTextW(dialogDC, windowText, nch, &textRC, DT_CENTER|DT_END_ELLIPSIS);
      SelectObject(dialogDC, dcFont);
   }
   EndPaint(hWnd, &paint);
}
Beispiel #10
0
static void draw_launchers( HDC hdc, RECT update_rect )
{
    COLORREF color = SetTextColor( hdc, RGB(255,255,255) ); /* FIXME: depends on background color */
    int mode = SetBkMode( hdc, TRANSPARENT );
    unsigned int i;
    LOGFONTW lf;
    HFONT font;

    SystemParametersInfoW( SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0 );
    font = SelectObject( hdc, CreateFontIndirectW( &lf ) );

    for (i = 0; i < nb_launchers; i++)
    {
        RECT dummy, icon = get_icon_rect( i ), title = get_title_rect( i );

        if (IntersectRect( &dummy, &icon, &update_rect ))
            DrawIconEx( hdc, icon.left, icon.top, launchers[i]->icon, icon_cx, icon_cy,
                        0, 0, DI_DEFAULTSIZE|DI_NORMAL );

        if (IntersectRect( &dummy, &title, &update_rect ))
            DrawTextW( hdc, launchers[i]->title, -1, &title,
                       DT_CENTER|DT_WORDBREAK|DT_EDITCONTROL|DT_END_ELLIPSIS );
    }

    SelectObject( hdc, font );
    SetTextColor( hdc, color );
    SetBkMode( hdc, mode );
}
Beispiel #11
0
/***********************************************************************
 * DrawShadowText [COMCTL32.@]
 *
 * Draw text with shadow.
 */
int WINAPI DrawShadowText(HDC hdc, LPCWSTR pszText, UINT cch, RECT *rect, DWORD dwFlags,
                          COLORREF crText, COLORREF crShadow, int ixOffset, int iyOffset)
{
    FIXME("(%p, %s, %d, %p, %d, 0x%08x, 0x%08x, %d, %d): stub\n", hdc, debugstr_w(pszText), cch, rect, dwFlags,
                                                                  crText, crShadow, ixOffset, iyOffset);
    return DrawTextW(hdc, pszText, cch, rect, DT_LEFT);
}
Beispiel #12
0
static void paint_document(HTMLDocumentObj *This)
{
    PAINTSTRUCT ps;
    RECT rect;
    HDC hdc;

    GetClientRect(This->hwnd, &rect);

    hdc = BeginPaint(This->hwnd, &ps);

    if(!(This->hostinfo.dwFlags & (DOCHOSTUIFLAG_NO3DOUTERBORDER|DOCHOSTUIFLAG_NO3DBORDER)))
        DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT|BF_ADJUST);

    if(!This->nscontainer) {
        WCHAR wszHTMLDisabled[100];
        HFONT font;

        LoadStringW(hInst, IDS_HTMLDISABLED, wszHTMLDisabled, sizeof(wszHTMLDisabled)/sizeof(WCHAR));

        font = CreateFontA(25,0,0,0,400,0,0,0,ANSI_CHARSET,0,0,DEFAULT_QUALITY,DEFAULT_PITCH,NULL);

        SelectObject(hdc, font);
        SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW));

        Rectangle(hdc, rect.left, rect.top, rect.right, rect.bottom);
        DrawTextW(hdc, wszHTMLDisabled,-1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);

        DeleteObject(font);
    }

    EndPaint(This->hwnd, &ps);
}
Beispiel #13
0
// *********************************************************************
// 					MeasureString()										
// *********************************************************************
void GdiLabelDrawer::MeasureString(CLabelInfo* lbl, CRect& rect)
{
	DrawTextW(_dc->m_hDC, lbl->text, -1, rect, DT_CALCRECT);

	// frame for GDI is very narrow; so we'll enlarge it a bit					
	rect.left -= rect.Height() / 6;
	rect.right += rect.Height() / 6;
}
Beispiel #14
0
/***********************************************************************
 *           ICONTITLE_Paint
 */
static BOOL ICONTITLE_Paint( HWND hwnd, HWND owner, HDC hDC, BOOL bActive )
{
    RECT rect;
    HFONT hPrevFont;
    HBRUSH hBrush;
    COLORREF textColor = 0;

    if( bActive )
    {
	hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION);
	textColor = GetSysColor(COLOR_CAPTIONTEXT);
    }
    else
    {
        if( GetWindowLongPtrA( hwnd, GWL_STYLE ) & WS_CHILD )
	{
	    hBrush = (HBRUSH) GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND);
	    if( hBrush )
	    {
		INT level;
		LOGBRUSH logBrush;
		GetObjectA( hBrush, sizeof(logBrush), &logBrush );
		level = GetRValue(logBrush.lbColor) +
			   GetGValue(logBrush.lbColor) +
			      GetBValue(logBrush.lbColor);
		if( level < (0x7F * 3) )
		    textColor = RGB( 0xFF, 0xFF, 0xFF );
	    }
	    else
		hBrush = GetStockObject( WHITE_BRUSH );
	}
	else
	{
	    hBrush = GetStockObject( BLACK_BRUSH );
	    textColor = RGB( 0xFF, 0xFF, 0xFF );
	}
    }

    GetClientRect( hwnd, &rect );
    DPtoLP( hDC, (LPPOINT)&rect, 2 );
    FillRect( hDC, &rect, hBrush );

    hPrevFont = SelectObject( hDC, hIconTitleFont );
    if( hPrevFont )
    {
	WCHAR buffer[80];

        INT length = GetWindowTextW( owner, buffer, sizeof(buffer)/sizeof(buffer[0]) );
        SetTextColor( hDC, textColor );
        SetBkMode( hDC, TRANSPARENT );

        DrawTextW( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX |
                   DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) );

	SelectObject( hDC, hPrevFont );
    }
    return (hPrevFont != 0);
}
int SensorListControl::CustomDrawText(HDC hdc, int rowIndex, int columnIndex, HFONT hFont, RECT& rect)
{
    WCHAR text[MaxTextLength] = {0};
    ListView_GetItemText(m_hWnd, rowIndex, columnIndex, text, _countof(text));

    SelectObject(hdc, hFont);

    return DrawTextW(hdc, text, (int)wcsnlen_s(text, MaxTextLength), &rect, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX);
}
Beispiel #16
0
/**********************************************************************
 *          PAINTING_DrawStateJam
 *
 * Jams in the requested type in the dc
 */
static BOOL PAINTING_DrawStateJam(HDC hdc, UINT opcode,
                                  DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
                                  LPRECT rc, UINT dtflags, BOOL unicode )
{
    HDC memdc;
    HBITMAP hbmsave;
    BOOL retval;
    INT cx = rc->right - rc->left;
    INT cy = rc->bottom - rc->top;

    switch(opcode)
    {
        case DST_TEXT:
        case DST_PREFIXTEXT:
            if(unicode)
                return DrawTextW(hdc, (LPWSTR)lp, (INT)wp, rc, dtflags);
            else
                return DrawTextA(hdc, (LPSTR)lp, (INT)wp, rc, dtflags);

        case DST_ICON:
            return DrawIconEx(hdc, rc->left, rc->top, (HICON)lp, cx, cy, 0, NULL, DI_NORMAL);

        case DST_BITMAP:
            memdc = CreateCompatibleDC(hdc);
            if(!memdc)
                return FALSE;
            hbmsave = (HBITMAP)SelectObject(memdc, (HBITMAP)lp);
            if(!hbmsave)
            {
                DeleteDC(memdc);
                return FALSE;
            }
            retval = BitBlt(hdc, rc->left, rc->top, cx, cy, memdc, 0, 0, SRCCOPY);
            SelectObject(memdc, hbmsave);
            DeleteDC(memdc);
            return retval;

        case DST_COMPLEX:
            if(func)
            {
                BOOL bRet;
                /* DRAWSTATEPROC assumes that it draws at the center of coordinates  */

                OffsetViewportOrgEx(hdc, rc->left, rc->top, NULL);
                bRet = func(hdc, lp, wp, cx, cy);
                /* Restore origin */
                OffsetViewportOrgEx(hdc, -rc->left, -rc->top, NULL);
                return bRet;
            }
            else
            {
                return FALSE;
            }
    }
    return FALSE;
}
Beispiel #17
0
 void DrawShita(const Chat &chat) {
     RECT rc;
     rc.top = rcWnd_.bottom - yPitch_ - static_cast<LONG>(chat.line * (int)((float)yPitch_ * CNJIni::GetSettings()->commentLineMargin));
     rc.bottom = rc.top + yPitch_;
     rc.left = 0;
     rc.right = rcWnd_.right;
     int shadow = (yPitch_ / 16);
     if ( yPitch_ > 24 && shadow == 1 ) {
         shadow = 2;
     }
     if ( shadow < 1 ) {
         shadow = 1;
     }
     const std::wstring &text = chat.text;
     SetTextColor(memDC_, RGB(0, 0, 0));
     DrawTextW(memDC_, text.c_str(), text.length(), &rc, DT_CENTER | DT_NOPREFIX);
     OffsetRect(&rc, -shadow, -shadow);
     SetTextColor(memDC_, chat.color);
     DrawTextW(memDC_, text.c_str(), text.length(), &rc, DT_CENTER | DT_NOPREFIX);
 }
    virtual BOOL on_draw   (HELEMENT he, UINT draw_type, HDC hdc, const RECT& rc ) 
    { 
      if( draw_type != DRAW_CONTENT )
        return FALSE; /*do default draw*/ 

      dom::element el = he;
      
      UINT pta = GetTextAlign(hdc);
      SetTextAlign(hdc, TA_LEFT | TA_TOP |TA_NOUPDATECP); 
#ifdef _WIN32_WCE
    CString fileName(el.text());
    CString dottedFileName;
    FormatFileName(hdc, fileName, dottedFileName, rc.right - rc.left);
    DrawTextW(hdc, dottedFileName, -1, const_cast<RECT*>(&rc), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_NOPREFIX | DT_NOCLIP);
#else
      DrawTextW(hdc, el.text(), -1, const_cast<RECT*>(&rc), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_PATH_ELLIPSIS | DT_NOPREFIX);
#endif
      SetTextAlign(hdc, pta); 
      return TRUE; /*skip default draw as we did it already*/ 
    }
Beispiel #19
0
/**********************************************************************
 *       BUTTON_DrawTextCallback
 *
 *   Callback function used by DrawStateW function.
 */
static BOOL CALLBACK BUTTON_DrawTextCallback(HDC hdc, LPARAM lp, WPARAM wp, int cx, int cy)
{
   RECT rc;
   rc.left = 0;
   rc.top = 0;
   rc.right = cx;
   rc.bottom = cy;

   DrawTextW(hdc, (LPCWSTR)lp, -1, &rc, (UINT)wp);
   return TRUE;
}
Beispiel #20
0
static int DrawTextUtf(HDC hDC, char *text, LPRECT lpRect, UINT uFormat, LPSIZE lpSize)
{
	int res;

	WCHAR *tmp = make_unicode_string(text);
	res = DrawTextW(hDC, tmp, -1, lpRect, uFormat);
	if (lpSize)
		GetTextExtentPoint32W(hDC, tmp, (int)mir_wstrlen(tmp), lpSize);
	SAFE_FREE((void**)&tmp);

	return res;
}
Beispiel #21
0
void WINAPI DrawStatusTextW (HDC hdc, LPCRECT lprc, LPCWSTR text, UINT style)
{
    RECT r = *lprc;
    UINT border = BDR_SUNKENOUTER;

    if (style & SBT_POPOUT)
        border = BDR_RAISEDOUTER;
    else if (style & SBT_NOBORDERS)
        border = 0;

    DrawEdge (hdc, &r, border, BF_RECT|BF_ADJUST);

    /* now draw text */
    if (text) {
        int oldbkmode = SetBkMode (hdc, TRANSPARENT);
        UINT align = DT_LEFT;
        int strCnt = 0;

        if (style & SBT_RTLREADING)
            FIXME("Unsupported RTL style!\n");
        r.left += 3;
        do {
            if (*text == '\t') {
                if (strCnt) {
                    DrawTextW (hdc, text - strCnt, strCnt, &r, align|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX);
                    strCnt = 0;
                }
                if (align==DT_RIGHT) {
                    break;
                }
                align = (align==DT_LEFT ? DT_CENTER : DT_RIGHT);
            } else {
                strCnt++;
            }
        } while(*text++);

        if (strCnt) DrawTextW (hdc, text - strCnt, -1, &r, align|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX);
	SetBkMode(hdc, oldbkmode);
    }
}
Beispiel #22
0
static HRESULT drawTextPart(HRESULT hr, struct drawState *s)
{
	COLORREF prevText;
	int prevMode;
	RECT r;
	uiTableValue *value;
	WCHAR *wstr;

	if (hr != S_OK)
		return hr;
	if (!s->m->hasText)
		return S_OK;
	// don't draw the text underneath an edit control
	if (s->t->edit != NULL && s->t->editedItem == s->iItem && s->t->editedSubitem == s->iSubItem)
		return S_OK;

	prevText = SetTextColor(s->dc, s->textColor);
	if (prevText == CLR_INVALID) {
		logLastError(L"SetTextColor()");
		return E_FAIL;
	}
	prevMode = SetBkMode(s->dc, TRANSPARENT);
	if (prevMode == 0) {
		logLastError(L"SetBkMode()");
		return E_FAIL;
	}

	value = uiprivTableModelCellValue(s->model, s->iItem, s->p->textModelColumn);
	wstr = toUTF16(uiTableValueString(value));
	uiFreeTableValue(value);
	// These flags are a menagerie of flags from various sources:
	// guessing, the Windows 2000 source leak, various custom
	// draw examples on the web, etc.
	// TODO find the real correct flags
	if (DrawTextW(s->dc, wstr, -1, &(s->m->realTextRect), DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX | DT_EDITCONTROL) == 0) {
		uiprivFree(wstr);
		logLastError(L"DrawTextW()");
		return E_FAIL;
	}
	uiprivFree(wstr);

	// TODO decide once and for all what to compare to here and with SelectObject()
	if (SetBkMode(s->dc, prevMode) != TRANSPARENT) {
		logLastError(L"SetBkMode() prev");
		return E_FAIL;
	}
	if (SetTextColor(s->dc, prevText) != s->textColor) {
		logLastError(L"SetTextColor() prev");
		return E_FAIL;
	}
	return S_OK;
}
    virtual BOOL on_draw   (HELEMENT he, UINT draw_type, HDC hdc, const RECT& rc ) 
    { 
      if( draw_type != DRAW_CONTENT )
        return FALSE; /*do default draw*/ 

      dom::element el = he;
      
      UINT pta = GetTextAlign(hdc);
      SetTextAlign(hdc, TA_LEFT | TA_TOP |TA_NOUPDATECP); 
      DrawTextW(hdc, el.text(), -1, const_cast<RECT*>(&rc), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_PATH_ELLIPSIS);
      SetTextAlign(hdc, pta); 
      return TRUE; /*skip default draw as we did it already*/ 
    }
static void Combo_OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
{
	LOGFONTW		lf;
	HFONT			hFont, hFontOld;
	wchar_t			szBuffer[256];
	RECT			rc;

	//draw fonts
	SetBkMode(lpDrawItem->hDC, TRANSPARENT);
	if(lpDrawItem->itemID != -1){
		CopyRect(&rc, &lpDrawItem->rcItem);
		if((lpDrawItem->itemState & ODS_SELECTED) == ODS_SELECTED){
			FillRect(lpDrawItem->hDC, &rc, GetSysColorBrush(COLOR_HIGHLIGHT));
			SetTextColor(lpDrawItem->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
		}
		else{
			FillRect(lpDrawItem->hDC, &rc, GetSysColorBrush(COLOR_WINDOW));
			SetTextColor(lpDrawItem->hDC, GetSysColor(COLOR_WINDOWTEXT));
		}
		
		SendDlgItemMessageW(hwnd, IDC_COMBO_FONT, CB_GETLBTEXT, (WPARAM)lpDrawItem->itemID, (LPARAM)szBuffer);
		OffsetRect(&rc, 4, 0);
		DrawTextW(lpDrawItem->hDC, szBuffer, -1, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER);

		ZeroMemory(&lf, sizeof(lf));
		lf.lfHeight = -MulDiv(8, GetDeviceCaps(lpDrawItem->hDC, LOGPIXELSY), 72);
		wcscpy(lf.lfFaceName, szBuffer);
		lf.lfQuality = PROOF_QUALITY;
		lf.lfPitchAndFamily = VARIABLE_PITCH;
		lf.lfOutPrecision = OUT_TT_PRECIS;
		lf.lfCharSet = DEFAULT_CHARSET;
		hFont = CreateFontIndirectW(&lf);
		hFontOld = SelectFont(lpDrawItem->hDC, hFont);
		OffsetRect(&rc, -8, 0);
		DrawTextW(lpDrawItem->hDC, L"Sample", -1, &rc, DT_RIGHT | DT_SINGLELINE | DT_VCENTER);
		SelectFont(lpDrawItem->hDC, hFontOld);
		DeleteFont(hFont);
	}
}
Beispiel #25
0
void CHyperLink::OnPaint()
{
	//initializare
	PAINTSTRUCT ps;
	BeginPaint(m_hWnd, &ps);

	HPEN hOldPen = (HPEN)SelectObject(ps.hdc, GetStockObject(NULL_PEN));
	HBRUSH hOldBrush = (HBRUSH)SelectObject(ps.hdc, GetSysColorBrush(COLOR_3DFACE));

	RECT clr;
	GetClientRect(m_hWnd, &clr);
	//se deseneaza controlul
	Rectangle(ps.hdc, 0, 0, clr.right, clr.bottom);
	SetBkMode(ps.hdc, TRANSPARENT);

	//se creeaza fontul
	LOGFONT logfont;
	HFONT hFont = (HFONT)SendMessage(GetParent(m_hWnd), WM_GETFONT, 0, 0);
	GetObject(hFont, sizeof(LOGFONT), &logfont);

	if (m_bUnderline && m_bIsLink)
	{
		logfont.lfUnderline = TRUE;
	}
	else 
		logfont.lfUnderline = FALSE;

	hFont = CreateFontIndirect(&logfont);
	HFONT hOldFont = (HFONT)SelectObject(ps.hdc, hFont);

	//se seteaza culoarea
	if (m_bIsLink)
		SetTextColor(ps.hdc, RGB(34,0,204));
	else SetTextColor(ps.hdc, 0);
	
	//se afiseaza textul
	int len = GetWindowTextLength(m_hWnd);
	len++;
	WCHAR* wstr = new WCHAR[len];
	GetWindowTextW(m_hWnd, wstr, len);

	DrawTextW(ps.hdc, wstr, -1, &clr, DT_LEFT);

	SelectObject(ps.hdc, hOldPen);
	SelectObject(ps.hdc, hOldBrush);
	DeleteObject(hOldFont);
	delete[] wstr;

	EndPaint(m_hWnd, &ps);
}
Beispiel #26
0
void CHyperLink::OnPaint(HWND hWnd)
{
	CHyperLink* pThis = (CHyperLink*)GetWindowLongPtrW(hWnd, GWL_USERDATA);
	PAINTSTRUCT ps;
	BeginPaint(hWnd, &ps);

	HDC hDC = ps.hdc;

	//se creeaza brush-ul
	HBRUSH hBrush = GetSysColorBrush(COLOR_3DFACE);
	SelectObject(hDC, hBrush);
	SetBkMode(hDC, TRANSPARENT);

	//se creeaza fontul
	LOGFONT logfont;
	HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
	GetObject(hFont, sizeof(LOGFONT), &logfont);

	if (pThis->m_bUnderline == TRUE)
	{
		logfont.lfUnderline = TRUE;
	}
	else 
		logfont.lfUnderline = FALSE;

	hFont = CreateFontIndirect(&logfont);
	SelectObject(hDC, hFont);

	//se seteaza culoarea
	SetTextColor(hDC, RGB(34,0,204));
	
	//se afiseaza textul
	int len = GetWindowTextLength(hWnd);
	len++;
	WCHAR* wstr = new WCHAR[len];
	GetWindowTextW(hWnd, wstr, len);

	RECT rect;
	GetClientRect(hWnd, &rect);

	DrawTextW(hDC, wstr, -1, &rect, DT_LEFT);

	DeleteObject(hBrush);
	DeleteObject(hFont);
	delete[] wstr;

	EndPaint(hWnd, &ps);
}
Beispiel #27
0
void Label_commit(Label* self)
{
	RECT rect;
	HDC hdc = self->impl->hdc;

	if(nullptr == self->impl->text)
		return;

	SetRect(&rect, 0, 0, self->impl->width, self->impl->height);
	FillRect(hdc, &rect, GetStockObject(BLACK_BRUSH));
	SetTextColor(hdc, RGB(255,255,255));
	SetBkMode(hdc, TRANSPARENT);
    DrawTextW(hdc, self->impl->text, -1, &rect, DT_NOCLIP);

	{
		unsigned char* bits;
		unsigned char* data;
		BITMAPINFO* bi;

		bi = malloc(sizeof(BITMAPINFOHEADER)+ 256*sizeof(RGBQUAD));
		memset(&bi->bmiHeader, 0, sizeof(BITMAPINFOHEADER));
		bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

		GetDIBits(hdc, self->impl->hbmp, 0, self->impl->height, nullptr, bi, DIB_RGB_COLORS);

		bits = malloc(GetBitmapBytesS(&bi->bmiHeader));
		data = malloc(self->texture->surfSizeInByte);

		if(GetDIBits(hdc, self->impl->hbmp, 0, self->impl->height, bits, bi, DIB_RGB_COLORS) == self->impl->height) {
			
			unsigned char* srcPixel = bits;
			unsigned char* dstPixel = data;
			size_t i;
			size_t pixelCnt = (size_t)(bi->bmiHeader.biWidth * bi->bmiHeader.biHeight);

			for(i = 0; i < pixelCnt; ++i) {
				*dstPixel = *srcPixel;
				dstPixel += 1;
				srcPixel += 4;
			}
			
			crTextureCommit(self->texture, data);
		}
		free(data);
		free(bits);
		free(bi);
	}
}
Beispiel #28
0
static VOID
NT5_DrawLogoffCaptionText(LPWSTR lpText,
                          HDC hdcMem)
{
    HFONT hFont;
    LOGFONTW LogFont;
    RECT TextRect;
    INT PrevBkMode;

    /* Setup the font we'll use */
    ZeroMemory(&LogFont, sizeof(LOGFONTW));
    LogFont.lfCharSet = DEFAULT_CHARSET;
    LogFont.lfHeight = 22;
    LogFont.lfWeight = 109; // From WinXP disassembly
    wcscpy_s(LogFont.lfFaceName, LF_FACESIZE, L"Arial");

    /* Create it */
    hFont = CreateFontIndirectW(&LogFont);
    if (hFont)
    {
        /* Set the font and font colour */
        SelectObject(hdcMem, hFont);
        SetTextColor(hdcMem, RGB(255, 255, 255));

        /* Create the text rect */
        TextRect.top = (g_pInfo->cy / 2) + 34;
        TextRect.bottom = (g_pInfo->cy / 2) + 34 + (GetDeviceCaps(hdcMem, LOGPIXELSY));
        TextRect.left = g_pInfo->cx / 3;
        TextRect.right = (g_pInfo->cx / 2) + 35 + 137;

        /* Set the background mode to transparent */
        PrevBkMode = SetBkMode(hdcMem, TRANSPARENT);

        /* Draw the text to the mem DC */
        DrawTextW(hdcMem,
                  lpText,
                  -1,
                  &TextRect,
                  DT_NOPREFIX | DT_WORDBREAK | DT_RIGHT); // WinXP disassembly uses 0x812

        /* Set the previous background mode */
        SetBkMode(hdcMem, PrevBkMode);

        /* Delete the font */
        DeleteObject(hFont);
    }
}
Beispiel #29
0
/***********************************************************************
 *           ICONTITLE_SetTitlePos
 */
static BOOL ICONTITLE_SetTitlePos( HWND hwnd, HWND owner )
{
    static const WCHAR emptyTitleText[] = {'<','.','.','.','>',0};
    WCHAR str[80];
    HDC hDC;
    HFONT hPrevFont;
    RECT rect;
    INT cx, cy;
    POINT pt;

    int length = GetWindowTextW( owner, str, sizeof(str)/sizeof(WCHAR) );

    while (length && str[length - 1] == ' ') /* remove trailing spaces */
        str[--length] = 0;

    if( !length )
    {
        strcpyW( str, emptyTitleText );
        length = strlenW( str );
    }

    if (!(hDC = GetDC( hwnd ))) return FALSE;

    hPrevFont = SelectObject( hDC, hIconTitleFont );

    SetRect( &rect, 0, 0, GetSystemMetrics(SM_CXICONSPACING) -
             GetSystemMetrics(SM_CXBORDER) * 2,
             GetSystemMetrics(SM_CYBORDER) * 2 );

    DrawTextW( hDC, str, length, &rect, DT_CALCRECT | DT_CENTER | DT_NOPREFIX | DT_WORDBREAK |
               (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) );

    SelectObject( hDC, hPrevFont );
    ReleaseDC( hwnd, hDC );

    cx = rect.right - rect.left +  4 * GetSystemMetrics(SM_CXBORDER);
    cy = rect.bottom - rect.top;

    pt.x = (GetSystemMetrics(SM_CXICON) - cx) / 2;
    pt.y = GetSystemMetrics(SM_CYICON);

    /* point is relative to owner, make it relative to parent */
    MapWindowPoints( owner, GetParent(hwnd), &pt, 1 );

    SetWindowPos( hwnd, owner, pt.x, pt.y, cx, cy, SWP_NOACTIVATE );
    return TRUE;
}
Beispiel #30
0
VOID
PaintText(
    IN LPDRAWITEMSTRUCT drawItem,
    IN PCONSOLE_STATE_INFO pConInfo,
    IN TEXT_TYPE TextMode)
{
    USHORT CurrentAttrib;
    COLORREF pbkColor, ptColor;
    COLORREF nbkColor, ntColor;
    HBRUSH hBrush;
    HFONT hOldFont;

    if (TextMode == Screen)
        CurrentAttrib = pConInfo->ScreenAttributes;
    else if (TextMode == Popup)
        CurrentAttrib = pConInfo->PopupAttributes;
    else
        return;

    nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)];
    ntColor  = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)];

    hBrush = CreateSolidBrush(nbkColor);
    if (!hBrush) return;

    hOldFont = SelectObject(drawItem->hDC, hCurrentFont);
    //if (hOldFont == NULL)
    //{
    //    DeleteObject(hBrush);
    //    return;
    //}

    FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);

    /* Add a few space between the preview window border and the text sample */
    InflateRect(&drawItem->rcItem, -2, -2);

    ptColor  = SetTextColor(drawItem->hDC, ntColor);
    pbkColor = SetBkColor(drawItem->hDC, nbkColor);
    DrawTextW(drawItem->hDC, szPreviewText, (INT)wcslen(szPreviewText), &drawItem->rcItem, 0);
    SetTextColor(drawItem->hDC, ptColor);
    SetBkColor(drawItem->hDC, pbkColor);

    SelectObject(drawItem->hDC, hOldFont);
    DeleteObject(hBrush);
}