Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » GDI » Regions » Downloads
 
Add your own
alternative version
Go to top

Guide to WIN32 Regions

, 10 Mar 2002
Guide to understanding how to create and use regions with the WIN32 SDK
rgnguide_demo.zip
RgnGuide.exe
rgnguide_src.zip
arrow.cur
RgnGuide.dsp
res
RgnGuide.ico
cursor1.cur
Toolbar.bmp
/* mainfrm.h ******************************************************************
Author:		Paul Watt
Date:		3/2/2002
Purpose:	
******************************************************************************/
#ifndef __MAINFRM_H
#define __MAINFRM_H

class CMainFrame : public CFrameWindowImpl<CMainFrame>, public CUpdateUI<CMainFrame>,
		public CMessageFilter, public CIdleHandler
{
public:
	DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

	CRgnGuideView m_view;

	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
			return TRUE;

		return m_view.PreTranslateMessage(pMsg);
	}

	virtual BOOL OnIdle()
	{
		HMENU hMenu = GetMenu();

		UINT nMode     = m_view.GetMode();
		UINT nViewMode = m_view.GetViewMode();

		UISetCheck(ID_SHAPE_RECTANGLE, ID_SHAPE_RECTANGLE == nMode);
		UISetCheck(ID_SHAPE_ELLIPSE, ID_SHAPE_ELLIPSE == nMode);
		UISetCheck(ID_SHAPE_ROUNDRECT, ID_SHAPE_ROUNDRECT == nMode);

		UISetCheck(ID_VIEW_1, RGN1 == nViewMode);
		UISetCheck(ID_VIEW_2, RGN2 == nViewMode);
		UISetCheck(ID_VIEW_ALL, ALL == nViewMode);
		UISetCheck(ID_VIEW_BREAKDOWN_1, BREAK1 == nViewMode);
		UISetCheck(ID_VIEW_BREAKDOWN_2, BREAK2 == nViewMode);

		UIUpdateToolBar();
		return FALSE;
	}

	BEGIN_MSG_MAP(CMainFrame)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
		COMMAND_ID_HANDLER(ID_FILE_CLEAR, OnFileClear)
		COMMAND_ID_HANDLER(ID_FILE_CLEAR_1, OnFileClear)
		COMMAND_ID_HANDLER(ID_FILE_CLEAR_2, OnFileClear)
		COMMAND_ID_HANDLER(ID_VIEW_ALL, OnView)
		COMMAND_ID_HANDLER(ID_VIEW_1, OnView)
		COMMAND_ID_HANDLER(ID_VIEW_2, OnView)
		COMMAND_ID_HANDLER(ID_VIEW_BREAKDOWN_1, OnView)
		COMMAND_ID_HANDLER(ID_VIEW_BREAKDOWN_2, OnView)
		COMMAND_RANGE_HANDLER(ID_SHAPE_RECTANGLE, ID_SHAPE_ROUNDRECT, OnShapeSet)
		COMMAND_ID_HANDLER(ID_VIEW_TOOLBAR, OnViewToolBar)
		COMMAND_ID_HANDLER(ID_VIEW_STATUS_BAR, OnViewStatusBar)
		CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
		CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
	END_MSG_MAP()

	BEGIN_UPDATE_UI_MAP(CMainFrame)
		UPDATE_ELEMENT(ID_SHAPE_RECTANGLE, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_SHAPE_ELLIPSE, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_SHAPE_ROUNDRECT, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)

		UPDATE_ELEMENT(ID_VIEW_1, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_VIEW_2, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_VIEW_ALL, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_VIEW_BREAKDOWN_1, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)
		UPDATE_ELEMENT(ID_VIEW_BREAKDOWN_2, UPDUI_MENUPOPUP | UPDUI_TOOLBAR)

	END_UPDATE_UI_MAP()

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		CreateSimpleToolBar();
		CreateSimpleStatusBar();

		m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);

		UIAddToolBar(m_hWndToolBar);
		UISetCheck(ID_VIEW_TOOLBAR, 1);
		UISetCheck(ID_VIEW_STATUS_BAR, 1);

		CMessageLoop* pLoop = _Module.GetMessageLoop();
		pLoop->AddMessageFilter(this);
		pLoop->AddIdleHandler(this);

		return 0;
	}

	LRESULT OnShapeSet(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		m_view.SetMode(wID);

		return 0;
	}


	LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		PostMessage(WM_CLOSE);
		return 0;
	}

	LRESULT OnFileClear(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
			//C: Clear the appropriate region based on the wID.
		if (ID_FILE_CLEAR == wID)
		{
			::SetRectRgn(::g_rgnDoc.hSrc1, 0,0,0,0);
			::SetRectRgn(::g_rgnDoc.hSrc2, 0,0,0,0);
		}
		else if (ID_FILE_CLEAR_1 == wID)
		{
			::SetRectRgn(::g_rgnDoc.hSrc1, 0,0,0,0);
		}
		else if (ID_FILE_CLEAR_2 == wID)
		{
			::SetRectRgn(::g_rgnDoc.hSrc2, 0,0,0,0);
		}


		RedrawWindow(NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);

		return 0;
	}

	LRESULT OnView(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
			//C: Clear the appropriate region based on the wID.
		if (ID_VIEW_ALL == wID)
		{
			m_view.SetViewMode(ALL);
		}
		else if (ID_VIEW_1 == wID)
		{
			m_view.SetViewMode(RGN1);
		}
		else if (ID_VIEW_2 == wID)
		{
			m_view.SetViewMode(RGN2);
		}
		else if (ID_VIEW_BREAKDOWN_1 == wID)
		{
			m_view.SetViewMode(BREAK1);
		}
		else if (ID_VIEW_BREAKDOWN_2 == wID)
		{
			m_view.SetViewMode(BREAK2);
		}

		return 0;
	}

	LRESULT OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		BOOL bNew = !::IsWindowVisible(m_hWndToolBar);
		::ShowWindow(m_hWndToolBar, bNew ? SW_SHOWNOACTIVATE : SW_HIDE);
		UISetCheck(ID_VIEW_TOOLBAR, bNew);
		UpdateLayout();
		return 0;
	}

	LRESULT OnViewStatusBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		BOOL bNew = !::IsWindowVisible(m_hWndStatusBar);
		::ShowWindow(m_hWndStatusBar, bNew ? SW_SHOWNOACTIVATE : SW_HIDE);
		UISetCheck(ID_VIEW_STATUS_BAR, bNew);
		UpdateLayout();
		return 0;
	}
};

#endif

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Paul M Watt
Architect
United States United States
I have been developing software for almost two decades. The majority of my expertise as well as my strongest language is C++ with the networking software as my domain of focus. I have had the opportunity to develop:
* Desktop applications (Data Layer, Business Layer, Presentation Layer)
* Application virtualization
* Web clients
* Mobile device management software
* Device drivers
* Embedded system software for
- IP routers
- ATM routers
- Microwave frequency modems
 
Over the years I have learned to value maintainable design solutions first. This has allowed me to adapt my projects to meet the challenges that inevitably appear during development, including:
* My own misjudgments
* Incomplete requirements
* Feature creep
* Poor decisions for which I have no control
 
I am a Mentor and frequent contributor to CodeProject.com with tutorial articles that teach others about the inner workings of the Windows APIs.
 
I am the owner of an open source project on GitHub called Network Alchemy[^], which is a set of Network APIs that are focused on helping developers write robust network communication software.
 
I maintain my own repository and blog at CodeOfTheDamned.com/[^], a site dedicated to guiding developers through the damn code.
Follow on   Twitter   LinkedIn

| Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 11 Mar 2002
Article Copyright 2002 by Paul M Watt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid