topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday May 19, 2022, 7:23 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - HwapX [ switch to compact view ]

Pages: [1]
1
Post New Requests Here / Re: Request - file path collector program
« on: September 18, 2021, 09:00 AM »
I know this is an old topic and it's already "resolved", but as the creator requested some features and I'm on vacation and very bored, I made a new version.

PathCollector.png

Features
  • Log paths to selected file
  • Drag and drop
  • Send to integration
  • Clipboard monitoring(log copied file/directories paths)
  • Filter paths by files, directories or both
  • Option to skip duplicates
  • Option to recurse directories path
  • Option to truncate output file every time the program is open
  • Option to set window always on top
  • Option to minimize to tray
  • Option to start with windows

Source and download can be found at https://github.com/HwapX/dcPathCollector

2
Please post some sample data and the expected command to be run.

3
I attached another version that not rely on rundll32, it has your own bootstrap and create an icon at systray, can be closed with double click on icon.

Due how Windows work two distinct versions are need one for 32 bits and another for 64 bits applications.

It was only tested under Windows XP 32 bits, because due my limited ram its the only Windows vm that i can run.

4
Just a proof of concept, this will add an check option "Remember Size/Pos" to Window system menu.

#include <stdio.h>
#include <windows.h>

#define MENU_SEPARATOR_POS 5
#define MENU_SEPARATOR_ID 0x0D10
#define MENU_REMEMBER_ID 0x0C10
#define MENU_REMEMBER_POS 6
#define MENU_REMEMBER_CAPTION "Remember Size/Pos"

#define INFO_FORMAT "x%dy%dw%dh%dm%d"

char *iniPath = NULL;

void WriteData(HWND hwnd, BOOL save) {
char filePath[MAX_PATH];

if(GetModuleFileName(NULL, filePath, MAX_PATH)) {
RECT rect;
char cls[MAX_PATH];
char value[MAX_PATH];
BOOL max = GetWindowLong(hwnd, GWL_STYLE) & WS_MAXIMIZE;
GetWindowRect(hwnd, &rect);
GetClassName(hwnd, cls, MAX_PATH);

sprintf(value, INFO_FORMAT, (int)rect.left, (int)rect.top, (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), max ? 1 : 0);

WritePrivateProfileString(filePath, save ? cls : NULL, value, iniPath);
}
}

BOOL ReadData(HWND hwnd, int *iX, int *iY, int *iW, int *iH, BOOL *bMax) {
char filePath[MAX_PATH];

if(GetModuleFileName(NULL, filePath, MAX_PATH)) {
char value[MAX_PATH];
char cls[MAX_PATH];

GetClassName(hwnd, cls, MAX_PATH);

if(GetPrivateProfileString(filePath, cls, "", value, MAX_PATH, iniPath) && value[0] != '\0') {
sscanf(value, INFO_FORMAT, iX, iY, iW, iH, bMax);
return TRUE;
}
}

return FALSE;
}

__declspec(dllexport) LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) {
if(nCode == HCBT_CREATEWND) {
CBT_CREATEWND *cbt = (CBT_CREATEWND*)lParam;
HMENU hm = GetSystemMenu((HWND)wParam, FALSE);

if(hm != NULL) {
BOOL max = FALSE;
UINT flags = ReadData((HWND)wParam, &cbt->lpcs->x, &cbt->lpcs->y, &cbt->lpcs->cx, &cbt->lpcs->cy, &max) ? MF_CHECKED : MF_UNCHECKED;

if(max)
cbt->lpcs->style = cbt->lpcs->style | WS_MAXIMIZE;

InsertMenu(hm, MENU_SEPARATOR_POS, MF_BYPOSITION | MF_SEPARATOR, MENU_SEPARATOR_ID, NULL);
InsertMenu(hm, MENU_REMEMBER_POS, MF_BYPOSITION | flags, MENU_REMEMBER_ID, MENU_REMEMBER_CAPTION);
}
} else if(nCode == HCBT_DESTROYWND/*nCode == HCBT_MOVESIZE || nCode == HCBT_MINMAX*/) {
HMENU hm = GetSystemMenu((HWND)wParam, FALSE);

if(hm != NULL)
WriteData((HWND)wParam, GetMenuState(hm, MENU_REMEMBER_ID, MF_BYCOMMAND) & MF_CHECKED);
}

return CallNextHookEx(NULL, nCode, wParam, lParam);
}

BOOL dup = FALSE;
__declspec(dllexport) LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) {
MSG *msg = (MSG*)lParam;
    if(msg->message == WM_SYSCOMMAND && msg->wParam == MENU_REMEMBER_ID) {
        if(!dup) {
            HMENU hm = GetSystemMenu(msg->hwnd, FALSE);

            UINT flags = GetMenuState(hm, MENU_REMEMBER_ID, MF_BYCOMMAND) & MF_CHECKED ? MF_UNCHECKED : MF_CHECKED;
            ModifyMenu(hm, MENU_REMEMBER_ID, MF_BYCOMMAND | flags, MENU_REMEMBER_ID, MENU_REMEMBER_CAPTION);
        }
        dup = !dup;
}

return CallNextHookEx(NULL, nCode, wParam, lParam);
}

__declspec(dllexport) int Hook() {
HHOOK cbtHook = NULL;
HHOOK wndHook = NULL;

HINSTANCE hDll = GetModuleHandle("spr.dll");
HOOKPROC proc;

if(hDll == NULL)
return -1;

proc = (HOOKPROC)GetProcAddress(hDll, "CBTProc");
cbtHook = SetWindowsHookEx(WH_CBT, proc, hDll, 0);

if(cbtHook == NULL)
return -2;

proc = (HOOKPROC)GetProcAddress(hDll, "GetMsgProc");
wndHook = SetWindowsHookEx(WH_GETMESSAGE, proc, hDll, 0);

if(wndHook == NULL)
return -3;

    Sleep(INFINITE);

UnhookWindowsHookEx(cbtHook);
UnhookWindowsHookEx(wndHook);

return 1;
}

__declspec(dllexport) void CALLBACK Load(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) {
Hook();
}

BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if(fdwReason == DLL_PROCESS_ATTACH) {
int size;
iniPath = malloc(MAX_PATH);
size = GetModuleFileName(hinstDLL, iniPath, MAX_PATH);
iniPath[size - 3] = 'i';
iniPath[size - 2] = 'n';
iniPath[size - 1] = 'i';
} else if(fdwReason == DLL_PROCESS_DETACH) {
free(iniPath);
}

return TRUE;
}

Compile with
gcc -shared -o spr.dll main.c -Wl,-- kill-at -s -Os

Run with
rundll32 spr.dll,Load
After that, new windows will have the option added and load their size/positions.

To disable, just kill the process. A side effect is that the existing windows will not have the menu removed, this is no big deal, as the option simply does nothing.

Be warned that the code has not been fully tested and can cause problems or unwanted side effects.

Pages: [1]