Mercurial > dwindows
comparison win/dw.c @ 82:aec9a0b0b539
Fixes for a resource leak.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 29 Mar 2002 07:21:41 +0000 |
parents | 8082cb0e7c2e |
children | 1eb72c0e8c79 |
comparison
equal
deleted
inserted
replaced
81:dea8021b4f47 | 82:aec9a0b0b539 |
---|---|
341 /* This function removes and handlers on windows and frees | 341 /* This function removes and handlers on windows and frees |
342 * the user memory allocated to it. | 342 * the user memory allocated to it. |
343 */ | 343 */ |
344 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) | 344 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) |
345 { | 345 { |
346 void *ptr = (void *)GetWindowLong(handle, GWL_USERDATA); | 346 ColorInfo *thiscinfo = (ColorInfo *)GetWindowLong(handle, GWL_USERDATA); |
347 | 347 |
348 #ifndef NO_SIGNALS | 348 #ifndef NO_SIGNALS |
349 dw_signal_disconnect_by_window(handle); | 349 dw_signal_disconnect_by_window(handle); |
350 #endif | 350 #endif |
351 | 351 |
352 if(ptr) | 352 if(thiscinfo) |
353 { | 353 { |
354 if(thiscinfo->hbrush) | |
355 DeleteObject(thiscinfo->hbrush); | |
356 | |
354 SetWindowLong(handle, GWL_USERDATA, 0); | 357 SetWindowLong(handle, GWL_USERDATA, 0); |
355 free(ptr); | 358 free(thiscinfo); |
356 } | 359 } |
357 return TRUE; | 360 return TRUE; |
358 } | 361 } |
359 | 362 |
360 /* This function returns 1 if the window (widget) handle | 363 /* This function returns 1 if the window (widget) handle |
1538 } | 1541 } |
1539 break; | 1542 break; |
1540 case WM_CHAR: | 1543 case WM_CHAR: |
1541 if(LOWORD(mp1) == '\t') | 1544 if(LOWORD(mp1) == '\t') |
1542 { | 1545 { |
1543 if(GetAsyncKeyState(VK_SHIFT)) | 1546 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
1544 _shift_focus_back(hWnd); | 1547 _shift_focus_back(hWnd); |
1545 else | 1548 else |
1546 _shift_focus(hWnd); | 1549 _shift_focus(hWnd); |
1547 return TRUE; | 1550 return TRUE; |
1548 } | 1551 } |
1609 _green[thiscinfo->fore], | 1612 _green[thiscinfo->fore], |
1610 _blue[thiscinfo->fore])); | 1613 _blue[thiscinfo->fore])); |
1611 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | 1614 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], |
1612 _green[thiscinfo->back], | 1615 _green[thiscinfo->back], |
1613 _blue[thiscinfo->back])); | 1616 _blue[thiscinfo->back])); |
1614 DeleteObject(thiscinfo->hbrush); | 1617 if(thiscinfo->hbrush) |
1618 DeleteObject(thiscinfo->hbrush); | |
1615 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], | 1619 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
1616 _green[thiscinfo->back], | 1620 _green[thiscinfo->back], |
1617 _blue[thiscinfo->back])); | 1621 _blue[thiscinfo->back])); |
1618 SelectObject((HDC)mp1, thiscinfo->hbrush); | 1622 SelectObject((HDC)mp1, thiscinfo->hbrush); |
1619 return (LONG)thiscinfo->hbrush; | 1623 return (LONG)thiscinfo->hbrush; |
1624 DW_GREEN_VALUE(thiscinfo->fore), | 1628 DW_GREEN_VALUE(thiscinfo->fore), |
1625 DW_BLUE_VALUE(thiscinfo->fore))); | 1629 DW_BLUE_VALUE(thiscinfo->fore))); |
1626 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | 1630 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), |
1627 DW_GREEN_VALUE(thiscinfo->back), | 1631 DW_GREEN_VALUE(thiscinfo->back), |
1628 DW_BLUE_VALUE(thiscinfo->back))); | 1632 DW_BLUE_VALUE(thiscinfo->back))); |
1629 DeleteObject(thiscinfo->hbrush); | 1633 if(thiscinfo->hbrush) |
1634 DeleteObject(thiscinfo->hbrush); | |
1630 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | 1635 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), |
1631 DW_GREEN_VALUE(thiscinfo->back), | 1636 DW_GREEN_VALUE(thiscinfo->back), |
1632 DW_BLUE_VALUE(thiscinfo->back))); | 1637 DW_BLUE_VALUE(thiscinfo->back))); |
1633 SelectObject((HDC)mp1, thiscinfo->hbrush); | 1638 SelectObject((HDC)mp1, thiscinfo->hbrush); |
1634 return (LONG)thiscinfo->hbrush; | 1639 return (LONG)thiscinfo->hbrush; |
1866 _wndproc(hWnd, msg, mp1, mp2); | 1871 _wndproc(hWnd, msg, mp1, mp2); |
1867 break; | 1872 break; |
1868 case WM_CHAR: | 1873 case WM_CHAR: |
1869 if(LOWORD(mp1) == '\t') | 1874 if(LOWORD(mp1) == '\t') |
1870 { | 1875 { |
1871 if(GetAsyncKeyState(VK_SHIFT)) | 1876 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
1872 { | 1877 { |
1873 if(cinfo->combo) | 1878 if(cinfo->combo) |
1874 _shift_focus_back(cinfo->combo); | 1879 _shift_focus_back(cinfo->combo); |
1875 else if(cinfo->buddy) | 1880 else if(cinfo->buddy) |
1876 _shift_focus_back(cinfo->buddy); | 1881 _shift_focus_back(cinfo->buddy); |
1949 _green[thiscinfo->fore], | 1954 _green[thiscinfo->fore], |
1950 _blue[thiscinfo->fore])); | 1955 _blue[thiscinfo->fore])); |
1951 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], | 1956 SetBkColor((HDC)mp1, RGB(_red[thiscinfo->back], |
1952 _green[thiscinfo->back], | 1957 _green[thiscinfo->back], |
1953 _blue[thiscinfo->back])); | 1958 _blue[thiscinfo->back])); |
1954 DeleteObject(thiscinfo->hbrush); | 1959 if(thiscinfo->hbrush) |
1960 DeleteObject(thiscinfo->hbrush); | |
1955 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], | 1961 thiscinfo->hbrush = CreateSolidBrush(RGB(_red[thiscinfo->back], |
1956 _green[thiscinfo->back], | 1962 _green[thiscinfo->back], |
1957 _blue[thiscinfo->back])); | 1963 _blue[thiscinfo->back])); |
1958 SelectObject((HDC)mp1, thiscinfo->hbrush); | 1964 SelectObject((HDC)mp1, thiscinfo->hbrush); |
1959 return (LONG)thiscinfo->hbrush; | 1965 return (LONG)thiscinfo->hbrush; |
1964 DW_GREEN_VALUE(thiscinfo->fore), | 1970 DW_GREEN_VALUE(thiscinfo->fore), |
1965 DW_BLUE_VALUE(thiscinfo->fore))); | 1971 DW_BLUE_VALUE(thiscinfo->fore))); |
1966 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), | 1972 SetBkColor((HDC)mp1, RGB(DW_RED_VALUE(thiscinfo->back), |
1967 DW_GREEN_VALUE(thiscinfo->back), | 1973 DW_GREEN_VALUE(thiscinfo->back), |
1968 DW_BLUE_VALUE(thiscinfo->back))); | 1974 DW_BLUE_VALUE(thiscinfo->back))); |
1969 DeleteObject(thiscinfo->hbrush); | 1975 if(thiscinfo->hbrush) |
1976 DeleteObject(thiscinfo->hbrush); | |
1970 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), | 1977 thiscinfo->hbrush = CreateSolidBrush(RGB(DW_RED_VALUE(thiscinfo->back), |
1971 DW_GREEN_VALUE(thiscinfo->back), | 1978 DW_GREEN_VALUE(thiscinfo->back), |
1972 DW_BLUE_VALUE(thiscinfo->back))); | 1979 DW_BLUE_VALUE(thiscinfo->back))); |
1973 SelectObject((HDC)mp1, thiscinfo->hbrush); | 1980 SelectObject((HDC)mp1, thiscinfo->hbrush); |
1974 return (LONG)thiscinfo->hbrush; | 1981 return (LONG)thiscinfo->hbrush; |
2004 LV_ITEM lvi; | 2011 LV_ITEM lvi; |
2005 int iItem; | 2012 int iItem; |
2006 | 2013 |
2007 if(LOWORD(mp1) == '\t') | 2014 if(LOWORD(mp1) == '\t') |
2008 { | 2015 { |
2009 if(GetAsyncKeyState(VK_SHIFT)) | 2016 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2010 _shift_focus_back(hWnd); | 2017 _shift_focus_back(hWnd); |
2011 else | 2018 else |
2012 _shift_focus(hWnd); | 2019 _shift_focus(hWnd); |
2013 return FALSE; | 2020 return FALSE; |
2014 } | 2021 } |
2098 break; | 2105 break; |
2099 #else | 2106 #else |
2100 case WM_CHAR: | 2107 case WM_CHAR: |
2101 if(LOWORD(mp1) == '\t') | 2108 if(LOWORD(mp1) == '\t') |
2102 { | 2109 { |
2103 if(GetAsyncKeyState(VK_SHIFT)) | 2110 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2104 _shift_focus_back(hWnd); | 2111 _shift_focus_back(hWnd); |
2105 else | 2112 else |
2106 _shift_focus(hWnd); | 2113 _shift_focus(hWnd); |
2107 return FALSE; | 2114 return FALSE; |
2108 } | 2115 } |
2124 switch( msg ) | 2131 switch( msg ) |
2125 { | 2132 { |
2126 case WM_CHAR: | 2133 case WM_CHAR: |
2127 if(LOWORD(mp1) == '\t') | 2134 if(LOWORD(mp1) == '\t') |
2128 { | 2135 { |
2129 if(GetAsyncKeyState(VK_SHIFT)) | 2136 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2130 _shift_focus_back(hWnd); | 2137 _shift_focus_back(hWnd); |
2131 else | 2138 else |
2132 _shift_focus(hWnd); | 2139 _shift_focus(hWnd); |
2133 return FALSE; | 2140 return FALSE; |
2134 } | 2141 } |
2509 } | 2516 } |
2510 } | 2517 } |
2511 #endif | 2518 #endif |
2512 if(LOWORD(mp1) == '\t') | 2519 if(LOWORD(mp1) == '\t') |
2513 { | 2520 { |
2514 if(GetAsyncKeyState(VK_SHIFT)) | 2521 if(GetAsyncKeyState(VK_SHIFT) & 0x8000) |
2515 _shift_focus_back(hwnd); | 2522 _shift_focus_back(hwnd); |
2516 else | 2523 else |
2517 _shift_focus(hwnd); | 2524 _shift_focus(hwnd); |
2518 return FALSE; | 2525 return FALSE; |
2519 } | 2526 } |
2526 _shift_focus(hwnd); | 2533 _shift_focus(hwnd); |
2527 break; | 2534 break; |
2528 case WM_TIMER: | 2535 case WM_TIMER: |
2529 if (hwndBubble) | 2536 if (hwndBubble) |
2530 { | 2537 { |
2538 _free_window_memory(hwndBubble, 0); | |
2531 DestroyWindow(hwndBubble); | 2539 DestroyWindow(hwndBubble); |
2532 hwndBubble = 0; | 2540 hwndBubble = 0; |
2533 KillTimer(hwnd, 1); | 2541 KillTimer(hwnd, 1); |
2534 } | 2542 } |
2535 break; | 2543 break; |
2550 if(!*bubble->bubbletext) | 2558 if(!*bubble->bubbletext) |
2551 break; | 2559 break; |
2552 | 2560 |
2553 if(hwndBubble) | 2561 if(hwndBubble) |
2554 { | 2562 { |
2563 _free_window_memory(hwndBubble, 0); | |
2555 DestroyWindow(hwndBubble); | 2564 DestroyWindow(hwndBubble); |
2556 hwndBubble = 0; | 2565 hwndBubble = 0; |
2557 KillTimer(hwndBubbleLast, 1); | 2566 KillTimer(hwndBubbleLast, 1); |
2558 } | 2567 } |
2559 | 2568 |
2560 if(!hwndBubble) | 2569 if(!hwndBubble) |
2561 { | 2570 { |
2562 POINTL ptlWork = {0,0}; | 2571 POINTL ptlWork = {0,0}; |
2563 ULONG ulColor = DW_CLR_YELLOW; | 2572 ULONG ulColor = DW_CLR_YELLOW; |
2564 SIZE size; | 2573 SIZE size; |
2574 HFONT hFont, oldFont = (HFONT)0; | |
2565 HDC hdc; | 2575 HDC hdc; |
2566 RECT rect; | 2576 RECT rect; |
2567 void *oldproc; | 2577 void *oldproc; |
2568 | 2578 |
2569 /* Use the WS_EX_TOOLWINDOW extended style | 2579 /* Use the WS_EX_TOOLWINDOW extended style |
2587 | 2597 |
2588 hwndBubbleLast = hwnd; | 2598 hwndBubbleLast = hwnd; |
2589 | 2599 |
2590 SetTimer(hwnd, 1, 3000, NULL); | 2600 SetTimer(hwnd, 1, 3000, NULL); |
2591 | 2601 |
2602 hFont = (HFONT)SendMessage(hwndBubble, WM_GETFONT, 0, 0); | |
2603 | |
2592 hdc = GetDC(hwndBubble); | 2604 hdc = GetDC(hwndBubble); |
2593 | 2605 |
2594 GetTextExtentPoint(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); | 2606 if(hFont) |
2607 oldFont = (HFONT)SelectObject(hdc, hFont); | |
2608 | |
2609 GetTextExtentPoint32(hdc, bubble->bubbletext, strlen(bubble->bubbletext), &size); | |
2610 | |
2611 if(hFont) | |
2612 SelectObject(hdc, oldFont); | |
2595 | 2613 |
2596 MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); | 2614 MapWindowPoints(hwnd, HWND_DESKTOP, (LPPOINT)&ptlWork, 1); |
2597 | 2615 |
2598 GetWindowRect(hwnd, &rect); | 2616 GetWindowRect(hwnd, &rect); |
2599 | 2617 |
2600 SetWindowPos(hwndBubble, | 2618 SetWindowPos(hwndBubble, |
2601 HWND_TOP, | 2619 HWND_TOP, |
2602 ptlWork.x, | 2620 ptlWork.x, |
2603 ptlWork.y + (rect.bottom-rect.top) + 1, | 2621 ptlWork.y + (rect.bottom-rect.top) + 1, |
2604 size.cx + 2, | 2622 size.cx + 8, |
2605 size.cy + 2, | 2623 size.cy + 2, |
2606 SWP_NOACTIVATE | SWP_SHOWWINDOW); | 2624 SWP_NOACTIVATE | SWP_SHOWWINDOW); |
2607 | 2625 |
2608 ReleaseDC(hwndBubble, hdc); | 2626 ReleaseDC(hwndBubble, hdc); |
2609 } | 2627 } |
2616 ReleaseCapture(); | 2634 ReleaseCapture(); |
2617 | 2635 |
2618 if(bMouseOver) | 2636 if(bMouseOver) |
2619 { | 2637 { |
2620 bMouseOver = 0; | 2638 bMouseOver = 0; |
2639 _free_window_memory(hwndBubble, 0); | |
2621 DestroyWindow(hwndBubble); | 2640 DestroyWindow(hwndBubble); |
2622 hwndBubble = 0; | 2641 hwndBubble = 0; |
2623 KillTimer(hwndBubbleLast, 1); | 2642 KillTimer(hwndBubbleLast, 1); |
2624 } | 2643 } |
2625 } | 2644 } |
2630 * stole it | 2649 * stole it |
2631 */ | 2650 */ |
2632 if(bMouseOver) | 2651 if(bMouseOver) |
2633 { | 2652 { |
2634 bMouseOver = 0; | 2653 bMouseOver = 0; |
2654 _free_window_memory(hwndBubble, 0); | |
2635 DestroyWindow(hwndBubble); | 2655 DestroyWindow(hwndBubble); |
2636 hwndBubble = 0; | 2656 hwndBubble = 0; |
2637 KillTimer(hwndBubbleLast, 1); | 2657 KillTimer(hwndBubbleLast, 1); |
2638 } | 2658 } |
2639 break; | 2659 break; |