# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1017386501 0 # Node ID aec9a0b0b5390786d4626dbc89d11a0f3fc79463 # Parent dea8021b4f4721c782c741b02c444d1ea97f4089 Fixes for a resource leak. diff -r dea8021b4f47 -r aec9a0b0b539 win/dw.c --- a/win/dw.c Wed Mar 27 10:37:26 2002 +0000 +++ b/win/dw.c Fri Mar 29 07:21:41 2002 +0000 @@ -343,16 +343,19 @@ */ BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) { - void *ptr = (void *)GetWindowLong(handle, GWL_USERDATA); + ColorInfo *thiscinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); #ifndef NO_SIGNALS dw_signal_disconnect_by_window(handle); #endif - if(ptr) + if(thiscinfo) { + if(thiscinfo->hbrush) + DeleteObject(thiscinfo->hbrush); + SetWindowLong(handle, GWL_USERDATA, 0); - free(ptr); + free(thiscinfo); } return TRUE; } @@ -1540,7 +1543,7 @@ case WM_CHAR: if(LOWORD(mp1) == '\t') { - if(GetAsyncKeyState(VK_SHIFT)) + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) _shift_focus_back(hWnd); else _shift_focus(hWnd); @@ -1611,7 +1614,8 @@ SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], _green[thiscinfo->back], _blue[thiscinfo->back])); - DeleteObject(thiscinfo->hbrush); + if(thiscinfo->hbrush) + DeleteObject(thiscinfo->hbrush); thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], _green[thiscinfo->back], _blue[thiscinfo->back])); @@ -1626,7 +1630,8 @@ SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), DW_GREEN_VALUE(thiscinfo->back), DW_BLUE_VALUE(thiscinfo->back))); - DeleteObject(thiscinfo->hbrush); + if(thiscinfo->hbrush) + DeleteObject(thiscinfo->hbrush); thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), DW_GREEN_VALUE(thiscinfo->back), DW_BLUE_VALUE(thiscinfo->back))); @@ -1868,7 +1873,7 @@ case WM_CHAR: if(LOWORD(mp1) == '\t') { - if(GetAsyncKeyState(VK_SHIFT)) + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) { if(cinfo->combo) _shift_focus_back(cinfo->combo); @@ -1951,7 +1956,8 @@ SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], _green[thiscinfo->back], _blue[thiscinfo->back])); - DeleteObject(thiscinfo->hbrush); + if(thiscinfo->hbrush) + DeleteObject(thiscinfo->hbrush); thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], _green[thiscinfo->back], _blue[thiscinfo->back])); @@ -1966,7 +1972,8 @@ SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), DW_GREEN_VALUE(thiscinfo->back), DW_BLUE_VALUE(thiscinfo->back))); - DeleteObject(thiscinfo->hbrush); + if(thiscinfo->hbrush) + DeleteObject(thiscinfo->hbrush); thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), DW_GREEN_VALUE(thiscinfo->back), DW_BLUE_VALUE(thiscinfo->back))); @@ -2006,7 +2013,7 @@ if(LOWORD(mp1) == '\t') { - if(GetAsyncKeyState(VK_SHIFT)) + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) _shift_focus_back(hWnd); else _shift_focus(hWnd); @@ -2100,7 +2107,7 @@ case WM_CHAR: if(LOWORD(mp1) == '\t') { - if(GetAsyncKeyState(VK_SHIFT)) + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) _shift_focus_back(hWnd); else _shift_focus(hWnd); @@ -2126,7 +2133,7 @@ case WM_CHAR: if(LOWORD(mp1) == '\t') { - if(GetAsyncKeyState(VK_SHIFT)) + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) _shift_focus_back(hWnd); else _shift_focus(hWnd); @@ -2511,7 +2518,7 @@ #endif if(LOWORD(mp1) == '\t') { - if(GetAsyncKeyState(VK_SHIFT)) + if(GetAsyncKeyState(VK_SHIFT) & 0x8000) _shift_focus_back(hwnd); else _shift_focus(hwnd); @@ -2528,6 +2535,7 @@ case WM_TIMER: if (hwndBubble) { + _free_window_memory(hwndBubble, 0); DestroyWindow(hwndBubble); hwndBubble = 0; KillTimer(hwnd, 1); @@ -2552,6 +2560,7 @@ if(hwndBubble) { + _free_window_memory(hwndBubble, 0); DestroyWindow(hwndBubble); hwndBubble = 0; KillTimer(hwndBubbleLast, 1); @@ -2562,6 +2571,7 @@ POINTL ptlWork = {0,0}; ULONG ulColor = DW_CLR_YELLOW; SIZE size; + HFONT hFont, oldFont = (HFONT)0; HDC hdc; RECT rect; void *oldproc; @@ -2589,9 +2599,17 @@ SetTimer(hwnd, 1, 3000, NULL); + hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); + hdc = GetDC(hwndBubble); - GetTextExtentPoint(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); + if(hFont) + oldFont = (HFONT)SelectObject(hdc, hFont); + + GetTextExtentPoint32(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); + + if(hFont) + SelectObject(hdc, oldFont); MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); @@ -2601,7 +2619,7 @@ HWND_TOP, ptlWork.x, ptlWork.y + (rect.bottom-rect.top) + 1, - size.cx + 2, + size.cx + 8, size.cy + 2, SWP_NOACTIVATE | SWP_SHOWWINDOW); @@ -2618,6 +2636,7 @@ if(bMouseOver) { bMouseOver = 0; + _free_window_memory(hwndBubble, 0); DestroyWindow(hwndBubble); hwndBubble = 0; KillTimer(hwndBubbleLast, 1); @@ -2632,6 +2651,7 @@ if(bMouseOver) { bMouseOver = 0; + _free_window_memory(hwndBubble, 0); DestroyWindow(hwndBubble); hwndBubble = 0; KillTimer(hwndBubbleLast, 1);