System wide right click context hook - visual-c++

**Hello..
i am creating English To Gujarati Dictionary WinForm Application.
I need to set a system wide hook to the right click context menu on for text selection.
it means when this application is running,and if user selects word from any program and right click on it gujarati meaning of that word should be displayed as menu item.
How to do this?
or any other options like Registery Programming,shell extentions etc...?
i have to do this,even if you say its not possible.
so please help me.**

Hooking the mouse activity is the easy part. See SetWindowsHookEx, and lots of questions regarding hooking in SO. This way, you can tell when the mouse is right-clicked.
Getting the selected text is the harder part. See WindowFromPoint, for starters. You'd have to recognize the control, and if appropriate get the selected text from it. This will not always be possible using simple Win32 functions, if the control is complex.
Adding the translation to the right-click menu is probably the impossible part. Adding stuff to explorer context menu is not a problem, because explorer provides that possibility. But various applications will have various right-click menus, without a way to extend them. They might not even use Win32 for the menus, for whatever reason. A better option, IMO, would be one of the following:
Forget about changing the right-click menu. Open a window next to the point of selection with whatever content you want, and let the application show its own right-click menu.
If the user right-clicks while, say, pressing shift, show your own right-click menu, and don't pass the message to the application. So the user will see only one menu, which is yours. The user must of course be aware of this combination.

Related

Keep taskbar icon, replace MFC dialog

I have a MFC dialog based application. User can change the language of the dialog, and I made this by closing existing dialog, and opening another with changed language. The problem is that the effect in the taskbar is that one icon is removed, and another identical is created in its place. If my application's icon is not the last icon in the task bar it will be perceived as it was moved to the end of taskbar icon set.
I want to retain icon's position in the taskbar, and rather to prevent icon flicker at all from happening. How do I do that?
The application must support OS'es from Windows XP to Windows 7.
EDIT: alternative question for which I would accept an answer is how to create an invisible window that is nevertheless shown in the taskbar, and how to forward relevant window messages from that window to my main window?
Make the dialog a child of another outer parent window. The parent can be a dialog or any other kind of window; all it will be providing is the title bar. If the user tries to resize it it will have to forward resizing commands to the dialog, but otherwise you shouldn't need to do much in the parent window.
Why not replace the dialog with a CFormView instead? That way there's a frame window that wraps around the dialog (which is embedded in a form view) and it's the frame window that owns the taskbar icon.
Create an SDI application that displays a CFormView. Display the dialog in the default language (or whatever langauge the user previously chose) on initialization. When the user chooses the 'change language' option, simply change the form view that's being displayed with a new one.
Bonus feature: with this design, the framework will take care of things like language-specific accelerators and menus for you with no effort on your part.
For more on how to do this, check out http://www.codeguru.com/cpp/w-d/doc_view/viewmanagement/article.php/c3341/Multiple-Views-Using-SDI.htm

How to create a simple text box asking for 2 inputs from customer in MFC

We have a legacy code MFC VC++ one.
I need to add a message box asking for 2 inputs(both are string).
No need to consider security issue. Just need input.
How to do this?
I am really not MFC guy. Searched several pages. Not good for me.
Best
Thank you
To get input you want a dialog, not a message box.
Assuming you're working in VS, you'll go to the resource view, expand the tree, right-click on "Dialog" and pick "Insert Dialog" from the pop-up menu. That'll let you draw your dialog, where you'll insert a couple of edit controls, probably with a static control next to each to describe what to enter there, etc. It'll start out with Ok and Cancel buttons, so you don't need to add those.
Once you've drawn what the dialog will look like, you need to add some code and such to back it up. Right click on one of the controls, and pick "Add Class" from the menu. That'll bring up a dialog that'll ask for the name of the class for the dialog. You'll enter some class name (e.g., "my_input") and it'll pick matching names for the source/header file. You'll probably want to change the base class from "CDHtmlDialog" to "CDialog". When you're happy with that, click "finish" and it'll create the class/files.
Then you'll go back to the dialog, right-click in one of the edit controls, and choose "add variable". To keep things simple toward the far right, change the "Category" from "Control" to "Value". Then pick a name for the string you'll receive from that control and click Ok. Repeat for the other control. Repeat for the other edit control (obviously choosing a different name for its variable).
The last thing you need to add is some code to invoke that dialog. To do that, you'll need to include the dialog's header in where you're going to use it. Then you'll add a bit of code something like:
my_input inp;
if (inp.DoModal() == IDOK) {
// retrieve your two strings
CString input1 = inp.field1;
Cstring input2 = inp.field2;
}

