示例#1
0
int CTransCtrl::TestDesktop( )
{
	
	HWND temp_DeskListViewHwnd = GetDesktopListView();
	
	temp_DeskListViewHwnd = GetDesktopListView( );
	

	if( !temp_DeskListViewHwnd )
	{

		if( !IsWindowVisible( m_hDeskListViewWnd ) )
			ShowWindow( m_hDeskListViewWnd, SW_SHOWNA );
		
		return 1;
	}

	m_hDeskListViewWnd = temp_DeskListViewHwnd;	
	
	return 0;
}
示例#2
0
static unsigned int GetDesktopIconInfoListW4(std::vector<WindowIconInfo> &vec,CSAORIOutput& out)
{
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    ::GetVersionEx( &osvi );

	bool isNT = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);

	// Windows NT系でしか利用できない関数を、Windows 95系に感知させない形で
	// 呼び出すための工夫
	HMODULE hDLL = GetModuleHandle("kernel32");
	PF_VIRTUALALLOCEX pVirtualAllocEx = (PF_VIRTUALALLOCEX)GetProcAddress(hDLL,"VirtualAllocEx");
	PF_VIRTUALFREEEX  pVirtualFreeEx  = (PF_VIRTUALFREEEX)GetProcAddress(hDLL, "VirtualFreeEx");

	//デスクトップウインドウ (左上0,0)
	HWND hWnd = GetDesktopListView();
	if ( ! hWnd ) { return 0; }

	//PIDを取って、内部に領域確保
	DWORD pid;  
	::GetWindowThreadProcessId(hWnd,&pid);

	HANDLE ph;
	void *ptr;
	
	if ( isNT ) {
		ph = ::OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, pid);
		if ( ! ph ) { return 0; }

		ptr = pVirtualAllocEx(ph,NULL,BUFFER_SIZE,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE);
		if ( ! ptr ) {
			::CloseHandle(ph);
			return 0;
		}
	}
	else {
        ph = ::CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, BUFFER_SIZE,NULL);
        ptr = ::MapViewOfFile(ph, FILE_MAP_ALL_ACCESS, 0, 0, 0);
	}

	//要素取得ループ
	unsigned int count = ListView_GetItemCount(hWnd);

	WindowIconInfo info;

	for ( int i = 0 ; i < count ; ++i ) {
		//プロセス内メモリにLVITEMを書いて取得、残りの領域に文字列を書いてもらう
		LVITEM li;
		ZeroMemory(&li,sizeof(li));
		li.mask = LVIF_TEXT;  
		li.iItem = i;
		li.iSubItem = 0;
		li.cchTextMax = BUFFER_SIZE-sizeof(LVITEM)-1;
		li.pszText = reinterpret_cast<char*>(ptr)+sizeof(LVITEM);
		
		DWORD numRead;
		char text_buffer[BUFFER_SIZE-sizeof(LVITEM)];

		if ( isNT ) {
			::WriteProcessMemory(ph, ptr, &li, sizeof(LVITEM), &numRead );
		}
		else {
			memcpy(ptr, &li, sizeof(LVITEM) );
		}

		::SendMessage(hWnd, LVM_GETITEM , 0, (LPARAM)ptr);

		if ( isNT ) {
			::ReadProcessMemory(ph, reinterpret_cast<char*>(ptr)+sizeof(LVITEM), text_buffer, BUFFER_SIZE-sizeof(LVITEM)-1, &numRead );
		}
		else {
			memcpy(text_buffer, reinterpret_cast<char*>(ptr)+sizeof(LVITEM), BUFFER_SIZE-sizeof(LVITEM)-1);
		}
		
		info.m_name = SAORI_FUNC::MultiByteToUnicode(text_buffer);

		ListView_GetItemPosition(hWnd,i,ptr);

		if ( isNT ) {
			::ReadProcessMemory(ph, ptr, &info.m_pt, sizeof(POINT), &numRead );
		}
		else {
			memcpy(&info.m_pt, ptr, sizeof(POINT) );
		}

		info.m_index = i;

		vec.push_back(info);
	}

	if ( isNT ) {
		pVirtualFreeEx(ph,ptr,0,MEM_RELEASE);
		::CloseHandle(ph);
	}
	else {
		::UnmapViewOfFile(ptr);
		::CloseHandle(ph);
	}

	return count;
}