How to make a dialog as same size as another dialog in MFC? - visual-c++

I am in process of creating a dialog IDD_DIALOG2 which i want to be in the same size as existing dialog IDD_DIALOG1, what would be the easiest way to do this in VC++?

Just resize in design view. The dialog's size shows up in the status bar.
(you could also edit the .rc file and copy the 4 numbers that follow the dialog's ID)

The sane way would be to look up the IDD_DIALOG1's dialog definition and use the same sizes.
If you don't have access to IDD_DIALOG1's dialog definition, you could bring up IDD_DIALOG1, use GetWindowRect() on it to record its actual size, close it, open IDD_DIALOG2, and then use MoveWindow() to resize to the same size. Not generally recommended, but it's possible.

It's possible to copy & paste the dialog in the Resource View - all the controls come with it also.

Related

Options of message box in Excel

We would like to change the font, color and size of the text displayed in message boxes.
Can/how do you VBA this?
Nothing tried, we are not finding any help in online manuals, including the Microsoft help site.
We would like to make the message box big, bold and loud.
Easy answer: You can't.
That's why you can't find anything about it in the official documentation of the MsgBox function.
A workaround can be to create your own UserForm where you are free in how to style it.
Add a UserForm in your workbook's code module, and configure it with as many Label and CommandButton controls as needed.
If the label text will be static, you can configure these all through the Properties window in the IDE:
Labels, Command Buttons, etc., are accessible Controls on the UserForm, and can be altered dynamically during runtime if needed, e.g., during the form's Initialize or Activate or any other event handlers. Controls on the form can even alter other controls, for example you could leverage the command button's Click event handler to modify the text associated with Label1 control, etc.
You can even add (or remove) controls (labels and such) dynamically, too, and fully control their appearance/formatting/etc.

System wide right click context hook

**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.

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

Problems with MFC link control wrapping

I'm using a CMFCLinkCtrl in my custom dialog that inherits from CDialog. The CMFCLinkCtrl is set dynamically using data that is set by the user in another part of the application, so I have to handle long urls.
Is there a way to have the link control truncate what is displayed in the dialog and add an ellipse to the end? Currently the control is wrapping to the next line when it is too long to fit in the dialog or sees the "//" in the http://.
Static controls have an SS_ENDELLIPSIS style that does exactly what you want, but unfortunately this won't work with CMFCLinkCtrl which is derived from CButton. So you have two choices:
Use a static control with the SS_ENDELLIPSIS style, but you'll have to set the text colour and font yourself, and handle click events and open the URL manually.
Subclass CMFCLinkCtrl and add custom drawing code to add the ellipsis.
I think you're out of luck. You'll have to do what casablanca said or without subclassing truncate the text yourself (calculate the font size and link control size) and set it using SetWindowText.
You can easily resize the control to contain the entire text using SizeToContent, but I don't think this works for you.

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