Click here to Skip to main content
11,795,848 members (79,766 online)
Click here to Skip to main content
Add your own
alternative version

Shell Tray Info - Arrange your system tray icons

, 26 Jun 2005 CPOL 236.8K 7.4K 89
A tool with full source code that enumerates tray icons and allows you to reposition them as well as send mouse messages.
	Author	:	Nishant Sivakumar
	Date	:	June 9, 2005
	Info	:	Template class that makes it easy to use data allocated
				in a different process. Useful when making inter-process
				SendMessage/PostMessage calls.			
	Contact	:


#pragma once

template<typename T> class CProcessData
		If you pass in a dwProcessId of 0, the current process Id is used.
		For the other arguments, see MSDN documentation for OpenProcess and
	CProcessData(DWORD dwProcessId = 0, DWORD dwDesiredAccess = PROCESS_ALL_ACCESS,
		DWORD flAllocationType = MEM_COMMIT, DWORD flProtect = PAGE_READWRITE)
		m_hProcess = OpenProcess(dwDesiredAccess, FALSE, 
			dwProcessId ? dwProcessId : GetCurrentProcessId());
			m_lpData = VirtualAllocEx(m_hProcess, NULL, sizeof T, 
				flAllocationType, flProtect);

				VirtualFreeEx(m_hProcess, m_lpData, NULL, MEM_RELEASE);

	//WriteData is used to copy data to memory in the foreign process
	BOOL WriteData(const T& data)
		return (m_hProcess && m_lpData) ? WriteProcessMemory(m_hProcess, m_lpData, 
			(LPCVOID)&data, sizeof T, NULL) : FALSE;

	//ReadData reads back data from memory in the foreign process
	BOOL ReadData(T* data)
		return (m_hProcess && m_lpData) ? ReadProcessMemory(m_hProcess, m_lpData, 
			(LPVOID)data, sizeof T, NULL) : FALSE;

	//Templated ReadData that's used to read a specific data type from
	//a memory address located in the foreign process
	template<typename TSUBTYPE> BOOL ReadData(TSUBTYPE* data, LPCVOID lpData)
		return m_hProcess ? ReadProcessMemory(m_hProcess, lpData, 
			(LPVOID)data, sizeof TSUBTYPE, NULL) : FALSE;

	//Gets the address of the allocated memory in the foreign process
	const T* GetData()
		return (m_hProcess && m_lpData) ? (T*)m_lpData : NULL;
	HANDLE m_hProcess;
	LPVOID m_lpData;

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nish Nishant
United States United States
Nish Nishant is a Software Architect/Consultant based out of Columbus, Ohio. He has over 15 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish is a recipient of the annual Microsoft Visual C++ MVP Award since 2002 (13 consecutive awards as of 2014).

Nish is an industry acknowledged expert in the Microsoft technology stack. He authored
C++/CLI in Action for Manning Publications in 2005, and had previously co-authored
Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on and another 250+ blog articles on his
WordPress blog. Nish is vastly experienced in team management, mentoring teams, and directing all stages of software development.

Contact Nish : You can reach Nish on his google email id voidnish.

Website and Blog

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151002.1 | Last Updated 27 Jun 2005
Article Copyright 2005 by Nish Nishant
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid