Monthly Archives: January 2012

Modeler Tool : RC 1

Here is the new version of Modeler1 Tool. It helps to draw Infrastructure diagrams. The next version will allow to design application diagrams.

C++ 11 – Everything you can read

Available on ATT web site and Bjarne Stroustrup (inventor of C++) space, here a FAQ for C++ 11:  FAQ C++ 11 : http://www2.research.att.com/~bs/C++0xFAQ.html

Why C++ is so important at Microsoft what is Microsoft commitment to C++. Windows 8 and C++ means:
New programming model for Windows 8 | Get the full power of your CPU and GPU | Use Windows 8 hardware capabilities to the fullest | Build for ARM | Visual C++ is The power and performance tool for Windows.

C++ is the ultimate object oriented programming approach. C++ programmers care about details.

C++ 11 is the new ISO standard for C++ language. What’s new in C++ 11 ? Check-out this Herb Sutter image from “Why C++” talk: http://ecn.channel9.msdn.com/content/WhyCPPCB2011.pdf
To read (for free) a 1334 PDf document about the C++ language, you can drownload the draft of the C++ Programming Language Specifications:  ISO/IEC 14882:2011 Programming Language C++ – draft

From Bjarne Stroustrup, “What is the new C++” : C++ is a language for building software infrastructure | C++ is a language for applications with large systems programming parts | C++ is a language for building and using libraries | C++ is a language for resource-constrained systems | C++ is a language for efficiently expressing abstractions | C++ is a language for general and efficient algorithms | C++ is a language for general and compact data structures | C++ is a lightweight abstraction language. The C++ document to read: BS-what-is-c++0x.pdf

To find advanced STL topics, check out Advanced STL channel9 sessions :

See Part 1 -> shared_ptr and friends | See Part 2 -> Algorithm optimization | See Part 3 -> STL’s comprehensive correctness checks | See Part 4 -> rvalue references, perfect forwarding, associative containers  | See part 5 -> http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Advanced-STL-5-of-n | From the presentation : vis-1.1.pptx

Windows 8 Essentials (UI and Internals)

This is a very lightweight version of “Windows 8 Best-Of” of a previous post.
It contains the Metro UI style inspiration and essentials native controls (XAML) and the complete list of API namespaces.
Inspiration of the Metro UI design comes from the transport area.

Windows 8 is powered with C++.

WinRT design comes with modern C++ and use advances technique like template meta programming. See Channel9 video about Windows Runtime Library: http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-2-C-at-BUILD-Windows-Runtime-LibraryWRL-Meet-Tarek-and-Sridhar

BUILD_Windows8_Essentials_Pichaud.pptx

Modeling Tool – alpha version

Here I am, with a preview alpha version of my Modeler tool.
It contains a basic Ribbon UI feature to draw simple shapes and a Infrastructure shapes.
In next version, I will allow application architecture shapes and custom n-tiers layer models.

ChristopheP | Why Visual C++ ? Power and Performance Tool for Windows.

Modeling and Ribbon UI

For the Microsoft TechDays in Paris and my C++ 11 session, I have prepared a real coding demo.
It’s like a simple drawing tool, and it allows to draw simple shapes. To a quick and dirty but cool user experience demo, I have switch some gdiplus drawing to directly loading pictures with transparency (png format).

Handling a property grid window

In my modeler tool, I can now handle Color and Text properties on objects.
Each property is handled by the CMFCPropertyGridProperty class and the default value type is COleVariant.
Enjoy the drawing stuff !

Drawing UI handlers – h file

Here are the prototyped rewritten classes. Will move from C++ MFC to C++ 11 modern code with STL sooner.

Element_h.docx

Here is the CElement class which contains basic and generic drawing objects:

class CElement : public CObject
{
public:
DECLARE_SERIAL(CElement);
CElement();
CElement(ElementType type);
virtual ~CElement(void);

// Operations
public:
virtual void Serialize(CArchive& ar);   // overridden for document i/o
CString ToString();
CString ToString(ElementType type);
static bool IsDrawable(ElementType type);
BOOL Intersects(const CRect& rect);
void InvalidateObj(void);
void Draw(CModeler1View * pView, CDC* pDC);

// Attributes
public:
CString m_name;
ElementType m_type;
CString m_objectId;
CString m_caption;
CString m_text;
CRect m_rect;
CPoint m_point;
CPoint m_last;
CElementManager * m_pManager;

CElementManager * GetManager() const
{
return m_pManager;
}
};

The CElementManager class contains the code for the UI handlers and some others stuff.

