How can I change toolbar runtime in MFC Visual C++ 2010 - visual-c++

I have two toolbars desgined of equal size and equal number of buttons.
Now based on some condition in code I want to change toolbars run time.
My prject is MDI application built in Visual C++2010 MFC.
Please help as early as possible.My application uses CMFCToolbar

If you are using CMFCToolbar you can just call: CMFCToolbar::GetCommandButtons (a static function). You get an Object array of all buttons in your system and you can change them accordingly (SetToolTip, SetImage ...)
The problem is that CMFCToolbar is variable and buttons can be inserted and dragged around. SO you need the access via GetCommandButons.
If you are using the classical CToolBar class the easiest way is just to add the button, so it always exists in the toolbar and in the bitmap.
If the button should not be visible at startup you just call DeleteButton with the index you receive from CommandToIndex.
To change the button you can just use SetButtonInfo.
If you need the button again, just call InsertButton, with the index where you want to have this button.You may save the previous index and used bitmap index before you delete it.

Related

what all the defalut classes will get invoke the time of creating a dialog

Could you please any one let me know what all the classes will get invoke at the time of creation of Dailog in Dialog based applications.
and please let me know the differnce bitween dialog based application and SDI and MDI's.
When the dialog is created only one class is invoked: the CDialog-derived class. A dialog based application is the simplest type of MFC app.
SDI and MDI applications create a frame window, with a menu, tool bar and status bar, a view window (inside the frame), and a document object. MDI also allows the user to open more than one file at a time and creates a document, MDI frame and view for each open document. Several types of view can be used, depending on what you wish to display.

How to write Coded UI Assert for Treeview.ItemsSource > 0

Background: Am just learning Coded UI. This is from a simple test app in WPF using VS 12.
I have created a Coded UI Test Project and a Coded UI Test.
I have recorded opening the app, clicking a button, and then closing the app and it will run through this in a Test Run.
Now I want to add an assertion to a Treeview. The scenario is a user opens a file, and it loads a treeview, and I want to make sure the Treeview has at least one item in it.
So I run the exe, open the Coded UI Test Builder and drag the crosshairs to the Treeview. It successfully hightlights the TreeView. It then shows the Add Assertions Dialog.
The Treeview is shown in the Dialog, but there is no "Control Specific" properties of ItemsSource. It shows only 5 control specific properties, such as HelpText, AccessKey etc.
I can add an assertion for HelpText, but that isn't what is needed.
So the question, why isn't ItemsSource being shown in the Assertion Dialog?
How do I get it to show?
After dragging the crosshairs tool onto a UI control the assertions dialogue is shown. To the right of the Add Assertion button there are four arrows arranged as Up, Down, Left and Right. Clicking these allow the selected control to be changed between siblings (Left and Right), ancestors (Up) and children (Down). Use these buttons to explore the tree control. I do not know what an "ItemsSource" is in the particular tree that you are viewing, it might not be an exposed property of the tree even if it is part of the implementation or the API. There may be other properties of some part of the tree that have the values you need.
I do not believe that Coded UI can generate an assertion to test that the tree contains at least one item. I believe you will need to hand code that part. My first thoughts there would be to get the UIControl object for the tree and then use its GetChildren method to find the items in the tree. That may need to be recursive to get all the elements in the tree.

Can I create a custom DialogPreference based on a pre-existing custom Dialog?

In my Android project I've already created a custom dialog: A class named SelectColorDialog, extending Dialog, that allows the user to view a large matrix of color cells in order to select a particular color. The dialog returns the selected color value (as Integer) to the dialog initiator – typically an Activity – via a callback function.
I've a similar custom dialog, SelectTypefaceDialog, to allow easy font selection. A list of available typefaces are shown, as ListView rows, each identified by name and with an associated short sample text rendered in that typeface. The available typefaces include usual droid fonts, such as NORMAL, MONOSPACE, etc. as well as any externally sourced TTF font files that the user cares to load into a particular subdirectory on the SDCard.
These custom dialogs were not initially designed to be used directly in conjunction with SharedPreferences, preferences definition XML files or with any PreferenceActivity. Instead of, each dialog can be popped up from any activity, via the user pressing a button or via a menu item. The activity classes that create these dialogs also have internal callback classes, selection event listeners, to detect when the user selects a color or font.
These two dialogs do not have OK and Cancel buttons. Instead, the user just clicks on an item - a view of some kind - in the dialog to select the corresponding color or typeface value (implicit OK) or else presses the device’s back button to dismiss the dialog with no action taken (implicit Cancel).
I would now like to go further and incorporate these two custom dialogs into the shared preferences framework via a preferences.XML and an associated PreferenceActivity.
I would prefer to base two DialogPreference subclasses directly on these existing dialogs if possible, but I cannot see how to do so. I suspect that I cannot, and that I'll need to start all over again, and copy or adapt all the java code that is presently in the custom dialog classes – for color or font display and selection – directly into the custom DialogPreference classes instead, perhaps by overriding onCreateDialogView() and/or other methods?
This question may be a bit old, but I hope to help those, looking at the same problem in future: just extend Preference instead of DialogPreference. DialogPreference is designed badly and expected "official" way to use custom Dialog - overriding protected showDialog method does not work, because this single method contains half of class logic.

adding buttons dynamically in android

I'm new to android development and needs help here.I want to create a layout where buttons are added dynamically.In this the no of buttons to be added are decided on the fly.(at run time) i.e depending upon the number return by server i want to add buttons.below is the layout i want to create.Please suggest me suitable solution.I was trying creating this layout with table layout.Thank You
http://i.stack.imgur.com/tbrEq.jpg
Read in your array of buttons and initialize your empty layout (i.e. setContentView). Then, create your buttons using the ImageButton constructor and call .addView(btn) from the layout where you want to insert the button. Don't forget to set any layout parameters you need.

How can I calculate the client area of an MFC CDialog without displaying it?

How can I obtain the Window Rect of a CDialog which is based on a dialog template. The dialog is not and can not be visible
It might be tricky with CDialog, because if you dont show the CDialog, the window handle is not created and you cant call GetClientRect.
Might i suggest calling CreateDialogIndirect instead to create the dialog, then you can get the client rect. You dont need to show the dialog. I think as long as the window handle is created, the GetClientRect should work. I am not an expert though and its been many years since i have written MFC code.
Well...
In Windows API-land, you could load the resource yourself (FindResourceEx, LoadResource), understand the binary structure of the dialog template resource (some clues at http://blogs.msdn.com/oldnewthing/archive/2004/06/22/162360.aspx), convert the size of the dialog in the dialog template from dialog units to pixels (check out http://msdn.microsoft.com/en-us/library/ms645475(VS.85).aspx).
I'd be curious why you'd want to do this, though.

Resources