Center taskbar icons with the registry [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I would like to position the icons on my taskbar windows 10 in the center of the desktop.
I know the famous TaskbarX does it but I don't know how to do it in python, could someone explain to me or give me the path in the registry to modify please
Example of center icons taskbar

On Windows 10, you can't center icons just by modifying the Windows Registry.
But on Windows 11 you just modify TaskbarAl (0 = left, 1 = centered) value in \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced.
What TaskbarX and other similar tools do for Windows 10 and prior versions, is to calculate the taskbar icons location using accessibility functions like UIAutomation or MSAA.
As shown in the picture above, using UI Accessibility Checker tool by Microsoft, this is showing the MSAA tree of the explorer.exe process, specially that instance that holds the taskbar.
First, find the taskbars instances, using EnumWindows and pick those beloging to explorer.exe process that has as Win Class Name "Shell_TrayWnd" (for primary monitor) and "Shell_SecondaryTrayWnd" (for the other monitors). Once you found them, using that tool as a guide, find the exact running applications list in that accessibility tree, for each taskbar instance (main monitor and secondary monitors). Once found the exact location of the taskbar list icons, pick the first one's left position and then the last one's right position. With that coordinates you will get its real width inside taskbar window, and using SetWindowPos modify its position in its taskbar area using its child windows container.
In the previous picture, you can see the hierarchy of child Windows inside the main taskbar's Shell_TrayWnd window handle, the child that contains the running applications is named ReBarWindow32 which has its own coordinates within that taskbar window, you just modify it using a timer or a shell event whenever a new process is started, or existing one is closed, or switched to another virtual desktop, and maybe other events, all that in order to re-adjust its location (centering in your case).
Normally, using timers will be polling the system unnecessarily, it is recommended to use the shell messages that Windows taskbar itself relies on, as mentioned here https://devblogs.microsoft.com/oldnewthing/20201228-00/?p=104610 you register your process as a shell message client or hook the shell message https://learn.microsoft.com/en-us/windows/win32/winmsg/about-hooks, that depends on you.
You can take a look a PowerToys source code, specially the module ShortCutGuide, that shows the taskbar's icon location with numbers. https://github.com/microsoft/PowerToys/blob/master/src/modules/ShortcutGuide/ShortcutGuide/tasklist_positions.cpp just find a way to port it to Python and proceed as mentioned above.
I repeat, Windows 10, doesn't offer that centering functionality out of the box unlike Windows 11.
If you see the last picture, that snapshot belongs to a child window hierarchy in Windows 11's taskbar, but if you'll compare to your Windows 10, 7, 8, etc. (using UUSpy tool or Spy++) you will notice that this picture shows extra child windows, specially using Xaml string in its class names. Those are new children that now holds not only the task list, but the Start menu button, search, widget, etc. they're not found in Windows 10 or previous versions. However, Windows 11 still keeps the older list child window "ReBarWindow32" (that one used in previous Windows versions) but it is hidden in favor of the new ones, and I guess they will remove it in the future, since this new one does the centering and animations when new apps are launched or closed, etc.

Related

Open new window - tkinter/tk taskbar/dock

How can I can a function and create a function for the icon context menu? I want to make the iconic Open New Window function pop-up when you right click on the icon menu in the taskbar/dock. See this question for more info on this kind of question.
Places I have looked but found nothing:
https://www.tcl.tk/man/tcl8.5/TkCmd/tk_mac.html#M15
https://pyinstaller.org/en/stable/feature-notes.html#open-event-handling-in-a-tkinter-based-gui-application
While there are a tiny subset of apple events that you can benefit from the DockMenu is not accessible directly via tkinter. Turns out mac is not really open for modifications and even smaller tasks can be hard. You could consider to use a system tray icon instead.

How to emulate mouse/keyboard events in a unfocused/minimized window?

I am trying to do some automation with Python, but I want to execute it and still being able to use my machine freely. So I am using PyWin32 to emulate some clicks and typing but it only works if I run the script while the window is open and focused.
There is a way to make my script only focus on a window, and still be able to click on that window without taking control over the mouse, even if the window is not focused (if it works when is minimized, is best!)?
i do not know the PyWin32 package but from a win32 api point of view the thing should be easy.
get a HWND of that window and post (PostMessage) the events you want to the window.
eg: WM_LBUTTONDOWN & WM_LBUTTONUP, WM_RBUTTONDOWN & WM_RBUTTONUP, WM_MOUSEMOVE...
look at the win32 help how to set the wParam & lParam data for the specific events.
i controlled diablo 3 this way for example ;)
Edit:
there is no need to be in focus or maximized for this
Edit Edit:
may be you should look after autoit, a widely used scrip language for window automation. I never used it but read the name very often in this context. it may also be usable from python.

How to get multiple widows to appear in a slightly different position?

I have this program that stores some information about my books, and this information is shown in windows, that appear whenever I double-click a book title in a list. But there is the possibility of searching for a book using it's title or author, and that can make the program open multiple windows. My problem is, all the windows are opened one over the other, and, until the I move a window, or close it, it seems that only one window was opened. Is it possible to, with python and tkinter, make the windows appear in slightly different positions?
You can use the geometry method of a window to specify where you want it to appear. For example, w.geometry("+100+200") will open the window w at coordinate 100,200. Each time you open a new window, adjust the coordinates appropriately.
Normally, though, this is something the window manager does for you. It's odd that it's not doing this for you.
The geometry method is documented here, among other places: http://effbot.org/tkinterbook/wm.htm#Tkinter.Wm.geometry-method

Globally poll which files are being dragged in Windows API?

I'm wondering if it's possible to globally poll which (if any) files are currently being dragged in Windows using the Windows API, independently of any particular window.
For example, I'm doing some stuff with networking where, when the user drags a file to the edge of the screen, it notifies a separate computer that the file has hit the screen edge. I've got my program running in the background, but it's not windowed, and it's hard (impossible) to place my window around all 4 screen edges.
I'm doing this in Python, but if I have to use another language and write a wrapper around it that's fine too.
You want to hook DoDragDrop.

Get active gtk window in python

How would I get a handle to the active gtk.Window in python? (not a window I created, but the currently focused window).
The answer is actually not OS-specific -- you can do it within GTK. You can get a list of all the toplevel windows from the application using gtk.window_list_toplevels(), then iterate through it until you find one where window.is_active() returns True.
If you want to consider other windows than the ones from your application, then you could try gtk.gdk.screen_get_default().get_toplevel_windows() but this will only get you GDK windows and not GTK windows, because you have no way of knowing whether those GDK windows are actually associated with GTK windows.
[Note: This answers the question as the OP originally phrased it, which other readers will probably be searching for - not the very different question that they changed it to in comments on the other answer.]
If you have a GtkApplication and have added your GtkWindows to it - which you should probably do, because GtkApplication can do lots of really cool stuff! - then you can use GtkApplication's much simpler API dedicated to this purpose:
Gtk.Application.get_active_window():
Gets the “active” window for the application.
The active window is the one that was most recently focused (within the application). This window may not have the focus at the moment if another application has it — this is just the most recently-focused window within this application.

Categories

Resources