ALT+TAB切换时小图标的添加 界面透明 屏幕大小 竖行字体 进程信息
一,ALT+TAB切换时小图标的添加 1 Dlg类中添加变量 protected: HICON m_hIcon; #define IDR_MAINFRAME 128 ICON IDR_MAINFRAME,IDC_STATIC,11,17,20,20 // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDR_MAINFRAME ICON DISCARDABLE "res\\crtApp.ico" 2 构造函数中加载 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 3 初始化 SetIcon(m_hIcon, TRUE); // Set big icon ALT+TAB SetIcon(m_hIcon, FALSE); // Set small icon 左上角小图标 4 使用 // Draw the icon dc.DrawIcon(100, 100, m_hIcon); // The system calls this to obtain the cursor to display while the user drags // the minimized window. Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } 二 Dlg::OnInitDialog() 1 获取屏幕大小 int w = GetSystemMetrics(SM_CXSCREEN); int h = GetSystemMetrics(SM_CYSCREEN); 2 界面透明 SetWindowPos(&wndTopMost,0,300,30,150,SWP_SHOWWINDOW); //移动界面位置 MoveWindow(0,300,30,150, TRUE); //移动界面位置 //VS2003以上版本 //SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(GetSafeHwnd (),GWL_EXSTYLE)|WS_EX_LAYERED); //SetLayeredWindowAttributes(0,200,LWA_ALPHA); //VS2003以下版本 SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) |0x00080000); HINSTANCE hInst = LoadLibrary(_T("User32.dll")); if (hInst) { typedef BOOL (WINAPI *MyFun)(HWND,COLORREF,BYTE,DWORD); MyFun myfun = NULL; myfun = (MyFun)GetProcAddress(hInst, "SetLayeredWindowAttributes"); if (myfun) myfun(GetSafeHwnd(),0,100,2); FreeLibrary(hInst); } 3, //竖行字体 Dlg::OnPaint() { CPaintDC dc(this);// device context for painting CRect rtClient; GetClientRect(rtClient); //获取客户区尺寸、位置信息 /////// 利用CFont::CreateFont(...)函数实现竖写汉字//////// CFont myFont; //创建字体对象 //创建逻辑字体 myFont.CreateFont(40, //字体高度(旋转后的字体宽度)=56 10, //字体宽度(旋转后的字体高度)=20 2700, //字体显示角度=270° 0, //nOrientation=0 6, //字体磅数=10 FALSE, //非斜体 FALSE, //无下划线 FALSE, //无删除线 DEFAULT_CHARSET, //使用缺省字符集 OUT_DEFAULT_PRECIS, //缺省输出精度 CLIP_DEFAULT_PRECIS,//缺省裁减精度 DEFAULT_QUALITY, //nQuality=缺省值 DEFAULT_PITCH, //nPitchAndFamily=缺省值 "@system"); //字体名=@system CFont *pOldFont=dc.SelectObject(&myFont);//选入设备描述表 //在客户区适当位置输出文字 dc.TextOut(rtClient.Width()/2+8,2, "单击返回主界面"); dc.SelectObject(pOldFont); //将myFont从设备环境中分离 myFont.DeleteObject(); //删除myFont对象 /* /////////// 利用LOGFONT结构实现竖写汉字////////////// LOGFONT lf; //定义字体结构 lf.lfWeight=8; //字体磅数=10 lf.lfHeight=20; //字体高度(旋转后的字体宽度)=56 lf.lfWidth=10; //字体宽度(旋转后的字体高度)=20 lf.lfUnderline=FALSE; //无下划线 lf.lfStrikeOut=FALSE; //无删除线 lf.lfItalic=FALSE; //非斜体 lf.lfEscapement=2700; //字体显示角度=270° lf.lfCharSet=DEFAULT_CHARSET; //使用缺省字符集 strcpy(lf.lfFaceName,"@system"); //字体名=@system CFont myLogFont; //定义字体对象 myLogFont.CreateFontIndirect(&lf); //创建逻辑字体 pOldFont=dc.SelectObject(&myLogFont);//选入设备描述表 //在客户区适当位置输出文字 // dc.TextOut(rtClient.Width()/2+5,rtClient.Height()/32, "点击返回主界面"); dc.SelectObject(pOldFont); //将myFont从设备环境中分离 myLogFont.DeleteObject(); //删除myLogFont对象 */ ... } 三 进程信息 #include <tlhelp32.h> long FindTargetProcess(const CString &m_strProcessName) { int nRet = 0; HANDLE hFind = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 *info = new PROCESSENTRY32; info->dwSize = sizeof(PROCESSENTRY32); nRet = 0; if (::Process32First(hFind, info) != NULL) { CString strName; while (::Process32Next(hFind, info) != FALSE) { strName = info->szExeFile; if (strName == m_strProcessName) { if (strName == "cmd.exe") { CString strCmd; strCmd.Format("taskkill /f /pid %u", info- >th32ProcessID); ::system(strCmd); } HANDLE hOpenPro = OpenProcess(PROCESS_ALL_ACCESS, TRUE, info->th32ProcessID); if (hOpenPro != NULL) { Sleep(200); nRet = 0; ::TerminateProcess(hOpenPro, 0); Sleep(1000); } } } ::CloseHandle(hFind); if (info != NULL) { delete info; } } return nRet; } //ExitProcess(0); char app[100] = {0}; long FindTargetProcess2(const CString &m_strProcessName) { int nRet = 0; HANDLE hFind = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 *info = new PROCESSENTRY32; info->dwSize = sizeof(PROCESSENTRY32); nRet = 0; DWORD pid = 0; if (::Process32First(hFind, info) != NULL) { CString strName; while (::Process32Next(hFind, info) != FALSE) { strName = info->szExeFile; if (strName == m_strProcessName) { pid = info->th32ProcessID; HANDLE hOpenPro = OpenProcess(PROCESS_ALL_ACCESS, TRUE, info->th32ProcessID); if (hOpenPro != NULL) { } } } ::CloseHandle(hFind); if (info != NULL) { delete info; } } return pid; } BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { DWORD pid = 0; DWORD tid = GetWindowThreadProcessId(hwnd, &pid); if (pid == (DWORD)lParam) { // printf("pid:%d\n", pid, tid); // DWORD lid = GetCurrentThreadId(); // AttachThreadInput(tid, lid, TRUE ); int w = GetSystemMetrics(SM_CXSCREEN); int h = GetSystemMetrics(SM_CYSCREEN); // BOOL b = SetWindowPos (hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); // PostMessage(hwnd, WM_SHOWWINDOW, true, SW_OTHERZOOM); HWND hw = hwnd; while (hw != NULL) { hw = GetParent(hwnd); if (hw) { printf("%x ", hw); hwnd = hw; } printf("\n"); } if (!GetWindowLong(hwnd, GWL_STYLE)&WS_VISIBLE) { return TRUE; } char buf[100] = {0}; GetWindowText(hwnd, buf, 100); CString str=buf; if (str == app ) { printf("%s\n", buf); ShowWindow(hwnd,SW_RESTORE); SetForegroundWindow(hwnd); return FALSE; } // SetActiveWindow(hwnd); // bool b = SetWindowPos (hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW); //AttachThreadInput(tid, lid, FALSE ); } return TRUE; } char app[100] = {0}; long FindTargetProcess2(const CString &m_strProcessName) { int nRet = 0; HANDLE hFind = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 *info = new PROCESSENTRY32; info->dwSize = sizeof(PROCESSENTRY32); nRet = 0; DWORD pid = 0; if (::Process32First(hFind, info) != NULL) { CString strName; while (::Process32Next(hFind, info) != FALSE) { strName = info->szExeFile; if (strName == m_strProcessName) { pid = info->th32ProcessID; HANDLE hOpenPro = OpenProcess(PROCESS_ALL_ACCESS, TRUE, info->th32ProcessID); if (hOpenPro != NULL) { } } } ::CloseHandle(hFind); if (info != NULL) { delete info; } } return pid; } BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { DWORD pid = 0; DWORD tid = GetWindowThreadProcessId(hwnd, &pid); if (pid == (DWORD)lParam) { // printf("pid:%d\n", pid, tid); // DWORD lid = GetCurrentThreadId(); // AttachThreadInput(tid, lid, TRUE ); int w = GetSystemMetrics(SM_CXSCREEN); int h = GetSystemMetrics(SM_CYSCREEN); // BOOL b = SetWindowPos (hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); // PostMessage(hwnd, WM_SHOWWINDOW, true, SW_OTHERZOOM); HWND hw = hwnd; while (hw != NULL) { hw = GetParent(hwnd); if (hw) { printf("%x ", hw); hwnd = hw; } printf("\n"); } if (!GetWindowLong(hwnd, GWL_STYLE)&WS_VISIBLE) { return TRUE; } char buf[100] = {0}; GetWindowText(hwnd, buf, 100); CString str=buf; if (str == app ) { printf("%s\n", buf); ShowWindow(hwnd,SW_RESTORE); SetForegroundWindow(hwnd); return FALSE; } // SetActiveWindow(hwnd); // bool b = SetWindowPos (hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW); //AttachThreadInput(tid, lid, FALSE ); } return TRUE; } SetTimer(777, 1000, 0);