Click here to Skip to main content
15,881,812 members
Articles / Desktop Programming / WTL

WTL Wizard for Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
2.88/5 (4 votes)
17 Feb 2002 116.6K   1.2K   24  
An App-Wizard which creates template WTL apps.
// maindlg.h : interface of the $$ATL_MAINDLG_CLASS$$ class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined($$FILE_NAME_SYMBOL$$_INCLUDED_)
#define $$FILE_NAME_SYMBOL$$_INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

$$IF(ATL_PROJTYPE_DLG)
[
$$IF(CREATE_AS_HOST)
	activex_dialog(idd = IDD_MAINDLG), 
$$ELSE
	dialog(idd = IDD_MAINDLG), 
$$ENDIF //CREATE_AS_HOST
	update_ui
]
class $$ATL_MAINDLG_CLASS$$ : public CMessageFilter, public CIdleHandler
{
public:
	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
$$IF(CREATE_AS_HOST)
		if((pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST) &&
		   (pMsg->message < WM_MOUSEFIRST || pMsg->message > WM_MOUSELAST))
			return FALSE;

		HWND hWndCtl = ::GetFocus();
		if(IsChild(hWndCtl))
		{
			// find a direct child of the dialog from the window that has focus
			while(::GetParent(hWndCtl) != m_hWnd)
				hWndCtl = ::GetParent(hWndCtl);

			// give control a chance to translate this message
			if(::SendMessage(hWndCtl, WM_FORWARDMSG, 0, (LPARAM)pMsg) != 0)
				return TRUE;
		}

$$ENDIF //CREATE_AS_HOST
		return IsDialogMessage(pMsg);
	}

	virtual BOOL OnIdle()
	{
		return FALSE;
	}

	void CloseDialog(int nVal)
	{
		DestroyWindow();
		::PostQuitMessage(nVal);
	}

	[ message_handler(WM_INITDIALOG) ]
	BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/)
	{
		// center the dialog on the screen
		CenterWindow();

		// set icons
		HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
			IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
		SetIcon(hIcon, TRUE);
		HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
			IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
		SetIcon(hIconSmall, FALSE);

		// register object for message filtering and idle updates
		CMessageLoop* pLoop = _Module.GetMessageLoop();
		ATLASSERT(pLoop != NULL);
		pLoop->AddMessageFilter(this);
		pLoop->AddIdleHandler(this);

		UIAddChildWindowContainer(m_hWnd);

		return TRUE;
	}

$$IF(CREATE_COM_SERVER)
	[ message_handler(WM_DESTROY) ]
	void OnDestroy()
	{
		// unregister message filtering and idle updates
		CMessageLoop* pLoop = _Module.GetMessageLoop();
		ATLASSERT(pLoop != NULL);
		pLoop->RemoveMessageFilter(this);
		pLoop->RemoveIdleHandler(this);
		// if UI is the last thread, no need to wait
		if(_Module.GetLockCount() == 1)
		{
			_Module.m_dwTimeOut = 0L;
			_Module.m_dwPause = 0L;
		}
		_Module.Unlock();
	}

$$ENDIF //CREATE_COM_SERVER
	[ command_handler(id = ID_APP_ABOUT) ]
	void OnAppAbout(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*window*/)
	{
		CAboutDlg dlg;
		dlg.DoModal();
	}

	[ command_handler(id = IDOK) ]
	void OnOK(UINT /*uNotifyCode*/, int nID, CButton /*button*/)
	{
		// TODO: Add validation code 
		CloseDialog(nID);
	}

	[ command_handler(id = IDCANCEL) ]
	void OnCancel(UINT /*uNotifyCode*/, int nID, CButton /*button*/)
	{
		CloseDialog(nID);
	}
};
$$ELIF(ATL_PROJTYPE_DLGMODAL)
[
$$IF(CREATE_AS_HOST)
	activex_dialog(idd = IDD_MAINDLG)
$$ELSE
	dialog(idd = IDD_MAINDLG)
$$ENDIF //CREATE_AS_HOST
]
class $$ATL_MAINDLG_CLASS$$
{
public:
	[ message_handler(WM_INITDIALOG) ]
	BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/)
	{
$$IF(CREATE_COM_SERVER)
		_Module.Lock();

$$ENDIF //CREATE_COM_SERVER
		// center the dialog on the screen
		CenterWindow();

		// set icons
		HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
			IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
		SetIcon(hIcon, TRUE);
		HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
			IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
		SetIcon(hIconSmall, FALSE);

		return TRUE;
	}

$$IF(CREATE_COM_SERVER)
	[ message_handler(WM_DESTROY) ]
	void OnDestroy()
	{
		// if UI is the last thread, no need to wait
		if(_Module.GetLockCount() == 1)
		{
			_Module.m_dwTimeOut = 0L;
			_Module.m_dwPause = 0L;
		}
		_Module.Unlock();
	}

$$ENDIF //CREATE_COM_SERVER
	[ command_handler(id = ID_APP_ABOUT) ]
	void OnAppAbout(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*window*/)
	{
		CSimpleDialog<IDD_ABOUTBOX, FALSE> dlg;
		dlg.DoModal();
	}

	[ command_handler(id = IDOK) ]
	void OnOK(UINT /*uNotifyCode*/, int nID, CButton /*button*/)
	{
		// TODO: Add validation code 
		EndDialog(nID);
	}

	[ command_handler(id = IDCANCEL) ]
	void OnCancel(UINT /*uNotifyCode*/, int nID, CButton /*button*/)
	{
		EndDialog(nID);
	}
};
$$ENDIF //ATL_PROJTYPE_DLGMODAL


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// $$INSERT_LOCATION_COMMENT$$

#endif // !defined($$FILE_NAME_SYMBOL$$_INCLUDED_)

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions