@@ -1541,8 +1541,8 @@ static BOOL CALLBACK enumWindowCallback_SecondaryTrayWnd(HWND hWnd, LPARAM lpara
1541
1541
wstring ClassNameLower = Mona_toLowerWs (ClassName);
1542
1542
if (ClassNameLower == L" shell_secondarytraywnd" ) {
1543
1543
CurrentSecondaryScreen = windowsHWNDs ();
1544
- TmpWorkerW = 0 ;
1545
- TmpTaskList = 0 ;
1544
+ TmpWorkerW = NULL ;
1545
+ TmpTaskList = NULL ;
1546
1546
CurrentSecondaryScreen.hWndTray = hWnd;
1547
1547
EnumChildWindows (hWnd, enumChildWindowCallback_SecondaryTrayWnd, NULL );
1548
1548
CurrentSecondaryScreen.hWndMSTaskSwWClass = TmpTaskList;
@@ -1954,9 +1954,6 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
1954
1954
1955
1955
1956
1956
if (!DetectedHWNDsForThisMouseClick) {
1957
- DetectedHWNDsForThisMouseClick = true ;
1958
-
1959
- Array_Windows_by_Screen.clear ();
1960
1957
// Primary screen variables:
1961
1958
Update_Primary_Screen_Windows_HWNDSs ();
1962
1959
@@ -1965,6 +1962,7 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
1965
1962
if (PrimaryScreen.hWndMSTaskSwWClass ) {
1966
1963
if (Fix_Taskbar_Size_Bug (PrimaryScreen.hWndMSTaskSwWClass )) {
1967
1964
// Fixed. Ignore this loop to get potentially new HWND and RECTs.
1965
+ DetectedHWNDsForThisMouseClick = false ;// IMPORTANT ver. 1.9.1 to fix program crash after the sleep mode.
1968
1966
if (UseFixForBugAfterSleepMode) {
1969
1967
SleepModeFix_Previous_TimeNow = TimeNow;
1970
1968
}
@@ -1974,13 +1972,17 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
1974
1972
}
1975
1973
}
1976
1974
1975
+ Array_Windows_by_Screen.clear ();
1976
+ // Before version 1.9.1 this array could be empty after the sleep mode bug fix, causing program crashes.
1977
1977
Array_Windows_by_Screen.push_back (PrimaryScreen);
1978
1978
// Shell_SecondaryTrayWnd:
1979
1979
EnumWindows (enumWindowCallback_SecondaryTrayWnd, NULL );
1980
1980
1981
1981
hDesktop = GetDesktopWindow ();
1982
1982
GetWindowRect (hDesktop, &desktop);
1983
1983
ShowDesktopStartPosition = desktop.right - DefaultShowDesktopButtonWidth;
1984
+
1985
+ DetectedHWNDsForThisMouseClick = true ;// Moved from top to bottom.
1984
1986
}
1985
1987
1986
1988
// Unfortunately we can't optimize it at the moment since cursor might move with dragged file from screen-to-screen.
@@ -1991,7 +1993,7 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
1991
1993
GetClassNameW (WindowUnderMouse, WindowClassName, MAX_PATH);
1992
1994
// std::wcout << L"Class Name Under Mouse: " << WindowClassName << L"\n";
1993
1995
if (_wcsicmp (WindowClassName, L" MSTaskListWClass" ) == 0 ) {
1994
- if (WindowUnderMouse != hWndMSTaskSwWClass) {
1996
+ if (WindowUnderMouse != PrimaryScreen. hWndMSTaskSwWClass ) {
1995
1997
if (PrintDebugInfo) {
1996
1998
std::wcout << L" Found Taskbar Window on Secondary Screen. Switching HWNDs to the other monitor mode. " << WindowUnderMouse << " \n " ;
1997
1999
}
@@ -2017,30 +2019,58 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
2017
2019
}
2018
2020
2019
2021
// ver 1.5 continued:
2020
- hWndTray = Array_Windows_by_Screen[WindowsScreenSet].hWndTray ;
2022
+ // WARNING: Detected some program crashes at this location. Attempting to code it more securely.
2023
+
2024
+ if (Array_Windows_by_Screen[WindowsScreenSet].hWndTray ) {
2025
+ hWndTray = Array_Windows_by_Screen[WindowsScreenSet].hWndTray ;
2026
+ }
2027
+ else {
2028
+ hWndTray = NULL ;
2029
+ }
2030
+
2021
2031
if (hWndTray) {
2022
- hWndTrayNotify = Array_Windows_by_Screen[0 ].hWndTrayNotify ;
2032
+ if (Array_Windows_by_Screen[0 ].hWndTrayNotify ) {
2033
+ hWndTrayNotify = Array_Windows_by_Screen[0 ].hWndTrayNotify ;
2034
+ }
2035
+ else {
2036
+ hWndTrayNotify = NULL ;
2037
+ }
2023
2038
}
2024
2039
else {
2025
- hWndTrayNotify = 0 ;
2040
+ hWndTrayNotify = NULL ;
2026
2041
}
2027
2042
2028
2043
if (hWndTray) {
2029
- hWndRebar = Array_Windows_by_Screen[0 ].hWndRebar ;
2044
+ if (Array_Windows_by_Screen[0 ].hWndRebar ) {
2045
+ hWndRebar = Array_Windows_by_Screen[0 ].hWndRebar ;
2046
+ }
2047
+ else {
2048
+ hWndRebar = NULL ;
2049
+ }
2030
2050
}
2031
2051
else {
2032
- hWndRebar = 0 ;
2052
+ hWndRebar = NULL ;
2033
2053
}
2034
2054
2035
2055
if (hWndRebar) {
2036
- hWndMSTaskSwWClass = Array_Windows_by_Screen[WindowsScreenSet].hWndMSTaskSwWClass ;
2056
+ if (Array_Windows_by_Screen[WindowsScreenSet].hWndMSTaskSwWClass ) {
2057
+ hWndMSTaskSwWClass = Array_Windows_by_Screen[WindowsScreenSet].hWndMSTaskSwWClass ;
2058
+ }
2059
+ else {
2060
+ hWndMSTaskSwWClass = NULL ;
2061
+ }
2037
2062
}
2038
2063
else {
2039
- hWndMSTaskSwWClass = 0 ;
2064
+ hWndMSTaskSwWClass = NULL ;
2040
2065
}
2041
2066
2042
2067
// Find a window that should be invisible when app has no active window!
2043
- TaskListThumbnailWnd = Array_Windows_by_Screen[0 ].TaskListThumbnailWnd ;
2068
+ if (Array_Windows_by_Screen[0 ].TaskListThumbnailWnd ) {
2069
+ TaskListThumbnailWnd = Array_Windows_by_Screen[0 ].TaskListThumbnailWnd ;
2070
+ }
2071
+ else {
2072
+ TaskListThumbnailWnd = NULL ;
2073
+ }
2044
2074
2045
2075
if (PrintDebugInfo) {
2046
2076
std::wcout << L" Found Taskbar Window: " << hWndMSTaskSwWClass << " \n " ;
0 commit comments