class CElementManager : public CObject
{
public:
DECLARE_SERIAL(CElementManager);
CElementManager();
virtual ~CElementManager(void);

// Attributes
public:
CTypedPtrList<CObList, CElement*> m_objects;
CTypedPtrList<CObList, CElement*> m_selection;
COLORREF m_paperColor;
// Page size in logical coordinates
CSize m_size;
CPoint m_lastPoint;
// Current working object
CString m_objectId;

// Operations
public:
virtual void Serialize(CArchive& ar);   // overridden for document i/o
CElement * FindElement(ElementType type);
CElement * FindElement(CString objectId);
CElement * ObjectAt(const CPoint & point);
static void ViewToManager(CModeler1View * pView, CPoint & point);
static void ViewToManager(CModeler1View * pView, CRect & rect);
static void ManagerToView(CModeler1View * pView, CPoint & point);
static void ManagerToView(CModeler1View * pView, CRect & rect);
COLORREF GetPaperColor() const { return m_paperColor; }
void Invalidate(CModeler1View * pView, CElement * pElement);
void InvalObj(CModeler1View * pView, CElement * pElement);
CSize GetSize() const { return m_size; }
void UpdatePropertyGrid(CModeler1View * pView, CElement * pElement);
void UpdateFromPropertyGrid(CString objectId, CString name, CString value);

// Managing Object Selection
public:
BOOL HasSelection();
BOOL IsSelected(CElement * pElement);
BOOL Select(CElement * pElement);
BOOL Deselect(CElement * pElement);
void SelectNone();

// Managing/Viewing Object Selection & Tracker helpers
public:
int GetHandleCount();
CPoint GetHandle(CElement * pElement, int nHandle);
void DrawTracker(CElement *pElement, CDC* pDC, TrackerState state);
HCURSOR GetHandleCursor(int nHandle);

// Overridables
public:
virtual void Draw(CModeler1View * pView, CDC * pDC);
virtual void DrawEx(CModeler1View * pView, CDC * pDC);
virtual void Update(CModeler1View * pView, LPARAM lHint, CObject* pHint);

// UI Handlers
public:
virtual void OnLButtonDown(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
virtual void OnLButtonDblClk(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
virtual void OnLButtonUp(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
virtual void OnMouseMove(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
};

Windows 8 Essentials

It the best from th Microsoft Build conference from September 2011.
153 slides to learn about Wimdows 8 and Metro Style Apps. Have fun !

BUILD_BEST-OF_Pichaud.pptx

Drawing UI handlers

Drawing a shape, select another, changing it’s properties in a docking Properties window, changing it’s attribute with the mouse for the size, using the Ribbon to modify some others attributes. Handling multiple shapes, connecting them, handle the zoom.
And always fast and fluid. C++ and Gdiplus. Small, efficient and a real user experience. More to come with clean C+ 11 code.

Modern C++ 11 code

Here is a real case study. I write a native modeler tool. First, to recover from Gdi learning, I have adapted DrawCli MFC sample. Next, because it is a sample, it is not clean so I have written from scratch and kept fast and fluid drawing techniques. I put Gdiplus to draw elements with shaders, gradients and sexy UI experience.
Here is the main classes as it.
It is under development. Feel free to adapt. I will move this code from MFC style to modern C++ 11 code. No not MFC collections and CString. Just STL vector<> and std::string.
A real case study for TechDays in Paris.

File contains element.h and element.cpp.

New article about Native Development (C++)

For the french software development magazine Programmez, I wrote an article about native development and the C++ power and performance fact. Next month, another article will cover Beginning with CRT and STL.

Drawing with C++

Use Gdi+. It is fast and it provides a real user experience.

What is Windows Runtime Library (WRL)

WRL is the new API for targeting Metro Style Applications available in Windows 8. WRL allows to build WinRT components. WinRT means Windows Runtime. It is all native development. Power and Performance for fast and fluid applications.

WRL is a C++ template library using traditional and new C++ programming features. It is build with standard ISO C++. C++/CX syntax looks like C++/CLI. C++/CX brings extensions to C++.

WRL is like the new ATL. It allows to build new COM components. There is no IDispatch, no managed code, no JIT nor any links to the .NET framework. WRL brings like a C++/CLI syntax but it is native, there is no managing code. WRL is very low level.

WRL do not use exceptions, internally. All API returns HRESULT. but projection allows other language to see exceptions.

WinRT components vs COM components. In COM, you have an IDL file which produces a H file and a TLB file and you create CPP and ATL, you build and you register your component. In WinRT, there is still IDL with a H file and a WINMD (metadata) file and you create CPP and WRL,  you build and you create a manifest and don’t need registration. At the code level, in WinRT, you just write class T : RuntimeClass<IInterface1, IInterface2>. You just need an IInspectable stuff. In WinRT, GUID are strings. The guideline is to write it as a namespace like company.component.version. Then the last step is to make the package of installation.

refclass and Hat ^

Marian Luparu, Jim Springfield and other VC++ folks from Channel9.

Windows 8 is a change for developers to write applications. Consuming WinRT API is the way to go. C++ is part of that. How to write great Metro Apps with C++.

WRL is a library. CX are C++ extensions. Hat is a pointer. ^ means *.

^ is a CComPtr. It a counter-based COM pointer. Refnew is used to activate a WinRT component.

In Windows team, the code is exception free. So how Windows team consumes WRL gave good feedback. Example:

CComPtr<IFoo> f; auto b=f.As<IBar>(); if( b == nullptr ) {…}

It needs to return the HRESULT explaining why if failed because QI (COM QueryInterface) returns an HRESULT with explains.

HRESULT hr = f.As<IBar>();

Other example:

IFoo * pf; IBar *pb; pb = pf; It should be mapped to CComPtr<IFoo> pf; CComPtr<IBar> pb = pf;

auto a = ref new uri(); // RoActivateInstance(“W::F::Uri”, &p);

It is life-time managed like a shared_ptr<T>.

It is easier to write COM now.

Windows 8 and C++

Microsoft commitment to C++:
}New programming model for Windows 8.
}Get the full power of your CPU and GPU.
}Use Windows 8 hardware capabilities to the fullest.
}Build for ARM.

Visual C++: The power and performance tool for Windows.

What is unique about C++

From Bjarne Stroustrup, “What is C++0x” :

• C++ is a language for building software infrastructure.
• C++ is a language for applications with large systems programming parts.
• C++ is a language for building and using libraries.
• C++ is a language for resource-constrained systems.
• C++ is a language for efficiently expressing abstractions.
• C++ is a language for general and efficient algorithms.
• C++ is a language for general and compact data structures.
• C++ is a lightweight abstraction language.

BS-what-is-c++0x.pdf