void CNetTrafficMonitorDlg::OnRButtonUp(UINT nFlags, CPoint point)
{
	// TODO:  在此添加消息处理程序代码和/或调用默认值
	//if (m_pSlider->IsWindowVisible())
	//{
	//	m_pSlider->ShowWindow(SW_HIDE);
	//}

	CMenu menu;
	menu.CreatePopupMenu();	// 声明一个弹出式菜单
	menu.AppendMenu(MF_STRING, IDC_SELFSTARTING, _T("开机启动"));
	//menu.AppendMenu(MF_STRING, IDC_TOPMOST, _T("置顶"));
	//CString strText;
	//strText.Format(_T("透明度: %d%%"), m_iTransparency);
	//menu.AppendMenu(MF_STRING, IDC_TRANSPARENCY, strText);
	menu.AppendMenu(MF_STRING, IDC_EXIT, _T("退出"));	// 增加菜单项“退出”,点击则发送消息给主窗口将程序结束
	if (m_bSelfStarting)
	{
		menu.SetMenuItemBitmaps(IDC_SELFSTARTING, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckYes, &m_cCheckYes);
	}
	else
	{
		menu.SetMenuItemBitmaps(IDC_SELFSTARTING, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckNo, &m_cCheckNo);
	}
	//if (m_bTopMost)
	//{
	//	menu.SetMenuItemBitmaps(IDC_TOPMOST, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckYes, &m_cCheckYes);
	//}
	//else
	//{
	//	menu.SetMenuItemBitmaps(IDC_TOPMOST, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cCheckNo, &m_cCheckNo);
	//}
	menu.SetMenuItemBitmaps(IDC_EXIT, MF_BYCOMMAND | MF_STRING | MF_ENABLED, &m_cExit, &m_cExit);
	//SetForegroundWindow();

	LPPOINT lpPoint = new tagPOINT();
	GetCursorPos(lpPoint);
	menu.TrackPopupMenu(TPM_LEFTALIGN, lpPoint->x, lpPoint->y, this);	// 确定弹出式菜单的位置

	menu.Detach();	// 资源回收
	menu.DestroyMenu();
	delete lpPoint;

	//CWnd::OnRButtonUp(nFlags, point);	// 屏蔽任务栏自己的右键菜单
}
Beispiel #2
0
void CProgressDlg::OnNMRClickListProgress(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	int nItem = pNMItemActivate->iItem;  //选中项的索引值
	if (-1 == nItem)
	{
		return ;
	}
	CMenu processMenu;   //操作目录
	processMenu.LoadMenu(IDR_MENU_PROCESS);
	CMenu *pSubMenu = processMenu.GetSubMenu(0);
	pSubMenu->SetMenuItemBitmaps(ID_PROC_TASKKILL, MF_BYCOMMAND, &m_MenuBmp[0], &m_MenuBmp[0]);  //图标
	pSubMenu->SetMenuItemBitmaps(ID_PROC_REFRESH, MF_BYCOMMAND, &m_MenuBmp[1], &m_MenuBmp[1]); 

	CPoint point;
	GetCursorPos(&point);  //获取光标位置
	pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
	*pResult = 0;
}
Beispiel #3
0
void CMainFrame::ToolbarMenu (CToolBar& wndToolbar, UINT nID) {
	int i, n, count;
	CMenu menu;
	CBitmap *bmp;
	CRect rect1, rect2;
	menu.CreatePopupMenu ();
	count = theSettings.GetSetting (nID, CSettings::sqCount);
	for (i = 0; i < count; ++i) {
		menu.AppendMenu (MF_STRING, n = theSettings.GetSetting (nID, CSettings::sqMenuID, true, (UINT)i), theSettings.GetSetting (nID, CSettings::sqName, (UINT)i));
		bmp = theApp.LoadBitmap (theSettings.GetSetting (nID, CSettings::sqBmpID, true, (UINT)i));
		menu.SetMenuItemBitmaps (n, MF_BYCOMMAND, bmp, bmp);
	}
	menu.CheckMenuRadioItem (0, count, theSettings.GetSetting (nID, CSettings::sqCurrent), MF_BYPOSITION);
	wndToolbar.GetWindowRect (&rect1);
	wndToolbar.GetToolBarCtrl ().GetRect (nID, &rect2);
	menu.TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect1.left + rect2.left, rect1.top + rect2.bottom, this);
}
Beispiel #4
0
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	// Load Lucida Grande font
	VERIFY(m_Font.CreatePointFont(80, _T("Lucida Sans Unicode")));

	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}
	m_wndStatusBar.SetPaneInfo(0,ID_INDICATOR_EVENTS,SBPS_NORMAL,60);
	m_wndStatusBar.SetPaneInfo(1,ID_SEPARATOR,SBPS_NORMAL,350);
	m_wndStatusBar.SetPaneInfo(2,ID_INDICATOR_CURSORINFO,SBPS_NORMAL,210);
	m_wndStatusBar.SetPaneInfo(3,ID_INDICATOR_IMAGEINFO,SBPS_STRETCH,0);

	m_wndStatusBar.SetFont(&m_Font);

	if( m_fastTimer == NULL )
    {
        m_fastTimer = ::SetTimer( m_hWnd, FAST_TIMER, sk_defualtFastTimerDelay, (TIMERPROC) NULL );   
    }
	if( m_slowTimer == NULL )
    {
        m_slowTimer = ::SetTimer( m_hWnd, SLOW_TIMER, sk_defualtSlowTimerDelay, (TIMERPROC) NULL );   
    }
	 	
	CFlyCap2_MFCDoc* pDoc = (CFlyCap2_MFCDoc*)GetActiveDocument();

	if (m_aboutDlg.Create(AboutDialog::IDD,this) == FALSE)
	{
		TRACE0("Failed to create about dialog box\n");
		return -1;      // fail to create UI
	}

	CMenu* mainMenu = GetMenu();
	m_bitmapHelp.LoadBitmap(IDB_BITMAP_HELP); 
	m_bitmapAbout.LoadBitmap(IDB_BITMAP_ABOUT); 
	m_bitmapSaveAs.LoadBitmap(IDB_BITMAP_SAVEAS); 
	m_bitmapExit.LoadBitmap(IDB_BITMAP_EXIT); 
	m_bitmapControl.LoadBitmap(IDB_BITMAP_CONTROL); 
	m_bitmapEventStatusBad.LoadBitmap(IDB_BITMAP_EVENT_BAD);
	m_bitmapEventStatusOK.LoadBitmap(IDB_BITMAP_EVENT_OK);
	mainMenu->SetMenuItemBitmaps(ID_LAUNCH_HELP,MF_BYCOMMAND, &m_bitmapHelp, &m_bitmapHelp);
	mainMenu->SetMenuItemBitmaps(ID_APP_ABOUT,MF_BYCOMMAND, &m_bitmapAbout, &m_bitmapAbout);
	mainMenu->SetMenuItemBitmaps(ID_FILE_SAVE_AS,MF_BYCOMMAND, &m_bitmapSaveAs, &m_bitmapSaveAs);
	mainMenu->SetMenuItemBitmaps(ID_APP_EXIT,MF_BYCOMMAND, &m_bitmapExit, &m_bitmapExit);
	mainMenu->SetMenuItemBitmaps(ID_CAMERACONTROL_TOGGLECAMERACONTROL,MF_BYCOMMAND, &m_bitmapControl, &m_bitmapControl);

    //Set Toolbar icon to true color (24 bit)
	CImageList	toolbarImageList;
	CBitmap		toolbarBitmap;

	// Create and set the enabled image list.
	toolbarBitmap.LoadBitmap(IDB_TOOLBAR_ENABLE);
	toolbarImageList.Create(30, 30, ILC_COLORDDB|ILC_MASK, 1, 1);
	toolbarImageList.Add(&toolbarBitmap, RGB(246,246,246));
	m_wndToolBar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM)toolbarImageList.m_hImageList);
	toolbarImageList.Detach();
	toolbarBitmap.Detach();

	// Create and set the disabled image list.
	toolbarBitmap.LoadBitmap(IDB_TOOLBAR_DISABLE);
	toolbarImageList.Create(30, 30, ILC_COLORDDB|ILC_MASK, 1, 1);
	toolbarImageList.Add(&toolbarBitmap, RGB(246,246,246));
	m_wndToolBar.SendMessage(TB_SETDISABLEDIMAGELIST, 0, (LPARAM)toolbarImageList.m_hImageList);
	toolbarImageList.Detach();
	toolbarBitmap.Detach();

    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	m_wndToolBar.SetFont(&m_Font);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
	return 0;
}
Beispiel #5
0
void CMainFrame::OnButtonSelectprocess()
{
	CMFCRibbonButton* pButton = (CMFCRibbonButton*)m_wndRibbonBar.FindByID( ID_BUTTON_SELECTPROCESS );
	CRect pos = pButton->GetRect( );
	ClientToScreen( &pos );

	CMenu menu;
	menu.CreatePopupMenu( );

	ClearProcMenuItems( );

	HANDLE ProcessList = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL );
	if (ProcessList != INVALID_HANDLE_VALUE)
	{
		PROCESSENTRY32 ProcInfo;
		ProcInfo.dwSize	= sizeof( PROCESSENTRY32 );
		BOOL rp = Process32First( ProcessList, &ProcInfo );

		bool bSkip = false;

		while( rp == TRUE )
		{
			// Are we filtering out processes

			if ( gbFilterProcesses )
			{
				for ( int i = 0; i < sizeof( CommonProcesses ) / sizeof( CommonProcesses[0] ) ; i ++ )
				{
					if ( strcmp( ProcInfo.szExeFile, CommonProcesses[i].c_str( ) ) == 0 )
					{
						//printf( "True %s\n", ProcInfo.szExeFile );
						bSkip = true;
					}
				}
			}

			if ( bSkip  )
			{
				bSkip = false;
				rp = Process32Next(ProcessList,&ProcInfo);
				continue;
			}

			HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, false, ProcInfo.th32ProcessID );

			if ( hProcess )
			{
				if ( is64bit( hProcess ) )
				{
					char filename[1024];
					DWORD len = sizeof(filename);
					GetModuleFileNameEx(hProcess,NULL,filename,1024);

					SHFILEINFO    sfi;
					SHGetFileInfo(filename,FILE_ATTRIBUTE_NORMAL,&sfi,sizeof(SHFILEINFO),SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);

					CBitmap* pBitmap = new CBitmap;
					CProcessMenuInfo Item;
					Item.ProcessId = ProcInfo.th32ProcessID;
					Item.pBitmap = pBitmap;

					CClientDC clDC(this);
					CDC dc;dc.CreateCompatibleDC(&clDC);
					int cx = 16;int cy = 16;
					pBitmap->CreateCompatibleBitmap(&clDC,cx,cy);
					CBitmap* pOldBmp = dc.SelectObject(pBitmap);
					dc.FillSolidRect(0,0,cx,cy,GetSysColor(COLOR_3DFACE));
					::DrawIconEx(dc.GetSafeHdc(),0,0,sfi.hIcon,cx,cy,0,NULL,DI_NORMAL);
					dc.SelectObject( pOldBmp );
					dc.DeleteDC();

					DWORD MsgID = WM_PROCESSMENU + ProcMenuItems.size();
					menu.AppendMenu( MF_STRING | MF_ENABLED, MsgID , ProcInfo.szExeFile );
					menu.SetMenuItemBitmaps(MsgID, MF_BYCOMMAND,pBitmap,pBitmap);

					ProcMenuItems.push_back(Item);
				}
				CloseHandle(hProcess);
			}
			rp = Process32Next(ProcessList,&ProcInfo);
		}
		CloseHandle(ProcessList);
	}

	menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_HORNEGANIMATION,pos.left,pos.bottom,this);
}
Beispiel #6
0
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
	m_Edit.ShowWindow(SW_HIDE);
	for (UINT i = 0; i < HotSpots.size(); i++)
	{
		if (HotSpots[i].Rect.PtInRect(point))
		{
			CNodeBase* pHitObject = (CNodeBase*)HotSpots[i].object;

			if (HotSpots[i].Type == HS_OPENCLOSE)
			{
				pHitObject->bOpen[HotSpots[i].Level] = !pHitObject->bOpen[HotSpots[i].Level];
			}
			else if (HotSpots[i].Type == HS_CLICK)
			{
				pHitObject->Update(HotSpots[i]);
			}
			else if (HotSpots[i].Type == HS_SELECT)
			{
				if (nFlags == MK_LBUTTON)
				{
					theApp.ClearSelection();
					Selected.clear();
					pHitObject->bSelected = true;
					Selected.push_back(HotSpots[i]);
				}
				if (nFlags == (MK_LBUTTON | MK_CONTROL))
				{
					pHitObject->bSelected = !pHitObject->bSelected;
					if (pHitObject->bSelected)
					{
						Selected.push_back(HotSpots[i]);
					}
					else
					{
						for (UINT s = 0; s < Selected.size(); s++)
						{
							if (Selected[s].object == pHitObject)
							{
								Selected.erase(Selected.begin() + s);
								break;
							}
						}
					}
				}
				if (nFlags == (MK_LBUTTON | MK_SHIFT))
				{
					if (Selected.size() > 0)
					{
						CNodeBase* pSelected = Selected[0].object;
						if (pSelected->pParent != pHitObject->pParent)
							continue;
						CNodeClass* pClass = (CNodeClass*)pSelected->pParent;
						//if (pClass->GetType() != nt_class) continue;

						UINT idx1 = FindNodeIndex(pSelected);
						if (idx1 == MAX_NODES)
							continue;
						UINT idx2 = FindNodeIndex(pHitObject);
						if (idx2 == MAX_NODES)
							continue;
						if (idx2 < idx1)
						{
							UINT idxTemp = idx1;
							idx1 = idx2;
							idx2 = idxTemp;
						}

						theApp.ClearSelection();
						Selected.clear();
						for (UINT s = idx1; s <= idx2; s++)
						{
							pClass->Nodes[s]->bSelected = true;
							HotSpot spot;
							//ZeroMemory(&spot, sizeof(HotSpot));
							spot.Address = pClass->offset + pClass->Nodes[s]->offset;
							spot.object = pClass->Nodes[s];
							Selected.push_back(spot);
						}
					}
				}
			}
			else if (HotSpots[i].Type == HS_DROP)
			{
				CRect client;
				GetClientRect(&client);
				ClientToScreen(&client);
				CMenu menu;
				menu.LoadMenu(MAKEINTRESOURCE(IDR_MENU_QUICKMODIFY));
				menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_HORNEGANIMATION, client.left + HotSpots[i].Rect.left, client.top + HotSpots[i].Rect.bottom, this);
			}
			else if (HotSpots[i].Type == HS_DELETE)
			{
				//isDeleting = true; // Ghetto fix to stop crashing from OnMouseHover
				for (UINT i = 0; i < Selected.size(); i++)
				{
					CNodeClass* pClass = (CNodeClass*)Selected[i].object->pParent;
					UINT idx = FindNodeIndex(Selected[i].object);
					if (idx != MAX_NODES)
					{
						delete pClass->Nodes[idx];
						pClass->Nodes.erase(pClass->Nodes.begin() + idx);
						theApp.CalcAllOffsets();
					}
				}
				Selected.clear();
				//isDeleting = false;
			}
			else if ((HotSpots[i].Type == HS_CHANGE_A) || (HotSpots[i].Type == HS_CHANGE_X))
			{
				ExchangeTarget = HotSpots[i];
				CRect pos = ExchangeTarget.Rect;
				ClientToScreen(&pos);

				CNodeBase* pNode = HotSpots[i].object;

				CMenu menu;
				menu.CreatePopupMenu();

				CImage img;
				img.LoadFromResource(AfxGetResourceHandle(), IDB_CLASSBITMAP);
				CBitmap bmp;
				bmp.Attach(img.Detach());

				for (UINT m = 0; m < theApp.Classes.size(); m++)
				{
					if ((HotSpots[i].Type == HS_CHANGE_X) && (pNode->pParent == theApp.Classes[m]))
						continue;
					menu.AppendMenu(MF_STRING | MF_ENABLED, WM_CHANGECLASSMENU + m, theApp.Classes[m]->Name);
					menu.SetMenuItemBitmaps(m, MF_BYPOSITION, &bmp, &bmp);
				}
				menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_NOANIMATION, pos.left, pos.bottom, this);
			}
			Invalidate();
		}
	}

	CWnd::OnLButtonDown(nFlags, point);
}
Beispiel #7
0
CMenu* CCementBD::SetModulesExtern()
{
	if(gListModuleExternal.GetCount() == 0) return 0;
    //---------------------------------------------------
    //Формируем меню внешних модулей
    CCementDoc* pDoc = (CCementDoc*)GetDocument();
	HINSTANCE hInst = AfxGetResourceHandle();
    pDoc->m_DefaultMenu = 
        ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_KRSCEMENTTYPE));
    if (pDoc->m_DefaultMenu == NULL)
        return 0;

    CMenu* menu = CMenu::FromHandle(pDoc->GetDefaultMenu());
    if(menu)
    {
        int iPos;
        CMenu* pPopup = NULL;
        for(iPos = 0; iPos < (int)menu->GetMenuItemCount(); iPos++)
        {
            if(menu->GetSubMenu(iPos)->GetMenuItemID(0) == ID_NASTROIKA_MODULES) 
            {
                pPopup = menu->GetSubMenu(iPos);
 		int ii = (int)pPopup->GetMenuItemCount();
               break;
            }
        }
        if(pPopup == NULL) return 0;


		CMenu *submenu = menu->GetSubMenu(iPos);
		if(submenu == NULL) return 0;
		int ii = (int)submenu->GetMenuItemCount();


        int cx = ::GetSystemMetrics(SM_CXMENUCHECK);
        int cy = ::GetSystemMetrics(SM_CYMENUCHECK);
        if(pPopup != NULL && gListModuleExternal.GetCount() > 0) 
        {
            pPopup->AppendMenu(MF_SEPARATOR, 0, LPCTSTR(0));

            for(int i = 0; i < gListModuleExternal.GetCount(); i++)
            {
                HICON hIconLarge, hIcon;
//                ExtractIconEx(gListModuleExternal.GetName2(i), 0, &hIconLarge, &hIcon, 1);
				CString Name2 = gListModuleExternal.GetName2txe(i);
				if(Name2.GetLength() == 0) continue;
				ExtractIconEx(Name2, 0, &hIconLarge, &hIcon, 1);
                //HICON hIcon = ExtractIcon(pApp->m_hInstance, gListModuleExternal.GetName2(i), 0);
                if(hIcon != NULL)
                {
                    ICONINFO iconinfo;
                    GetIconInfo(hIcon, &iconinfo);
                    HANDLE hLoad = CopyImage(HANDLE(iconinfo.hbmColor), IMAGE_BITMAP, cx+1, cy+1, LR_COPYFROMRESOURCE);
                    CBitmap *pBmp = CBitmap::FromHandle(HBITMAP(hLoad));
                    CString str;
                    str.Format(" %d", i);
                    str += ".  " + gListModuleExternal.GetName(i);
                    BOOL flg = pPopup->AppendMenu(MF_STRING | MF_ENABLED, ID_MENU_MODULE_EXTERNAL + i, str);
                    pPopup->SetMenuItemBitmaps(i+2, MF_BYPOSITION, pBmp, pBmp);
                    //BOOL res = menu->SetMenuItemBitmaps(2, MF_BYPOSITION, pBmp, pBmp);
                    //int zzz = 0;
                }
            }
        }
        CMDIFrameWnd* frame = ((CMDIChildWnd *) GetParent())->GetMDIFrame();
        frame->MDISetMenu(menu, NULL);
        frame->DrawMenuBar();
    }
    //-------------------------------------------------------------------------
	return menu;
}
Beispiel #8
0
void CMainFrame::OnButtonSelectProcess()
{
	HANDLE hProcess = 0;
	void* pBuffer = NULL;
	ULONG cbBuffer = 0x20000;
	HANDLE hHeap = NULL;
	NTSTATUS Status = STATUS_INFO_LENGTH_MISMATCH;
	bool bHasEnumeratedProcesses = false;
	PSYSTEM_PROCESS_INFORMATION infoP = NULL;

	CMFCRibbonButton* pButton = NULL;
	
	pButton = static_cast<CMFCRibbonButton*>(m_wndRibbonBar.FindByID(ID_BUTTON_SELECTPROCESS));

	CRect pos = pButton->GetRect();
	ClientToScreen(&pos);

	CMenu menu;
	menu.CreatePopupMenu();

	ClearProcMenuItems();

	static HMODULE hNtdll = (HMODULE)Utils::GetLocalModuleHandle("ntdll.dll");
	static tNtQuerySystemInformation fnQSI = (tNtQuerySystemInformation)Utils::GetProcAddress(hNtdll, "NtQuerySystemInformation");

	hHeap = GetProcessHeap();
	Status = STATUS_INFO_LENGTH_MISMATCH;

	while (!bHasEnumeratedProcesses)
	{
		pBuffer = HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cbBuffer);
		if (pBuffer == NULL)
			return;

		Status = fnQSI(SystemProcessInformation, pBuffer, cbBuffer, &cbBuffer);
		if (Status == STATUS_INFO_LENGTH_MISMATCH)
		{
			HeapFree(hHeap, NULL, pBuffer);
			cbBuffer *= 2;
		}
		else if (!NT_SUCCESS(Status))
		{
			HeapFree(hHeap, NULL, pBuffer);
			return;
		}
		else
		{
			bHasEnumeratedProcesses = true;
			infoP = (PSYSTEM_PROCESS_INFORMATION)pBuffer;
			while (infoP)
			{	
				if (infoP->ImageName.Length)
				{
					char pName[256];
					memset(pName, 0, sizeof(pName));
					WideCharToMultiByte(0, 0, infoP->ImageName.Buffer, infoP->ImageName.Length, pName, 256, NULL, NULL);
					// Are we filtering out processes
					if (gbFilterProcesses)
					{
						bool skip = false;
						for (int i = 0; i < sizeof(CommonProcesses) / sizeof(*CommonProcesses); i++) 
						{
							if ( _stricmp( pName, CommonProcesses[ i ] ) == 0 || (DWORD)infoP->UniqueProcessId == GetCurrentProcessId( ) )
							{
								skip = true;
								break;
							}
						}

						if (skip)
						{
							if (!infoP->NextEntryOffset)
								break;
							infoP = (PSYSTEM_PROCESS_INFORMATION)((unsigned char*)infoP + infoP->NextEntryOffset);
							continue;
						}
					}

					hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, (DWORD)infoP->UniqueProcessId);
					if (hProcess)
					{
						#ifdef _WIN64
						if (Utils::GetProcessPlatform(hProcess) == Utils::ProcessPlatformX64)
						#else
						if (Utils::GetProcessPlatform(hProcess) == Utils::ProcessPlatformX86)
						#endif
						{
							TCHAR filename[1024];
							GetModuleFileNameEx(hProcess, NULL, filename, 1024);

							SHFILEINFO sfi;
							SHGetFileInfo(filename, FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);

							CBitmap* pBitmap = new CBitmap();
							CProcessMenuInfo Item;
							Item.ProcessId = (DWORD)infoP->UniqueProcessId;
							Item.pBitmap = pBitmap;

							CClientDC clDC(this);
							CDC dc; dc.CreateCompatibleDC(&clDC);

							int size = 16;
							pBitmap->CreateCompatibleBitmap(&clDC, size, size);
							CBitmap* pOldBmp = dc.SelectObject(pBitmap);

							dc.FillSolidRect(0, 0, size, size, GetSysColor(COLOR_3DFACE));
							::DrawIconEx(dc.GetSafeHdc(), 0, 0, sfi.hIcon, size, size, 0, NULL, DI_NORMAL);
							dc.SelectObject(pOldBmp);
							dc.DeleteDC();

							DWORD MsgID = (DWORD)(WM_PROCESSMENU + ProcMenuItems.size());

							CString proccessString;
							proccessString.Format(_T("%hs (%i)"), pName, (DWORD)infoP->UniqueProcessId); 

							menu.AppendMenu(MF_STRING | MF_ENABLED, MsgID, proccessString.GetBuffer());
							menu.SetMenuItemBitmaps(MsgID, MF_BYCOMMAND, pBitmap, pBitmap);

							ProcMenuItems.push_back(Item);
						}

						CloseHandle(hProcess);
					}
				}

				if (!infoP->NextEntryOffset)
					break;
				infoP = (PSYSTEM_PROCESS_INFORMATION)((unsigned char*)infoP + infoP->NextEntryOffset);
			}
		}
	}

	menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_HORNEGANIMATION, pos.left, pos.bottom, this);
	
	return;
}
Beispiel #9
0
void CFileView::OnNMRClickListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	CString strCurPath;
	GetDlgItem(IDC_EDIT_CURPATH)->GetWindowText(strCurPath);
	if (strCurPath.IsEmpty())
	{
		return;
	}
	CMenu fileMenu;
	fileMenu.LoadMenu(IDR_MENU_FILE);
	CMenu *pSubMenu = fileMenu.GetSubMenu(0);
    
	pSubMenu->SetMenuItemBitmaps(ID_FILE_RUN, MF_BYCOMMAND, &m_MenuBmp[0], &m_MenuBmp[0]);  //运行
	pSubMenu->SetMenuItemBitmaps(ID_FILE_FLUSH, MF_BYCOMMAND, &m_MenuBmp[1], &m_MenuBmp[1]); //刷新
	pSubMenu->SetMenuItemBitmaps(ID_FILE_COPY, MF_BYCOMMAND, &m_MenuBmp[2], &m_MenuBmp[2]);   //copy
	pSubMenu->SetMenuItemBitmaps(ID_FILE_PASTE, MF_BYCOMMAND, &m_MenuBmp[3], &m_MenuBmp[3]);   //paste
	pSubMenu->SetMenuItemBitmaps(ID_FILE_DEL, MF_BYCOMMAND, &m_MenuBmp[4], &m_MenuBmp[4]);   //删除
	pSubMenu->SetMenuItemBitmaps(ID_FILE_UPLOAD, MF_BYCOMMAND, &m_MenuBmp[5], &m_MenuBmp[5]);   //上传
	pSubMenu->SetMenuItemBitmaps(ID_FILE_DOWNLOAD, MF_BYCOMMAND, &m_MenuBmp[6], &m_MenuBmp[6]);  //下载
	pSubMenu->SetMenuItemBitmaps(ID_FILE_CREATE, MF_BYCOMMAND, &m_MenuBmp[7], &m_MenuBmp[7]);  //新建
    int nItem = pNMItemActivate->iItem;  //选中项的索引值
    if (-1 == nItem) //没有选中项
	{
		pSubMenu->EnableMenuItem(ID_FILE_RUN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		pSubMenu->EnableMenuItem(ID_FILE_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		pSubMenu->EnableMenuItem(ID_FILE_DEL, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		pSubMenu->EnableMenuItem(ID_FILE_DOWNLOAD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		pSubMenu->EnableMenuItem(ID_FILE_RENAME, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		pSubMenu->EnableMenuItem(ID_FILE_ATTRIBUTE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		if (!m_bCopy)  //能不能拷贝
		{
			pSubMenu->EnableMenuItem(ID_FILE_PASTE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);   //粘贴
		}
	}
	else
	{
		CString strType = m_listCtrl.GetItemText(nItem, 1);
		if (_T("文件夹") == strType) //选中的是文件夹
		{
			pSubMenu->EnableMenuItem(ID_FILE_RUN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);   //运行
			pSubMenu->EnableMenuItem(ID_FILE_COPY, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //复制
			pSubMenu->EnableMenuItem(ID_FILE_PASTE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //粘贴
			pSubMenu->EnableMenuItem(ID_FILE_UPLOAD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //上传
			pSubMenu->EnableMenuItem(ID_FILE_DOWNLOAD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); //下载
			pSubMenu->EnableMenuItem(ID_FILE_CREATE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //新建文件夹
			pSubMenu->EnableMenuItem(ID_FILE_ATTRIBUTE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
		}
		else //选中是文件
		{
			pSubMenu->EnableMenuItem(ID_FILE_PASTE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //粘贴
			pSubMenu->EnableMenuItem(ID_FILE_UPLOAD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //上传
			pSubMenu->EnableMenuItem(ID_FILE_CREATE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);  //新建文件夹
		}
	}
	CPoint point;
	GetCursorPos(&point);  //获取光标位置
	pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, this);
	*pResult = 0;
}