Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Capturing Window Controls and Modifying their properties

, 19 Feb 2005
A Spy tool program like MS Spy++ that lets you capture window controls and modify their properties. Useful for learning window handles and their properties.
windowspy_src.zip
zDump
zDump
README
zDump.dsw
zDump.dsp
Graphics
XPtheme
zDump.exe.manifest
icons
124.ico
123.ico
FloatingFinder.ico
zDump2.ico
zDump1.ico
DockedFinder.ico
1.ico
2.ico
13.ico
cursors
Finder.cur
zDump.exe
/* DumpWin.cpp --

   This file is part of the "zero Dump 0.1".

   Copyright (C) 2004-2005 Ashkbiz Danehkar
   All Rights Reserved.

   zero Dump library are free software; you can redistribute them
   and/or modify them under the terms of the GNU General Public License as
   published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYRIGHT.TXT.
   If not, write to the Free Software Foundation, Inc.,
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

   Ashkbiz Danehkar
   <ashkbiz@yahoo.com>
*/
#include "stdafx.h"
#include "zDump.h"
#include "DumpWin.h"

#ifdef _DEBUG
#define DEBUG_NEW
#endif

int  iTitle=0;
char *szTitle=NULL;
char szClassName[64];
char szStyle[64];
char szDimension[128];
DWORD dwStyle;
DWORD dwExtendedStyle;
UINT dwID;
char szProcess[64];
char szHandle[64];

BOOL	m_bCarriageReturn;
DWORD	m_dwIndentLevel;
DWORD	m_dwIndentSize;
DWORD	m_dwDetails;

bool SaveToRegistry(bool StayOnTop);
bool LoadFromRegistry(bool *StayOnTop);

void DumpTitle(HWND hWnd);
void DumpClassName(HWND hWnd);
void DumpStyles(HWND hWnd);
void DumpDimension(HWND hWnd);

void DumpWindow(HWND hWnd);
void GetWindowInfo(HWND hWnd);


//----------------------------------------------------------------------------
bool SaveToRegistry(bool StayOnTop)
{
    char KeyMain[127];
	HKEY RootKey=HKEY_CURRENT_USER;
    strcpy(KeyMain,"Software\\zDump");
    bool Result;
	HKEY hKeyOption;
	DWORD dwDispos;
	if(ERROR_SUCCESS!=::RegCreateKeyEx(RootKey,KeyMain,
									0,NULL,
									REG_OPTION_NON_VOLATILE	
									,KEY_ALL_ACCESS,NULL,
									&hKeyOption,&dwDispos))
	{
		return FALSE;
	}
    __try 
    {
		if(::RegOpenKeyEx(RootKey,KeyMain,0,KEY_ALL_ACCESS,&hKeyOption)== ERROR_SUCCESS) 
        {	
			::RegSetValueEx(hKeyOption,
						"StayOnTop",0,
						REG_DWORD,
						reinterpret_cast<BYTE *>(&StayOnTop),
						4);
			Result=TRUE;
        }
		else Result=FALSE;
    }
	__finally
    {
       ::RegCloseKey(hKeyOption);
    }
    return(Result);
}
//----------------------------------------------------------------------------
bool LoadFromRegistry(bool *StayOnTop)
{
    char KeyMain[127];
	HKEY RootKey=HKEY_CURRENT_USER;
    strcpy(KeyMain,"Software\\zDump");
	HKEY hKeyOption;
	bool Result;
	DWORD dwSize     = 0; 
	DWORD dwDataType = 0; 
	DWORD dwValue    = 0; 
	if(::RegOpenKeyEx(RootKey,KeyMain,0,KEY_ALL_ACCESS,&hKeyOption) != ERROR_SUCCESS) 
	{ 
		return FALSE;
	}
    __try 
	{
		if(::RegOpenKeyEx(RootKey,KeyMain,0,KEY_ALL_ACCESS,&hKeyOption) == ERROR_SUCCESS) 
		{ 

			dwSize = sizeof(StayOnTop); 
			::RegQueryValueEx(hKeyOption,
						"StayOnTop",NULL,
						&dwDataType,
						reinterpret_cast<BYTE *>(StayOnTop),
						&dwSize);
			Result=TRUE;
        }
		else Result=FALSE;
    }
	__finally
    {
		::RegCloseKey(hKeyOption);
    }
    return(Result);
}