How to make a custom dialog in InstallShield?

I'm trying to understand InstallShield (2009)/InstallScript on the fly, because I'm modifying someone else's installation script.
One of the dialogs during the installation procedure previously had one textbox on it, asking for a SQL Server instance, assuming a certain database name. Now I've just completed an enhancement enabling you to choose any database name, not just the default, and I need to add a field to this dialog so the user can input the chosen DB name. Monkey see, monkey do, just make a new control and duplicate and adapt whatever functionality the form had for the first textbox - easy enough, right?
Umm... problem here. It seems that the "SdShowDlgEdit1" form is a generic thing that gets shipped with InstallShield, and is used all over, wherever you have a dialog that needs one textbox. Change that form, and it changes everywhere that it's called... so now I have a spurious 2nd textbox appearing all over my installation wherever there was a single text box before.
Oops. Undo changes, and change the reference to "SdShowDlgEdit2", which is - you guessed it - InstallShield's standard form for dialogs needing 2 textboxes. Now that would be great.... excepting that the previous developer got there before me and added a "browse" button to that form for a place where he needed the 2nd text box to contain a folder path. I don't want that "browse" button, and I can't delete it.
So I think, why don't I create a custom form of my own, and not get under anyone else's toes? So I clone the form, rename the new instance to "EnterDbDetails", delete the "Browse" button and make the form look just right.
Then I go back into the InstallScript to redirect to "EnterDbDetails" and discover that the EzDefineDialog function requires me to pass in the "Resource ID" of the form. Now what was it again... 12018... great... fill in all necessary details, compile, build, and give it a whirl. Looks lovely, all the right default values are filled into the two text boxes - but hey! Why is the browse button there? And why is the text on the labels not what I set?
Back to InstallScript, check the Resource ID - turns out that the original "SdShowDlgEdit2" also has a Resource ID of 12018. Well, that explains that nicely. Silly that InstallShield allows you to have two forms with the same ID, but whatever... So let's go back to my "EnterDbDetails" form and change the ID...
... but the Resource Identifier property is read-only! WTF?
So now I can't use any of the standard forms, and I can't use a custom form because it won't let me change the resource ID.
I am stumped. Can anyone please explain how you are supposed to do something like this, which really ought to be the simplest thing in the world?
Creating New Custom Dialogs in InstallScript and InstallScript MSI Projects
Quote from the site (2015 edition) :
To create a custom dialog, you need to perform the following general steps:
Use the New Dialog Wizard to add a new custom dialog to your project. For more information, see Using the New Dialog Wizard to Add a New Custom Dialog to an InstallScript or InstallScript MSI Project.
Add controls to the dialog. For more information, see Adding a Control to a Dialog in an InstallScript or InstallScript MSI Project.
Create a script function that loads the dialog into memory, displays it on the screen, handles the end user’s interaction with the dialog’s controls, and closes the dialog when the user is finished with it. For more information, see Using InstallScript to Implement Custom Dialogs.
To create a new dialog:
Open the Dialogs view. The Dialogs view is located in the User Interface section of the View List.
Right-click the All Dialogs explorer and then click New Dialog. The Dialog Wizard opens. Click Next to dismiss the Welcome panel.
In the Dialog Template panel, click Interior Wizard Panel, and select the Let me insert this dialog in a User Interface sequence check box.
In the User Interface panel, select Installation in the User Interface Sequence list. In the list of dialogs, select InstallWelcome. Based on these selections, InstallShield will insert your new dialog in sequence immediately following the InstallWelcome dialog.
In the Dialog Position and Condition panel, leave the default settings, and click Finish. Your new dialog appears in the Dialogs list.
Right-click the dialog and select Rename. Rename the dialog WelcomeBitmap.
Using the same technique, you can insert additional dialogs in your installation’s user interface.
In this step, you will modify the WelcomeBitmap dialog that you just created:
First, create a bitmap (using a program like Microsoft Paint) that measures 300 by 150.
Open the Dialogs view.
Expand the WelcomeBitmap dialog’s node. Click English (United States) to open the Dialog Editor.
Click the Dialog Bold Title text box at the top of the dialog. In the Text field, type Welcome Bitmap. This changes the dialog’s main title.
Click the Dialog Normal Description text box at the top of the dialog. In the Text field, type Displays my welcome bitmap. This changes the dialog’s description.
Click the Bitmap button on the Dialog Control toolbar and use the cursor to drag a box on the dialog. Set the Height to 150 and the Width to 300.
In the File field browse to the bitmap file that you created in step 1.
After rebuilding the project (by pressing F7) and running it (by pressing CTRL+F5), the Welcome Bitmap dialog will appear after the Install Welcome dialog.
You need to edit the ResourceID (to something unique) in the Dialog table which is found in the Direct Editor under Additional Tools section in the Installation Designer.
By custimizing standard InstallShield dialogs, like sdWelcome, sdFinish and sdFinishReboot you will be able to use the dialogs default script APIs with the performed customization's

Visual C++ ListBox as Preference Chooser

So I'm building a tool that allows a user to edit a whole bunch of preferences for various things. There are several groups of settings, too many to use a TabControl without creating arrow sliders to view all of the tabs, so I decided I would try and use a ListBox to list the groups of preferences, and then when they click on them, the settings that they can change show up to the right of the box.
I'm just not sure how to do this. Obviously it would invoke something in the OnSelectionChanged function of the ListBox, but I'm not sure where to go from there. Surely a dialog can have dynamic design, right? Would I mimic the creation of a tabbed-dialog where I create my designs and then bind them to the TabControl, and just do something similar for the ListBox? Again, it's not the ListBox itself that is dynamic. The user will click on "Settings A" from the ListBox, and to the right of the ListBox will be settings 1, 2, and 3 that each have textboxs/radios/checks.
Any hints on how I can accomplish this? I just think it looks nicer than having a whole bunch of tabs lined up across the top of the box. Thanks in advance to any brilliant minds who can help me out. I'm versed in C++, but I'm very much a beginner at VC++.
You can a vertical splitter with two panes:
one which contains the list
another one which contains the configuration dialogs you would normally use in a tab control
Each time the list selection changes you can load the appropriate dialog in the right pane. You can find a splitter tutorial here: http://www.codeproject.com/KB/wtl/wtl4mfc7.aspx

Group box with title as Check box

I am using Visual Studio 6.0 (VC++ with MFC) in Windows XP platform. I am trying to create a group box with the title of the group box as a check box. My intention is this: If the check box is enabled, the controls inside the group box should be enabled; or else disabled.
Is this possible to accomplish? If yes, please give me some directions.
Thanks.
There are a few things you can try, depending on how true you want to stay to your idea and how much work you are prepared to put into the effort:
Simple method
Use a normal group box, and then inside this make the first item be the checkbox. This is simple to accomplish, but you lose the goal of having the checkbox as the title.
Funky drawing method 1
Use a normal group box, then in the space over where you know the title is to go, place your checkbox. You will have to perform some tricky calculation to get it to fit in nicely and draw well without flicker.
Funky drawing method 2
Use some form of superclass or subclass/subclass on the group box. You can override the WM_PAINT handler to draw in only the frame for the group box. Place a normal checkbox in the place where you know the title is to go. This should work better because you will have more control over the drawing, but it is likely to be tricky to get right. In my experience, subclassing is lower risk to implement than superclassing.
Are you using the Dialog editor? If so, put down the group box. Next, on top of it, put a check box over the line of the group box. Edit the resource to set the Z order, or do it in code. You want the checkbox to be on top of the group box. Add a handler for the checkbox and enable / disable controls depending on the check box state.
I wrote one called CGroupCheck a few years back and it's available from CodeProject: http://www.codeproject.com/KB/buttons/groupcheck123.aspx

Resources