Re: Win+E integration
Posted: 12 Jan 2018 11:37
Then maybe you should short-press it 
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
I am sorry for this...shpkong wrote:hyzhangzhy!
Your program launch dozens of XYplorer instance when long pressing Win+E...
which stuck my OS...
Code: Select all
#include <Windows.h>
#include <shlwapi.h>
#include <stdio.h>
HHOOK _hook;
KBDLLHOOKSTRUCT kbdStruct;
DWORD dwLast;
DWORD dwCurrent;
bool isActionExcuted = false;
bool isFirstPress = true;
char path[256];
char className[20];
HWND XYplorerWindow = NULL;
HANDLE KeyUpEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
HANDLE KeyDownEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
BOOL __stdcall EnumWindowsProc(HWND hwnd, LPARAM lparam)
{
GetClassNameA(hwnd, className, 20);
if (strcmp(className, "ThunderRT6FormDC") == 0 && IsWindowVisible(hwnd))
{
XYplorerWindow = hwnd;
}
return true; //return true to continue enuming Windows
}
LRESULT __stdcall HookCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
kbdStruct = *((KBDLLHOOKSTRUCT*)lParam);
if ((kbdStruct.vkCode == 0x45) && (GetKeyState(VK_LWIN) & 0x80000))//WIN+E down
{
if (wParam == WM_KEYDOWN)
{
SetEvent(KeyDownEvent);
return true;
}
else if (wParam == WM_KEYUP)
{
SetEvent(KeyUpEvent);
}
}
}
return CallNextHookEx(_hook, nCode, wParam, lParam);
}
void SetHook()
{
if (!(_hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookCallback, NULL, 0)))
{
MessageBoxW(NULL, (LPCWSTR)"The hook installation has failed!", (LPCWSTR)"Error", MB_ICONERROR);
}
}
void ReleaseHook()
{
UnhookWindowsHookEx(_hook);
}
DWORD WINAPI workThreadFunc(LPVOID lpParam)
{
while (WaitForSingleObject(KeyDownEvent, INFINITE) == WAIT_OBJECT_0)
{
if (WaitForSingleObject(KeyUpEvent, 500) == WAIT_OBJECT_0)
{
if (!isActionExcuted) //
{
EnumWindows(EnumWindowsProc, NULL);
if (XYplorerWindow == NULL)
{
WinExec((LPCSTR)path, SW_SHOW);
}
else
{
SwitchToThisWindow(XYplorerWindow, TRUE);
}
XYplorerWindow = NULL;
}
isActionExcuted = false;
}
else if (!isActionExcuted)
{
WinExec((LPCSTR)path, SW_SHOW);
isActionExcuted = true;
}
ResetEvent(KeyDownEvent);
ResetEvent(KeyUpEvent);
}
return 0;
}
void main()
{
FILE *fp;
fopen_s(&fp, "xypath.ini", "r");
if (fp == NULL)
{
printf("******************* XYplorer Win + E Helper in C *******************\n\nEnter your XYplorer full file path for the first time to use.\n\n");
while (true)
{
printf("Enter here: ");
gets_s(path, 256);
int res = PathFileExistsA(path);
if (res == 0)
{
printf("Can not find that file! Try again! \n\n");
}
else
{
fopen_s(&fp, "xypath.ini", "w");
fprintf(fp, path);
break;
}
}
}
else
{
fgets(path, 256, fp);
}
fclose(fp);
FreeConsole();
SetHook();
HANDLE workThread = CreateThread(NULL, 0, workThreadFunc, NULL, 0, NULL);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
}
ReleaseHook();
}
Code: Select all
MD5: a77a5526e0473794e67abc71a896d8cb