//---------------------------------------------------------------------------
void DumpTitle(HWND hWnd)
{
	int iLen;
	GetClassName(hWnd, szClassName, sizeof(szClassName)/sizeof(TCHAR));
	CharUpperBuff(szClassName,(DWORD)strlen(szClassName));
	if((strstr(szClassName,"EDIT")==NULL)&&(strstr(szClassName,"BOX")==NULL))
	{
		iLen = GetWindowTextLength(hWnd);
		szTitle=new TCHAR[iLen+1];
		memset(szTitle,0,iLen+1);
		GetWindowText(hWnd,szTitle,iLen+1);
	}
	else
	{
		iLen=128;
		szTitle=new TCHAR[iLen+1];
		memset(szTitle,0,iLen+1);
		HWND hWndParent=GetParent(hWnd);
		SendDlgItemMessage(hWndParent,dwID,
						   WM_GETTEXT, 
						   iLen+1, (LPARAM)szTitle);
		szTitle[127]=0;
	}
	SetDlgItemText(hwndMain,IDC_CAPTION,szTitle);
}

//---------------------------------------------------------------------------
void DumpClassName(HWND hWnd)
{
	GetClassName(hWnd, szClassName, sizeof(szClassName)/sizeof(TCHAR));
	SetDlgItemText(hwndMain,IDC_CLASS,szClassName);
}

//---------------------------------------------------------------------------
void DumpStyles(HWND hWnd)
{
	_itoa(dwStyle,szStyle,16);
	CharUpperBuff(szStyle,(DWORD)strlen(szStyle));
	SetDlgItemText(hwndMain,IDC_STYLE,szStyle);
}

//---------------------------------------------------------------------------
void DumpDimension(HWND hWnd)
{
	char sztemp[10];
	RECT wndRect;
	GetWindowRect(hWnd,&wndRect);
	strcpy(szDimension,"(");
	_itoa(wndRect.left,sztemp,10);
	strcat(szDimension,sztemp);
	strcat(szDimension," ,");
	_itoa(wndRect.top,sztemp,10);
	strcat(szDimension,sztemp);
	strcat(szDimension,")-(");
	_itoa(wndRect.right,sztemp,10);
	strcat(szDimension,sztemp);
	strcat(szDimension," ,");
	_itoa(wndRect.bottom,sztemp,10);
	strcat(szDimension,sztemp);
	strcat(szDimension,") ");
	_itoa(wndRect.right-wndRect.left,sztemp,10);
	strcat(szDimension,sztemp);
	strcat(szDimension,"x");
	_itoa(wndRect.bottom-wndRect.top,sztemp,10);
	strcat(szDimension,sztemp);
	SetDlgItemText(hwndMain,IDC_RECT,szDimension);
}

//---------------------------------------------------------------------------
void DumpWindow(HWND hWnd)
{
	if (!IsWindow(hWnd)) return;
	//WINDOWINFO wininfo=GetWindowInfo(hWnd,&wininfo);
	dwID = GetWindowLong(hWnd, GWL_ID);
	dwStyle =GetWindowLong(hWnd, GWL_STYLE);
	dwExtendedStyle =GetWindowLong(hWnd, GWL_EXSTYLE);
	DumpTitle(hWnd);
	DumpClassName(hWnd);
	DumpStyles(hWnd);
	DumpDimension(hWnd);
}

//---------------------------------------------------------------------------
void GetWindowInfo(HWND hWnd)
{	
	DumpWindow(hWnd);
}

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 GNU General Public License (GPLv3)

Share

About the Author

Ashkbiz Danehkar
Other
Australia Australia
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140902.1 | Last Updated 19 Feb 2005
Article Copyright 2005 by Ashkbiz Danehkar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid