Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Applications » Downloads
 
Add your own
alternative version

Window Tabifier

, 29 Mar 2008 CPOL
A simple application for hosting several Windows in one parent window
windowtabifier_demo.zip
WindowTabifier_demo
About.dll
DragAndDropFileComponent.dll
TabStrip.dll
Window Tabifier.exe
windowtabifier_src.zip
Window Tabifier
Window Tabifier
bin
DLL's
About.dll
DragAndDropFileComponent.dll
TabStrip.dll
documents-32x32.png
folder-documents.ico
Properties
Settings.settings
Thumbs.db
Window Tabifier.csproj.user
Window.cd
Windows-Desktop-32x32.png
windowtabifier_srcvs2005.zip
WindowTabifier_srcVS2005
Window Tabifier
bin
DLLs
About.dll
DragAndDropFileComponent.dll
TabStrip.dll
documents-32x32.png
Properties
Settings.settings
Resources
folder-documents.ico
Thumbs.db
Thumbs.db
Window Tabifier.csproj.user
window.cd
Windows-Desktop-32x32.png
windowtabifier_srcvs2008.zip
WindowTabifier_srcVS2008
Window Tabifier
bin
DLLs
About.dll
DragAndDropFileComponent.dll
TabStrip.dll
documents-32x32.png
folder-documents.ico
Properties
Settings.settings
Thumbs.db
Window Tabifier.csproj.user
window.cd
Windows-Desktop-32x32.png
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace WindowTabifier
{
    public class window
    {
        #region private fields
        private IntPtr handle;
        private string title;
        private int style;
        private int previousstyle;
        private IntPtr parent;
        private IntPtr previousparent;
        private winapi.RECT rect;
        private Size size;
        private Point location;

        private static List<window> openwnd;
        #endregion

        #region Properties

        public IntPtr Handle
        {
            get { return handle; }
        }

        public string Title
        {
            get { return title; }
        }

        public int Style
        {
            get { return style; }
        }

        public IntPtr Parent
        {
            get { return parent; }
        }

        public Size Size
        {
            get { return size; }
        }

        public Point Location
        {
            get { return location; }
        }

        public int PreviousStyle
        {
            get { return previousstyle; }
        }

        #endregion

        public window(IntPtr handle)
        {
            this.handle = handle;

            title = gettext();
            parent = getparent();
            style = getstyle();
            winapi.GetWindowRect(handle, out rect);
            size = new Size(rect.Right - rect.Left, rect.Bottom - rect.Top);
            location = new Point(rect.Left, rect.Top);
        }

        public void SetParent(IntPtr ParentHandle)
        {
            previousparent = winapi.SetParent(handle, ParentHandle);
            parent = ParentHandle;
        }

        public void RestoreParent()
        {
            parent = previousparent;
            previousparent = winapi.SetParent(handle, previousparent);
        }

        public void Move(Point Location,Size size, bool repaint)
        {
            winapi.MoveWindow(handle, Location.X, Location.Y, size.Width, size.Height, repaint);
        }

        public void SetStyle(int index, IntPtr value)
        {
            previousstyle = winapi.SetWindowLong(handle, index, value);
            style = value.ToInt32();
        }

        public bool Close()
        {
            bool result = winapi.PostMessage(handle, winapi.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
            
            if (!result)
            {
                result = winapi.PostMessage(handle, winapi.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
            }

            return result;
        }

        public string GetExecutablePath()
        {
            uint dwProcessId;
            winapi.GetWindowThreadProcessId(handle, out dwProcessId);
            IntPtr hProcess = winapi.OpenProcess(winapi.ProcessAccessFlags.VMRead | winapi.ProcessAccessFlags.QueryInformation, false, dwProcessId);
            StringBuilder path = new StringBuilder(1024);
            winapi.GetModuleFileNameEx(hProcess, IntPtr.Zero, path, 1024);
            winapi.CloseHandle(hProcess);
            return path.ToString();
        }

        public static List<window> GetOpenWindows()
        {
            openwnd = new List<window>();

            winapi.EnumWindowsProc callback = new winapi.EnumWindowsProc(EnumWindows);
            winapi.EnumWindows(callback, 0);

            List<window> result = new List<window>(openwnd);
            openwnd.Clear();

            result.RemoveAt(result.Count - 1);
            return result;
        }

        private static bool EnumWindows(IntPtr hWnd, int lParam)
        {
            if (!winapi.IsWindowVisible(hWnd) || hWnd == winapi.statusbar)
                return true;

            openwnd.Add(new window(hWnd));
            
            return true;
        }

        private string gettext()
        {
            StringBuilder title = new StringBuilder(256);
            winapi.GetWindowText(handle, title, 256);

            return title.ToString();
        }

        private IntPtr getparent()
        {
            return winapi.GetParent(handle);
        }

        private int getstyle()
        {
            return winapi.GetWindowLong(handle, winapi.GWL_STYLE);
        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Giorgi Dalakishvili
Software Developer
Georgia Georgia
No Biography provided
Follow on   Google+

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 29 Mar 2008
Article Copyright 2008 by Giorgi Dalakishvili
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid