Click here to Skip to main content
12,999,845 members (51,452 online)
Click here to Skip to main content


90 bookmarked
Posted 26 Jun 2005

Shell Tray Info - Arrange your system tray icons

, 26 Jun 2005
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 the Principal Software Architect/Consultant for Ganymede Software Solutions LLC, and is based out of Columbus, Ohio. He has over 17 years of software industry experience in various roles including Lead Software Architect, Principal Software Engineer, and Product Manager. Nish was a Microsoft Visual C++ MVP between 2002 and 2015.

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 : If you are interested in hiring Nish as a consultant, you can reach him via his google email id voidnish.

Company Website :

You may also be interested in...

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