• 获取当前焦点窗口进程名


     1 void GetForegroundWindowProc(CString& szProcPath)
     2 {
     3     HWND hWnd = ::GetForegroundWindow();
     4     WCHAR winClass[128];
     5     WCHAR winTitle[128];
     6     //通过句柄获取窗口类名
     7     ::GetClassName(hWnd, winClass, 128);
     8 
     9     //通过句柄获取窗口标题
    10     ::GetWindowText(hWnd, winTitle, 128);
    11 
    12     printf("!!!%s, winClass = %S!
    ", __FUNCTION__, winClass);
    13     printf("!!!%s, winTitle = %S!
    ", __FUNCTION__, winTitle);
    14 
    15     DWORD dwThreadId;
    16     DWORD dwProcId;
    17     dwThreadId = GetWindowThreadProcessId(hWnd, &dwProcId);
    18     printf("dwProcId = %ul
    ", dwProcId);
    19     printf("dwThreadId = %ul
    ", dwThreadId);
    20 
    21     HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dwProcId);
    22     WCHAR proname[MAX_PATH] = { 0 };
    23 
    24     DWORD dwRetLength = GetModuleFileNameEx(hProcess, NULL, proname, MAX_PATH);
    25     if (dwRetLength)
    26     {
    27         szProcPath = proname;
    28     }
    29 }
     1 bool ParseFileName(_In_ const CString& filePath, _Out_ CString& fileName)
     2 {
     3     WCHAR fPath[MAX_PATH] = { 0 };
     4     PWCHAR pfTail;
     5     wcscpy_s(fPath, filePath.GetString());
     6     pfTail = fPath + filePath.GetLength();
     7     while (pfTail != fPath && *pfTail != L'\')
     8     {
     9         pfTail--;
    10     }
    11     if (pfTail == fPath)
    12         return false;
    13     fileName = ++pfTail;
    14     return true;
    15 }
  • 相关阅读:
    更新增加一个门店ID字段的值
    测试成功,修改能运行代码--待优化
    奶粉运营,跑数据三个模板。
    子查询返回多条报错误
    分析跑数口径与表内在关系逻辑
    NAVICAT PREMIUM 初识
    长沙生活
    金蝶用户操作
    EXCEL对比重复数据
    处理链长期检查问题
  • 原文地址:https://www.cnblogs.com/endenvor/p/10882709.html
Copyright © 2020-2023  润新知