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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Due to internal controls and regulations, the amount of long term archival data is increasing every year. Since magnetic tape does not need to be periodically operated or connected to a power source, there will be no data loss because of performance degradation due to the drive actuator. Read this white paper to learn about a series of tests that determined magnetic tape is a reliable long-term storage solution for up to 30 years.

Most Popular Programming Stories

More for Developers

RSS Feeds