How do I navigate from a dialog button to the code behind? - c++

Cant believe I cant figure out how to do this.
If im looking at a created dialog in the dev studio and it has an ok button, how do I quickly get to the code for when the OK button is clicked?
At the moment I have to copy the resource ID for the dialog e.g. 'IDD_MYDIALOG'
search for that in the source files, open the source file, then start looking for an On_Ok() style function then do a search on that function then open it.
Thanks
ps Id also like to know how to do the same for menu selections.

Related

How can I open an *modal* file dialog with IFileOpenDialog?

I've been trying to implement a file dialog into my C++ application for a while now, and I achieved good success with the code described in this article (It is german, but the code should be understandable):
https://msdn.microsoft.com/de-de/library/windows/desktop/ff485843(v=vs.85).aspx
However, using this code in my window class, which is a CDialogImpl, I just can't find out how to make this file picker modal. If I use this code, I can just spawn multiple file picker.
Of course, I could just keep track of the state by adding a member variable representing the state, but it would still not solve the problem of being able to click around in the main window while the dialog is opened.
Is there any way which would allow me to make this window modal? I've been trying to scan through all available methods, but I couldn't find anything. I didn't find any flags which could be passed in the creation, neither any options which I could set after creation.
Any help is appreciated!
The example you link to is very simple and has no UI other than the file dialog. Your program is more complex, having a window from which the file dialog is invoked.
You need to provide an owner for the file dialog. When you do that the owner is disabled, part of what makes the dialog modal. Failing to pass an owner means that the other windows are not disabled and so still respond to user input.
The example code provides no owner, but since there are no other windows in that program, that is benign. Modality is only meaningful when there are multiple windows.
So, to solve the problem, pass the owner, the handle of your window, to the Show method of the file dialog.
Disabling owner windows is one of the key parts of a modal dialog. You will find that any API for modal dialogs expects you to specify an owner. Get into the habit of expecting to provide that ownwr window, and looking for the means to do so.

Context menu handler for folders

I am trying to wrap my head around Microsoft's shell extension context menu handler example.
Its implementation only shows a context menu on a .cpp file right-click. I want to try to extend it to allow it to show the context menu whenever a folder, drive, or empty space is right-clicked in Explorer as well.
So far I was only able to modify it to register right-clicks for all file types, not just .cpp files by specifying * when registering it:
hr = RegisterShellExtContextMenuHandler(L"*",
CLSID_FileContextMenuExt,
L"CppShellExtContextMenuHandler.FileContextMenuExt");
I must be missing something else because it won't pop up for folders. I have tried this suggestion but it did not work.
How can I extend this sample to also have it work for folders? Am I missing something from the registry?
Edit: Thanks to Igor's suggestion, I got it to work for folders and drives, but it does not show up when you right-click the desktop or when you right click blank space in a folder, and I did register for Directory\Background and DesktopBackground. Why is this?

Show Message Bar in ribbon mfc

Probabbly i am not sure what to search for ... But the idea is to display a message bar bellow ribbon control. When user try to edit a read only file. I don't want user to click on OK to remove error message. Thats why i can't use MessageBox.
Status bar doesn't seem right place to display error messages.
Which control i should start exploring.
MSOffice normally displays such message when user opens files in protected view .
I don't want you to do research for me, I just want the right direction i will do the rest.
Thanks
You can easily use CMFCCaptionBar for such an attempt. When you create a ribbon bar SDI application you get sample code for free.
Also it is possible to hide and Show such a bar on the fly with ShowWindow. Also this code is generated by the wizard.

Accessing a right click context menu from an external application

After performing some Google-fu and searching Stack Overflow I've been unable to find a way to access the right click menu of an item and read data or select an item from it. I've looked up methods for SendMessage and PostMessage
What I've done so far:
This is an example of post here that would have been exactly what I want if it didn't use Qt and would work on an external application. Everything I've been able to find is about creating a right click menu when I just want to view an external application's right click menu.
I've tried getting the handle of the context menu using Spy++ but the menu just disappears as soon as I select the "Find Window" option in Spy++ (which is to be expected).
The only way I could think of doing this is using mouse_event to display the box but then I don't know where to go from there. I feel like this would also be very inefficient.
I'm working on some legacy code so I don't have a lot of choice in what I can use, if it's possible I'd like to not use libraries that aren't included in Visual Studio 2008.
What I'm trying to do:
I'm looking for a way to access the right click context menu in an external application and read the data in it and then select an item. I feel like this should be really simple but my research skills are subpar. If anyone can point me in the right direction I would really appreciate it.
Thank you for reading!
The only way you can get hold of a context menu is to make the application display it. It doesn't exist otherwise. (The other question you give as an example is regarding the Windows Shell menu which is designed to be useable)
A window gets sent WM_CONTEXTMENU when the user right clicks, so you could use SendMessage() to invoke the menu, or failing that just send a right click.
After a bit of googling, I think context menus have a classname of #32768, so you could use FindWindowEx to find a child window handle with the matching classname.
Once you have the window handle, you can use the MN_GETHMENU message to get hold of the menu handle.

QT Menu how to create a new window?

I am working in QT Creator.
I would like to mention that I am beginner in this software. I succeeded to create a menu that has: Edit and Open. I would like to create a new window when " Open " from menu bar is clicked. Till now I succeeded to print a message in QMessageBox when I press Open. What is the code for linking Open clicked with a new window? Is it possible to somehow drag and drop a new window in mainwindow.ui and than link it with Open on action Open_activated()?
THX . Appreciate
P.S I AM WORKING IN UBUNTU/C++ language
This is probably too late to answer but as I am also a beginner and struggled a lot to figure out this, I would like to share a solution that worked for me and according to me this is one of the simplest solution out there for a beginner.
Follow this link. It's possible that in the future that link might not exists, hence I am writing down a detailed version, as detailed as possible because I think for an absolute beginner (like myself) it can be very useful.
Default mainwindow.cpp
Go to "mainwindow.ui" (or whatever .ui one has)
Right-click outside the window and activate "Action Editor" if it wasn't already activated:
Right-click on the window and create "Menu-bar" and then double-clicking on "type here" you can rename it as "Open" or something which will then drop-down another box where you can again type the name you desire, let's say "message".
When created menu item "message" is created corresponding item will apear in the "Action Editor"
Right-click on the "message" in the Action Editor and click "go to slot" which will lead you to the specific slot in the mainwindow.cpp:
Here you can create a small window with whatever message you want to display.
[![Window creating code]11 etc goes here.]12
****don't forget to include "QTextEditor", go to mainwindow.h and #include "
On compiling & executing we will see :
Most of the question is already answered by this previous question. It leaves one part open, namely how that slot is called.
Well, you answered that: the menu entry "Open" is a QAction. You can connect that action to the slot which you just created.