Custom Control 1. Create a new dialog If you have a SDI/MDI, get a dialog by these steps, Insert->Resource, click dialog, click New ... Hint: Don't expand dialog. Just click the label dialog. 2. Add a static text to your dialog 3. Go to your static's properties and rename it. 4. View->ClassWizard 5. You'll see a prompt asking to create a new class for your dialog. Do so, and give that dialog a reasonable name. Exit ClassWizard 6. Add a new class and inherit from CStatic. This will be your new custom control. 7. Open Class Wizard, tab panel member variables, class name: your dialog, add a variable to your static text, category: control, variable type: your custom class 8. Let's add an OnPaint() to your custom control. Do this. In Class Wizard, Class name: your custom control class, Object ID: scroll down and select your custom control, Messages: WM_PAINT 9. In OnPaint(), paint your control a solid color. 10. Add a Create() function to your custom control. 11. You will call Create() whenever you want to place one of your controls on your view. Code your Create() to call CWnd::Create(). Set your control to be a 100 x 100 in size. Info: Calling CStatic::Create() also works, but for some reason the left and right click handlers cease to receive input. Instead input is funneled to the parentWnd. A probable cause is an implicit call to CWnd::EnableWindow(). Adding Custom Controls to a View 1. In your view, add a handler for left button clicks 2. Add your custom control's header file to the view's cpp file 3. In your left click handler, call the Create() function of your custom control to add the control to the view. Removing Custom Controls from a View 1. See CWnd::DestroyWindow() Right click context sensitive menu 1. Add a handler for right clicks to your custom control 2. Follow the instructions to create a popup menu, popup.txt 3. In your right click handler, display your popup menu. See your popup.txt for instructions. Getting input focus 1. In your left click and right click handler, call SetFocus(). CButton derived custom classes don't need this as they seem to call SetFocus() automatically. 2. Add handlers for WM_SETFOCUS and WM_KILLFOCUS. In SetFocus(), color your control yellow, In KillFocus, color your control red. If you do this right, you can visually follow the focus as you click on each control. Drag move your custom control 1. Add a boolean variable for drag status 2. Add handlers for left button up/down and mouse move 3. On left button down, set your drag boolean variable to true 4. On left button up, set your drag boolean variable to false. 5. In mouse move, check your drag boolean. a. If drag is on, move your control b. If you're tracking using CRectTracker, set your drag boolean variable to false after the Track() call. The Track() function stops when the user releases the mouse button which is the time where you want drag move to stop. Removing Screen flicker 1. In your Custom control's paint function you must implement double buffering. Even with double buffering there is still flicker. That is because the background and your control are trying to update the same portion of the screen. 2. In the parent of your custom control, turn on the style WS_CLIPCHILDREN by either Create() or SetStyle(). This tells the background not to draw in the area occupied by your control.