Creating the Monitor Custom Control

Environment: VC6 Win95/NT3.51 or later

In an attempt to imitate the famous monitor of the MS Windows Display properties dialog box, I've built this custom control to provide the functionality of representing the screen display with a bitmap image background.

The control is implemented as a CMonitor class publicly derived from CWnd, in an MFC regular Dll project, but of course the class can be extracted—together with the relevant resources—to be directly included in your MFC exe project. Also, an MFC dialog-based project was built dependent on the basic DLL project, to test and demonstrate the behaviour of the monitor custom control.

By using the VC++ ZoomIn tool, I was able to capture the monitor image from the MS Windows Display properties dialog box. The image was included in the project together with an identical monochrome bitmap of the monitor to act as a mask for laying the monitor transparently against any background.

The monitor behaviour, as demonstrated by the TestMonitor Dialog box, can be summarized as:

  • Laying itself transparently against any background. This can be shown by changing the combobox background selection and also by moving the monitor against the selected background, although the normal practice is using the monitor control in a plain color dialog box without being moved.
  • Transparency here is meant to expose the selected background through the monitor display area when the background image is not occupying the full display area, and of course to naturally display the monitor, just as an icon.
  • The main purpose of the control is to display a background image, centered, stretched, or tiled, within the monitor control display area that represents the screen display. On creation, the control is able to detect the screen dimensions by using the API function GetSystemMetrics() with the SM_CXSCREEN and SM_CYSCREEN parameters. Those dimensions are stored as data members and the user is given the ability to change them, which affects the displayed image that adjusts its size to match the new dimensions.
// SOURCE CODE HINTS

// a public static member function used for registering the
// control window class

static BOOL CMonitor::RegisterWndClass(HINSTANCE hInstance);

// a global function defined and used for transparently
// displaying the monitor

extern "C" __declspec(dllexport)
BOOL MaskImage(HDC hDC, int nXDest, int nYDest, int nWidth,
               int nHeight, HBITMAP hbmImage, int nXSrc,
               int nYSrc, HBITMAP hbmMask);

// the global control window procedure function

LRESULT CALLBACK AFX_EXPORT
CMonitorWndProc(HWND hWnd, UINT message, WPARAM wParam,
                                         LPARAM lParam);

// a set of user defined Windows control messages to
// communicate with the control

#define MM_SETIMAGE              WM_USER + 0
#define MM_GETIMAGE              WM_USER + 1
#define MM_SETDISPLAYSTYLE       WM_USER + 2
#define MM_GETDISPLAYSTYLE       WM_USER + 3
#define MM_SETREF                WM_USER + 4
#define MM_GETREF                WM_USER + 5

// a dummy function is used to be called from the client program
// to ensure the dll loading

extern "C" __declspec(dllexport)
void MonitorDllEntry() {}        // dummy function

I hope that this code can be useful. I'll appreciate any comments.

Downloads

Download demo project - 16 Kb
Download source - 56 Kb



Comments

  • Quite Cool and Unique.

    Posted by Legacy on 09/10/2002 12:00am

    Originally posted by: Anonymous

    Quite Cool and Unique.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Corporate e-Learning technology has a long and diverse pedigree. As far back as the 1980s, companies were adopting computer-based training to supplement traditional classroom activities. More recently, rich web-based applications have added streaming audio and video, real-time collaboration and other new tools to the e-Learning mix. At the same time, the growing availability of informal learning tools--a category that includes everything from web searches to social media posts--are having a major impact on …

  • Live Event Date: July 30, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You may already know about some of the benefits of Bluemix, IBM's open platform for developing and deploying mobile and web applications. Check out this upcoming eSeminar that focuses on building an Android application using the MobileData service, with a walk-through of the real process and workflow used to build and link the MobileData service within your application. Join IBM's subject matter experts as they show you the way to build a base …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds