void AeroControlBase::FillRect(LPRECT prc, HDC hdcPaint, Color clr) const
{
    std::unique_ptr<SolidBrush> pBrush(new SolidBrush(clr));
    std::unique_ptr<Graphics> myGraphics(new Graphics(hdcPaint));

    myGraphics->FillRectangle(pBrush.get(), prc->left, prc->top,
        prc->right - 1 - prc->left, prc->bottom - 1 - prc->top);
}
void AeroControlBase::DrawRect(LPRECT prc, HDC hdcPaint, DashStyle dashStyle, Color clr, REAL width) const
{
    std::unique_ptr<Pen> myPen(new Pen(clr, width));
    myPen->SetDashStyle(dashStyle);
    std::unique_ptr<Graphics> myGraphics(new Graphics(hdcPaint));

    myGraphics->DrawRectangle(myPen.get(), prc->left, prc->top,
        prc->right - 1 - prc->left, prc->bottom - 1 - prc->top);
}
Beispiel #3
0
int main()
{
	Graphics myGraphics(20 * OBJ_WIDTH, 20 * OBJ_HEIGHT, 0, SDL_HWSURFACE, 100);
	Map myMap(&myGraphics);
	Game myGame(&myGraphics, &myMap);
	
	int ret = myGame.StartGame("level1.map");

	bool bRunning = true;
	while (bRunning){
		// begin next level
		if (ret == 1){
			string next_filename = myGame.NextLevel();
			myGame.StartGame(next_filename);
		}
		else if (ret == 0){
			// re flush
			return 0;
		}
	}
	return 0;
}
LRESULT AeroControlBase::ButtonWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
    case WM_SETTEXT:
    case WM_ENABLE:
    case WM_STYLECHANGED:
        {
            LRESULT res = DefSubclassProc(hWnd, uMsg, wParam, lParam);
            InvalidateRgn(hWnd, NULL, FALSE);
            return res;
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            if(hdc)
            {
                LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
                LONG_PTR dwButtonStyle = LOWORD(dwStyle);
                LONG_PTR dwButtonType = dwButtonStyle&0xF;
                RECT rcClient;
                VERIFY(GetClientRect(hWnd, &rcClient));

                if((dwButtonType&BS_GROUPBOX)==BS_GROUPBOX)
                {
                    ///
                    /// it must be a group box
                    ///
                    HTHEME hTheme = OpenThemeData(hWnd, L"Button");
                    if(hTheme)
                    {
                        BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                        params.dwFlags        = BPPF_ERASE;

                        RECT rcExclusion = rcClient;
                        params.prcExclude = &rcExclusion;

                        ///
                        /// We have to calculate the exclusion rect and therefore
                        /// calculate the font height. We select the control's font
                        /// into the DC and fake a drawing operation:
                        ///
                        HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                        if(hFontOld)
                            hFontOld = (HFONT) SelectObject(hdc, hFontOld);

                        RECT rcDraw = rcClient;
                        DWORD dwFlags = DT_SINGLELINE;

                        ///
                        /// we use uppercase A to determine the height of text, so we
                        /// can draw the upper line of the groupbox:
                        ///
                        DrawTextW(hdc, L"A", -1,  &rcDraw, dwFlags|DT_CALCRECT);

                        if (hFontOld)
                        {
                            SelectObject(hdc, hFontOld);
                            hFontOld    = NULL;
                        }

                        VERIFY(InflateRect(&rcExclusion, -1, -1*RECTHEIGHT(rcDraw)));

                        HDC hdcPaint = NULL;
                        HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB,
                            &params, &hdcPaint);
                        if (hdcPaint)
                        {
                            ///
                            /// now we again retrieve the font, but this time we select it into
                            /// the buffered DC:
                            ///
                            hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);


                            VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));

                            VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));
                            int iPartId = BP_GROUPBOX;

                            int iState = GetStateFromBtnState(dwStyle, FALSE, FALSE, 0L, iPartId, FALSE);

                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));

                            COLORREF cr = RGB(0x00, 0x00, 0x00);
                            VERIFY(GetEditBorderColor(hWnd, &cr));
                            ///
                            /// add the alpha value:
                            ///
                            cr |= 0xff000000;

                            std::unique_ptr<Pen> myPen( new Pen(Color(cr), 1) );
                            std::unique_ptr<Graphics> myGraphics( new Graphics(hdcPaint) );
                            int iY = RECTHEIGHT(rcDraw)/2;
                            Rect rr = Rect(rcClient.left, rcClient.top+iY,
                                RECTWIDTH(rcClient), RECTHEIGHT(rcClient)-iY-1);
                            GraphicsPath path;
                            GetRoundRectPath(&path, rr, 10);
                            myGraphics->DrawPath(myPen.get(), &path);
                            //myGraphics->DrawRectangle(myPen, rcClient.left, rcClient.top + iY,
                            //  RECTWIDTH(rcClient)-1, RECTHEIGHT(rcClient) - iY-1);
                            myGraphics.reset();
                            myPen.reset();

                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        int iX = RECTWIDTH(rcDraw);
                                        rcDraw = rcClient;
                                        rcDraw.left += iX;
                                        DrawTextW(hdcPaint, szText, -1,  &rcDraw, dwFlags|DT_CALCRECT);
                                        VERIFY(PatBlt(hdcPaint, rcDraw.left, rcDraw.top , RECTWIDTH(rcDraw) + 3, RECTHEIGHT(rcDraw), BLACKNESS));
                                        rcDraw.left++;
                                        rcDraw.right++;
                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint, iPartId, iState, szText, -1,
                                            dwFlags, &rcDraw, &DttOpts));

                                    }

                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }

                            VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));

                        }

                        VERIFY(S_OK==CloseThemeData(hTheme));
                    }
                }

                else if(dwButtonType==BS_CHECKBOX || dwButtonType==BS_AUTOCHECKBOX ||
                    dwButtonType==BS_3STATE || dwButtonType==BS_AUTO3STATE || dwButtonType==BS_RADIOBUTTON || dwButtonType==BS_AUTORADIOBUTTON)
                {
                    HTHEME hTheme = OpenThemeData(hWnd, L"Button");
                    if(hTheme)
                    {
                        HDC hdcPaint = NULL;
                        BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                        params.dwFlags        = BPPF_ERASE;
                        HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &params, &hdcPaint);
                        if (hdcPaint)
                        {
                            VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));

                            VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));

                            LRESULT dwCheckState = SendMessage(hWnd, BM_GETCHECK, 0, NULL);
                            POINT pt;
                            RECT rc;
                            GetWindowRect(hWnd, &rc);
                            GetCursorPos(&pt);
                            BOOL bHot = PtInRect(&rc, pt);
                            BOOL bFocus = GetFocus()==hWnd;

                            int iPartId = BP_CHECKBOX;
                            if(dwButtonType==BS_RADIOBUTTON || dwButtonType==BS_AUTORADIOBUTTON)
                                iPartId = BP_RADIOBUTTON;

                            int iState = GetStateFromBtnState(dwStyle, bHot, bFocus, dwCheckState, iPartId, FALSE);

                            int bmWidth = int(ceil(13.0 * GetDeviceCaps(hdcPaint, LOGPIXELSX) / 96.0));

                            UINT uiHalfWidth = (RECTWIDTH(rcClient) - bmWidth)/2;

                            ///
                            /// we have to use the whole client area, otherwise we get only partially
                            /// drawn areas:
                            ///
                            RECT rcPaint = rcClient;

                            if(dwButtonStyle & BS_LEFTTEXT)
                            {
                                rcPaint.left += uiHalfWidth;
                                rcPaint.right += uiHalfWidth;
                            }
                            else
                            {
                                rcPaint.left -= uiHalfWidth;
                                rcPaint.right -= uiHalfWidth;
                            }


                            ///
                            /// we assume that bmWidth is both the horizontal and the vertical
                            /// dimension of the control bitmap and that it is square. bm.bmHeight
                            /// seems to be the height of a striped bitmap because it is an absurdly
                            /// high dimension value
                            ///
                            if((dwButtonStyle&BS_VCENTER)==BS_VCENTER) /// BS_VCENTER is BS_TOP|BS_BOTTOM
                            {
                                int h = RECTHEIGHT(rcPaint);
                                rcPaint.top = (h - bmWidth) / 2;
                                rcPaint.bottom = rcPaint.top + bmWidth;
                            }
                            else if(dwButtonStyle&BS_TOP)
                            {
                                rcPaint.bottom = rcPaint.top + bmWidth;
                            }
                            else if(dwButtonStyle&BS_BOTTOM)
                            {
                                rcPaint.top =  rcPaint.bottom - bmWidth;
                            }
                            else // default: center the checkbox/radiobutton vertically
                            {
                                int h = RECTHEIGHT(rcPaint);
                                rcPaint.top = (h - bmWidth) / 2;
                                rcPaint.bottom = rcPaint.top + bmWidth;
                            }


                            VERIFY(S_OK==DrawThemeBackground(hTheme, hdcPaint, iPartId, iState, &rcPaint, NULL));
                            rcPaint = rcClient;


                            VERIFY(S_OK==GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc));

                            if(dwButtonStyle & BS_LEFTTEXT)
                                rc.right -= bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);
                            else
                                rc.left += bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);

                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));


                            HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        DWORD dwFlags = DT_SINGLELINE /*|DT_VCENTER*/;
                                        if(dwButtonStyle&BS_MULTILINE)
                                        {
                                            dwFlags|=DT_WORDBREAK;
                                            dwFlags&= ~(DT_SINGLELINE |DT_VCENTER);
                                        }

                                        if((dwButtonStyle&BS_CENTER)==BS_CENTER) /// BS_CENTER is BS_LEFT|BS_RIGHT
                                            dwFlags|=DT_CENTER;
                                        else if(dwButtonStyle&BS_LEFT)
                                            dwFlags|=DT_LEFT;
                                        else if(dwButtonStyle&BS_RIGHT)
                                            dwFlags|=DT_RIGHT;


                                        if((dwButtonStyle&BS_VCENTER)==BS_VCENTER) /// BS_VCENTER is BS_TOP|BS_BOTTOM
                                            dwFlags|=DT_VCENTER;
                                        else if(dwButtonStyle&BS_TOP)
                                            dwFlags|=DT_TOP;
                                        else if(dwButtonStyle&BS_BOTTOM)
                                            dwFlags|=DT_BOTTOM;
                                        else
                                            dwFlags|=DT_VCENTER;

                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint, iPartId,
                                            iState, szText, -1, dwFlags, &rc, &DttOpts));

                                        ///
                                        /// if our control has the focus, we also have to draw the focus rectangle:
                                        ///
                                        if(bFocus)
                                        {
                                            ///
                                            /// now calculate the text size:
                                            ///
                                            RECT rcDraw = rc;

                                            ///
                                            /// we use GDI's good old DrawText, because it returns much more
                                            /// accurate data than DrawThemeTextEx, which takes the glow
                                            /// into account which we don't want:
                                            ///
                                            VERIFY(DrawTextW(hdcPaint, szText, -1,  &rcDraw, dwFlags|DT_CALCRECT));
                                            if(dwFlags&DT_SINGLELINE)
                                            {
                                                dwFlags &= ~DT_VCENTER;
                                                RECT rcDrawTop;
                                                DrawTextW(hdcPaint, szText, -1,  &rcDrawTop, dwFlags|DT_CALCRECT);
                                                rcDraw.top = rcDraw.bottom - RECTHEIGHT(rcDrawTop);
                                            }

                                            if(dwFlags & DT_RIGHT)
                                            {
                                                int iWidth = RECTWIDTH(rcDraw);
                                                rcDraw.right = rc.right;
                                                rcDraw.left = rcDraw.right - iWidth;
                                            }

                                            RECT rcFocus;
                                            VERIFY(IntersectRect(&rcFocus, &rc, &rcDraw));

                                            DrawFocusRect(&rcFocus, hdcPaint);
                                        }
                                    }

                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }

                            VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
                        }
                        VERIFY(S_OK==CloseThemeData(hTheme));
                    }


                }
                else if(BS_PUSHBUTTON==dwButtonType || BS_DEFPUSHBUTTON==dwButtonType)
                {
                    ///
                    /// it is a push button
                    ///
                    HTHEME hTheme = OpenThemeData(hWnd, L"Button");
                    if(hTheme)
                    {
                        HDC hdcPaint = NULL;
                        BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
                        params.dwFlags        = BPPF_ERASE;
                        HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &params, &hdcPaint);
                        if (hdcPaint)
                        {
                            VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));

                            VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));

                            LRESULT dwCheckState = SendMessage(hWnd, BM_GETCHECK, 0, NULL);
                            POINT pt;
                            RECT rc;
                            GetWindowRect(hWnd, &rc);
                            GetCursorPos(&pt);
                            BOOL bHot = PtInRect(&rc, pt);
                            BOOL bFocus = GetFocus()==hWnd;
                            int iPartId = BP_PUSHBUTTON;

                            if(dwButtonStyle==BS_RADIOBUTTON || dwButtonStyle==BS_AUTORADIOBUTTON)
                                iPartId = BP_RADIOBUTTON;


                            int iState = GetStateFromBtnState(dwStyle, bHot, bFocus, dwCheckState, iPartId, GetCapture()==hWnd);

                            ///
                            /// we have to use the whole client area, otherwise we get only partially
                            /// drawn areas:
                            ///
                            RECT rcPaint = rcClient;
                            VERIFY(S_OK==DrawThemeBackground(hTheme, hdcPaint, iPartId, iState, &rcPaint, NULL));


                            VERIFY(S_OK==GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc));


                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));


                            HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        DWORD dwFlags = DT_SINGLELINE | DT_CENTER | DT_VCENTER;
                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint,
                                            iPartId, iState, szText, -1, dwFlags, &rc, &DttOpts));

                                        ///
                                        /// if our control has the focus, we also have to draw the focus rectangle:
                                        ///
                                        if(bFocus)
                                        {
                                            RECT rcDraw = rcClient;
                                            VERIFY(InflateRect(&rcDraw, -3, -3));
                                            DrawFocusRect(&rcDraw, hdcPaint);
                                        }

                                    }

                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }

                            VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
                        }
                        VERIFY(S_OK==CloseThemeData(hTheme));
                    }
                }
                else
                    //PaintControl(hWnd, hdc, &ps.rcPaint, (m_dwFlags & WD_DRAW_BORDER)!=0);
                    PaintControl(hWnd, hdc, &ps.rcPaint, false);
            }

            EndPaint(hWnd, &ps);
            return 0;
        }
        break;
    case WM_DESTROY:
    case WM_NCDESTROY:
        RemoveWindowSubclass(hWnd, SubclassProc, Button);
        subclassedControls.erase(hWnd);
        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
