Skip to content

Commit

Permalink
Updated to ver. 2.2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
HerMajestyDrMona authored Jan 10, 2022
1 parent 4a6a124 commit 8162d54
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 7 deletions.
153 changes: 150 additions & 3 deletions Windows11DragAndDropToTaskbarFix/Windows11DragAndDropToTaskbarFix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,15 @@ void Mona_Load_Configuration(bool DebugPrintNow = false) {
continue;
}

if (NewIsConfigLineEqualTo(line, "StartThisProgramAsAdministrator", "1") || NewIsConfigLineEqualTo(line, "StartThisProgramAsAdministrator", "true")) {
StartThisProgramAsAdministrator = true;
continue;
}
else if (NewIsConfigLineEqualTo(line, "StartThisProgramAsAdministrator", "0") || NewIsConfigLineEqualTo(line, "StartThisProgramAsAdministrator", "false")) {
StartThisProgramAsAdministrator = false;
continue;
}

if (NewIsConfigLineEqualTo(line, "UseTheNewBestMethodEver", "1") || NewIsConfigLineEqualTo(line, "UseTheNewBestMethodEver", "true")) {
UseTheNewBestMethodEver = true;
continue;
Expand Down Expand Up @@ -1701,7 +1710,8 @@ bool Fix_Taskbar_Size_Bug(HWND Moomintrollen) {
ShowWindow(Hwnd, SW_HIDE);
Sleep(5);
ShowWindow(Hwnd, SW_SHOW);
Sleep(100);
//Sleep(100);
Sleep(500);//Attempt to fix issue https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix/issues/45
ShowWindow(Hwnd, SW_HIDE);
if (ShowConsoleWindowOnStartup) {
ShowWindow(GetConsoleWindow(), SW_SHOW);
Expand Down Expand Up @@ -1904,6 +1914,27 @@ bool IsCursorIconAllowed() {
return true;
}

bool IsCurrentCursorIconStopOrDrag() {
CURSORINFO cursorInfo = { 0 };
cursorInfo.cbSize = sizeof(cursorInfo);
if (::GetCursorInfo(&cursorInfo))
{
if (PrintDebugInfo) {
std::wcout << L"IsCurrentCursorIconStop(): Cursor Info: " << cursorInfo.hCursor << endl;
}

/*HCURSOR hCursorBeam = LoadCursor(NULL, IDC_NO);
if (cursorInfo.hCursor == hCursorBeam) {
return true;
}*/

if (cursorInfo.hCursor == (HCURSOR)0x170DE9 || cursorInfo.hCursor == (HCURSOR)0x10017) {
return true;
}
}
return false;
}

void AdvancedSleep() {
if (UseFixForBugAfterSleepMode) {
SleepModeFix_Previous_TimeNow = TimeNow;
Expand Down Expand Up @@ -2020,6 +2051,54 @@ bool CheckControlPixelsAboveTheMouseOnTaskbar() {
return false;*/
}


bool KnownPixelColors_CookieFileExists() {
//Windows11DragAndDropToTaskbarPartialFix
wstring TmpFile = std::filesystem::temp_directory_path().wstring() + KnownPixelDetectedCookieFilename;
if (FileExists(TmpFile.c_str())) {
return true;
}
return false;
}

bool KnownPixelColors_CookieFileCreate() {
wstring TmpFile = std::filesystem::temp_directory_path().wstring() + KnownPixelDetectedCookieFilename;
HANDLE h = CreateFileW(TmpFile.c_str(), // name of the file
GENERIC_WRITE, // open for writing
0, // sharing mode, none in this case
0, // use default security descriptor
CREATE_ALWAYS, // overwrite if exists
FILE_ATTRIBUTE_NORMAL,
0);
if (h)
{
CloseHandle(h);
return true;
//std::cout << "CreateFile() succeeded\n";
}
else
{
//std::cerr << "CreateFile() failed:" << GetLastError() << "\n";
}
return false;
}

BOOL IsElevated() {
BOOL fRet = FALSE;
HANDLE hToken = NULL;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
TOKEN_ELEVATION Elevation;
DWORD cbSize = sizeof(TOKEN_ELEVATION);
if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) {
fRet = Elevation.TokenIsElevated;
}
}
if (hToken) {
CloseHandle(hToken);
}
return fRet;
}

int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nShowCmd)
{
hPrevWindow = hPrev;
Expand Down Expand Up @@ -2060,6 +2139,24 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
LastSettingsChangeTime = NowSettingsChangeTime;
Mona_Load_Configuration();

//ver 2.2 check if run as administrator:
if (StartThisProgramAsAdministrator) {
if (!IsElevated()) {
if (Commandline.find(L"restart-as-administrator") != std::wstring::npos) {
//Do nothing, just in case it failed so we don't create a forkbomb
}
else {
wstring RestartNowWstr = L"restart-as-administrator-restart-ignore-mutex";
ShellExecuteW(NULL, L"runas", CurrentExeWorks.c_str(), RestartNowWstr.c_str(), NULL, SW_SHOW);
return 0;
}
}
}

if (IsElevated()) {
TheProgramIsRunningAsAdministratorRightNow = true;
}

bool ReloadConfigToShowDebugInfo = false;
if (!ShowConsoleWindowOnStartup) {
//ShowWindow(GetConsoleWindow(), SW_HIDE);
Expand Down Expand Up @@ -2151,6 +2248,12 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
}
}

if (DetectKnownPixelColorsToPreventAccidentalEvents) {
if (KnownPixelColors_CookieFileExists()) {
CorrectPixelsEverDetectedUsingCookieFile = true;
}
}


while (!InterruptMainThread) {
try {
Expand Down Expand Up @@ -2510,6 +2613,12 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
}
//Test pixel check, ver. 2.0.0.0:
if (DetectKnownPixelColorsToPreventAccidentalEvents) {

//ver. 2.2 check if "stop" cursor icon instead.
if (IsCurrentCursorIconStopOrDrag()) {
DetectedCorrectPixelsInThisClick = true;
}

if (!DetectedCorrectPixelsInThisClick) {
if (CheckControlPixelsAboveTheMouseOnTaskbar()) {
DetectedCorrectPixelsInThisClick = true;
Expand All @@ -2523,15 +2632,34 @@ int APIENTRY wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int nS
std::wcout << L"DetectKnownPixelColorsToPreventAccidentalEvents: Detected INCORRECT pixel colors. Ignoring the loop..." << endl;
}
}
//ver. 2.2
if (!CorrectPixelsEverDetectedUsingCookieFile) {
if (DetectedCorrectPixelsInThisClick) {
CorrectPixelsEverDetectedUsingCookieFile = true;
if (KnownPixelColors_CookieFileCreate()) {
if (PrintDebugInfo) {
std::wcout << L"DetectKnownPixelColorsToPreventAccidentalEvents: SUCCESSFULLY created Tmp File..." << endl;
}
}
else {
if (PrintDebugInfo) {
std::wcout << L"DetectKnownPixelColorsToPreventAccidentalEvents: FAILED to create Tmp File..." << endl;
}
}
}
}
}

//
//Hotfix. If somebody uses different curosr styles, or some icons modifications that make pixels detection impossible, then behave as if DetectKnownPixelColorsToPreventAccidentalEvents was false. So always after program restart... or no thats a bad idea. Might be annoying for people working in Word since computer start.
// TODO some different detection.
//if (EVERDetectedCorrectPixels) {

if (CorrectPixelsEverDetectedUsingCookieFile) {
if (!DetectedCorrectPixelsInThisClick) {
AdvancedSleep();
continue;
}
}
//}
}

Expand Down Expand Up @@ -2758,7 +2886,7 @@ void ClickedConfigureFromTray() {
if (!FileExistsW(ConfigFileBase.c_str())) {
std::ofstream ofs(ConfigFileBase.c_str(), std::ofstream::out);
ofs << "//Should the program run automatically on system startup? 1 = true, 0 = false." << endl
<< "AutomaticallyRunThisProgramOnStartup=1"<< endl << endl << "//For more configuration options, please visit: https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix/blob/main/CONFIGURATION.md" << endl;
<< "AutomaticallyRunThisProgramOnStartup=1" << endl << "StartThisProgramAsAdministrator=0" << endl << endl << "//For more configuration options, please visit: https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix/blob/main/CONFIGURATION.md" << endl;
ofs.close();
if (FileExistsW(ConfigFileBase.c_str())) {
LastSettingsChangeTime = ReturnConfigFileTime();
Expand Down Expand Up @@ -2844,13 +2972,20 @@ LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM
NameAndVer = L"Windows 11 Drag && Drop to the Taskbar (Fix)";
NameAndVer2 = L"ver. " + ProgramVersion + L". Created by Dr. Mona Lisa.";
NameRestart = L"Restart (PID: " + to_wstring(CurrentProcessID) + L")";
if (!TheProgramIsRunningAsAdministratorRightNow) {
NameRestart = L"* Restart (PID: " + to_wstring(CurrentProcessID) + L")";
}
if (RestartedCrashedTimes == 1) {
NameRestart = NameRestart + L" [Crashed: " + to_wstring(RestartedCrashedTimes) + L" time]...";
}
else if (RestartedCrashedTimes > 0) {
NameRestart = NameRestart + L" [Crashed:" + to_wstring(RestartedCrashedTimes) + L" times]...";
}
NameRestart = NameRestart + L"...";
NameRestartAsAdmin = L"Restart as administrator...";
if (TheProgramIsRunningAsAdministratorRightNow) {
NameRestartAsAdmin = L"* Restart as administrator...";
}

AppendMenuW(Hmenu, MF_MENUBREAK, 0, NULL);
//AppendMenu(Hmenu, MF_BITMAP, 2, (LPCTSTR)hbitmap);
Expand All @@ -2864,6 +2999,7 @@ LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM
AppendMenuW(Hmenu, MF_SEPARATOR, 0, NULL);
AppendMenuW(Hmenu, MF_STRING, ID_TRAY_OPENPATH, L"Open program folder...");
AppendMenuW(Hmenu, MF_STRING, ID_TRAY_RESTART, NameRestart.c_str());
AppendMenuW(Hmenu, MF_STRING, ID_TRAY_RESTARTADMIN, NameRestartAsAdmin.c_str());
AppendMenuW(Hmenu, MF_STRING, ID_TRAY_EXIT, L"Quit...");
AppendMenuW(Hmenu, MF_MENUBREAK, 0, NULL);
//Make some texts bold:
Expand Down Expand Up @@ -2968,6 +3104,17 @@ LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM
PostQuitMessage(0);
break;
}
case ID_TRAY_RESTARTADMIN: {
if (ShowTrayIcon) {
Shell_NotifyIcon(NIM_DELETE, &notifyIconData);
}
InterruptRestartProgramRunAs = true;
InterruptMouseWatchdogThread = true;
InterruptRestartProgram = true;
InterruptMainThread = true;
PostQuitMessage(0);
break;
}
case ID_TRAY_CONFIGURE: {
ClickedConfigureFromTray();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ int DefaultShowDesktopButtonWidth = 20;
int DefaultSingleWindowPreviewThumbnailWidth = 250;
int DefaultSingleWindowPreviewThumbnailHeight = 250;
bool UseAlternativeTrayIcon = false;
bool StartThisProgramAsAdministrator = false;//ver 2.2
bool TheProgramIsRunningAsAdministratorRightNow = false;

//bool KeepConsoleWindowVisibleEvenWhenDebugInfoIsDisabled = false;

bool ConfigFileChangeTimeMonitorAllowed = true;
Expand All @@ -71,11 +74,12 @@ int SleepTimeButtonsElevenPlusMilliseconds = 5;//Unused by default
int AnimationLagButtonsElevenPlusMilliseconds = 100;//Unused by default

//Dynamic variables:
wstring ProgramVersion = L"2.1.0.0";
wstring ProgramVersion = L"2.2.0.0";
wstring GitHubConfiguration = L"https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix/blob/main/CONFIGURATION.md";
wstring GitHubReleases = L"https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix/releases";
wstring GitHubAbout = L"https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix";
wstring GitHubChangeLog = L"https://github.com/HerMajestyDrMona/Windows11DragAndDropToTaskbarFix/blob/main/CHANGELOG.md";
wstring KnownPixelDetectedCookieFilename = L"W11DADTTPX_KnownPixelDetected.emptyfile";
wstring CurrentExeWorks = L"";
wstring CurrentExeWorksFilenameOnly = L"";
wstring CurrentExeWorksPath = L"";
Expand Down Expand Up @@ -220,6 +224,7 @@ int ConfigButtonID = 6;
wstring NameAndVer = L"";
wstring NameAndVer2 = L"";
wstring NameRestart = L"";
wstring NameRestartAsAdmin = L"";
MENUITEMINFO ItemInfo;
bool AllowedCursorIconInThisClick = true;
bool DetectedIconInThisClick = false;
Expand All @@ -230,6 +235,7 @@ long long int Previous_DPI_UniqueID_of_the_click = -1;
double Current_DPI_Scale_X = 1.0;
double Current_DPI_Scale_Y = 1.0;
bool EVERDetectedCorrectPixels = false;//Always false on program start.
bool CorrectPixelsEverDetectedUsingCookieFile = false;//False on program start

//Functions:
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
Expand Down Expand Up @@ -286,9 +292,13 @@ void ClickedCheckForUpdatesFromTray();
void ClickedConfigureFromTray();
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
bool IsCursorIconAllowed();
bool IsCurrentCursorIconStopOrDrag();
void AdvancedSleep();
void Update_Pseudo_DPI_Scale();
bool CheckControlPixelsAboveTheMouseOnTaskbar();
bool KnownPixelColors_CookieFileExists();
bool KnownPixelColors_CookieFileCreate();
BOOL IsElevated();


#ifndef DONT_INCLUDE_UNUSED_FUNCTIONS_TO_PREVENT_PSEUDO_ANTIVIRUSES_FROM_THROWING_FALSE_POSITIVES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Dr Mona Lisa"
VALUE "FileDescription", "Windows 11 Drag & Drop to the Taskbar (Fix)"
VALUE "FileVersion", "2.1.0.0"
VALUE "FileVersion", "2.2.0.0"
VALUE "InternalName", "Windows11DragAndDropToTaskbarFix.exe"
VALUE "LegalCopyright", "(C) 2021 Copyright by Dr.MonaLisa. All Rights Reserved."
VALUE "LegalCopyright", "(C) 2022 Copyright by Dr.MonaLisa. All Rights Reserved."
VALUE "OriginalFilename", "Windows11DragAndDropToTaskbarFix.exe"
VALUE "ProductName", "Windows 11 Drag & Drop to the Taskbar (Fix)"
VALUE "ProductVersion", "2.1.0.0"
VALUE "ProductVersion", "2.2.0.0"
END
END
BLOCK "VarFileInfo"
Expand Down
1 change: 1 addition & 0 deletions Windows11DragAndDropToTaskbarFix/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
#define ID_TRAY_ABOUT 1007
#define ID_TRAY_CHANGELOG 1008
#define ID_TRAY_OPENPATH 1009
#define ID_TRAY_RESTARTADMIN 1010
#define WM_SYSICON (WM_USER + 1)

0 comments on commit 8162d54

Please sign in to comment.