Click here to Skip to main content
15,885,766 members
Articles / Desktop Programming / ATL

Win32 Dialog Helpers

Rate me:
Please Sign up or sign in to vote.
4.94/5 (38 votes)
18 Apr 200311 min read 274K   3.1K   79  
Easy support for dialog resizing and ActiveX controls
This article provides a few samples to enable features in WIN32 dialogs such as support for dialog resizing and ActiveX controls. VC++6 / VC++7.x projects are provided.
#pragma once



// CSampleAxDialog : sample resizable dialog implementation
//

class CSampleAxDialog : public CAxDialogImpl<CSampleAxDialog>
{
protected:
	HICON			m_hIcon;
	CResizableGrip	m_grip;

public:
    enum { IDD = IDD_SAMPLEACTIVEXDIALOG };

    BEGIN_MSG_MAP(CSampleAxDialog)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
		MESSAGE_HANDLER(WM_SIZE, OnSize)
		MESSAGE_HANDLER(WM_SIZING, OnSizing)
        COMMAND_ID_HANDLER(IDOK, OnOK)
        COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
    END_MSG_MAP()

    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        CenterWindow();

		m_hIcon = ::LoadIcon(_Module.GetResourceInstance(),MAKEINTRESOURCE(IDI_APPICON));
		SetIcon(m_hIcon, TRUE);			// Set big icon
		SetIcon(m_hIcon, FALSE);		// Set small icon

		m_grip.InitGrip( m_hWnd );
		m_grip.ShowSizeGrip();

		HWND hMediaPlayer = GetDlgItem(IDC_MEDIAPLAYER1);
		{
			CResizableControl *pListDynamics = m_grip.AddDynamicControls();
			if (pListDynamics)
			{
				pListDynamics->Init(hMediaPlayer);
				pListDynamics->AllowResizeOnResize();
			}
		}

		HWND hOk = GetDlgItem(IDOK);
		{
			CResizableControl *pListDynamics = m_grip.AddDynamicControls();
			if (pListDynamics)
			{
				pListDynamics->Init(hOk);
				pListDynamics->AllowMoveXOnResize();
			}
		}

		HWND hCancel = GetDlgItem(IDCANCEL);
		{
			CResizableControl *pListDynamics = m_grip.AddDynamicControls();
			if (pListDynamics)
			{
				pListDynamics->Init(hCancel);
				pListDynamics->AllowMoveXOnResize();
			}
		}

        return TRUE;    // let the system set the focus
    }

    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        EndDialog(IDCANCEL);
        return 0;
    }

	// called by framework while resizing
    LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
		DORESIZE(m_grip)
        return 0;
    }

	// called by framework while resizing, to allow min max bound adjustement
	LRESULT OnSizing(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		MINMAX(150,150)
		return 0;
	}



    LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        EndDialog(IDOK);
        return 0;
    }

    LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        EndDialog(IDCANCEL);
        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.


Written By
France France
Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).

Need a fast Excel generation component? Try xlsgen.

Comments and Discussions