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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • Stories about devastating cyberattacks are plaguing the news. Why? The DNS protocol is easy to exploit. See your network the way hackers do—as an easy target. Learn how you can effectively secure your DNS infrastructure today.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds