Click here to Skip to main content
15,886,689 members
Articles / Desktop Programming / Win32

Stopwatch

Rate me:
Please Sign up or sign in to vote.
4.97/5 (29 votes)
3 Jan 2015CPOL6 min read 66.1K   1.5K   43  
Benchmark C++ std::vector vs raw arrays, move assignable/constructable & copy assignable/constructable
// DeviceContextExample.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "DeviceContextExample.h"


#include "hwinapplication.h"
#include "hwinform.h"
#include "hwinmenu.h"
#include "hwinstdctrls.h"
#include "hwinenvironment.h"
#include "hwinfiledialog.h"
#include <iostream>

using namespace harlinn::windows;

enum class DeviceContextExampleType
{
    DrawBitmap,
    DrawCaption,
    DrawCaptionFrameControlCloseButton,
    DrawCaptionFrameControlMinimizeButton,
    DrawCaptionFrameControlMaximizeButton,
    DrawCaptionFrameControlRestoreButton,
    DrawCaptionFrameControlHelpButton,
    DrawMenuBarFrameControlArrow,
    DrawMenuBarFrameControlCheck,
    DrawMenuBarFrameControlBullet,
    DrawMenuBarFrameControlArrowRight,
    DrawScrollBarFrameControlUp,
    DrawScrollBarFrameControlDown,
    DrawScrollBarFrameControlLeft,
    DrawScrollBarFrameControlRight,
    DrawScrollBarFrameControlComboBox,
    DrawScrollBarFrameControlSizeGrip,
    DrawScrollBarFrameControlSizeGripRight,
    DrawButtonFrameControlCheckBox,
    DrawButtonFrameControlRadioImage,
    DrawButtonFrameControlRadioMask,
    DrawButtonFrameControlRadioButton,
    DrawButtonFrameControlThreeState,
    DrawButtonFrameControlPushButton,
    DrawEdgeRaisedOuter,
    DrawEdgeSunkenOuter,
    DrawEdgeRaisedInner,
    DrawEdgeSunkenInner,
    DrawEdgeRaised,
    DrawEdgeSunken,
    DrawEdgeEtched,
    DrawEdgeBump,
    DrawFocusRect,
    DrawStateNormal,
    DrawStatePrefix,
    DrawStateDithered,
    DrawStateDisabled,
    DrawStateMono,
    DrawStateHidePrefix,
    DrawStatePrefixOnly,
    DrawStateRight,
    DrawDesktopWallPaper,
    DrawChord,
	DrawScreenWidthAndHeight
};

class DeviceContextExampleForm : public Form
{
    DeviceContextExampleType type;
    std::shared_ptr<BitmapHandle> bitMap;
public:
    typedef Form Base;
    DeviceContextExampleForm();
protected:
    virtual void DoOnInitialize();
    virtual void DoOnPaint(Message& message);

private:
    void InitializeMenuBar();
    void OpenImageFile();

