mirror of
https://github.com/Ximi1970/systray-x.git
synced 2026-02-19 20:56:46 +01:00
wibdowctrl-win : add callback data struct for enumWindowsTitleProc function
This commit is contained in:
@@ -76,7 +76,9 @@ bool WindowCtrlWin::findWindow( const QString& title )
|
||||
{
|
||||
m_tb_windows = QList< quint64 >();
|
||||
|
||||
EnumWindows( &enumWindowsTitleProc, (LPARAM)(LPSTR)( title.toStdString().c_str() ) );
|
||||
EnumWindowsTitleProcData data{ *this, title.toStdString() };
|
||||
|
||||
EnumWindows( &enumWindowsTitleProc, reinterpret_cast<LPARAM>(&data) );
|
||||
|
||||
if( m_tb_windows.length() == 0 )
|
||||
{
|
||||
@@ -92,11 +94,12 @@ bool WindowCtrlWin::findWindow( const QString& title )
|
||||
*/
|
||||
BOOL CALLBACK WindowCtrlWin::enumWindowsTitleProc( HWND hwnd, LPARAM lParam )
|
||||
{
|
||||
auto& data = *reinterpret_cast<EnumWindowsTitleProcData*>(lParam);
|
||||
std::array<char, 128> buffer;
|
||||
int written = GetWindowTextA( hwnd, buffer.data(), int(buffer.size()) );
|
||||
if( written && strstr( buffer.data(), (char*)lParam ) != nullptr )
|
||||
if( written && strstr( buffer.data(), data.title.c_str() ) != nullptr )
|
||||
{
|
||||
m_tb_windows.append( (quint64)hwnd );
|
||||
data.window_ctrl.m_tb_windows.append( (quint64)hwnd );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
@@ -9,11 +9,21 @@
|
||||
*/
|
||||
#include <Windows.h>
|
||||
|
||||
/*
|
||||
* Standard library includes
|
||||
*/
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
* Qt includes
|
||||
*/
|
||||
#include <QObject>
|
||||
|
||||
/*
|
||||
* Forward declarations
|
||||
*/
|
||||
class WindowCtrlWin;
|
||||
|
||||
/**
|
||||
* @brief The WindowCtrlWin class
|
||||
*/
|
||||
@@ -29,6 +39,12 @@ class WindowCtrlWin : public QObject
|
||||
HWND hwnd;
|
||||
};
|
||||
|
||||
struct EnumWindowsTitleProcData
|
||||
{
|
||||
WindowCtrlWin& window_ctrl;
|
||||
const std::string title;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user