📄 processprioritydlg.cpp
字号:
// ProcessPriorityDlg.cpp : implementation file
//
#include "winuser.h"
#include "stdafx.h"
#include "ProcessPriority.h"
#include "ProcessPriorityDlg.h"
#include <afxpriv.h >
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProcessPriorityDlg dialog
CProcessPriorityDlg::CProcessPriorityDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProcessPriorityDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProcessPriorityDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CProcessPriorityDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProcessPriorityDlg)
DDX_Control(pDX, IDC_LIST1, m_Lsit);
DDX_Control(pDX, IDC_COMBO_THREAD, m_Thread);
DDX_Control(pDX, IDC_COMBO_PROCESS, m_Process);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProcessPriorityDlg, CDialog)
//{{AFX_MSG_MAP(CProcessPriorityDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_COMBO_PROCESS, OnSelchangeComboProcess)
ON_CBN_SELCHANGE(IDC_COMBO_THREAD, OnSelchangeComboThread)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_KICKIDLE,OnKickIdle)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProcessPriorityDlg message handlers
BOOL CProcessPriorityDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
int m,n;
m=n=m_Process.AddString("Normal");
m_Process.SetItemData(n,NORMAL_PRIORITY_CLASS);
n=m_Process.AddString("High");
m_Process.SetItemData(n,HIGH_PRIORITY_CLASS);
n=m_Process.AddString("Idle");
m_Process.SetItemData(n,IDLE_PRIORITY_CLASS);
m_Process.SetCurSel(m);
m=n=m_Thread.AddString("Normal");
m_Thread.SetItemData(n,THREAD_PRIORITY_NORMAL);
n= m_Thread.AddString("Below Normal");
m_Thread.SetItemData(n,THREAD_PRIORITY_BELOW_NORMAL);
n= m_Thread.AddString("Above Normal");
m_Thread.SetItemData(n,THREAD_PRIORITY_ABOVE_NORMAL);
n= m_Thread.AddString("Lowest");
m_Thread.SetItemData(n,THREAD_PRIORITY_LOWEST);
n= m_Thread.AddString("Highest");
m_Thread.SetItemData(n,THREAD_PRIORITY_HIGHEST);
m_Thread.SetCurSel(m);
return TRUE; // return TRUE unless you set the focus to a control
}
void CProcessPriorityDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CProcessPriorityDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CProcessPriorityDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CProcessPriorityDlg::OnIdleHanle()
{
}
LRESULT CProcessPriorityDlg::OnKickIdle(WPARAM wp, LPARAM lCount)
{
static int nCount=-1;
TCHAR sz[20];
wsprintf(sz,TEXT("%u"),++nCount);
m_Lsit.SetCurSel(m_Lsit.AddString(sz));
while(m_Lsit.GetCount()>100)
{
m_Lsit.DeleteString(0);
}
Sleep((DWORD)GetDlgItemInt(IDC_EDIT_SLEEP));
return 0;
}
//DEL int CProcessPriorityDlg::DoModal()
//DEL {
//DEL // TODO: Add your specialized code here and/or call the base class
//DEL BOOL fQuit=FALSE;
//DEL while(!fQuit)
//DEL {
//DEL MSG msg;
//DEL if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
//DEL {
//DEL if(!IsDialogMessage(&msg))
//DEL {
//DEL if(msg.message==WM_QUIT)
//DEL {
//DEL fQuit=TRUE;
//DEL }
//DEL else
//DEL {
//DEL TranslateMessage(&msg);
//DEL DispatchMessage(&msg);
//DEL }
//DEL }
//DEL }
//DEL else
//DEL {
//DEL OnIdleHanle() ;
//DEL }
//DEL }
//DEL
//DEL return CDialog::DoModal();
//DEL }
void CProcessPriorityDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
//DEL void CProcessPriorityDlg::OnEditchangeComboProcess()
//DEL {
//DEL SetPriorityClass(GetCurrentProcess(),m_Lsit.GetItemData(m_Lsit.GetCurSel()));
//DEL }
void CProcessPriorityDlg::OnSelchangeComboProcess()
{
// TODO: Add your control notification handler code here
int n=m_Process.GetCurSel();
if(!MessageBeep(0))
{
::AfxMessageBox("fail");
}
DWORD data=m_Process.GetItemData(n);
if(!SetPriorityClass(GetCurrentProcess(),data))
{
::AfxMessageBox("fail");
}
}
void CProcessPriorityDlg::OnSelchangeComboThread()
{
// TODO: Add your control notification handler code here
SetThreadPriority(GetCurrentThread(),m_Thread.GetItemData(m_Thread.GetCurSel()));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -