mirror of
https://github.com/Ximi1970/systray-x.git
synced 2026-02-04 21:39:02 +01:00
Add find window by title
This commit is contained in:
@@ -39,6 +39,7 @@ unix:!macx: {
|
||||
QMAKE_LFLAGS += -lX11
|
||||
}
|
||||
win32: {
|
||||
LIBS += User32.lib
|
||||
# QMAKE_LFLAGS += -static -lwinpthread -static-libgcc -static-libstdc++ $$(QMAKE_LFLAGS_WINDOWS)
|
||||
|
||||
#
|
||||
|
||||
@@ -2,12 +2,23 @@
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
||||
/*
|
||||
* System includes
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Statics
|
||||
*/
|
||||
QList< WinId > WindowCtrlWin::m_tb_windows;
|
||||
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
WindowCtrlWin::WindowCtrlWin( QObject *parent) : QObject( parent )
|
||||
{
|
||||
|
||||
m_tb_windows = QList< WinId >();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +27,10 @@ WindowCtrlWin::WindowCtrlWin( QObject *parent) : QObject( parent )
|
||||
*/
|
||||
bool WindowCtrlWin::findWindow( const QString& title )
|
||||
{
|
||||
m_tb_windows = QList< WinId >();
|
||||
|
||||
EnumWindows( &EnumWindowsProc, (LPARAM)(LPSTR)( title.toStdString().c_str() ) );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,6 +40,28 @@ bool WindowCtrlWin::findWindow( const QString& title )
|
||||
*/
|
||||
void WindowCtrlWin::displayWindowElements( const QString& title )
|
||||
{
|
||||
findWindow( title );
|
||||
|
||||
foreach( quint64 win_id, getWinIds() )
|
||||
{
|
||||
emit signalConsole( QString( "Found: XID %1" ).arg( win_id ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Callback for the window enumaration
|
||||
*/
|
||||
BOOL CALLBACK WindowCtrlWin::EnumWindowsProc( HWND hwnd, LPARAM lParam )
|
||||
{
|
||||
char buffer[ 128 ];
|
||||
int written = GetWindowTextA( hwnd, buffer, 128 );
|
||||
if( written && strstr( buffer, (char*)lParam ) != NULL )
|
||||
{
|
||||
m_tb_windows.append( (quint64)hwnd );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,12 +4,20 @@
|
||||
#ifndef WINDOWCTRLWIN_H
|
||||
#define WINDOWCTRLWIN_H
|
||||
|
||||
/*
|
||||
* System includes
|
||||
*/
|
||||
#include <Windows.h>
|
||||
|
||||
/*
|
||||
* Qt includes
|
||||
*/
|
||||
#include <QObject>
|
||||
|
||||
/*
|
||||
* Define the windows Id
|
||||
*/
|
||||
typedef unsigned long WinId;
|
||||
typedef quint64 WinId;
|
||||
|
||||
/**
|
||||
* @brief The WindowCtrlWin class
|
||||
@@ -72,6 +80,18 @@ class WindowCtrlWin : public QObject
|
||||
*/
|
||||
void hideWindow( WinId window, bool state );
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief EnumWindowsProc. Callback for window enumaration.
|
||||
*
|
||||
* @param hwnd Handle of window.
|
||||
* @param lParam Argument passed by EnumWindows.
|
||||
*
|
||||
* @return State of callback. (TRUE = continue / FALSE = stop)
|
||||
*/
|
||||
static BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam );
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
@@ -103,7 +123,7 @@ class WindowCtrlWin : public QObject
|
||||
/**
|
||||
* @brief m_tb_window. The Thunderbird windows.
|
||||
*/
|
||||
QList< WinId > m_tb_windows;
|
||||
static QList< WinId > m_tb_windows;
|
||||
};
|
||||
|
||||
#endif // WINDOWCTRLWIN_H
|
||||
|
||||
@@ -154,7 +154,7 @@ void WindowCtrl::slotShowHide()
|
||||
{
|
||||
m_state = "normal";
|
||||
|
||||
foreach( unsigned long win_id, getWinIds() )
|
||||
foreach( quint64 win_id, getWinIds() )
|
||||
{
|
||||
hideWindow( win_id, false );
|
||||
normalizeWindow( win_id );
|
||||
@@ -165,7 +165,7 @@ void WindowCtrl::slotShowHide()
|
||||
} else {
|
||||
m_state = "minimized";
|
||||
|
||||
foreach( unsigned long win_id, getWinIds() )
|
||||
foreach( quint64 win_id, getWinIds() )
|
||||
{
|
||||
if( m_minimize_hide )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user