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

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds