/* DumpWin.cpp --
This file is part of the "ZImport 0.1".
Copyright (C) 2006-2007 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 <stdio.h>
#include "main.h"
#include "DumpWin.h"
#ifdef _DEBUG
#define DEBUG_NEW
#endif
static int iTitle=0;
static char *szTitle=NULL;
static char szClassName[64];
static char szStyle[64];
static char szDimension[128];
static DWORD dwStyle;
static DWORD dwExtendedStyle;
static UINT dwID;
static char szProcess[64];
static char szHandle[64];
static BOOL m_bCarriageReturn;
static DWORD m_dwIndentLevel;
static DWORD m_dwIndentSize;
static DWORD m_dwDetails;
bool SaveToRegistry(bool StayOnTop);
bool LoadFromRegistry(bool *StayOnTop);
static void DumpTitle(HWND hWnd);
static void DumpClassName(HWND hWnd);
static void DumpStyles(HWND hWnd);
static 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\\ZImport");
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\\ZImport");
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);
}
//---------------------------------------------------------------------------
static 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);
}
//---------------------------------------------------------------------------
static void DumpClassName(HWND hWnd)
{
GetClassName(hWnd, szClassName, sizeof(szClassName)/sizeof(TCHAR));
SetDlgItemText(hwndMain,IDC_CLASS,szClassName);
}
//---------------------------------------------------------------------------
static void DumpStyles(HWND hWnd)
{
sprintf(szStyle, "%08X", dwStyle);
SetDlgItemText(hwndMain,IDC_STYLE,szStyle);
}
//---------------------------------------------------------------------------
static void DumpDimension(HWND hWnd)
{
RECT wndRect;
GetWindowRect(hWnd,&wndRect);
sprintf(szDimension, "(%d, %d)-(%d, %d) %dx%d",wndRect.left, wndRect.top, wndRect.right, wndRect.bottom, wndRect.right-wndRect.left, wndRect.bottom-wndRect.top);
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);
}