MFC: Line control for separating parts of dialog boxes in C++ - c++

I am looking for the class name of an MFC Common Control for the caption and line that divide the dialog box into sections: "Section", "Headers and Footers", "Page, and "Preview" in the image below.
It appears that this likely a standard control, but I haven't been able to figure out how to create it so far.

Unless you're dead set on that exact look, this is done with a group box. It will look a little different, as it draws a box all the way around a group, so the result would look something like this:
If you're really set on a line at the top but not bottom or sides, you'll probably have to do that yourself. You'd (at least normally) do this with a custom control. As simple of one as you're looking at here (caption, line, doesn't need to accept any input from the user) that'll be a trivial one to implement, but you'd normally do it as a separate project, then use that in your project.

Related

Disabling a ComboBox item in Win32 API

I would like to disable an item in a combobox in my Win32 application (C++). I'm not quite sure how to do this. I'm trying to achieve something that looks like this:
Notice how CollectionItem2 and 3 are greyed-out.
Any help would be very much appreciated!
If you truly need a combobox for this, then (as #IInspectable said) you'll need to do a custom drawn control. Basically, you'll have to store some information saying which items are disabled/grayed, and draw the items appropriately based on whether they're enabled or not.
There may be a somewhat easier way though. This is normally done with a Split Button. This is button with the BS_SPLITBUTTON style set. When the drop-down part of the button is clicked, it sends a BCN_DROPDOWN notification.
You normally respond to that by displaying a menu, typically using TrackPopupMenu to display it immediately below the button (or immediately to its right, if you prefer). This is a normal menu, so it can have items enabled, disabled, grayed, have check boxes, etc., as you see fit.
If you're using MFC, it has a CSplitButton class that wraps the Split Button, simplifying the code a little bit--you can pass an identifier of a menu and sub-menu when you create the CSplitButton object, and it handles things from there.
A sample result probably looks pretty familiar:
Note: MFC also has a CMfcMenuButton class. This has roughly similar functionality, but is somewhat clumsier to use. If memory serves, it is compatible with older versions of Windows (but the split button goes back to Vista, so it's fine unless you really need to support XP).

Two column TPopupMenu to list shortcuts right aligned

Using Borland/CodeGear/Ebarcadero C++ Builder 2009. Is it possible to show shortcuts (or other text), right aligned in a second column in a TPopupMenu ?
For instance:
[image] Open File ctrl-O
[image] Close File ctrl-W
[image] BlahBlah ctrl-B
etc.
If so, how ?
I checked the break property on an item, but the results is not exactly what I want, since items are selectable on their own, instead of the complete line. Also it's not drawn that nicely.
Your feedback appreciated.
A menu item can have an image (see the TMenuItem.ImageIndex property), and can have a shortcut assigned (see the TMenuItem.ShortCut property). The VCL will automatically draw those elements for you, exactly as you have shown.
By default, they are a little squished together. You can use the TMenuItem.OnMeasureItem event to extend the Width:
If you still do not like the way the default drawing looks, or you want different text than the ShortCut to appear on the right side, you will have to owner-draw the menu items yourself (see the TMenuItem.OnDrawItem and TMenuItem.OnAdvancedDrawItem events), then you can make the menu items appear however you want.

Remove horizontal divider line from mfc wizard

I have a mfc wizard in which I implemented code for re-sizability. There's a horizontal divider line at the bottom of the wizard dialog, as shown by the red arrow in the picture, which I need to get rid of.
Since I don't know the ID of that line, I haven't included it in my resize code. Because of that, when I resize the wizard, the line keeps messing up the dialog.
It would be a great help if the ID of the divider or a method to remove it can be found.
Thanks.
On my machine (Win8.1) the ID is 3026, as shown with Spy++; have a look if it's the same on yours and/or other machines. Otherwise you could still enumerate all windows and look for the one with the STATIC window class. Then just DestroyWindow() that.
That said, I don't think the line is the issue here; the issue is that your dialog isn't redrawing itself properly. And I speculate that this is caused by it assuming a fixed size. Wizards aren't meant to be resized (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb774544%28v=vs.85%29.aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/bb246463%28v=vs.85%29.aspx). Even if you destroy the line, other content you will put there is going to be invalidated incorrectly as well, I think.
Maybe you can work around it by manually invalidating or playing with various clip related windows styles. However the real answer is 'don't do that'.

Qt - Display several, selectable lines

Im writing a tool that simulates Turing machines.
Here, Ive got a transition table of a such a machine
When a cell is double-clicked, a little dialog pops up (which is a custom widget, derived from QFrame) and should allow editing the contens of a cell. A cell may contain several rules (those |q2, 3, R| and such) and I want that little dialog to show these. The thing is that a user should be able to add and remove rules. At first, I wanted to use QLabels for that, which is fine with the adding aspect, but how do I remove existing rules? I planned having the user select the rules and click "Remove" but do I make sure the entire rule (QLabel) is selected?
Or should I take a completely ddifferennt approach to removing? Like letting every label have an own checkbox?
I would like to keep it as simple as possible. For example, QTableWidget is too "fat" for this, I feel like
You should use a QListWidget - this will allow multiple lines, multiple selection, without the cells or horizontal/vertical headers.
http://qt-project.org/doc/qt-4.8/qlistwidget.html

How do I write a WYSIWYG editor?

I would like to program a WYSIWYG editor for HTML. I'm looking for a high level approach, which I will eventually be implementing in C++.
My initial approach is to create a hierarchy of classes which extend a common base class (node). So object "body" would contain object "p" which would contain object "b" which would contain some text.
class node {
node *parent;
vector<node> children;
string name;
map<string,string> attributes;
string text;
virtual void render(const rect &rect, const point &offset) = 0;
virtual void onEvent(const event &e);
}
The main engine would call something like body.render(screen, point(0, 0)), which would recursively render its children.
The cursor would be represented by a pointer into the object hierarchy, and each node would have its own internal cursor state, and would respond to keyboard events when it is the selected node.
For example, if the user hits the left-arrow, and the "p" node is selected, the "p" node's reaction to the keypress might be to change the current node to the parent of "p".
Abstractly, it seems like this could work, the closest thing I can find to what I'm looking for is Sigil, which at first glance seems pretty intimidating to study (main.cpp is 70k).
Before I go down this road, I was wondering if anyone had a simpler approach, or can see any pitfalls with this method.
A simpler approach, if you can do this, is to embed a web browser in your application and set contentEditable="true" on <body>. If you're on Windows, you can use the built-in one, or you can embed an engine like Gecko or WebKit.
You can look at doing color picking.
Basically you render everything twice. Once is what is displayed to the user.
The other is a bunch of bounding boxes done in unique random colours that you can turn back into pointers via a hashtable lookup or whatever. This allows you to quickly locate what is under a mouse cursor without having to recursively look up every object. You might want to miss the currently selecvted object from the color picking that way you can click twice to get the object below you current one (if you want to keep going for lower you will need to mess around with zorder depth somehow. Maybe don't render anything in the selected elements bounding box region that is over the zorder of your currently selected object).
Finally once you have selected the specific element you can enter a sub editing mode. For example turning a block of text into an editable text box with a blinking cursor, drawing borders/handles around your element to allow you to resize/manipulate it and showing a list of properties.
Realistically if your looking at making a HTML WYSIWYG editor, that will also require a HTML rendering engine. Unless you plan to make your own from scratch (which is a massive undertaking by itself), or only plan on implementing a very limited subset of HTML (which would still be fairly time-consuming). Most HTML renderer engines will include some kind of support for tapping into things like object picking. It might be worth grabbing webkit and seeing what it supports. Maybe look at the Chromium source code (Chrome includes an inbuilt webpage inspector that isn't too far off being an editor (it allows object picking and runtime editing of properties but the editing isn't totally WYSIWYG since its done in an external window, but that might be enough for what you want.
You might even do better to look at writing you editor (or parts of it) as some kind of JavaScript/Grease Monkey extension that you can load over the page being edited. You could write your whole editor in HTML or just add some support handle wrapper script that communicates to your native program.