Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QCoreApplication>
- #include <QDebug>
- #include "UIAutomation.h"
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- IUIAutomation *uiauto;
- CoInitialize(NULL);
- HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation),(void**)&uiauto);
- HWND topWindow = GetForegroundWindow();
- if(topWindow == NULL)
- return 0;
- IUIAutomationElement *windElem;
- hr = uiauto->ElementFromHandle(topWindow, &windElem);
- if(FAILED(hr))
- {
- qDebug() << "Can’t access the Window in focus!";
- return 0;
- }
- BSTR bWinName;
- hr = windElem->get_CurrentName(&bWinName);
- if(FAILED(hr))
- return 0;
- QString windowName = QString::fromStdWString(std::wstring(bWinName, SysStringLen(bWinName)));
- SysFreeString(bWinName);
- qDebug() << windowName;
- if(uiauto != NULL)
- uiauto->Release();
- CoUninitialize();
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement