MFC: How to add clear button inside CEdit? - c++

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?

Related

What is the best way to create custom menu with WinAPI

Since there is no way to deep customizing (a gradient background for example) win32 controls (such as buttons, menu items e.t.c) many people advise to create an own custom control.
And if I need a custom button I will use WM_MOUSEMOVE, WM_LBUTTONDOWN and a shadow buffer. I will draw all controls on the shadow buffer and then use BitBlt(hDC, ...) for my window.
But if I want to create a custom menu I must to foresee that menu can be drawn outside of the client area.
At first I need to mouse tracking outside of the client area. SetCapture(hWnd) seems to be a bad solution as it blocks mouse tracking for windows below.
Then I need to draw/erase items outside of my window. Erasing with InvalidateRect(NULL, NULL, TRUE/FALSE) seems to be a bad solution too as it cause of blinking.
What is the best approach to create custom menu with WinAPI?
Runtime menus that can appear anywhere on the screen can be shown with TrackPopupMenu() function. Create the menu with CreateMenu(), AppendMenu() etc, then show it with TrackPopupMenu().

How to set size and Transparent / Clear CMFCToolBar Button and Icon in mfc?

I have created some (CMFCToolBar) toolbars and added buttons and icons to them. I read on Microsoft's official website that CMFCToolBar takes 23x22 button size and 16x15 icon size (ref: link).
If I use 16x15 for the icons, then icons appear blurry. This is because the icons are originally with size 16x16. I used the function SetSizes(CSize (23,23), CSize(16,16)) to change icon size but the icons do not appear right:
Is there another way to set icon and button size?
Update
I called the SetSize function before create toolbar but the icon still appear a little blurry:
I want to know if there is a way to set Icon/button Transparent or make it clear like we can set toolbar transparent through TBSTYLE_TRANSPARENT in CreateEx function.
SetSizes is a static function that affects the complete library.
It should be called before you create any toolbar or menu object.
Best location is in InitInstance of you applicxation.
But my tipp: Use the sizes that are recommended! 16x15 and 23x22....
Transparency can be done with standard 32bit RGB/A bitmaps.
If you have a 16 color bitmap you should use RGB(192,192,192) as the standard color for the background. It is automatically replaced with the needed background color.
This has been answered here too.

C++ WinAPI - How to make button appear pressed?

I have in my editor few editing modes. I can choose specific mode using buttons that are placed on a toolbar. I want to indicate which mode is currently on. When I press appropriate button - I want to make the clicked button remain pushed. How do I do that in WinAPI? My toolbar uses bitmaps for icons if that's relevant.
There used to be a way to get something like the look and feel of a toolbar by using a normal check box with the BS_PUSHLIKE style set. But that got broken a bit with Windows XP because of mouse hover effects, so it's not widely used any more.
If you want to create your own toolbar, without the help of MFC, there is an MSDN article that covers the creation and management of a toolbar window (actually a dedicated window class as part of the Common Controls Library).

Writing controls like a button in C++\Win32 (not MFC or CLI)?

I have several questions concerning the controls like a button, if You could answer i would be very much pleased.
Questions:
Is there any way to create a control like a button, but not-standard, i mean, not that strict-rectangled button
How do I handle mouse hover events within the control
Regards,
Galymzhan Sh
It's relatively easy. If you want the same behaviour as a button (click, hover etc etc), then the best bet is to subclass the button control.
Have a read of the following MSDN articles:
http://msdn.microsoft.com/en-us/library/bb773183.aspx
http://msdn.microsoft.com/en-us/library/ms997565.aspx
http://msdn.microsoft.com/en-us/library/ms633569.aspx
This one is tricky one.
I developed my own GUI, it is advance topic.
Here is how i developed mine.
Create class called button
In button class, create all
variables needed like the width and
Height of the button
Have a render function
If you gonna let users load their own
texture for the button, you should
include a load function
Create class for wrapper
Have a Add button function and use ids for buttons
Have a EventProc that checks for hovers, clicks...
Have a Render controls function to render all buttons
This is just simple way to write buttons

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.