ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

App that works in combo with Desktop Coral by remembering app window locations

<< < (2/2)

apinel:
I'm attaching a screenshot of my desktop
-apinel (February 18, 2020, 07:52 AM)
--- End quote ---
Can't await to fully understand the required functionality.

best regards!
-KodeZwerg (February 18, 2020, 09:51 AM)
--- End quote ---

My apologies! I did not include an attachment.  Please see it here.

App that works in combo with Desktop Coral by remembering app window locations

KodeZwerg:
Images say more than a thousand words, especialy when my motherlanguage ain't english  :P

Last description + photo tell me, i can't help.

My solution would be a generic windows helper, but redesigning a foreign application and it's child windows, i am very sorry, such skills i do not have yet.

Like Sorryformymen wrote, the AHK professionals should take over on that or my **ps part might work...

Good luck!


**ps:
Since i do not know that Coral thing, i would look out for a configuration file or registry entry, back it up and play back via batch when Coral is loaded, just a suggestion if Coral works with any kind of configuration.

Deozaan:
Does GridMove do what you need? I remember using it 10+ years ago and really liking it at the time.

HwapX:
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,LoadAfter 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.

HwapX:
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.

Navigation

[0] Message Index

[*] Previous page

Go to full version