Fantastical Notion
//多色窗口设置
单文档+C^View的定制
#define RED RGB(255, 0, 0)
#define GREEN RGB(0, 255, 0)
#define BLUE RGB(0, 0, 255)
#define BLACK RGB(0, 0, 0)
#define GREEN RGB(0, 255, 0)
#define BLUE RGB(0, 0, 255)
#define BLACK RGB(0, 0, 0)
void CMutiColorWindowsView::OnDraw(CDC* pDC)
{
CMutiColorWindowsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
{
CMutiColorWindowsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CRect r;
// TODO: 在此处为本机数据添加绘制代码
GetClientRect(r);
if(r.right>750 && r.right<1000 || r.bottom>750 && r.bottom<1000)
pDC->FillSolidRect(r, RED);
else if(r.right>500 && r.right<750 || r.bottom>500 && r.bottom<750)
pDC->FillSolidRect(r, GREEN);
else if(r.right<500 || r.bottom<500)
pDC->FillSolidRect(r, BLUE);
else
pDC->FillSolidRect(r, BLACK);
// TODO: 在此处为本机数据添加绘制代码
GetClientRect(r);
if(r.right>750 && r.right<1000 || r.bottom>750 && r.bottom<1000)
pDC->FillSolidRect(r, RED);
else if(r.right>500 && r.right<750 || r.bottom>500 && r.bottom<750)
pDC->FillSolidRect(r, GREEN);
else if(r.right<500 || r.bottom<500)
pDC->FillSolidRect(r, BLUE);
else
pDC->FillSolidRect(r, BLACK);
}
————————————————————————————————————————————————————————————————
//不规则窗口建立
CRgn m_rgn;
BOOL CunRegularWindowsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
{
CDialog::OnInitDialog();
// 将“关于...”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
……
if (pSysMenu != NULL)
{
……
// TODO: 在此添加额外的初始化代码
CRect rcDialog;
GetClientRect(rcDialog);
m_rgn.CreateEllipticRgn(rcDialog.left, rcDialog.top, rcDialog.Width(),
rcDialog.Height());
SetWindowRgn((HRGN)m_rgn, TRUE);
m_rgn.DeleteObject();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
GetClientRect(rcDialog);
m_rgn.CreateEllipticRgn(rcDialog.left, rcDialog.top, rcDialog.Width(),
rcDialog.Height());
SetWindowRgn((HRGN)m_rgn, TRUE);
m_rgn.DeleteObject();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
——————————————————————————————————————————————————————————————————
//显示运行进程
CListCtrl m_listProcess;
CImageList m_imgSmall;
CImageList m_imgSmall;
BOOL CEnumProcessDlg::OnInitDialog()
{
……
// TODO: 在此添加额外的初始化代码
m_imgSmall.Create(16, 16, ILC_MASK | ILC_COLORDDB, 1, 100);
m_imgSmall.Create(16, 16, ILC_MASK | ILC_COLORDDB, 1, 100);
m_listProcess.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_listProcess.SetBkColor(RGB(247,247,255));
m_listProcess.SetTextColor(RGB(0,0,255));
m_listProcess.SetTextBkColor(RGB(247,247,255));
m_listProcess.InsertColumn(0, L"Process File Name", LVCFMT_LEFT, 250, 0);
m_listProcess.InsertColumn(1, L"Process ID", LVCFMT_CENTER, 100, 1);
m_listProcess.InsertColumn(2, L"Parent ProID", LVCFMT_CENTER, 100, 2);
}
void CEnumProcessDlg::OnBnClickedButtonCatch()
{
// TODO: 在此添加控件通知处理程序代码
{
// TODO: 在此添加控件通知处理程序代码
// m_listProcess.InsertItem(0,L"01");
// m_listProcess.SetItemText(0, 1, L"chetnao");
// m_listProcess.SetItemText(0, 2, L"921984");
//
// m_listProcess.InsertItem(1,L"02");
// m_listProcess.SetItemText(1,1,L"mada");
// m_listProcess.SetItemText(1,2,L"345678");
//
// m_listProcess.InsertItem(2,L"03");
// m_listProcess.SetItemText(2,1,L"luoxian");
// m_listProcess.SetItemText(2,2,L"987654");
// m_listProcess.SetItemText(0, 1, L"chetnao");
// m_listProcess.SetItemText(0, 2, L"921984");
//
// m_listProcess.InsertItem(1,L"02");
// m_listProcess.SetItemText(1,1,L"mada");
// m_listProcess.SetItemText(1,2,L"345678");
//
// m_listProcess.InsertItem(2,L"03");
// m_listProcess.SetItemText(2,1,L"luoxian");
// m_listProcess.SetItemText(2,2,L"987654");
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(snapshot == NULL) return;
m_listProcess.SetRedraw(FALSE);
if(snapshot == NULL) return;
m_listProcess.SetRedraw(FALSE);
PROCESSENTRY32 processinfo;
MODULEENTRY32 moduleinfo;
processinfo.dwSize = sizeof(processinfo);
BOOL status = Process32First(snapshot, &processinfo);
Module32First(snapshot, &moduleinfo);
SHFILEINFO shSmall;
MODULEENTRY32 moduleinfo;
processinfo.dwSize = sizeof(processinfo);
BOOL status = Process32First(snapshot, &processinfo);
Module32First(snapshot, &moduleinfo);
SHFILEINFO shSmall;
CString str;
int indexImage;
m_listProcess.SetImageList(&m_imgSmall, LVSIL_SMALL);
while(status) {
ZeroMemory(&shSmall, sizeof(shSmall));
SHGetFileInfo(moduleinfo.szExePath,
0, &shSmall,
sizeof(shSmall),
SHGFI_ICON |
SHGFI_SMALLICON);
indexImage = m_imgSmall.Add(shSmall.hIcon); //MODULEENTRY32 可以提供程序的Path但是会出现乱码
int indexImage;
m_listProcess.SetImageList(&m_imgSmall, LVSIL_SMALL);
while(status) {
ZeroMemory(&shSmall, sizeof(shSmall));
SHGetFileInfo(moduleinfo.szExePath,
0, &shSmall,
sizeof(shSmall),
SHGFI_ICON |
SHGFI_SMALLICON);
indexImage = m_imgSmall.Add(shSmall.hIcon); //MODULEENTRY32 可以提供程序的Path但是会出现乱码
//PROCESSENTRY32 只能提供filename,在ProcessID与ParentProcessID起着重要作用
int nCount = m_listProcess.GetItemCount();
int nCount = m_listProcess.GetItemCount();
m_listProcess.InsertItem(nCount, processinfo.szExeFile, indexImage);
str.Format(L"%d", processinfo.th32ProcessID);
m_listProcess.SetItemText(nCount, 1, str);
str.Format(L"%d", processinfo.th32ParentProcessID);
m_listProcess.SetItemText(nCount, 2, str);
m_listProcess.SetItemText(nCount, 1, str);
str.Format(L"%d", processinfo.th32ParentProcessID);
m_listProcess.SetItemText(nCount, 2, str);
status = Process32Next(snapshot, &processinfo);
Module32Next(snapshot, &moduleinfo);
}//while
Module32Next(snapshot, &moduleinfo);
}//while
m_listProcess.SetRedraw(TRUE);
}
// typedef struct tagPROCESSENTRY32 {
// DWORD dwSize;
// DWORD cntUsage;
// DWORD th32ProcessID;
// ULONG_PTR th32DefaultHeapID;
// DWORD th32ModuleID;
// DWORD cntThreads;
// DWORD th32ParentProcessID;
// LONG pcPriClassBase;
// DWORD dwFlags;
// TCHAR szExeFile[MAX_PATH];
// } PROCESSENTRY32, *PPROCESSENTRY32;
// typedef struct _SHFILEINFO {
// HICON hIcon;
// int iIcon;
// DWORD dwAttributes;
// TCHAR szDisplayName[MAX_PATH];
// TCHAR szTypeName[80];
// } SHFILEINFO;
————————————————————————————————————————————————————————————————
设置图标与位图
void CStaticTextDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CStatic *pStatic1 = (CStatic*) GetDlgItem(IDC_STATIC1);
pStatic1->SetWindowText("");
pStatic1->ModifyStyle(0x0, SS_ICON | SS_CENTERIMAGE);
pStatic1->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
}
void CEx5Dlg::OnButton3()
{
// TODO: Add your control notification handler code here
CStatic *pStatic3=(CStatic*)GetDlgItem(IDC_STATIC3);
pStatic3->SetWindowText("");
pStatic3->ModifyStyle(0x0,SS_BITMAP|SS_CENTERIMAGE);
pStatic3->SetBitmap(::LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP1)));
}
// HICON hIcon;
// int iIcon;
// DWORD dwAttributes;
// TCHAR szDisplayName[MAX_PATH];
// TCHAR szTypeName[80];
// } SHFILEINFO;
————————————————————————————————————————————————————————————————
设置图标与位图
void CStaticTextDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CStatic *pStatic1 = (CStatic*) GetDlgItem(IDC_STATIC1);
pStatic1->SetWindowText("");
pStatic1->ModifyStyle(0x0, SS_ICON | SS_CENTERIMAGE);
pStatic1->SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
}
void CEx5Dlg::OnButton3()
{
// TODO: Add your control notification handler code here
CStatic *pStatic3=(CStatic*)GetDlgItem(IDC_STATIC3);
pStatic3->SetWindowText("");
pStatic3->ModifyStyle(0x0,SS_BITMAP|SS_CENTERIMAGE);
pStatic3->SetBitmap(::LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP1)));
}