    void DrawBitmap(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawCaption(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawCaptionFrameControlCloseButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawCaptionFrameControlMinimizeButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawCaptionFrameControlMaximizeButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawCaptionFrameControlRestoreButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawCaptionFrameControlHelpButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawMenuBarFrameControlArrow(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawMenuBarFrameControlCheck(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawMenuBarFrameControlBullet(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawMenuBarFrameControlArrowRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlUp(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlDown(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlLeft(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlComboBox(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlSizeGrip(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawScrollBarFrameControlSizeGripRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawButtonFrameControlCheckBox(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawButtonFrameControlRadioImage(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawButtonFrameControlRadioMask(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawButtonFrameControlRadioButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawButtonFrameControlThreeState(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawButtonFrameControlPushButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeRaisedOuter(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeSunkenOuter(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeRaisedInner(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeSunkenInner(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeRaised(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeSunken(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeEtched(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawEdgeBump(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawFocusRect(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStateNormal(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStatePrefix(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStateDithered(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStateDisabled(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStateMono(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStateHidePrefix(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStatePrefixOnly(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawStateRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawDesktopWallPaper(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
    void DrawChord(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );
	void DrawScreenWidthAndHeight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect );


};


DeviceContextExampleForm::DeviceContextExampleForm()
    : Base(),type(DeviceContextExampleType::DrawCaptionFrameControlCloseButton)
{
    SetText(L"DeviceContext example");
}

void DeviceContextExampleForm::DoOnInitialize()
{
    Base::DoOnInitialize(); 

    InitializeMenuBar();
}

void DeviceContextExampleForm::InitializeMenuBar()
{
#define ADD_ITEM( choice, submenu, text ) \
    auto choice##_ = submenu->AddMenuItem(text); \
    choice##_->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::choice; InvalidateRect(); })

    auto self = As<DeviceContextExampleForm>();

    auto menuBar = make_component<MenuBar>(self);

    auto fileSubMenu1 = menuBar->AddSubMenu(L"&File");
    auto openImage = fileSubMenu1->AddMenuItem(L"Open");
    openImage->OnClick.connect([&](MenuItem* sender)
    { 
        OpenImageFile(); 
        type = DeviceContextExampleType::DrawBitmap; 
        InvalidateRect(); 
    });



    auto subMenu1 = menuBar->AddSubMenu(L"Submenu1");


    auto drawCaption = subMenu1->AddMenuItem(L"DrawCaption");
    drawCaption->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawCaption; InvalidateRect(); });

    auto drawCaptionFrameControlSubMenu = subMenu1->AddSubMenu(L"DrawCaptionFrameControl");

    

    auto drawCaptionFrameControlCloseButton = drawCaptionFrameControlSubMenu->AddMenuItem(L"CloseButton");
    drawCaptionFrameControlCloseButton->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawCaptionFrameControlCloseButton; InvalidateRect(); });

    auto drawCaptionFrameControlMinimizeButton = drawCaptionFrameControlSubMenu->AddMenuItem(L"MinimizeButton");
    drawCaptionFrameControlMinimizeButton->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawCaptionFrameControlMinimizeButton; InvalidateRect(); });

    auto drawCaptionFrameControlMaximizeButton = drawCaptionFrameControlSubMenu->AddMenuItem(L"MaximizeButton");
    drawCaptionFrameControlMaximizeButton->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawCaptionFrameControlMaximizeButton; InvalidateRect(); });

    auto drawCaptionFrameControlRestoreButton = drawCaptionFrameControlSubMenu->AddMenuItem(L"RestoreButton");
    drawCaptionFrameControlRestoreButton->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawCaptionFrameControlRestoreButton; InvalidateRect(); });

    auto drawCaptionFrameControlHelpButton = drawCaptionFrameControlSubMenu->AddMenuItem(L"HelpButton");
    drawCaptionFrameControlHelpButton->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawCaptionFrameControlHelpButton; InvalidateRect(); });


    auto drawMenuBarFrameControlSubMenu = subMenu1->AddSubMenu(L"DrawMenuBarFrameControl");


    auto drawMenuBarFrameControlArrow = drawMenuBarFrameControlSubMenu->AddMenuItem(L"Arrow");
    drawMenuBarFrameControlArrow->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawMenuBarFrameControlArrow; InvalidateRect(); });

    auto drawMenuBarFrameControlCheck = drawMenuBarFrameControlSubMenu->AddMenuItem(L"Check");
    drawMenuBarFrameControlCheck->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawMenuBarFrameControlCheck; InvalidateRect(); });

    auto drawMenuBarFrameControlBullet = drawMenuBarFrameControlSubMenu->AddMenuItem(L"Bullet");
    drawMenuBarFrameControlBullet->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawMenuBarFrameControlBullet; InvalidateRect(); });

    auto drawMenuBarFrameControlArrowRight = drawMenuBarFrameControlSubMenu->AddMenuItem(L"ArrowRight");
    drawMenuBarFrameControlArrowRight->OnClick.connect([&](MenuItem* sender){ type = DeviceContextExampleType::DrawMenuBarFrameControlArrowRight; InvalidateRect(); });


    auto drawScrollBarFrameControlSubMenu = subMenu1->AddSubMenu(L"DrawScrollBarFrameControl");


    ADD_ITEM(DrawScrollBarFrameControlUp,drawScrollBarFrameControlSubMenu,L"Up");
    ADD_ITEM(DrawScrollBarFrameControlDown,drawScrollBarFrameControlSubMenu,L"Down");
    ADD_ITEM(DrawScrollBarFrameControlLeft,drawScrollBarFrameControlSubMenu,L"Left");
    ADD_ITEM(DrawScrollBarFrameControlRight,drawScrollBarFrameControlSubMenu,L"Right");
    ADD_ITEM(DrawScrollBarFrameControlComboBox,drawScrollBarFrameControlSubMenu,L"ComboBox");
    ADD_ITEM(DrawScrollBarFrameControlSizeGrip,drawScrollBarFrameControlSubMenu,L"SizeGrip");
    ADD_ITEM(DrawScrollBarFrameControlSizeGripRight,drawScrollBarFrameControlSubMenu,L"SizeGripRight");

    auto drawButtonFrameControlSubMenu = subMenu1->AddSubMenu(L"DrawButtonFrameControl");

    ADD_ITEM(DrawButtonFrameControlCheckBox,drawButtonFrameControlSubMenu,L"CheckBox");
    ADD_ITEM(DrawButtonFrameControlRadioImage,drawButtonFrameControlSubMenu,L"RadioImage");
    ADD_ITEM(DrawButtonFrameControlRadioMask,drawButtonFrameControlSubMenu,L"RadioMask");
    ADD_ITEM(DrawButtonFrameControlRadioButton,drawButtonFrameControlSubMenu,L"RadioButton");
    ADD_ITEM(DrawButtonFrameControlThreeState,drawButtonFrameControlSubMenu,L"ThreeState");
    ADD_ITEM(DrawButtonFrameControlPushButton,drawButtonFrameControlSubMenu,L"PushButton");

    auto drawEdgeSubMenu = subMenu1->AddSubMenu(L"DrawEdge");

    ADD_ITEM(DrawEdgeRaisedOuter,drawEdgeSubMenu,L"Raised Outer");
    ADD_ITEM(DrawEdgeSunkenOuter,drawEdgeSubMenu,L"Sunken Outer");
    ADD_ITEM(DrawEdgeRaisedInner,drawEdgeSubMenu,L"Raised Inner");
    ADD_ITEM(DrawEdgeSunkenInner,drawEdgeSubMenu,L"Sunken Inner");
    ADD_ITEM(DrawEdgeRaised,drawEdgeSubMenu,L"Raised");
    ADD_ITEM(DrawEdgeSunken,drawEdgeSubMenu,L"Sunken");
    ADD_ITEM(DrawEdgeEtched,drawEdgeSubMenu,L"Etched");
    ADD_ITEM(DrawEdgeBump,drawEdgeSubMenu,L"Bump");

    ADD_ITEM(DrawFocusRect,subMenu1,L"DrawFocusRect");

    auto drawStateSubMenu = subMenu1->AddSubMenu(L"DrawState");

    ADD_ITEM(DrawStateNormal,drawStateSubMenu,L"Normal");
    ADD_ITEM(DrawStatePrefix,drawStateSubMenu,L"Prefix");
    ADD_ITEM(DrawStateDithered,drawStateSubMenu,L"Dithered");
    ADD_ITEM(DrawStateDisabled,drawStateSubMenu,L"Disabled");
    ADD_ITEM(DrawStateMono,drawStateSubMenu,L"Mono");
    ADD_ITEM(DrawStateHidePrefix,drawStateSubMenu,L"HidePrefix");
    ADD_ITEM(DrawStatePrefixOnly,drawStateSubMenu,L"PrefixOnly");
    ADD_ITEM(DrawStateRight,drawStateSubMenu,L"Right");
    ADD_ITEM(DrawScreenWidthAndHeight,drawStateSubMenu,L"Screen Width And Height");

    ADD_ITEM(DrawDesktopWallPaper,subMenu1,L"DrawDesktopWallPaper");

    SetMenu(menuBar);
};


void DeviceContextExampleForm::OpenImageFile()
{
    auto fileOpenDialog = harlinn::windows::FileOpenDialog::Create();
    if(fileOpenDialog->Show(GetSafeHandle()))
    {
        auto item = fileOpenDialog->GetResult();
        String fileName = item.GetDisplayName(SIGDN_FILESYSPATH);
        bitMap = BitmapHandle::LoadFromFile(fileName);
    }
}



void DeviceContextExampleForm::DoOnPaint(Message& message)
{
    Base::DoOnPaint(message);
    RECT rect = this->GetClientRect();
    auto dc = std::make_shared<PaintDeviceContextHandle>(As<Control>());

    auto controlBrush = std::make_shared<BrushHandle>(SysColor::Control);
    dc->DrawFilledRectangle(rect,controlBrush);

    InflateRect(&rect,-20,-20);

    switch(type)
    {
        case DeviceContextExampleType::DrawBitmap:
            DrawBitmap(dc,rect);
            break;
        case DeviceContextExampleType::DrawCaption:
            DrawCaption(dc,rect);
            break;
        case DeviceContextExampleType::DrawCaptionFrameControlCloseButton:
            DrawCaptionFrameControlCloseButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawCaptionFrameControlMinimizeButton:
            DrawCaptionFrameControlMinimizeButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawCaptionFrameControlMaximizeButton:
            DrawCaptionFrameControlMaximizeButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawCaptionFrameControlRestoreButton:
            DrawCaptionFrameControlRestoreButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawCaptionFrameControlHelpButton:
            DrawCaptionFrameControlHelpButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawMenuBarFrameControlArrow:
            DrawMenuBarFrameControlArrow(dc,rect);
            break;
        case DeviceContextExampleType::DrawMenuBarFrameControlCheck:
            DrawMenuBarFrameControlCheck(dc,rect);
            break;
        case DeviceContextExampleType::DrawMenuBarFrameControlBullet:
            DrawMenuBarFrameControlBullet(dc,rect);
            break;
        case DeviceContextExampleType::DrawMenuBarFrameControlArrowRight:
            DrawMenuBarFrameControlArrowRight(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlUp:
            DrawScrollBarFrameControlUp(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlDown:
            DrawScrollBarFrameControlDown(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlLeft:
            DrawScrollBarFrameControlLeft(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlRight:
            DrawScrollBarFrameControlRight(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlComboBox:
            DrawScrollBarFrameControlComboBox(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlSizeGrip:
            DrawScrollBarFrameControlSizeGrip(dc,rect);
            break;
        case DeviceContextExampleType::DrawScrollBarFrameControlSizeGripRight:
            DrawScrollBarFrameControlSizeGripRight(dc,rect);
            break;
        case DeviceContextExampleType::DrawButtonFrameControlCheckBox:
            DrawButtonFrameControlCheckBox(dc,rect);
            break;
        case DeviceContextExampleType::DrawButtonFrameControlRadioImage:
            DrawButtonFrameControlRadioImage(dc,rect);
            break;
        case DeviceContextExampleType::DrawButtonFrameControlRadioMask:
            DrawButtonFrameControlRadioMask(dc,rect);
            break;
        case DeviceContextExampleType::DrawButtonFrameControlRadioButton:
            DrawButtonFrameControlRadioButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawButtonFrameControlThreeState:
            DrawButtonFrameControlThreeState(dc,rect);
            break;
        case DeviceContextExampleType::DrawButtonFrameControlPushButton:
            DrawButtonFrameControlPushButton(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeRaisedOuter:
            DrawEdgeRaisedOuter(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeSunkenOuter:
            DrawEdgeSunkenOuter(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeRaisedInner:
            DrawEdgeRaisedInner(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeSunkenInner:
            DrawEdgeSunkenInner(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeRaised:
            DrawEdgeRaised(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeSunken:
            DrawEdgeSunken(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeEtched:
            DrawEdgeEtched(dc,rect);
            break;
        case DeviceContextExampleType::DrawEdgeBump:
            DrawEdgeBump(dc,rect);
            break;
        case DeviceContextExampleType::DrawFocusRect:
            DrawFocusRect(dc,rect);
            break;
        case DeviceContextExampleType::DrawStateNormal:
            DrawStateNormal(dc,rect);
            break;
        case DeviceContextExampleType::DrawStatePrefix:
            DrawStatePrefix(dc,rect);
            break;
        case DeviceContextExampleType::DrawStateDithered:
            DrawStateDithered(dc,rect);
            break;
        case DeviceContextExampleType::DrawStateDisabled:
            DrawStateDisabled(dc,rect);
            break;
        case DeviceContextExampleType::DrawStateMono:
            DrawStateMono(dc,rect);
            break;
        case DeviceContextExampleType::DrawStateHidePrefix:
            DrawStateHidePrefix(dc,rect);
            break;
        case DeviceContextExampleType::DrawStatePrefixOnly:
            DrawStatePrefixOnly(dc,rect);
            break;
        case DeviceContextExampleType::DrawStateRight:
            DrawStateRight(dc,rect);
            break;
        case DeviceContextExampleType::DrawDesktopWallPaper:
            DrawDesktopWallPaper(dc,rect);
            break;
		case DeviceContextExampleType::DrawScreenWidthAndHeight:
			DrawScreenWidthAndHeight(dc,rect);
			break;


    }
}


void DeviceContextExampleForm::DrawBitmap(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    if(bitMap)
    {
        POINT pt = {rect.left,rect.top};
        SIZE sz = {rect.right - rect.left, rect.bottom - rect.top};
        dc->DrawBitmap(bitMap,pt,sz);
    }
}

void DeviceContextExampleForm::DrawCaption(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    int height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );
    rect.bottom = rect.top + height;
    dc->DrawCaption(As<Control>(),rect,DrawCaptionOptions::Active | DrawCaptionOptions::Text | DrawCaptionOptions::Icon |DrawCaptionOptions::Gradient | DrawCaptionOptions::Buttons);
}

void DeviceContextExampleForm::DrawCaptionFrameControlCloseButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawCaptionFrameControl(DrawFrameControlCaptionPart::CloseButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawCaptionFrameControlMinimizeButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawCaptionFrameControl(DrawFrameControlCaptionPart::MinimizeButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawCaptionFrameControlMaximizeButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawCaptionFrameControl(DrawFrameControlCaptionPart::MaximizeButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawCaptionFrameControlRestoreButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawCaptionFrameControl(DrawFrameControlCaptionPart::RestoreButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawCaptionFrameControlHelpButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawCaptionFrameControl(DrawFrameControlCaptionPart::HelpButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawMenuBarFrameControlArrow(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawMenuBarFrameControl(DrawFrameControlMenuBarPart::Arrow,rect,DrawFrameControlOptions::None);
}
void DeviceContextExampleForm::DrawMenuBarFrameControlCheck(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawMenuBarFrameControl(DrawFrameControlMenuBarPart::Check,rect,DrawFrameControlOptions::None);
}
void DeviceContextExampleForm::DrawMenuBarFrameControlBullet(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawMenuBarFrameControl(DrawFrameControlMenuBarPart::Bullet,rect,DrawFrameControlOptions::None);
}
void DeviceContextExampleForm::DrawMenuBarFrameControlArrowRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawMenuBarFrameControl(DrawFrameControlMenuBarPart::ArrowRight,rect,DrawFrameControlOptions::None);
}


void DeviceContextExampleForm::DrawScrollBarFrameControlUp(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::Up,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawScrollBarFrameControlDown(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::Down,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawScrollBarFrameControlLeft(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::Left,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawScrollBarFrameControlRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::Right,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawScrollBarFrameControlComboBox(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::ComboBox,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawScrollBarFrameControlSizeGrip(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::SizeGrip,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawScrollBarFrameControlSizeGripRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawScrollBarFrameControl(DrawFrameControlScrollBarPart::SizeGripRight,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawButtonFrameControlCheckBox(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawButtonFrameControl(DrawFrameControlButtonOptions::CheckBox,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawButtonFrameControlRadioImage(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawButtonFrameControl(DrawFrameControlButtonOptions::RadioImage,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawButtonFrameControlRadioMask(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawButtonFrameControl(DrawFrameControlButtonOptions::RadioMask,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawButtonFrameControlRadioButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawButtonFrameControl(DrawFrameControlButtonOptions::RadioButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawButtonFrameControlThreeState(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawButtonFrameControl(DrawFrameControlButtonOptions::ThreeState,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawButtonFrameControlPushButton(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawButtonFrameControl(DrawFrameControlButtonOptions::PushButton,rect,DrawFrameControlOptions::None);
}

void DeviceContextExampleForm::DrawEdgeRaisedOuter(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::RaisedOuter,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeSunkenOuter(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::SunkenOuter,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeRaisedInner(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::RaisedInner,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeSunkenInner(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::SunkenInner,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeRaised(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::Raised,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeSunken(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::Sunken,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeEtched(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::Etched,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawEdgeBump(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawEdge(rect,BorderStyle::Bump,BorderFlags::Rectangle);
}

void DeviceContextExampleForm::DrawFocusRect(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawFocusRect(rect);
}

void DeviceContextExampleForm::DrawStateNormal(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState Normal");
    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::Normal);
}

void DeviceContextExampleForm::DrawStatePrefix(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState &Prefix");
    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::Prefix);
}

void DeviceContextExampleForm::DrawStateDithered(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState Dithered");
    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::Dithered);
}

void DeviceContextExampleForm::DrawStateDisabled(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState Disabled");
    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::Disabled);
}

void DeviceContextExampleForm::DrawStateMono(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState Mono");
    auto brush = std::make_shared<BrushHandle>(RGB(0xFF,0,0));
    dc->DrawStateW(brush,s,rect.left,rect.top,DrawStateFlags::Mono);
}

void DeviceContextExampleForm::DrawStateHidePrefix(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState &Prefix");
    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::HidePrefix);
}

void DeviceContextExampleForm::DrawStatePrefixOnly(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState &Prefix");
    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::PrefixOnly);
}

void DeviceContextExampleForm::DrawStateRight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

    String s(L"DrawState Right");
    dc->DrawStateW(s,rect.left,rect.top,rect.right - rect.left,height,DrawStateFlags::Right);
}

void DeviceContextExampleForm::DrawDesktopWallPaper(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    dc->DrawDesktopWallPaper();
}


void DeviceContextExampleForm::DrawChord(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
    POINT start = {rect.left};
    POINT end;
    dc->DrawChord(rect,start,end);
}

void DeviceContextExampleForm::DrawScreenWidthAndHeight(const std::shared_ptr<DeviceContextHandle>& dc,RECT& rect )
{
	auto height = Environment::SystemMetrics::CaptionHeight();
    rect.top = rect.top + ( ((rect.bottom - rect.top)/2) - (height/2) );

	auto screenHeight = Environment::SystemMetrics::ScreenHeight();
	auto screenWidth  = Environment::SystemMetrics::ScreenWidth();

	MapMode mapMode = dc->MapMode();
	dc->SetMapMode(MapMode::LoMetric);

	POINT pt = {(LONG)screenWidth,(LONG)screenHeight};
	::DPtoLP(dc->GetHDC(),&pt,1);

	dc->SetMapMode(mapMode);

    String s = String::Format(L"Width %d, Height %d",pt.x,pt.y);

    dc->DrawStateW(s,rect.left,rect.top,DrawStateFlags::Normal);
}



int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);
    try
    {
        auto application = make_component<Application>();
        auto form = make_control<DeviceContextExampleForm>();

        auto result = application->Run(form);

        return result;

    }
    catch(std::exception& exc)
    {
        std::cout << exc.what() << std::endl;
    }
    catch(...)
    {
        
    }
    return 0;
}


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions