A
A
Alexander2021-05-25 09:42:33
Python
Alexander, 2021-05-25 09:42:33

How to change the main menu in the application through win32api?

Good afternoon!
There is a task: to change the menu in win application. As an example, I took a notepad, learned how to enter text into it through win32api.
We also managed to get the menu handle and count the number of items.
But how to get the text (name) of this menu itself?
Get subitems and click on them?
I use python3.7 and the win32api library for this.
Tell me, please, in which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2021-05-25
@plot147

Click on the menu. This is a C# analog in python, look at the likeness.

[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, Message msg, int wParam, int lParam);

PostMessage(handle, WM_COMMAND, 2, 0); // File->New subtitle

PostMessage(handle, WM_COMMAND, 3, 0); // File->New from clipboard

PostMessage(handle, WM_COMMAND, 5, 0); // File->Open text or subtitle

PostMessage(handle, WM_COMMAND, 6, 0); // File->Open video

In addition,
getting the menu by the window pointer
https://docs.microsoft.com/en-us/windows/win32/api...
Getting the number of items
https://docs.microsoft.com/en-us/windows/win32/ api...
Getting element Id
https://docs.microsoft.com/en-us/windows/win32/api...
Element information
https://docs.microsoft.com/en-us/windows/win32/ api...
and finally the caption of the element
https://docs.microsoft.com/en-us/windows/win32/api...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question