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

Professional System Library: Introduction

, 22 Nov 2010
A simplified and unified way for accessing most frequently used information about Process, System, and Environment.
ProcessViewer32_bin.zip
SimpleProcessViewer.exe
Interop.ProSysLib.dll
ProSysLib.dll
ProcessViewer64_bin.zip
SimpleProcessViewer.exe
Interop.ProSysLib.dll
ProSysLib.dll
ProcessViewer_bin.zip
PSL64v0.9.dll
Interop.ProSysLib.dll
ProcessViewer.exe
PSL32v0.9.dll
ProSysLib_v0.9.zip
ProSysLib_v0.9
Bin
PSL32v0.9.dll
PSL64v0.9.dll
Help
Samples
C#2008
ProcessInfo
Properties
Settings.settings
ProcessViewer
Properties
Settings.settings
VB6
CPUInfo.exe
CPUInfo.frm
CPUInfo.frx
CPUInfo.vbp
CPUInfo.vbw
VC2008
Deployment
Src
mssccprj.scc
ProSysLib.def
ProSysLib.rgs
ProSysLib.vcproj.vspscc
ProSysLib.vssscc
PSLSystem.rgs
PSLv0.3Setup.zip
PSLv0.3Setup.exe
PSLv0.4Setup.zip
PSLv0.4Setup.exe
PSLv0.7Setup.zip
PSLv0.7Setup.exe
SimpleProcessViewer_src.zip
SimpleProcessViewer
Properties
Settings.settings
// PSLWindow.cpp : Implementation of CPSLWindow

#include "stdafx.h"
#include "PSLWindow.h"

CPSLWindow::CPSLWindow()
{
	m_dwThreadID = 0;
	m_dwProcessID = 0;
}

HRESULT CPSLWindow::FinalConstruct()
{
	return S_OK;
}

void CPSLWindow::FinalRelease()
{
}

void CPSLWindow::Initialize(HWND hWnd)
{
	if(!m_hWnd)
	{
		Attach(hWnd);
		m_dwThreadID = ::GetWindowThreadProcessId(m_hWnd, &m_dwProcessID);
	}
}

bool CPSLWindow::IsValidWindow()
{
	if(m_hWnd)
	{
		if(IsWindow())
			return true;
		else
			m_hWnd = NULL;
	}
	return false;
}

////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////

STDMETHODIMP CPSLWindow::get_ID(VARIANT * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		CPSLUtilities::SetVariantBig(pValue, GetWindowLongPtr(GWLP_ID));
	else
		CPSLUtilities::SetVariantBig(pValue, 0);

	PSL_END
}

STDMETHODIMP CPSLWindow::put_ID(VARIANT newValue)
{
	PSL_BEGIN

	if(IsValidWindow())
	{
		bool bError = false;
		ABIG ID = CPSLUtilities::GetVariantBig(&newValue, &bError);
		if(!bError)
			SetWindowLongPtr(GWLP_ID, ID);
	}

	PSL_END
}

