1 ///////////////////////////////
\r
6 #include "resource.h"
\r
7 #include "RibbonUI.h"
\r
9 // Definitions for the CView class
\r
11 void CView::OnCreate()
\r
13 // OnCreate is called automatically during window creation when a
\r
14 // WM_CREATE message received.
\r
16 // Tasks such as setting the icon, creating child windows, or anything
\r
17 // associated with creating windows are normally performed here.
\r
19 TRACE(_T("OnCreate\n"));
\r
21 // Set the window's icon
\r
22 SetIconSmall(IDI_SMALL);
\r
23 SetIconLarge(IDI_SIMPLERIBBON);
\r
25 // Set the window title
\r
26 SetWindowText(LoadString(IDS_APP_TITLE).c_str());
\r
28 if (GetWinVersion() >= 2601) // Ribbon only supported on Windows 7 and above
\r
30 if (CreateRibbon(this))
\r
31 TRACE(_T("Ribbon Created Succesfully\n"));
\r
33 TRACE(_T("Failed to create ribbon\n"));
\r
38 void CView::OnDestroy()
\r
40 if (GetWinVersion() >= 2601) // Ribbon only supported on Windows 7 and above
\r
45 // End the application when the window is destroyed
\r
46 ::PostQuitMessage(0);
\r
49 void CView::OnDraw(CDC* pDC)
\r
51 // OnPaint is called automatically whenever a part of the
\r
52 // window needs to be repainted.
\r
54 // Centre some text in our view window
\r
55 CRect r = GetClientRect();
\r
56 r.top += GetRibbonHeight();
\r
57 pDC->DrawText(_T("Simple Ribon Demo"), -1, r, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
\r
60 void CView::OnInitialUpdate()
\r
62 // OnInitialUpdate is called after the window is created.
\r
63 // Tasks which are to be done after the window is created go here.
\r
65 TRACE(_T("OnInitialUpdate\n"));
\r
68 void CView::OnSize()
\r
70 CRect r = GetClientRect();
\r
71 r.top += GetRibbonHeight();
\r
75 void CView::PreCreate(CREATESTRUCT& cs)
\r
77 // This function will be called automatically by Create. It provides an
\r
78 // opportunity to set various window parameters prior to window creation.
\r
79 // You are not required to set these parameters, any paramters which
\r
80 // aren't specified are set to reasonable defaults.
\r
82 // Set some optional parameters for the window
\r
83 cs.dwExStyle = WS_EX_CLIENTEDGE; // Extended style
\r
84 cs.lpszClass = _T("View Window"); // Window Class
\r
87 cs.cx = 400; // width
\r
88 cs.cy = 300; // height
\r
91 STDMETHODIMP CView::Execute(UINT32 nCmdID, UI_EXECUTIONVERB verb, const PROPERTYKEY* key, const PROPVARIANT* ppropvarValue, IUISimplePropertySet* pCommandExecutionProperties)
\r
93 UNREFERENCED_PARAMETER(pCommandExecutionProperties);
\r
94 UNREFERENCED_PARAMETER(ppropvarValue);
\r
95 UNREFERENCED_PARAMETER(key);
\r
96 UNREFERENCED_PARAMETER(verb);
\r
102 TRACE(_T("Button 1\n"));
\r
105 TRACE(_T("Button 2\n"));
\r
108 TRACE(_T("Button 3\n"));
\r
111 TRACE(_T("Button 4\n"));
\r
114 TRACE(_T("Button 5\n"));
\r
117 TRACE(_T("Button 6\n"));
\r
119 case cmdToggleButton1:
\r
120 TRACE(_T("Toggle Button 1\n"));
\r
122 case cmdToggleButton2:
\r
123 TRACE(_T("Toggle Button 2\n"));
\r
126 TRACE(_T("Exit button\n"));
\r
129 TRACE(_T("Unknown button\n"));
\r
136 STDMETHODIMP CView::OnViewChanged(UINT32 viewId, UI_VIEWTYPE typeId, IUnknown* pView, UI_VIEWVERB verb, INT32 uReasonCode)
\r
138 UNREFERENCED_PARAMETER(viewId);
\r
139 UNREFERENCED_PARAMETER(uReasonCode);
\r
141 HRESULT hr = E_NOTIMPL;
\r
143 // Checks to see if the view that was changed was a Ribbon view.
\r
144 if (UI_VIEWTYPE_RIBBON == typeId)
\r
148 // The view was newly created.
\r
149 case UI_VIEWVERB_CREATE:
\r
153 // The view has been resized. For the Ribbon view, the application should
\r
154 // call GetHeight to determine the height of the ribbon.
\r
155 case UI_VIEWVERB_SIZE:
\r
157 IUIRibbon* pRibbon = NULL;
\r
158 UINT uRibbonHeight;
\r
160 hr = ((IUnknown*)pView)->QueryInterface(IID_PPV_ARGS(&pRibbon));
\r
163 // Call to the framework to determine the desired height of the Ribbon.
\r
164 hr = pRibbon->GetHeight(&uRibbonHeight);
\r
165 m_uRibbonHeight = uRibbonHeight;
\r
166 pRibbon->Release();
\r
167 // Use the ribbon height to position controls in the client area of the window.
\r
171 // The view was destroyed.
\r
172 case UI_VIEWVERB_DESTROY:
\r
181 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
190 break; // and also do default processing for this message
\r
193 // pass unhandled messages on for default processing
\r
194 return WndProcDefault(uMsg, wParam, lParam);
\r