LRESULT AeroControlBase::StaticWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_SETTEXT:
    case WM_ENABLE:
    case WM_STYLECHANGED:
        {
            LRESULT res = DefSubclassProc(hWnd, uMsg, wParam, lParam);
            InvalidateRgn(hWnd, NULL, FALSE);
            return res;
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);

            if(hdc)
            {
                HDC hdcPaint = NULL;
                RECT rcClient;
                VERIFY(GetClientRect(hWnd, &rcClient));

                LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
                LONG_PTR dwStyleEx = GetWindowLongPtr(hWnd, GWL_EXSTYLE);

                HTHEME hTheme = OpenThemeData(NULL, L"ControlPanelStyle");
                if(hTheme)
                {
                    HPAINTBUFFER hBufferedPaint = NULL;
                    if (dwStyleEx & WS_EX_TRANSPARENT)
                    {
                        BP_PAINTPARAMS paintParams = {0};
                        paintParams.cbSize = sizeof(paintParams);
                        paintParams.dwFlags = BPPF_ERASE;
                        BLENDFUNCTION blendf = {0};
                        blendf.BlendOp = AC_SRC_OVER;
                        blendf.AlphaFormat = AC_SRC_ALPHA;
                        blendf.SourceConstantAlpha = 255;
                        paintParams.pBlendFunction = &blendf;
                        hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, &paintParams, &hdcPaint);
                    }
                    else
                        hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, NULL, &hdcPaint);

                    if (hdcPaint)
                    {
                        VERIFY(PatBlt(hdcPaint, 0, 0, RECTWIDTH(rcClient), RECTHEIGHT(rcClient), BLACKNESS));
                        VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));
                        LONG_PTR dwStaticStyle = dwStyle&0x1F;


                        if(dwStaticStyle==SS_ICON || dwStaticStyle==SS_BITMAP)
                        {
                            bool bIcon = dwStaticStyle==SS_ICON;
                            HANDLE hBmpIco = (HANDLE)SendMessage(hWnd, STM_GETIMAGE, bIcon ? IMAGE_ICON:IMAGE_BITMAP, NULL);
                            if(hBmpIco)
                            {
                                std::unique_ptr<Bitmap> pBmp( bIcon ? new Bitmap((HICON)hBmpIco) : new Bitmap((HBITMAP)hBmpIco, NULL) );
                                std::unique_ptr<Graphics> myGraphics( new Graphics(hdcPaint) );
                                std::unique_ptr<CachedBitmap> pcbmp( new CachedBitmap(pBmp.get(), myGraphics.get()) );
                                VERIFY(Ok==myGraphics->DrawCachedBitmap(pcbmp.get(), 0,0));
                            }
                        }
                        else if(SS_BLACKRECT==dwStaticStyle || SS_GRAYRECT==dwStaticStyle || SS_WHITERECT==dwStaticStyle)
                        {
                            ARGB argb = 0L;
                            switch (dwStaticStyle)
                            {
                            case SS_BLACKRECT:
                                argb = 0xFF000000;
                                break;
                            case SS_GRAYRECT:
                                argb = 0xFF808080;
                                break;
                            case SS_WHITERECT:
                                argb = 0xFFFFFFFF;
                                break;
                            default:
                                ASSERT(0);
                                break;
                            }
                            Color clr(argb);

                            FillRect(&rcClient, hdcPaint, clr);
                        }
                        else if(SS_BLACKFRAME==dwStaticStyle || SS_GRAYFRAME==dwStaticStyle || SS_WHITEFRAME==dwStaticStyle)
                        {
                            ARGB argb = 0L;
                            switch (dwStaticStyle)
                            {
                            case SS_BLACKFRAME:
                                argb = 0xFF000000;
                                break;
                            case SS_GRAYFRAME:
                                argb = 0xFF808080;
                                break;
                            case SS_WHITEFRAME:
                                argb = 0xFFFFFFFF;
                                break;
                            }
                            Color clr(argb);

                            DrawRect(&rcClient, hdcPaint, DashStyleSolid, clr, 1.0);
                        }
                        else
                        {
                            DTTOPTS DttOpts = {sizeof(DTTOPTS)};
                            DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            DttOpts.crText   = RGB(255, 255, 255);
                            DttOpts.iGlowSize = 12; // Default value

                            VERIFY(DetermineGlowSize(&DttOpts.iGlowSize));

                            HFONT hFontOld = (HFONT)SendMessage(hWnd, WM_GETFONT, 0L, NULL);
                            if(hFontOld)
                                hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
                            int iLen = GetWindowTextLength(hWnd);

                            if(iLen)
                            {
                                iLen+=5; // 1 for terminating zero, 4 for DT_MODIFYSTRING
                                LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
                                if(szText)
                                {
                                    iLen = GetWindowTextW(hWnd, szText, iLen);
                                    if(iLen)
                                    {
                                        DWORD dwFlags = DT_WORDBREAK;

                                        switch (dwStaticStyle)
                                        {
                                        case SS_CENTER:
                                            dwFlags |= DT_CENTER;
                                            break;
                                        case SS_RIGHT:
                                            dwFlags |= DT_RIGHT;
                                            break;
                                        case SS_LEFTNOWORDWRAP:
                                            dwFlags &= ~DT_WORDBREAK;
                                            break;
                                        }

                                        if(dwStyle & SS_CENTERIMAGE)
                                        {
                                            dwFlags |= DT_VCENTER;
                                            dwFlags &= ~DT_WORDBREAK;
                                        }

                                        if(dwStyle & SS_ENDELLIPSIS)
                                            dwFlags |= DT_END_ELLIPSIS|DT_MODIFYSTRING;
                                        else if(dwStyle & SS_PATHELLIPSIS)
                                            dwFlags |= DT_PATH_ELLIPSIS|DT_MODIFYSTRING;
                                        else if(dwStyle & SS_WORDELLIPSIS)
                                            dwFlags |= DT_WORD_ELLIPSIS|DT_MODIFYSTRING;

                                        if (dwStyleEx&WS_EX_RIGHT)
                                            dwFlags |= DT_RIGHT;

                                        if(dwStyle & SS_NOPREFIX)
                                            dwFlags |= DT_NOPREFIX;

                                        VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint, 0, 0,
                                            szText, -1, dwFlags, &rcClient, &DttOpts));

                                        if(dwStyle&SS_SUNKEN || dwStyle&WS_BORDER)
                                            DrawRect(&rcClient, hdcPaint, DashStyleSolid, Color(0xFF, 0,0,0), 1.0);
                                    }
                                    VERIFY(!LocalFree(szText));
                                }
                            }

                            if (hFontOld)
                            {
                                SelectObject(hdcPaint, hFontOld);
                                hFontOld    = NULL;
                            }
                        }

                        VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
                    }

                    VERIFY(S_OK==CloseThemeData(hTheme));
                }
            }

            EndPaint(hWnd, &ps);
            return 0;
        }
        break;
    case WM_NCDESTROY:
    case WM_DESTROY:
        RemoveWindowSubclass(hWnd, SubclassProc, Static);
        subclassedControls.erase(hWnd);
        break;
    }

    return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
