How to size to content a CStatic control programmatically - mfc

I have a Dialog box where I show a record from database.
I want the CStatic fields to size to content.
How can I do this.
I am getting a black space at the end of static field. Here is the image attached.
I don't want the black space in my field.

Size to content is not the best way to solve this, you would be better off deriving a class from CStatic and make it transparent by:
overriding WM_CTLCOLOR
overriding WM_ERASEBKGND()
and use this class instead of CStatic for these fields.
See this SO question and my answer for more details.

Related

How to change font of MFC PropertySheet

I have a class derived from CPropertySheet. Please let me know how can I change the font of this propertysheet tab along with fonts in all pages. Currently they used system font only.
Also I would like the dialog box to come up at specific location on screen and remain there only. Please let me know how can I change location of propertysheet dialog when it is getting initialised.
Thanks
CPropertySheet inherits the SetFont method from CWnd. You could call this method from CPropertySheet::OnInitDialog. Do the same thing in the pages to set their font.

Handling dynamic text editing in an MFC CView

I have a class that implements OnDraw to draw text and images to a CView. At certain times (ie onClick) I would like this text to be editable in place. What would be the best way to implement this?
Have the class have a CEdit object that I hide and show and draw over
the top of my text.
Handle key presses in the class and implement my
own editing
Have something external to the class control whether to show the edit box or my class
Something else?
Go with your first idea, create a CEdit box when you need some text editing. If you look at how a ListCtrl handles rename functionality it does exactly that.

MFC add scrollbar to CWnd member

I have a member of CWnd class name mywindow
and i want to add to it a scroll-bar.
how i can do it?
i try already to do:
mywindow.EnableScrollBarCtrl(SB_BOTH,TRUE);
it display both Horizontal and Vertical scroll-bars,
but i cannot push the buttons or move the scroll-bars.
i try also after the first command:
mywindow.EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH);
and it change nothing.
can someone could show me a simple example how to add scroll-bar to this member?
thanks a lot,
Tal
Enabling the scroll bars isn't enough. You have to react to the window messages WM_HSCROLLand WM_VSCROLL. Using the GetScrollInfo method you get the position (value) of the scroll bars and then you draw your window content according to this position.
Look up some scroll bar tutorials such as http://www.codeproject.com/KB/dialog/scrolling_support.aspx . In essence, dwo's comment above is what you need to do - handle those messages and set the virtual client area size.
There must be some 'overflow' before scroll bars became active.
Write some 'sufficiently long' data in your view and the scrollbars will become active (at least, that was my experience time ago).
Usually scroll bars get handled 'automatically' from MFC components like (for instance) text editor or form view. I.e. will became visible when needed also without explicit call EnableScrollBarCtrl ...

Changing the background image of property page - MFC

Can anybody tell me if there is any way of adding a background image to property page in MFC? I'm able to set the background image for dialog but not able to do the same for property page?
Inherit CPropertyPage and override OnEraseBkgnd. You can paint a bitmap into the provided device context.

Placing a image inside an CEdit control in Win32

I'm trying to achieve an effect where there's a visible logo inside an edit control and the logo becomes hidden when the user places the focus on the edit control.
What's the best way to approach this? Would it be better to place an image control on top of the edit control or paint the background of the edit control transparent and position the image control behind the edit control? Or possibly some other method?
The EDIT control has very broken paint behavior, you'll never get there by overriding the WM_PAINT message handler or using transparency. Yes, overlay it with a STATIC control that you hide when you see text being entered.