From 0d89c966fd49b019cedb43556d746a81a40a84be Mon Sep 17 00:00:00 2001 From: Ximi1970 Date: Sun, 23 Feb 2020 22:57:17 +0100 Subject: [PATCH] close experiments --- app/SysTray-X/SysTray-X.pro | 26 +----------- app/SysTray-X/windowctrl-win.cpp | 69 ++++++++++++++++++++++++++++++-- app/SysTray-X/windowctrl-win.h | 19 +++++++++ app/SysTray-X/windowctrl.cpp | 22 ++++++---- 4 files changed, 100 insertions(+), 36 deletions(-) diff --git a/app/SysTray-X/SysTray-X.pro b/app/SysTray-X/SysTray-X.pro index 7890ea9..b84bfc4 100644 --- a/app/SysTray-X/SysTray-X.pro +++ b/app/SysTray-X/SysTray-X.pro @@ -39,36 +39,14 @@ unix:!macx: { QMAKE_LFLAGS += -lX11 } win32: { - LIBS += User32.lib # QMAKE_LFLAGS += -static -lwinpthread -static-libgcc -static-libstdc++ $$(QMAKE_LFLAGS_WINDOWS) # # Windows host (not used in cross compiling with mingw on Linux) # contains(QMAKE_HOST.os, Windows): { - contains(QMAKE_HOST.version, 192): { - # - # Windows 10 Universal CRT - # - UCRT_INCLUDE = "C:/Program Files (x86)/Windows Kits/10/include/10.0.10240.0/ucrt" - UCRT_LIBS = "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt" - - INCLUDEPATH += $$UCRT_INCLUDE - - contains(QMAKE_TARGET.arch, x86_64) { - CONFIG(debug, debug|release) { - LIBS += $$UCRT_LIBS"/x64/ucrtd.lib" - } else { - LIBS += $$UCRT_LIBS"/x64/ucrt.lib" - } - } else { - CONFIG(debug, debug|release) { - LIBS += $$UCRT_LIBS"/x86/ucrtd.lib" - } else { - LIBS += $$UCRT_LIBS"/x86/ucrt.lib" - } - } - } + LIBS += User32.lib + LIBS += Comctl32.lib } } unix:macx: { diff --git a/app/SysTray-X/windowctrl-win.cpp b/app/SysTray-X/windowctrl-win.cpp index 30f767a..599f9df 100644 --- a/app/SysTray-X/windowctrl-win.cpp +++ b/app/SysTray-X/windowctrl-win.cpp @@ -5,7 +5,7 @@ /* * System includes */ - +#include /* * Statics @@ -31,7 +31,12 @@ bool WindowCtrlWin::findWindow( const QString& title ) EnumWindows( &EnumWindowsProc, (LPARAM)(LPSTR)( title.toStdString().c_str() ) ); - return false; + if( m_tb_windows.length() == 0 ) + { + return false; + } + + return true; } @@ -103,8 +108,6 @@ void WindowCtrlWin::normalizeWindow( quint64 window ) */ void WindowCtrlWin::hideWindow( HWND hwnd ) { - emit signalConsole( "Hide" ); - long style = GetWindowLong( hwnd, GWL_STYLE ); style &= ~(WS_VISIBLE); @@ -114,4 +117,62 @@ void WindowCtrlWin::hideWindow( HWND hwnd ) SetWindowLong( hwnd, GWL_STYLE, style ); } + + + + +/* +LRESULT CALLBACK WindowCtrlWin::mySubClassProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData ) +{ + MessageBoxA( NULL, "Test", "Test", MB_OK ); + + switch(uMsg) + { + case WM_LBUTTONDOWN: + MessageBoxA( NULL, "Button down!", "Debug", MB_OK ); + break; + + case WM_NCDESTROY: + RemoveWindowSubclass( hWnd, &mySubClassProc, 1 ); + break; + } + + return DefSubclassProc(hWnd, uMsg, wParam, lParam); +} +*/ + +/* + * Callback for the window enumaration + */ +LRESULT CALLBACK WindowCtrlWin::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) +{ + MessageBoxA( NULL, "Test", "Test", MB_OK ); + + return TRUE; + + if( uMsg == WM_CLOSE ) + { + return TRUE; + } + +// return CallWindowProc( prev, hwnd, uMsg,wParam, lParam); + + return DefWindowProc( hwnd, uMsg, wParam, lParam ); +} + + +/* + * Close experiment + */ +void WindowCtrlWin::closeWindow( HWND hwnd ) +{ + emit signalConsole("Close Window intercept"); + +// SetWindowSubclass( hwnd, &mySubClassProc, 1, 0); + + MessageBoxA( NULL, "Start test", "Test", MB_OK ); + + WNDPROC prev = (WNDPROC)SetWindowLongPtr( hwnd, GWLP_WNDPROC, (LONG_PTR)&WindowCtrlWin::WindowProc ); +} + #endif // Q_OS_WIN diff --git a/app/SysTray-X/windowctrl-win.h b/app/SysTray-X/windowctrl-win.h index 9c40097..c2610b1 100644 --- a/app/SysTray-X/windowctrl-win.h +++ b/app/SysTray-X/windowctrl-win.h @@ -30,6 +30,11 @@ class WindowCtrlWin : public QObject */ explicit WindowCtrlWin( QObject *parent = nullptr ); + + void closeWindow( HWND hwnd ); + + + /** * @brief findWindow. Find window with title. * @@ -87,6 +92,20 @@ class WindowCtrlWin : public QObject */ static BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam ); + /** + * @brief WindowProc + * + * @param hwnd + * @param uMsg + * @param wParam + * @param lParam + * + * @return + */ + static LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); + + static LRESULT CALLBACK mySubClassProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData ); + signals: /** diff --git a/app/SysTray-X/windowctrl.cpp b/app/SysTray-X/windowctrl.cpp index 1640eb7..2561ae9 100644 --- a/app/SysTray-X/windowctrl.cpp +++ b/app/SysTray-X/windowctrl.cpp @@ -48,8 +48,7 @@ void WindowCtrl::slotWindowTest1() displayWindowElements( "- Mozilla Thunderbird" ); // findWindow( 4313 ); - -// captureWindow( "Debugging with Firefox Developer Tools - Mozilla Thunderbird" ); +// captureWindow( "- Mozilla Thunderbird" ); emit signalConsole("Test 1 done"); } @@ -61,6 +60,13 @@ void WindowCtrl::slotWindowTest2() // Do something. + +// foreach( quint64 win_id, getWinIds() ) +// { +// closeWindow( (HWND)win_id ); +// } + + /* * Disconnect container? */ @@ -86,25 +92,25 @@ void WindowCtrl::slotWindowTest3() bool WindowCtrl::captureWindow( const QString& title ) { - Q_UNUSED( title ) + emit signalConsole("Capture"); -#ifdef FF_NEET - - unsigned long WinId; if( !findWindow( title ) ) { + emit signalConsole("Capture error"); return false; } /* * Wrap Thunderbird window */ - m_tb_window = QWindow::fromWinId( WinId ); + m_tb_window = QWindow::fromWinId( getWinIds()[ 0 ] ); m_tb_window->parent(); m_tb_container = QWidget::createWindowContainer( m_tb_window ); -#endif + m_tb_container->show(); + + emit signalConsole("Capture done"); return true; }