STDMETHODIMP CPSLWindow::get_Style(long * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = GetWindowLong(GWL_STYLE);
	else
		*pValue = 0;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_StyleEx(long * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = GetWindowLong(GWL_EXSTYLE);
	else
		*pValue = 0;

	PSL_END
}

STDMETHODIMP CPSLWindow::put_Style(long newValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		SetWindowLong(GWL_STYLE, newValue);

	PSL_END
}

STDMETHODIMP CPSLWindow::put_StyleEx(long newValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		SetWindowLong(GWL_EXSTYLE, newValue);

	PSL_END
}

STDMETHODIMP CPSLWindow::get_UserData(VARIANT * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		CPSLUtilities::SetVariantBig(pValue, GetWindowLongPtr(GWLP_USERDATA));
	else
		CPSLUtilities::SetVariantBig(pValue, 0);

	PSL_END
}

STDMETHODIMP CPSLWindow::put_UserData(VARIANT newValue)
{
	PSL_BEGIN

	if(IsValidWindow())
	{
		bool bError = false;
		ABIG UserData = CPSLUtilities::GetVariantBig(&newValue, &bError);
		if(!bError)
			SetWindowLongPtr(GWLP_USERDATA, UserData);
	}

	PSL_END
}

STDMETHODIMP CPSLWindow::get_Handle(VARIANT * pValue)
{
	PSL_BEGIN

	IsValidWindow();
	CPSLUtilities::SetVariantBig(pValue, (ABIG)m_hWnd);

	PSL_END
}

STDMETHODIMP CPSLWindow::get_Parent(IPSLWindow ** ppValue)
{
	PSL_BEGIN

	*ppValue = m_ParentWnd;
	if(IsValidWindow())
	{
		HWND hParentWnd = ::GetParent(m_hWnd);
		if(::IsWindow(hParentWnd))
		{
			CPSLWindow * pWindow = m_ParentWnd;
			pWindow->Initialize(hParentWnd);
			pWindow->Release();
		}
	}

	PSL_END
}

STDMETHODIMP CPSLWindow::get_ClassName(BSTR * pValue)
{
	PSL_BEGIN

	TCHAR buffer[256];
	buffer[0] = '\0';
	if(IsValidWindow())
		::GetClassName(m_hWnd, buffer, 256);
	*pValue = ::SysAllocString(buffer);
	
	PSL_END
}

STDMETHODIMP CPSLWindow::get_ThreadID(long * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = m_dwThreadID;
	else
		*pValue = 0;
	
	PSL_END
}

STDMETHODIMP CPSLWindow::get_ProcessID(long * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = m_dwProcessID;
	else
		*pValue = 0;
	
	PSL_END
}

STDMETHODIMP CPSLWindow::get_IsValid(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	*pValue = IsWindow()?VARIANT_TRUE:VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_IsChild(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = ((GetStyle() & WS_CHILD) == WS_CHILD)?VARIANT_TRUE:VARIANT_FALSE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_IsTopLevel(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = ((GetStyle() & WS_CHILD) == WS_CHILD)?VARIANT_FALSE:VARIANT_TRUE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_IsVisible(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = IsWindowVisible()?VARIANT_TRUE:VARIANT_FALSE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_IsExternal(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = (m_dwProcessID == ::GetCurrentProcessId())?VARIANT_FALSE:VARIANT_TRUE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_IsBridge(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
	{
		HWND hParentWnd = ::GetParent(m_hWnd);
		if(::IsWindow(hParentWnd))
		{
			DWORD dwProcessID = 0;
			::GetWindowThreadProcessId(hParentWnd, &dwProcessID);
			*pValue = (m_dwProcessID == dwProcessID)?VARIANT_FALSE:VARIANT_TRUE;
		}
		else
			*pValue = VARIANT_FALSE;
	}
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::get_Enabled(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = IsWindowEnabled()?VARIANT_TRUE:VARIANT_FALSE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::put_Enabled(VARIANT_BOOL newValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		EnableWindow(newValue?TRUE:FALSE);

	PSL_END
}

STDMETHODIMP CPSLWindow::get_Text(BSTR * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
	{
		int iLength = ::GetWindowTextLength(m_hWnd);
		TCHAR * pBuffer = new TCHAR[iLength + 1];
		::GetWindowText(m_hWnd, pBuffer, iLength + 1);
		*pValue = ::SysAllocString(pBuffer);
		delete []pBuffer;
	}
	else
		*pValue = _bstr_t(_T("")).copy();

	PSL_END
}

STDMETHODIMP CPSLWindow::put_Text(BSTR newValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		SetWindowText(_bstr_t(newValue));

	PSL_END
}

STDMETHODIMP CPSLWindow::SendMsg(long Msg, VARIANT wParam, VARIANT lParam, VARIANT * pValue)
{
	PSL_BEGIN

	_bstr_t wText, lText;
	if(IsValidWindow())
	{
		WPARAM W = 0;
		LPARAM L = 0;
		bool bError = false;
		if(wParam.vt == VT_BSTR)
		{
			wText = wParam.bstrVal;
			W = (WPARAM)(LPCTSTR)wText;
		}
		else
		{
			W = CPSLUtilities::GetVariantBig(&wParam, &bError);
			if(bError)
				return MakeException(exInvalidParameter);
		}
		if(lParam.vt == VT_BSTR)
		{
			lText = lParam.bstrVal;
			L = (LPARAM)(LPCTSTR)lText;
		}
		else
		{
			L = CPSLUtilities::GetVariantBig(&lParam, &bError);
			if(bError)
				return MakeException(exInvalidParameter);
		}
		LRESULT lResult = ::SendMessage(m_hWnd, Msg, W, L);
		CPSLUtilities::SetVariantBig(pValue, lResult);
	}

	PSL_END
}

STDMETHODIMP CPSLWindow::PostMsg(long Msg, VARIANT wParam, VARIANT lParam, VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	*pValue = VARIANT_FALSE;
	if(IsValidWindow())
	{
		bool bError = false;
		WPARAM W = CPSLUtilities::GetVariantBig(&wParam, &bError);
		if(bError)
			return MakeException(exInvalidParameter);
		LPARAM L = CPSLUtilities::GetVariantBig(&lParam, &bError);
		if(bError)
			return MakeException(exInvalidParameter);
		*pValue = ::PostMessage(m_hWnd, Msg, W, L);
	}

	PSL_END
}

STDMETHODIMP CPSLWindow::Destroy(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = CWindow::DestroyWindow()?VARIANT_TRUE:VARIANT_FALSE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLWindow::Update(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	if(IsValidWindow())
		*pValue = CWindow::UpdateWindow()?VARIANT_TRUE:VARIANT_FALSE;
	else
		*pValue = VARIANT_FALSE;

	PSL_END
}

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

Vitaly Tomilov
Software Developer (Senior) Sibedge IT
Ireland Ireland
My online CV: cv.vitalytomilov.com

| Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 22 Nov 2010
Article Copyright 2008 by Vitaly Tomilov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid