Overriding another windows WindowProc in C++ - c++

I'm working on a personal project where I need to invoke my function after an menu item in another process is clicked.
I'm using
BOOL enumeratingWindowsSucceeded = ::EnumWindows(enumWindowsProc, NULL);
to retrieve the handles to all of the currently open windows on my computer and using
GetSystemMenu(...)
and
AppendMenu(...)
to add an item into all the window's title bar context menu.
Now the problem is when the menu item is clicked in the other window's context menu, my program does not know about it.
Is there a way to override the WindowsProc of another window so that my process can execute some piece of code? Or is there a better way to make the menu item communicate with my program?
Thanks!

Related

Is there a way to make MessageBox not freeze the application?

I'm currently experimenting around with message boxes using the Windows.h module in C++ and I'm curious if there is a way to make the function not hang/freeze the application.
I tried using the MessageBox function and it just hangs/freezes the application until there is user input to the messagebox
The Windows API function MessageBox will create a modal dialog box, which means that the owner window gets disabled and the function will only return as soon as the dialog box is closed.
If you don't want the owner window to get disabled and want the function to return immediately, you should instead create a modeless dialog box using the functions CreateDialog or CreateDialogIndirect.
Another option besides using CreateDialog would be to create a secondary thread and use MessageBox with a NULL hWnd argument.

Attach a pop-up menu to a self-defined event in GLUT?

I know that with GLUT, I can create a Pop-up Menu with glutCreateMenu, glutAddMenuEntry, glutAttachMenu.
And there are three events can be used with glutAttachMenu -- "GLUT_RIGHT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_LEFT_BUTTON".
However, I want this Pop-up menu show when some other event happens, such as double-click (assuming that I have written a function DoubleClick() which will return true if there is a double-click).
How can I implement this?

MFC menu item doesn't open dialog box

I am having a proglem with the MFC application and the DialogBox. I am quiet sure I've done everything well with this tutorial: https://msdn.microsoft.com/en-us/library/6wb9s9ah.aspx
but still it doesn't work...
1. I've created new project with simple menu commands.
2. I've created new menu item (+ID) and new resource DialogBox (+ID).
3. Then I've added a new class named CParameters with the Class Wizard. For the BaseClass I've typed in CDialog.
4. I've created new handler on the menu item and added the code
CParameters dlg;
dlg.DoModal();
I think this is it, and this should work... But it doesnt... What is missing??
Here is my project, you can access it freely:
https://www.dropbox.com/sh/e6ajoxqk76hkuvn/AACRMY8bgcuyXguFwP240QB9a?dl=0
Additionally I want to insert TextEditors and to change parameters in my program from the dialog box.
A scan of your source code reveals that you are trying to handle the menu item event within the class that is going to display the dialog.
void CParameters::OnParam()
{
// TODO: Add your command handler code here
CParameters dlg;
dlg.DoModal();
}
I don't see anywhere else that you actually instantiate the dialog class (I may have missed it). What you are trying is incorrect. You cannot handle the menu item event within the same class that displays the dialog because that class (CParameters) has not been instantiated, so, it cannot respond to the menu event. Typically, the menu event would be handled in the mainframe class.
If you are doing this by adding a new menu item from a simple SDI application, then trying adding that part of code in
CMainFrame::OnEdit
OnEdit method used here is obtained from the Event Handler for the new menu item and Message type being COMMAND.

Win32 API, Get Child Windows for Game

I'm using this code to get the child windows of all open processes.
The code itself is working correctly, I get a 2 dimensional list of handles. Each index has a list of handles to the child windows of a specific process.
I'm trying to get a child window of a game. The game itself is inside window. It appears in the task manager and in my task bar. There is a button inside the game I press that opens a new window. The new window does not appear in the task manager but it does appear on the task bar.
The problem is the code in the link above will not return any child windows for the game even though a new window has opened and it can be seen in the task bar.
Any Ideas what I could be doing wrong?
Ok found the solution, should have used GetWindowText instead.

Adding Menu and Submenu options to Window Menu in MAC using wXwidget C++

Hi I am new to Mac using wxWidget.
I need to add a sub menu and some menu items under the Window Menu on MAC.
I am able to do same for Window menu on PC but not on MAC.
Also, I am not getting event for click on Window Menu to the function attached with EVT_MENU_OPEN event.
Please help.
I don't really understand the question clearly. However you may have to do something like this for a menu on mac.
m_menuBar = new wxMenuBar();
#if defined(__WXMAC__)
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macAboutMenuItemId, wxT("About"));
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macWindowMenuItemId, wxT("Window"));
m_menuBar->SetAppleMenuItemLabel(wxApp::s_macExitMenuItemId, wxT("Quit"));
#endif
where s_macAboutMenuItemId, s_macWindowMenuItemId, s_macExitMenuItemId are your respective menu ids defined.
and regarding not getting event for click on Window Menu to the function attached with EVT_MENU_OPEN event, check if you have correct entries(Menu id, corresponding function name) in the declared event table.