topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Wednesday October 28, 2020, 7:39 am
  • 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

Author Topic: App that works in combo with Desktop Coral by remembering app window locations  (Read 3463 times)

apinel

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
Looking for an app that could be used in combo with Desktop Coral, where the app would ensure certain windows (or all windows) are restored to their preferred positions if I were to, for example, shut down my computer.  Currently I have the Desktop Coral area in the bottom with two app windows occupying that space.  However, after rebooting the two windows are kicked out of the Desktop Coral area and I have to manually put them back in, which of course isn't efficient.  It would be great if there was an app that could remember the location of the windows and override the nature of Windows to kick them out from the Desktop Coral area.

I have Windows 10.  Much appreciated.
« Last Edit: December 11, 2019, 09:17 PM by apinel »

Sorryformyen

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 10
    • View Profile
    • Donate to Member
There don't seem to be many alternatives that do what Desktop Coral does (or try to do), but the output can be a combination with Autohotkey (here you'll have to use the help of the AHK forum to get your ideal code) or an alternative to Workspace Utilities.

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 513
    • View Profile
    • Donate to Member
This sound a bit challenging, i could try to create a program with this behavior, tell me if i am wrong on any line:

boot phase:
1. create a program thats only icon driven (notification area where the clock is)
2. ability to auto-load my app when windows boot
3. load last settings in memory
4. wait some time to give windows a chance to load other auto-loaded applications
5. as soon as a new process is loaded check if my app has a setting stored and force new window to be moved to stored position

icon phase
1. create minimal menu entries like "save current positions", "auto load my app on/off", "reset settings"

shut down phase:
1. let my app wait until windows shuts down
2. crawl thru all current active windows and remember their position
3. let windows shut down normal

problematic phase where i dont know yet how to handle:
1. applications that are minimized could be a problem since their positions arent revealed
2. applications that are just notification icons (like my own app), same as above

future phase:
1. maby create a window where you can see and edit stored settings...
2. maby create a window where you could choose wich windows you like to save manual...
3. other stuff that you like to have...


would such a thing be a solution to your request?


ps: the app that i create has nothing to do with desktop coral, it's standalone on it's own.
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

apinel

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
This sound a bit challenging, i could try to create a program with this behavior, tell me if i am wrong on any line:

boot phase:
1. create a program thats only icon driven (notification area where the clock is)
2. ability to auto-load my app when windows boot
3. load last settings in memory
4. wait some time to give windows a chance to load other auto-loaded applications
5. as soon as a new process is loaded check if my app has a setting stored and force new window to be moved to stored position

icon phase
1. create minimal menu entries like "save current positions", "auto load my app on/off", "reset settings"

shut down phase:
1. let my app wait until windows shuts down
2. crawl thru all current active windows and remember their position
3. let windows shut down normal

problematic phase where i dont know yet how to handle:
1. applications that are minimized could be a problem since their positions arent revealed
2. applications that are just notification icons (like my own app), same as above

future phase:
1. maby create a window where you can see and edit stored settings...
2. maby create a window where you could choose wich windows you like to save manual...
3. other stuff that you like to have...


would such a thing be a solution to your request?


ps: the app that i create has nothing to do with desktop coral, it's standalone on it's own.

Hello KodeZwerg,

Thanks for volunteering.  I'm attaching a screenshot of my desktop, which will help explain what I need.  The bottom of the desktop shows three app windows:
1) A news headline window app (see the red fonts in all caps).
2) A clock window app (very bottom).
3) A trading watchlist app (on the right).

These three windows reside in Desktop Coral space.  I've blocked off the space on the bottom of the desktop using Desktop Coral and the three windows reside there.

Sometimes if the desktop goes to sleep or let's say I restart my computer I have to:
1) Block off the bottom space using Desktop Coral again.
2) Reside the three window apps and place them in the Desktop Coral area.
This process takes me about 2-3 minutes.  Ideally I would like it to be automatic. 

Please let me know if that's something that you could produce or if you need more details.

Much appreciated! 

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 513
    • View Profile
    • Donate to Member
I'm attaching a screenshot of my desktop
Can't await to fully understand the required functionality.

best regards!
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

apinel

  • Participant
  • Joined in 2019
  • *
  • default avatar
  • Posts: 7
    • View Profile
    • Donate to Member
I'm attaching a screenshot of my desktop
Can't await to fully understand the required functionality.

best regards!

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

desktop.jpgApp that works in combo with Desktop Coral by remembering app window locations

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 513
    • View Profile
    • Donate to Member
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.
sorry bad english and Delphi are my hobby ;)
politeness is not one of my strengths in writing, just because it sounds rough doesn't mean that I mean it rough.

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,172
    • View Profile
    • Donate to Member
Does GridMove do what you need? I remember using it 10+ years ago and really liking it at the time.

HwapX

  • Member
  • Joined in 2015
  • **
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
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.

HwapX

  • Member
  • Joined in 2015
  • **
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
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.