Click here to Skip to main content
12,623,027 members (36,695 online)
Click here to Skip to main content
Articles » Multimedia » GDI » Regions » Downloads

Stats

184K views
5.9K downloads
123 bookmarked
Posted

Guide to WIN32 Regions

, 10 Mar 2002 CPOL
Guide to understanding how to create and use regions with the WIN32 SDK
RgnGuide.exe
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
Engineer
United States United States
I am a software architect and I have been developing software for nearly two decades. Over the years I have learned to value maintainable solutions first. This has allowed me to adapt my projects to meet the challenges that inevitably appear during development. I use the most beneficial short-term achievements to drive the software I develop towards a long-term vision.

C++ is my strongest language. However, I have also used x86 ASM, ARM ASM, C, C#, JAVA, Python, and JavaScript to solve programming problems. I have worked in a variety of industries throughout my career, which include:
• Manufacturing
• Consumer Products
• Virtualization
• Computer Infrastructure Management
• DoD Contracting

My experience spans these hardware types and operating systems:
• Desktop
o Windows (Full-stack: GUI, Application, Service, Kernel Driver)
o Linux (Application, Daemon)
• Mobile Devices
o Windows CE / Windows Phone
o Linux
• Embedded Devices
o VxWorks (RTOS)
o Greenhills Linux
o Embedded Windows XP

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 creator of an open source project on GitHub called Alchemy[^], which is an open-source compile-time data serialization library.

I maintain my own repository and blog at CodeOfTheDamned.com/[^], because code maintenance does not have to be a living hell.

You may also be interested in...

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