Beispiel #6
0
void CMStudioView::OnDraw(CDC* pDC)
{
	CMStudioDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc || !pDoc->m_pImage || m_ViewType == EMPTY)
		return;

	CRect rect;
	GetClientRect(rect);
	
	
	int w = pDoc->m_pImage->GetWidth();
	int h = pDoc->m_pImage->GetHeight();

	Gdiplus::Graphics myGraphics(*pDC);
	

	float maxw = float(rect.Width())/float(w);
	float maxh = float(rect.Height())/float(h);
	
	float Zoom = 0;

	if(maxh < maxw)
		Zoom = maxh;
	else
		Zoom = maxw;
	

	if(pDoc->m_pImage_Selected)
	{
		myGraphics.DrawImage(pDoc->m_pImage_Selected,(float)0,(float)0,w*Zoom,h*Zoom);
	}
	else
	{
	if(m_ViewType == ORIGINAL && pDoc->m_pImage)
		myGraphics.DrawImage(pDoc->m_pImage,(float)0,(float)0,w*Zoom,h*Zoom);
	if(m_ViewType == RESULT && pDoc->m_pResultImage)
		myGraphics.DrawImage(pDoc->m_pResultImage,(float)0,(float)0,w*Zoom,h*Zoom);
	}
	
	int x = int((m_current_draw.x-5)*Zoom);
	int y = int((m_current_draw.y-5)*Zoom);
    int width = int(5*Zoom);
    int height = int(5*Zoom);

	Pen pen(Color::Red);
	myGraphics.DrawEllipse(&pen,x,y,width,height);
	

	//CRgn   rgnA, rgnB;

	//CPoint ptVertex[5];

	//ptVertex[0].x = 180;
	//ptVertex[0].y = 80;
	//ptVertex[1].x = 100;
	//ptVertex[1].y = 160;
	//ptVertex[2].x = 120;
	//ptVertex[2].y = 260;
	//ptVertex[3].x = 240;
	//ptVertex[3].y = 260;
	//ptVertex[4].x = 260;
	//ptVertex[4].y = 160;

	//VERIFY(rgnA.CreatePolygonRgn( ptVertex, 5, ALTERNATE));

	//CRect rectRgnBox;
	//int nRgnBoxResult = rgnA.GetRgnBox( &rectRgnBox );
	//ASSERT( nRgnBoxResult != ERROR || nRgnBoxResult != NULLREGION );

	//CBrush brA, brB;
	//VERIFY(brA.CreateSolidBrush( RGB(255, 0, 0) ));  // rgnA Red
	//VERIFY(pDC->FrameRgn( &rgnA, &brA, 2, 2 ));
	//VERIFY(brB.CreateSolidBrush( RGB(0, 0, 255) ));  // Blue
	//rectRgnBox.InflateRect(3,3);
	//pDC->FrameRect( &rectRgnBox, &brB );

}
Beispiel #7
0
BOOL CMyDialog::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	//	BOOL bResult=CDialog::OnEraseBkgnd(pDC);
	if (!m_bHaveStoreBgDC)
	{
		CRect rect;
		GetClientRect(rect);
		m_bHaveStoreBgDC=TRUE;
		Color 	clrStart=Color(230,230,230);
		Color 	clrEnd=Color(255,255,255);
		
		m_StoreBgDC.DeleteDC();
		m_StoreBgDC.CreateCompatibleDC(pDC);
		CBitmap bmp;
		bmp.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
		CBitmap *pOldBmp=m_StoreBgDC.SelectObject(&bmp);
		Graphics myGraphics(m_StoreBgDC.m_hDC);	
		LinearGradientBrush linGrBrush(
			Rect(0,0,rect.Width(),rect.Height()),
			clrStart,
			clrEnd, 
			LinearGradientModeVertical);
		myGraphics.FillRectangle(&linGrBrush, 0,31,rect.Width(),rect.Height()); 
		
		Color clrCaptionStart(219,219,220);
		Color clrCaptionEnd(190,192,193);
		LinearGradientBrush linGrBrush1(
			Rect(0,0,rect.Width(),30),
			clrCaptionStart,
			clrCaptionEnd, 
			LinearGradientModeVertical);
		myGraphics.FillRectangle(&linGrBrush1, 0,0,rect.Width(),30); 
		
		DrawCloseButton(&m_StoreBgDC,DTS_NORMAL);
		DrawMinButton(&m_StoreBgDC,DTS_NORMAL);
		
		CPen MarkPen(PS_SOLID,1,RGB(158,158,158));
		CBrush *pOldBrush=(CBrush *)m_StoreBgDC.SelectStockObject(NULL_BRUSH);
		CPen *pOldPen=m_StoreBgDC.SelectObject(&MarkPen);
		m_StoreBgDC.RoundRect(m_rcMin.left-1,m_rcMin.top-5,m_rcClose.right+1,m_rcClose.bottom+1,5,5);	
		
		CPen penBorder(PS_SOLID,1,RGB(150,150,150));
		m_StoreBgDC.SelectObject(&penBorder);	
		m_StoreBgDC.MoveTo(0,30);
		m_StoreBgDC.LineTo(rect.Width(),30);
		m_StoreBgDC.MoveTo(m_rcClose.left-1,1);
		m_StoreBgDC.LineTo(m_rcClose.left-1,21);
		rect.DeflateRect(0,0,1,1);
		m_StoreBgDC.RoundRect(rect,CPoint(7,5));
		m_StoreBgDC.SelectObject(pOldPen);
		m_StoreBgDC.SelectObject(pOldBrush);
		
		
		rect.bottom=30;
		HICON hIcon=GetIcon(FALSE);
		if (hIcon)   //画Icon
		{
			DrawIconEx(m_StoreBgDC.m_hDC,5,7,hIcon,16,16,0,NULL,DI_NORMAL | DI_COMPAT);
			rect.left+=21;
			m_rcIcon.SetRect(5,7,21,23);
		}
		CString str;
		GetWindowText(str);
		if (str!="") //写标题
		{
			rect.left+=5;
			rect.top+=4;
			m_StoreBgDC.SetBkMode(TRANSPARENT);
			COLORREF OldClr=m_StoreBgDC.SetTextColor(RGB(50,50,50));
			CFont font;
			font.CreatePointFont(100,"雅黑",&m_StoreBgDC);
			CFont *pOldFont=m_StoreBgDC.SelectObject(&font);
			m_StoreBgDC.DrawText(str,rect,DT_VCENTER | DT_SINGLELINE);
			m_StoreBgDC.SelectObject(pOldFont);
			m_StoreBgDC.SetTextColor(OldClr);
			font.DeleteObject();
		}
		/*		m_StoreBgDC.SelectObject(pOldBmp);*/
		bmp.DeleteObject();
	}
	CRect rect;
	GetClientRect(rect);
	pDC->BitBlt(0,0,rect.Width(),rect.Height(),&m_StoreBgDC,0,0,SRCCOPY);
	return TRUE;
}
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    //从lpDrawItemStruct获取控件的相关信息
    CRect rect =  lpDrawItemStruct->rcItem;
    CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
    int nSaveDC=pDC->SaveDC();
    UINT state = lpDrawItemStruct->itemState;

    TCHAR strText[MAX_PATH + 1];
    ::GetWindowText(m_hWnd, strText, MAX_PATH);
    BOOL bFocus=m_bOver;   //按钮是否被选中(点击或tab或默认)
    CString strImgPath = "" ;

    //获取按钮的状态
    if (state & ODS_FOCUS || state & ODS_SELECTED || state & ODS_DEFAULT)
    {
        bFocus = TRUE;
    }

    if (m_bIsDrawImgBtn)
    {
        if (bFocus)  //有焦点或鼠标经过
        {
            strImgPath = m_strPathHover;
        }
        else
        {
            strImgPath = m_strPathNormal;
        }
        Graphics gs(pDC->m_hDC);
        Image img(strImgPath.AllocSysString());
        gs.DrawImage(&img,0,0,rect.Width(),rect.Height());
    }
    else
    {
        Color clrStart,clrEnd;
        COLORREF clrBorder;
        if (bFocus)
        {
            clrStart=m_clrTodStartHover;
            clrEnd=m_clrBottomEndHover;
            clrBorder=m_clrBorderHover;

        }
        else
        {
            clrStart=m_clrTodStartNormal;
            clrEnd=m_clrBottomEndNormal;
            clrBorder=m_clrBorderNormal;
        }
        int cxBorder=GetSystemMetrics(SM_CXEDGE);
        int cyBorder=GetSystemMetrics(SM_CYEDGE);
        Graphics myGraphics(pDC->m_hDC);
        LinearGradientBrush linGrBrush(
            Rect(0,0,rect.Width()/*-cxBorder*/,rect.Height()/*-cyBorder*/),
            clrStart,//Color(255, 238, 238, 238),
            clrEnd,//Color(200, 208,208,208),
            LinearGradientModeVertical);
        myGraphics.FillRectangle(&linGrBrush, 1,1,rect.Width()-cxBorder,rect.Height()-cyBorder);

        // 	CRgn rgn;
        // 	rgn.CreateRoundRectRgn(rect.left,rect.top,rect.right,rect.bottom,2,2);
        // 	myGraphics.FillRegion(&linGrBrush,&Region((HRGN)rgn.m_hObject));

        CPen pen;
        pen.CreatePen(PS_SOLID,1,clrBorder);//RGB(162,203,236)
        pDC->SelectObject(&pen);
        pDC->SelectStockObject(NULL_BRUSH);
        pDC->RoundRect(&rect,CPoint(3,3));

        //	pDC->SetPixel(rect.right-2,rect.bottom-2,clrEnd.ToCOLORREF());
    }
    //显示按钮的文本
    if (strText!=NULL)
    {
        CFont* pFont = GetFont();
        CFont* pOldFont = pDC->SelectObject(pFont);
        CSize szExtent = pDC->GetTextExtent(strText, lstrlen(strText));
        CPoint pt( rect.CenterPoint().x - szExtent.cx / 2+1, rect.CenterPoint().y - szExtent.cy / 2+1);
        if (state & ODS_SELECTED)
            pt.Offset(1, 1);
        int nMode = pDC->SetBkMode(TRANSPARENT);
        //输出首字母带下划线效果文本
        if (state & ODS_DISABLED)
            pDC->DrawState(pt, szExtent, strText, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
        else
            pDC->DrawState(pt, szExtent, strText, DSS_NORMAL, TRUE, 0, (HBRUSH)NULL);

        pDC->SelectObject(pOldFont);
        pDC->SetBkMode(nMode);
    }

    pDC->RestoreDC(nSaveDC);
}