Click here to Skip to main content
15,885,025 members
Articles / Programming Languages / C++/CLI

MaChat - a chat with a browser for LANs

Rate me:
Please Sign up or sign in to vote.
4.97/5 (27 votes)
30 Jul 200211 min read 582.1K   12.4K   119  
This article shows how to create a Chat for Local Area Networks which uses the WebBrowser control to display the messages.
// *****************************************************************************
// 
//  (c) Crownwood Consulting Limited 2002 
//  All rights reserved. The software and associated documentation 
//  supplied hereunder are the proprietary information of Crownwood Consulting 
//	Limited, Haxey, North Lincolnshire, England and are supplied subject to 
//	licence terms.
// 
//  Magic Version 1.6	www.dotnetmagic.com
// *****************************************************************************

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using Crownwood.Magic.Win32;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Collections;

namespace Crownwood.Magic.Controls
{
    public class TabControlDesigner :  System.Windows.Forms.Design.ParentControlDesigner
    {
        private IDesignerHost _designerHost = null;
        private ISelectionService _selectionService = null;

        public override ICollection AssociatedComponents
        {
            get 
            {
                if (base.Control is Crownwood.Magic.Controls.TabControl)
                    return ((Crownwood.Magic.Controls.TabControl)base.Control).TabPages;
                else
                    return base.AssociatedComponents;
            }
        }

        public IDesignerHost DesignerHost
        {
            get
            {
                // Is this the first time the accessor has been called?
                if (_designerHost == null)
                {
                    // Then grab and cache the required interface
                    _designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
                }

                return _designerHost;
            }
        }

        public ISelectionService SelectionService
        {
            get
            {
                // Is this the first time the accessor has been called?
                if (_selectionService == null)
                {
                    // Then grab and cache the required interface
                    _selectionService = (ISelectionService)GetService(typeof(ISelectionService));
                }

                return _selectionService;
            }
        }

        protected override bool DrawGrid
        {
            get { return false; }
        }
        protected override void WndProc(ref Message msg)
        {
            // Test for the left mouse down windows message
            if (msg.Msg == (int)Win32.Msgs.WM_LBUTTONDOWN)
            {
                // Get access to the TabControl we are the designer for
                Crownwood.Magic.Controls.TabControl tabControl = this.SelectionService.PrimarySelection as Crownwood.Magic.Controls.TabControl;

                // Check we have a valid object reference
                if (tabControl != null)
                {
                    // Extract the mouse position
                    int xPos = (int)((uint)msg.LParam & 0x0000FFFFU);
                    int yPos = (int)(((uint)msg.LParam & 0xFFFF0000U) >> 16);

                    // Ask the TabControl to change tabs according to mouse message
                    tabControl.ExternalMouseTest(msg.HWnd, new Point(xPos, yPos));
                }
            }
            else
            {
                if (msg.Msg == (int)Win32.Msgs.WM_LBUTTONDBLCLK)
                {
                    // Get access to the TabControl we are the designer for
                    Crownwood.Magic.Controls.TabControl tabControl = this.SelectionService.PrimarySelection as Crownwood.Magic.Controls.TabControl;

                    // Check we have a valid object reference
                    if (tabControl != null)
                    {
                        // Extract the mouse position
                        int xPos = (int)((uint)msg.LParam & 0x0000FFFFU);
                        int yPos = (int)(((uint)msg.LParam & 0xFFFF0000U) >> 16);

                        // Ask the TabControl to process a double click over an arrow as a simple
                        // click of the arrow button. In which case we return immediately to prevent
                        // the base class from using the double to generate the default event
                        if (tabControl.WantDoubleClick(msg.HWnd, new Point(xPos, yPos)))
                            return;
                    }
                }
            }

            base.WndProc(ref msg);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect macmichal.pl
Poland Poland
Micheal is an independent consultant - www.macmichal.pl.
He's main areas of interest are: DDD\CqRS, TDD, SaaS, Design Patterns, Architecture. He specializes in .Net/C# for the early beginning of it and T-SQL. He's a writer, blogger (blog.macmichal.pl) and speaker.

In his spare time, he's climbing the mountains all over the Europe.

Comments and Discussions