Manually create a dialog child window using an ID from resource.h - visual-c++

I want to add a simple panel to a dialog created using Visual Studio resource editor, but the resource editor doesn't allow this - I need to add my own CWnd as a dialog child. However that way I think I have to use CWnd::Create manually, and pass in names for the class and the window.
I want to create an ID like IDC_MYPANEL, and as much as possible add the window so it works like something defined in the template. What's the right way to do this, and what's the best MFC class to use as a simple panel... just use CWnd itself?

What do you mean by 'a simple panel'? If it's a custom control, derive from CWnd, override Create() and call CWnd::Create() with NULL as the class name so that MFC makes its own, and add a line to resource.h with the IDC_XXX value of your control. If it's a sub-dialog, with controls on it, derive from CDialog and call CDialog::Create() with the IDD that you define in your dialog.
The only difference when creating a control at runtime is that in OnInitDialog, you do some Create() and initialisation things, and you don't include a DDX_Control() line for that control. For the rest everything works the same.

Related

How to add a new method in Pharo?

In the Nautilus System Browser (Pharo 6) there's a right-click command to Add package... as well as Add class... and even Add protocol..., but I can't find anywhere a way to Add method....
Where is that command?
In Pharo, adding a method is not as explicit as the other elements. To add a new method:
Select the protocol for the method, and you should see a template in the editor pane:
messageSelectorAndArgumentNames
"comment stating purpose of message"
| temporary variable names |
statements
Edit this template to make a new method,
Save (Right-click Accept) it using Ctrl-S.
In fact, any time you change a method's definition (e.g., messageSelectorAndArgumentNames) and save it in the editor (Right-click Accept or Ctrl-S), it will create a new method.
For more details, see the section 1.3 of Developing a simple counter document (emphasis is mine):
Create a method
Now let us create the accessor methods for the instance variable count. Start
by selecting the class Counter in a browser, and make sure the you are editing the instance side of the class (i.e., we define methods that will be sent to
instances) by deselecting the Class side radio button.
Create a new protocol by bringing the menu of methods protocol list. Select
the newly created protocol. Then in the bottom pane, the edit field displays
a method template laying out the default structure of a method. As a general
hint, double click at the end of or beginning of the text and start typing your
method. Replace the template with the following method definition:
count
"return the current value of the value instance variable"
^ count
This defines a method called count, taking no arguments, having a method
comment and returning the instance variable count. Then choose accept in
the menu to compile the method.

deriving Dialogs from a custom Dialog using mfc

I am trying to define a custom Dialog Template with certain members such as m_hImage, m_hName, and the m_hIcon in it. I want to then derive Dialogs using this Template.
I am not using any buttons(Ok,cancel etc.) in this template. Do i still need to declare or define OnOk(), OnCancel() etc.
Can anybody tell me what are the other methods I need to declare in this template class?
My goal is to just prepare this template dialog so that each dialog derived from this template contains a icon on the title bar (m_hIcon) , the image (m_hImage) on the upper left corner, and the image name (m_hName) on the upper right corner of dialog.
No, you need not to override any of the methods. You may however need to override OnInitDialog, otherwise you won't have any dialog initialization. This is the overridden method where you can setup the icon for dialog.

Adding controls on CFrameWnd MFC

How can I add control(like ListCtrl and CButtons) on CFrameWnd?
Thanks
Your best bet would probably be to create a CDialogBar and stick your controls on that.
CListCtrl is the same as CListView. You can also create button by calling directly button’s Create member or calling Create API passing BUTTON as the name of the class.
If you want to use many controls like in a dialog why not to use CFormView derived class as your view?

Visual C++: Dialog editor has forgotten what class is linked to the dialog template

I created a dialog and then created a class linked to it using the wizard. Somehow VC++ has forgotten this and now wants me to create a class whenever I double-click on a control in the editor to create a handler.
Are these mappings stored in a file I can edit, or does VC++ try to deduce this and I'm stuck with it?
In the header file for your dialog you should have a line like:
enum { IDD = IDD_ABOUTBOX_DLGTEST };
This specifies the resource ID for your dialog. Have you changed the ID for your dialog in the dialog Properties? Either change it back, or change the enum in the header file.
Note, any change might not get picked up by the wizard until you've done a re-compile.
As well as njplumridge's answer, also check that you have the right #include "projectname.h" file in all your classes.
You can sometimes have problems with MFC tools mapping if you change the name of the project but leave the projectname.h file unchanged.
But there's no extra mapping file to worry about, it's all inferred from the source code.

How does MonoTouch autogenerate XIB code behind?

I'm a C# programmer dabbling in a bit of iPhone development using MonoTouch.
I add a new View Interface Definition to my project and double click to open it up in Interface Builder. I add a UIButton. I save the file, and inspect the xib.designer.cs file, and I can see no reference to the new button.
I downloaded the code from http://monotouchexamples.com/ where I could see an example of autogenerated code behind :
[MonoTouch.Foundation.Connect("infoButton")]
private MonoTouch.UIKit.UIButton infoButton {
get {
return ((MonoTouch.UIKit.UIButton)(this.GetNativeField("infoButton")));
}
set {
this.SetNativeField("infoButton", value);
}
}
I opened up MainWindow.xib in interface builder. I notice a few differences. File's Owner is of type UIApplication instead of NSObject. What is the importance of this? There is an App Delegate object of type AppDelegate. I can't add an AppDelegate to my own view, or at least I can't find it in the Library. Do I need to add one? I can see that the existing controls on MainWindow.xib have Referencing Outlets to the App Delegate. I add a new button and I want to hook it up. When I click and drag a New Referencing Outlet to the App Delegate a context menu appears that lists the existing controls. How do I add a new element to this list, or where does this list come from?
I've been spoilt by the Visual Studio world where I just dump a button on a form and start writing code for the click event. Could someone provide some pointers about the steps needed to get this working on MonoTouch?
Thanks,
Patrick
Adding a button by itself is not enough. The button is not accessible outside the Interface Builder. You need add an Outlet, and connect the button with the outlet in Interface Builder.
Remember: Outlets are the members in your Controller class that get a reference to the controls, you can't just access the controls without them.
As Dave says, you need to add an outlet to your controller class, and connect your button to that outlet, before any auto-generated code will appear. This caught me out too initially.
You choose your controller class in the Interface Builder library window, choose 'outlets' in the bottom part of the library, and add an outlet there. You then need to select your button, choose the connections tab of the inspector window, and drag from the "New referencing outlet" circle over to your controller class. Interface Builder will then prompt you to choose an outlet to connect to. Then when you save, you should get the auto-generated code appear in the .xib.designer.cs file, and then you should be able to reference your button via that outlet variable in your .xib.cs file.
It sounds like the project I created is out of date - I remember there were quite a few changes around how the generated buttons are created in the designer file. I will update the project soon for you.
As Dave said, to get the code to be auto generated you need to add an outlet with Interface Builder. There should be an example on this video here - http://bit.ly/aWoItN but the server seems to be down at the moment.
Hope this helps,
ChrisNTR

Resources