comparison pidgin/plugins/win32/transparency/win2ktrans.c @ 29803:c3cd8f9fe4b1

Avoid looking up functions by name that will be present on all supported Windows versions.
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 19 Feb 2010 19:27:23 +0000
parents 4aa5400b1b99
children
comparison
equal deleted inserted replaced
29802:5434f768917b 29803:c3cd8f9fe4b1
70 static const char *OPT_WINTRANS_BL_ALPHA = "/plugins/gtk/win32/wintrans/bl_alpha"; 70 static const char *OPT_WINTRANS_BL_ALPHA = "/plugins/gtk/win32/wintrans/bl_alpha";
71 static const char *OPT_WINTRANS_BL_ONFOCUS= "/plugins/gtk/win32/wintrans/bl_solid_onfocus"; 71 static const char *OPT_WINTRANS_BL_ONFOCUS= "/plugins/gtk/win32/wintrans/bl_solid_onfocus";
72 static const char *OPT_WINTRANS_BL_ONTOP = "/plugins/gtk/win32/wintrans/bl_always_on_top"; 72 static const char *OPT_WINTRANS_BL_ONTOP = "/plugins/gtk/win32/wintrans/bl_always_on_top";
73 static GSList *window_list = NULL; 73 static GSList *window_list = NULL;
74 74
75 static BOOL (*MySetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags) = NULL;
76
77 /* 75 /*
78 * CODE 76 * CODE
79 */ 77 */
80 78
81 /* Set window transparency level */ 79 /* Set window transparency level */
82 static void set_wintrans(GtkWidget *window, int alpha, gboolean enabled, 80 static void set_wintrans(GtkWidget *window, int alpha, gboolean enabled,
83 gboolean always_on_top) { 81 gboolean always_on_top) {
84 if (MySetLayeredWindowAttributes) { 82
85 HWND hWnd = GDK_WINDOW_HWND(window->window); 83 HWND hWnd = GDK_WINDOW_HWND(window->window);
86 LONG style = GetWindowLong(hWnd, GWL_EXSTYLE); 84 LONG style = GetWindowLong(hWnd, GWL_EXSTYLE);
87 if (enabled) { 85 if (enabled) {
88 style |= WS_EX_LAYERED; 86 style |= WS_EX_LAYERED;
89 } else { 87 } else {
90 style &= ~WS_EX_LAYERED; 88 style &= ~WS_EX_LAYERED;
91 } 89 }
92 SetWindowLong(hWnd, GWL_EXSTYLE, style); 90 SetWindowLong(hWnd, GWL_EXSTYLE, style);
93 91
94 92
95 if (enabled) { 93 if (enabled) {
96 SetWindowPos(hWnd, 94 SetWindowPos(hWnd,
97 always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 95 always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST,
98 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 96 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
99 MySetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA); 97 SetLayeredWindowAttributes(hWnd, 0, alpha, LWA_ALPHA);
100 } else { 98 } else {
101 /* Ask the window and its children to repaint */ 99 /* Ask the window and its children to repaint */
102 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, 100 SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
103 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 101 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
104 102
105 RedrawWindow(hWnd, NULL, NULL, 103 RedrawWindow(hWnd, NULL, NULL,
106 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN); 104 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
107 } 105 }
108 } 106
109 } 107 }
110 108
111 /* When a conv window is focused, if we're only transparent when unfocused, 109 /* When a conv window is focused, if we're only transparent when unfocused,
112 * deal with transparency */ 110 * deal with transparency */
113 static gboolean focus_conv_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) { 111 static gboolean focus_conv_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) {
489 487
490 /* 488 /*
491 * EXPORTED FUNCTIONS 489 * EXPORTED FUNCTIONS
492 */ 490 */
493 static gboolean plugin_load(PurplePlugin *plugin) { 491 static gboolean plugin_load(PurplePlugin *plugin) {
494 MySetLayeredWindowAttributes = (void*) wpurple_find_and_loadproc(
495 "user32.dll", "SetLayeredWindowAttributes");
496
497 if (!MySetLayeredWindowAttributes) {
498 purple_debug_error(WINTRANS_PLUGIN_ID,
499 "SetLayeredWindowAttributes API not found (Required W2K+)\n");
500 return FALSE;
501 }
502 492
503 purple_signal_connect(purple_conversations_get_handle(), 493 purple_signal_connect(purple_conversations_get_handle(),
504 "conversation-created", plugin, 494 "conversation-created", plugin,
505 PURPLE_CALLBACK(new_conversation_cb), NULL); 495 PURPLE_CALLBACK(new_conversation_cb), NULL);
506 496