[Winpt-commits] r414 - trunk/Src
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sat Feb 11 17:45:17 CET 2012
Author: twoaday
Date: 2012-02-11 17:45:17 +0100 (Sat, 11 Feb 2012)
New Revision: 414
Modified:
trunk/Src/ChangeLog
trunk/Src/wptCurrWnd.cpp
Log:
2012-02-11 Timo Schulz <twoaday at gmx.net>
* wptCurrWnd.cpp (get_current_wnd): store thread ID
pair to avoid side-effects.
(paste_window_content): Likewise.
(copy_window_content): Likewise.
Modified: trunk/Src/ChangeLog
===================================================================
--- trunk/Src/ChangeLog 2012-02-11 16:33:43 UTC (rev 413)
+++ trunk/Src/ChangeLog 2012-02-11 16:45:17 UTC (rev 414)
@@ -1,3 +1,10 @@
+2012-02-11 Timo Schulz <twoaday at gmx.net>
+
+ * wptCurrWnd.cpp (get_current_wnd): store thread ID
+ pair to avoid side-effects.
+ (paste_window_content): Likewise.
+ (copy_window_content): Likewise.
+
2012-02-06 Timo Schulz <twoaday at gmx.net>
* wptNLS.cpp (gettext_free_current_domain): Replace free()
Modified: trunk/Src/wptCurrWnd.cpp
===================================================================
--- trunk/Src/wptCurrWnd.cpp 2012-02-11 16:33:43 UTC (rev 413)
+++ trunk/Src/wptCurrWnd.cpp 2012-02-11 16:45:17 UTC (rev 414)
@@ -143,28 +143,23 @@
/* Get the current window and return it in @r_main.
- Return value: The Window with the keyboard focus. */
+ Return value: The window with the keyboard focus. */
static HWND
get_current_wnd (HWND main, int use_hotkey, HWND *r_main)
{
- HWND prev, fg;
-
- if (use_hotkey)
- prev = GetForegroundWindow ();
- else {
+ if (!use_hotkey) {
*r_main = GetNextWindow (main, GW_HWNDNEXT);
return PTD_get_current_window ();
}
-
- SetForegroundWindow (prev);
- AttachThreadInput (GetCurrentThreadId(),
- GetWindowThreadProcessId (prev, NULL),
- TRUE);
- fg = GetFocus ();
- AttachThreadInput (GetCurrentThreadId (),
- GetWindowThreadProcessId (prev, NULL),
- FALSE);
+ HWND prev = GetForegroundWindow ();
+ DWORD src_thread = GetCurrentThreadId();
+ DWORD dst_thread = GetWindowThreadProcessId (prev, NULL);
+
+ SetForegroundWindow (prev);
+ AttachThreadInput (src_thread, dst_thread, TRUE);
+ HWND fg = GetFocus ();
+ AttachThreadInput (src_thread, dst_thread, FALSE);
*r_main = prev;
return fg;
@@ -177,20 +172,18 @@
A return value of 0 indicates a problem. */
int
copy_window_content (HWND old_hwnd, HWND *r_main, HWND *r_focus, int use_hotkey)
-{
- HWND hwnd;
- int rc;
-
- rc = WPTERR_GENERAL;
- hwnd = get_current_wnd (old_hwnd, use_hotkey, r_main);
+{
+ int rc = WPTERR_GENERAL;
+ HWND hwnd = get_current_wnd (old_hwnd, use_hotkey, r_main);
if (!hwnd)
return rc;
*r_focus = hwnd;
clip_clear ();
-
- AttachThreadInput (GetCurrentThreadId (),
- GetWindowThreadProcessId (hwnd, NULL),
- TRUE);
+
+ DWORD src_thread = GetCurrentThreadId ();
+ DWORD dst_thread = GetWindowThreadProcessId (hwnd, NULL);
+
+ AttachThreadInput (src_thread, dst_thread, TRUE);
SetFocus (hwnd);
/* First we try to send a simple clipboard copying command and check
if the clipboard contains some text. */
@@ -214,9 +207,7 @@
rc = WPTERR_SUCESS;
leave:
- AttachThreadInput (GetCurrentThreadId (),
- GetWindowThreadProcessId (hwnd, NULL),
- FALSE);
+ AttachThreadInput (src_thread, dst_thread, FALSE);
return rc;
}
@@ -225,30 +216,24 @@
in @ctx and reset the current window to @old_hwnd if possible. */
int
paste_window_content (HWND old_hwnd, HWND main, HWND focus)
-{
- HWND hwnd, lost;
-
- hwnd = focus;
+{
+ HWND hwnd = focus;
/* Restore window when in minimized state. */
if (IsIconic (main))
ShowWindow (hwnd, SW_SHOWNORMAL);
SetForegroundWindow (hwnd);
-
- AttachThreadInput (GetCurrentThreadId (),
- GetWindowThreadProcessId (hwnd, NULL),
- TRUE);
-
- lost = SetFocus (hwnd);
+ DWORD src_thread = GetCurrentThreadId();
+ DWORD dst_thread = GetWindowThreadProcessId (hwnd, NULL);
+
+ AttachThreadInput (src_thread, dst_thread, TRUE);
+ HWND lost = SetFocus (hwnd);
window_msg_em_set_pos (hwnd, 0);
window_msg_paste ();
- window_msg_em_set_pos (hwnd, 1);
+ window_msg_em_set_pos (hwnd, 1);
+ AttachThreadInput (src_thread, dst_thread, FALSE);
- AttachThreadInput (GetCurrentThreadId(),
- GetWindowThreadProcessId (hwnd, NULL),
- FALSE);
-
SetForegroundWindow (lost);
return 0;
}
More information about the Winpt-commits
mailing list