I created an application with the MFC wizard and added the splitter functionality.
The wizard will add a variable CSplitterWndEx m_wndSplitter to class CChildFrame.
After that, a split view will be created with a horizontal scrollbar and a vertical scrollbar.
But the rich edit view also has its own scroll bar.
How can I keep only one scrollbar and keep the split functionality?
Thanks in advance.
The scroll bar is created with respected to the style given on creation of splitter window. Please refer the following link
https://learn.microsoft.com/en-us/cpp/mfc/reference/csplitterwnd-class?view=msvc-170#create
if the style is modified as below, the scrollbars will not be created
DWORD dwStyle = WS_CHILD | WS_VISIBLE | SPLS_DYNAMIC_SPLIT.
To show the Splitter for dynamic split, we need the scrollbars which creates space to display the splitter.
Related
Totally invisible means the window is not visible to the user, is not shown on the taskbar and is not present in Alt+Tab/Win+Tab views.
I want to create such window and be able to capture it with Windows Graphics Capture API. Here is what I already did:
I create a hidden window and then create a child window. This removes the child window from the taskbar.
Then I cloak the child window which makes it invisible on the
screen.
What I can't do is removing it from the task switcher (Alt+Tab/Win+Tab). Adding WS_EX_NOACTIVATE or WS_EX_TOOLWINDOW or removing WS_VISIBLE styles does the job, but makes it non-capturable by the API.
I have already read this, but it doesn't help: https://devblogs.microsoft.com/oldnewthing/20071008-00/?p=24863
Is it possible to achieve what I want? If yes - how? Thanks!
Setting WS_EX_TOOLWINDOW style on the window after capture item creation doesn't stop capturing.
I have a legacy project where i need to add a multi-line text box to the view.
I first simply want to create a textbox in onDraw function in my view class to put a text box on screen. The rectangle of the textbox keeps blinking. I can't select it or do anything.
The view class is inherented from CView. The info. i got from research is that CEdit usually added to dialog class, but i can still add it to any view.
CRect rect(100, 100, 300, 200);
CEdit test;
test.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | ES_MULTILINE | WS_VSCROLL, \
rect, this, 1);
I'm totally new to this, and before i get into all the handle and messaging, i just want to simply create a text box and type some text in it.
Thank you for the help in advance.
You probably don't want to create the edit control in your OnDraw. In fact, unless your view contains something else you need to draw, you may not need to handle OnDraw at all.
When you have a view hosting a control, you usually want to create that control in the view's OnCreate, so it's created after the view's own window is created (which will be the control's parent) but before the view's window is displayed (so the control can be displayed at the same time).
In this case, the view probably won't need to deal with drawing at all. It probably will need to deal with:
sizing: resize the control to fit the new size of the view's client area.
focus: when the view receives focus, immediately give focus to the control.
Commands: you pretty routinely want to deal with things like:
cut/copy/paste to/from the control
put data into the control (e.g., from a file)
get data out of the control (e.g., save to a file)
set the control's font
I'm making an MFC dialog-based application in Visual C++ 2005. I added a scroll bar to an edit box. How do I program the scroll bar to make it work?
The windows styles wS_VSCROLL and WS_HSCROLL control if there is a scroll bar present or not. Normally you just setup these styles as part of the resource dialog template.
With MFC you use the "CWnd::ShowScrollBar" method to turn the scroll bar on/off.
When scrollbars are turned on, then they should work automatically for edit controls. You don't need to do anything.
http://www.functionx.com/visualc/controls/scrollbar.htm
has code you can use to control the scroll bar.
I created an SDI MFC app without the doc/view support. The MFC template gives me an app with a blank window (And a menu, etc)
I want to show my CFormView object on that main window. (Based on a dlg made in the gui editor)
How do I do that? CreateWindow and showwindow don't seem to be all that is needed. All the web pages I find seem to talk about MDI and other stuff that is not in my app.
This view is never going to change. It will have one list box control on it and that is all. How do I get a new form view to appear?
Additionally, how do I get a floating window with one control on it to appear as well? (DLG boxes and DoModal() will not work for me here.)
Give your CFormView the WS_CHILD style
Create it as a MODELESS dialog with the app window as the parent window
resize it to fit the parent's client area, or resize the parent to fit it.
The WS_CHILD style is not a default style for a dialog template, but you can add it.
this will cause the dialog to show up inside the client area of the main frame window you when create it.
You may also want to add a call to IsDialogMessage() to your message pump. This is needed get the TAB key to behave the way you expect it do in a dialog.
Edit ----
I'm not an MFC programmer, so I can only guess how you would go about this in MFC.
Presumably you still have dialog templates, so you would go into your .RC file
and remove the WS_POPUP and add the WS_CHILD style to your template declaration. like this:
IDD_WHATEVER DIALOG DISCARDABLE 0, 0, 275, 217
STYLE DS_MODALFRAME | DS_3DLOOK | WS_CHILD | WS_VISIBLE
CAPTION "General"
FONT 8, "MS Sans Serif"
BEGIN
// etc
END
Modeless dialogs are created in Win32 by using CreateDialog rather than DialogBox, in
MFC by using Create() rather than DoModal().
There are three places where menus show up in the new MFC functionality (Feature Pack):
In menu bars (CMFCMenuBar)
In popup menus (CMFCPopupMenu)
In the 'dropdown menu' version of CMFCButton
I want to put icons (high-color and with transparancy) in the menus in all of them. I have found CFrameWndEx::OnDrawMenuImage() which I can use to custom draw the icons in front of the menu bar items. It's not very convenient, having to implement icon drawing in 2008, but it works. For the others I haven't found a solution yet. Is there an automagic way to set icons for menus?
This is how I got it to work:
First
, as the others said, create an invisible toolbar next to your main toolbar (I'm using the usual names based on AppWizard's names):
MainFrm.h:
class CMainFrame
{
//...
CMFCToolBar m_wndToolBar;
CMFCToolBar m_wndInvisibleToolBar;
//...
};
MainFrm.cpp:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
//...
// Normal, visible toolbar
if(m_wndToolBar.Create(this,
TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
{
VERIFY( m_wndToolBar.LoadToolBar(
theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME) );
// Only the docking makes the toolbar visible
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndToolBar);
}
// Invisible toolbar; simply calling Create(this) seems to be enough
if(m_wndInvisibleToolBar.Create(this))
{
// Just load, no docking and stuff
VERIFY( m_wndInvisibleToolBar.LoadToolBar(IDR_OTHERTOOLBAR) );
}
}
Second: The images and toolbar resources
IDR_MAINFRAME and IDR_MAINFRAME_256 were generated by AppWizard. The former is the ugly 16 color version and the latter is the interesting high color version.
Despite its name, if I remember correctly, even the AppWizard-generated image has 24bit color depth. The cool thing: Just replace it with a 32bit image and that'll work, too.
There is the invisible toolbar IDR_OTHERTOOLBAR: I created a toolbar with the resource editor. Just some dummy icons and the command IDs. VS then generated a bitmap which I replaced with my high color version. Done!
Note
Don't open the toolbars with the resource editor: It may have to convert it to 4bit before it can do anything with it. And even if you let it do that (because, behind Visual Studio's back, wou're going to replace the result with the high color image again, ha!), I found that it (sometimes?) simply cannot edit the toolbar. Very strange.
In that case I advise to directly edit the .rc file.
I believe (but I may be wrong) that these classes are the same as the BCGToolbar classes that were included in MFC when Microsoft bought BCG. If so, you can create a toolbar with and use the same ID on a toolbar button as in the menu items you want to create icons for, and they should appear automatically. Of course, you don't have to actually display the toolbars.
In BCGToolbar, it's enough to create a toolbar in the resources & load it (but not display the window), but the toolbar button must have the same ID as the menu item you want to link it to.
Try using this function:
CMFCToolBar::AddToolBarForImageCollection(UINT uiResID,
UINT uiBmpResID=0,
UINT uiColdResID=0,
UINT uiMenuResID=0,
UINT uiDisabledResID=0,
UINT uiMenuDisabledResID=0);
So e.g.:
CMFCToolBar::AddToolBarForImageCollection(IDR_TOOLBAROWNBITMAP_256);
Worked very well for me.
One thing that can catch a person by surprise is that for customizable (ie, non-locked) toolbars, the first toolbar you make, the framework splits up and turns into some sort of palette bitmap of all icons in the program. If you try to add more toolbars later (or different toolbars) that have bitmaps (or pngs) with a different color depth than that first one, they seem to fail because it can't add them to the same palette.