4 // This file contains the implementation of a tool window that hosts a .NET user control
10 #include <VSLWindows.h>
12 #include "..\%ProjectName%UI\Resource.h"
14 class %ProjectClass
%WindowPane
:
15 public CComObjectRootEx
<CComSingleThreadModel
>,
16 public VsWindowPaneFromResource
<%ProjectClass
%WindowPane
, IDD_
%ProjectClass
%_DLG
>,
17 public VsWindowFrameEventSink
<%ProjectClass
%WindowPane
>,
18 public VSL::ISupportErrorInfoImpl
<
19 InterfaceSupportsErrorInfoList
<IVsWindowPane
,
20 InterfaceSupportsErrorInfoList
<IVsWindowFrameNotify
,
21 InterfaceSupportsErrorInfoList
<IVsWindowFrameNotify3
> > > >
23 VSL_DECLARE_NOT_COPYABLE(%ProjectClass
%WindowPane
)
27 // Protected constructor called by CComObject<%ProjectClass%WindowPane>::CreateInstance.
28 %ProjectClass
%WindowPane() :
29 VsWindowPaneFromResource()
32 ~%ProjectClass
%WindowPane() {}
36 BEGIN_COM_MAP(%ProjectClass
%WindowPane
)
37 COM_INTERFACE_ENTRY(IVsWindowPane
)
38 COM_INTERFACE_ENTRY(IVsWindowFrameNotify
)
39 COM_INTERFACE_ENTRY(IVsWindowFrameNotify3
)
40 COM_INTERFACE_ENTRY(ISupportErrorInfo
)
43 BEGIN_MSG_MAP(%ProjectClass
%WindowPane
)
44 COMMAND_HANDLER(IDC_CLICKME_BTN
, BN_CLICKED
, OnButtonClick
)
47 // Function called by VsVsWindowPaneFromResource at the end of SetSite; at this point the
48 // window pane is constructed and sited and can be used, so this is where we can initialize
49 // the event sink by siting it.
50 void PostSited(IVsPackageEnums::SetSiteResult
/*result*/)
52 VsWindowFrameEventSink
<%ProjectClass
%WindowPane
>::SetSite(GetVsSiteCache());
55 // Callback function called by ToolWindowBase when the size of the window changes.
56 void OnFrameSize(int x
, int y
, int w
, int h
)
59 CWindow
button(this->GetDlgItem(IDC_CLICKME_BTN
));
61 button
.GetWindowRect(&buttonRectangle
);
63 OffsetRect(&buttonRectangle
, -buttonRectangle
.left
, -buttonRectangle
.top
);
65 int iLeft
= (w
- buttonRectangle
.right
) / 2;
71 int iTop
= (h
- buttonRectangle
.bottom
) / 2;
77 button
.SetWindowPos(NULL
, iLeft
, iTop
, 0, 0, SWP_NOSIZE
);
80 LRESULT
OnButtonClick(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& bHandled
)
82 // Load the message from the resources.
84 VSL_CHECKBOOL_GLE(strMessage
.LoadStringW(_AtlBaseModule
.GetResourceInstance(), IDS_BUTTONCLICK_MESSAGE
));
86 // Get the title of the message box (it is the same as the tool window's title).
88 VSL_CHECKBOOL_GLE(strTitle
.LoadStringW(_AtlBaseModule
.GetResourceInstance(), IDS_WINDOW_TITLE
));
90 // Get the UI Shell service.
91 CComPtr
<IVsUIShell
> spIVsUIShell
= GetVsSiteCache().GetCachedService
<IVsUIShell
, SID_SVsUIShell
>();
93 VSL_CHECKHRESULT(spIVsUIShell
->ShowMessageBox(0, GUID_NULL
, strTitle
, strMessage
, NULL
, 0, OLEMSGBUTTON_OK
, OLEMSGDEFBUTTON_FIRST
, OLEMSGICON_INFO
, FALSE
, &lResult
));
101 class %ProjectClass
%ToolWindow
:
102 public VSL::ToolWindowBase
<%ProjectClass
%ToolWindow
>
105 // Constructor of the tool window object.
106 // The goal of this constructor is to initialize the base class with the site cache
107 // of the owner package.
108 %ProjectClass
%ToolWindow(const PackageVsSiteCache
& rPackageVsSiteCache
):
109 ToolWindowBase(rPackageVsSiteCache
)
113 // Caption of the tool window.
114 const wchar_t* const GetCaption() const
116 static CStringW strCaption
;
117 // Avoid to load the string from the resources more that once.
118 if (0 == strCaption
.GetLength())
121 strCaption
.LoadStringW(_AtlBaseModule
.GetResourceInstance(), IDS_WINDOW_TITLE
));
126 // Creation flags for this tool window.
127 VSCREATETOOLWIN
GetCreationFlags() const
129 return CTW_fInitNew
|CTW_fForceCreate
;
132 // Return the GUID of the persintence slot for this tool window.
133 const GUID
& GetToolWindowGuid() const
135 return CLSID_guidPersistanceSlot
;
138 IUnknown
* GetViewObject()
140 // Should only be called once per-instance
141 VSL_CHECKBOOLEAN_EX(m_spView
== NULL
, E_UNEXPECTED
, IDS_E_GETVIEWOBJECT_CALLED_AGAIN
);
143 // Create the object that implements the window pane for this tool window.
144 CComObject
<%ProjectClass
%WindowPane
>* pViewObject
;
145 VSL_CHECKHRESULT(CComObject
<%ProjectClass
%WindowPane
>::CreateInstance(&pViewObject
));
147 // Get the pointer to IUnknown for the window pane.
148 HRESULT hr
= pViewObject
->QueryInterface(IID_IUnknown
, (void**)&m_spView
);
151 // If QueryInterface failed, then there is something wrong with the object.
152 // Delete it and throw an exception for the error.
154 VSL_CHECKHRESULT(hr
);
160 // This method is called by the base class after the tool window is created.
161 // We use it to set the icon for this window.
166 srpvt
.intVal
= IDB_FRAME_IMAGES
;
167 // We don't want to make the window creation fail only becuase we can not set
168 // the icon, so we will not throw if SetProperty fails.
169 if (SUCCEEDED(GetIVsWindowFrame()->SetProperty(VSFPROPID_BitmapResource
, srpvt
)))
172 GetIVsWindowFrame()->SetProperty(VSFPROPID_BitmapIndex
, srpvt
);
177 CComPtr
<IUnknown
> m_spView
;