I want to set the height and the width of the dockable panes. I tried passing the value in the CRect parameter to the OnCreate function but that didnt work. can anybody help in resolving this
You can probably get the effect you want by calling SetWindowPos(... SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE), this will work in the case the pane is undocked.
I don't know if the result will constructive at all when the pane is docked or hidden. You can also add handlers for WM_SIZING and WM_SIZE in your CDockablePane derived class to limit the size of the pane within a desired range.
MFC manages the pane sizes and uses values stored in the registry. That is a real pain, especially when a pane disappears in a new version of your software. I don't know of an easy way to turn this off. But it can be done.
Related
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 have tried to change orientation property of CSpinButtonCtrl in C++ MFC.
By default I have specified orientation property as vertical, nevertheless when I try to change property style to horizontal (UDS_HORZ) during execution, it doesn't work...
Sample code
CRect rect;
CWnd *pWnd;
pWnd = GetDlgItem(IDC_SPIN_GRAD_CONTRAST);
pWnd->GetWindowRect(&rect);
((CSpinButtonCtrl*)pWnd)->Create(WS_VISIBLE | UDS_HORZ, rect, pWnd->GetParent(), IDC_SPIN_GRAD_CONTRAST);
It creates a horizontal spin button control.
What I pretend to do is find any way to change the style without changing position and behaviour of the control previously created
I will appreciate any kind of help.
Some styles of controls can only be used when you create the control.
AFAIK you have to recreate the control.
On the other hand I looked into the source code of the CMFCSpinButtonCtrl. Using this allows dynamically changing the orientation. Make sure that you force to redraw the control.
PS: Changing this at runtime seams to be a strange scenario for me.
I have created a window using the WS_EX_NOACTIVATE flag and it works great as far as not taking focus when you click the window. However when I drag the window or try to resize it, it doesn't redraw the window as your are moving and resizing it, only at the very end once you release the mouse button. Is there a way around this? I would like to see the window as I am resizing it. I have searched many documents, but I still don't find the resolution...
If you need a window that doesn't take focus when clicked, but can still be interacted with, you need to handle the WM_MOUSEACTIVATE, and return MA_NOACTIVATE.
Additional information and fully working sample code has been published by Raymond Chen. See How can I have a window that rejects activation but still receives pointer input?
It's a Windows bug. You need to call SetWindowPos(hwnd, 0, x, y, width, height, 0) on WM_MOVING. The coordinates to set are given to you in lParam which is a RECT*.
Note that doing this will activate the owned window and deactivate the owner, which is not what you want (and SWP_NOACTIVATE has no effect either).
To avoid that, you need to set WS_CHILD on the owned window. But set it after you created the window, via SetWindowLong(), otherwise your owned window will get clipped, like any child window.
And, as you probably already figured out, this only works for windows with WS_EX_TOOLWINDOW ex style. I wasn't able to make the owned window stay deactivated with any other style combination that doesn't include WS_EX_TOOLWINDOW.
That's winapi for you :(
I have my own custom painted caption bar for a window. I have also painted a bitmap on this bar which I want to know when someone hovers over it with the mouse cursor. I have handled the WM_NCMOUSEMOVE message but this seems to only be triggered over the borders and not my caption area itself.
How can I detect when the mouse is over a certain area of the caption bar?
This is with Visual C++ 2010.
Update:
I have worked out the problem to an extent. I (deliberately) do not have the WS_CAPTION style set on the window and instead I handle the WM_NCCALCSIZE and manually adjust the size of the non-client area - shifting it down by 20 pixels in this case. This means that the area that I am "forcing" as a non-client area does not get WM_NCMOUSEMOVE messages but neither does it get WM_MOUSEMOVE messages either. One way round it is to force the WM_CAPTION style, get rid of my custom code on WM_NCCALCSIZE but this isn't ideal. Is there a way round it?
Update2:
It is the same problem with WM_NCHITTEST messages. The area does not get these triggered unless I have WS_CAPTION style set which I don't want. Also it is somehow affecting the client area in that it no longer gets WM_LBUTTONDOWN messages.
I am not quite positive what you mean, but I think you are saying you want to check for a certain section of the caption bar being moused over. if so, then maybe try tracking window size and position, and then check to see if, relative to your window position and size, that section of the bar would be moused over (in pixels). This is the only way I can think of that doesn't use OS specific functions, which I try my best to avoid.
I want to create a Window like when a context menu pops up or clicking the menubar. I want a Window that will be like this and that I can take over its paint event. Sort of like what is created when you select a sub tool in Photoshop.
EDIT:I want to know how to create controls like the one that comes when you select a sub tool in Photoshop, these do not seem to have a parent window. Those little description popups are a good example of this type of window, and menu items, those rectangles have no parent window.
Thanks
EDIT2: see this: http://cdn-viper.demandvideo.com/media/CB3C805F-421E-45AE-8359-39D59D8F0165/jpeg/20412728-192C-462A-AF8E-1F30BA77AE05_2.jpg
You will notice the window for the sub tools, it is not constrained to a parent window.
But how do they get a nice shadow
around it, and how does it still stay
with the main window without a parent?
That's your real question.
There are several ways of getting the shadow. One is that the window is actually two windows, the "shadow" plus the "main" window.
When you create the flyout window (that's what it's called), you position it near the toolbar. If the toolbar gets a WM_MOVE message, it's your responsibility to call MoveWindow() on the flyout to keep it lined up.
Edited to add
The dwExStyle parameter of CreateWindowEx() should include WS_EX_LAYERED and probably WS_EX_TRANSPARENT, because the 'shadow' will use alpha blending. The hWndParent parameter is the application's main window. The x and y parameters must be calculated as an offset of whatever button the window is to be associated with.