Placing a image inside an CEdit control in Win32 - c++

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.

Related

MFC: How to add clear button inside CEdit?

I need to add a clear button inside the CEdit control like this:
And I used CMFCEditBrowseCtrl, as described in this article:
MFC Feature Pack - CMFCEditBrowseCtrl.
But the problem is that it shows a very small icon on monitors with high pixel density:
I tried to set a big icon, but the button remains narrow:
Could you please advice some solution?

How to prevent the text within the static control from getting clipped?

I am having a static control in which I am setting some text. When I am trying to set lengthy text in the static control the text is getting clipped.
Can anyone please let me know, how can I prevent the text from getting clipped.
The problem is that a static control always clips a word, that is longer than the width of the control. If you use the SS_LEFT style words are wrapped into the next line. So a higher control would help (I can read in the comments that this is possible).
But the Style must be SSLEFT and not SS_LEFTNOWRAP!
Another solution would be to use a Read Only Edit control without a border In this case you can scroll inside the edit control, because it is possible to give it the focus. Also you are able to use a vertical or horizontal scrollbar.
As long as you don't use WS_TABSTOP you will se no real difference between a read only edit control without a border and a static control. Except that the edit control can be activated with the mouse.
Make the static text control larger than the text you a putting in it. A window draws in its client and non-client space. It clips to its window.
If you're concerned about space on a dialog or form, or, language translation could be a possible issue, then you should consider using a CStatic tool tip. Using a tool tip would allow you to keep the current size for the control and provide a mechanism to display its full text. When the user mouses over the CStatic, a tool tip pops up to display the entire text. It's a compromise I've had to use to balance UI design with space on a dialog.

can't change mfc controls order

I have a dialog box with a list box,slider and a button.
I tried to change the background color but I couldn't managed to change that, so i thought that if I add a "picture control" as a bitmap and put it in the background i will succed, but now the problem is that the "picture control" is on top of all the controls.
I tried to change the the tab control with Ctrl+d but it didn't change anything.
I also tried to use SetWindowPos to top or buttom but also it didn't change anything.
I noticed that if I click in the location of the button it's brought to the front as I want.
Is there any way to "click" all the controls at the begining? do i miss something in order to bring the control to the top?
If you need to change the background colour of the dialog box, you need to handle the WM_CTLCOLORDLG message and return the handle to a brush (if the brush is not a stock object, make sure you delete the brush after the dialog box is closed) -- or, you can process the WM_ERASEBKGND message and erase the background yourself.
I tried to change the the tab control with Ctrl+D but it didn't change anything. I also tried to use SetWindowPos to top or buttom but also it didn't change anything.
Ctrl+D does get you in reordering mode, however there is a more reliable way of checking. The dialog template is in text form in .RC file, where you can review the order of control with text editor and sort lines manually the way you wish. This will be the order of control creation and tab order as well. Sometimes it's even easier to reorder controls this way.
More to that, when your application is running, Spy++ SDK tool can enumerate windows and again it will give you window order for checking.
SetWindowPos with proper arguments changes Z-order of controls on runtime as well.

Custom dropdown for CComboBox

I'm trying to create a custom dropdown for a derivative of CComboBox. The dropdown will be a calendar control plus some 'hotspots', e.g.
So I figure the best way to achieve this is to have a simple CWnd-derived class which acts as the parent to the calendar control, and have it paint the hotspots itself.
The window needs to be a popup window - I think - rather than a child window so that it isn't clipped. But doing this causes the dialog (on which the combobox control is placed) to stop being the topmost (foreground?) window, leading to its frame being drawn differently:
alt text http://img693.imageshack.us/img693/3474/35148785.png
This spoils the illusion that the dropdown is part of the combobox since its acting more like a modal dialog at this point. Any suggestions on how I make the custom dropdown behave like the regular dropdown?
Are there any other pitfalls I need to watch out for, e.g. focus and mouse capture issues?
When you create your popup window, you need to specify its owner. Owned popup windows will activate their owner when you activate them. Not specifying an owner will cause your window to get activated, which causes the change in the owner you're seeing.
Yeah I had this problem once. A quick google makes me suspect I solved this by using CreateWindowEx() and specifying WS_EX_NOACTIVATE. I have some other code that achieves the same effect by making the window with WS_EX_TOOLWINDOW rather than as a popup window, but I'm not sure of why that was done that way, my intuition would say that making it a popup window would be the way to go.
You can find in the following links two sample project that put in the CComboBox dropdown window a CTreeCtrl or a CListCtrl controls ... similar, you can put whatever you need there. Here is the links:
Tree ComboBox Control
and
List ComboBox Control
I hope this help you.

Creating custom transparent control

I am trying to create a custom control that displays a bitmap with per-pixel alphablend (as some of you already know for other questions).
Right now I am using a custom control in the resource editor and I attach it to a class derived from CWnd. When I register my custom class I set the hbrBackground of the WNDCLASS structe to NULL_BRUSH to achive the transparency of the control.
In the OnPaint of the control I use AlphaBlend to paint the per-pixel alpha blend bitmap.
This works quite well but I have this two problems:
I want to change the displayed bitmap when the mouse is over the control. As the control is transparent, the areas that one bitmap that are not overlapped by the other bitmap are not erased. How can I erase the background when the image is changed?
The second problem is related with two overlapping controls. My control is painted over other control that has a gradient (in fact is inside other control). The problem is that if I put my control before in the z-order the other controls overlap my control and mine is not displayed. If I put the other control before in the z-order I can not get the mouse message in my control.
Maybe I am doing something wrong or I am wrong in how I am trying to implement my control. Any kind of help would be appreciated.
Thanks,
Javier
I'll take a chance. :-)
This should give you all you need to accomplish what I think you want.
General Solution for Transparent Controls
As far as Z-order issues, the z-order does not affect message priority. You'll need to post some code so we can determine what is happening there.