Button and font looks low-res windows.h - c++

I am playing around with a simple C++ window and I created a button with CreateWindowEx, but when I compile and run, the button and its text has a very low resolution.
My button:
Windows Button:
Do I have to add something to my .manifest file? or my resource.rc file? I am pretty lost.

You need to send a WM_SETFONT message to the control with the font you want it to use.
To get the proper font you call SystemParametersInfo with SPI_GETNONCLIENTMETRICS to have it fill in a NONCLIENTMETRICS struct, then use CreateFontIndirect on the lfMessageFont member of the struct.
Also take a look at this function: SetProcessDPIAware
I suspect DPI scaling is what is causing the button to look blurry.

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 keep the focus on the top window of 1st screen after clicking 2nd screen

we have one desktop(1st screen) to display the image and another touchscreen(2nd screen) for the control, we wrote a virtual keyboard(html&javascript) on touchscreen, ideally when we touch the keys on the touchscreen, we could input text in editbox(in an input dialog window) in the 1st desktop. Now the problem is the mouse is lost(originally it is in a input dialog in 1st desktop) when we touch the touchscreen, so we have to create a global window in C++ program, and manually copy each possible input dialog window to this global window when it is in use, also we need to set focus for each possible editbox in this input dialog window. please see this:
for each possible input dialog, we add
extern HWND activeInputWindow;
activeInputWindow=m_Edit_Name.m_hWnd;
also for each possible input box in this window we have to add
activeInputWindow=GetDlgItem(IDC_EDIT_TEST)->m_hWnd;
then the program always do this to get back the original window after clicking the touchscreen(2nd window)
extern HWND activeInputWindow;
if(IsWindow(activeInputWindow))
::SetFocus(activeInputWindow);
suppose we have 10 input window and 10 input boxes in each window,then I need to code 100 places! There must have some simple ways, windows osk.exe (virtual keyboard) have no problem for this but we have to use our own virtual keyboard.... I tried GetTopWindow() and GetForegroundWindow() but not working.. Many thanks for the help
This is trying to solve the problem using the wrong tools. What you really want is a window that receives input, but rejects activation. To achieve this, handle the WM_MOUSEACTIVATE message by returning MA_NOACTIVATE. This also works for touch input.
See How can I have a window that rejects activation but still receives pointer input? for all the ins and outs.
The problem is that your virtual keyboard is stealing the focus of the edit control. You'll need to prevent this.
Try to set the flag WS_EX_NOACTIVATE for a window's style or other approaches from this or this answers.

Program that displays content on screen but no window

In windows: I would like to know if it is possible (and if so, how) to make a program in C++ that displays images/text on the screen directly, meaning no window; if you are still confused about what I am after some examples are: Rocketdock and Rainmeter.
you can do it certainly without using Qt or any other framework. Just Win32 API helps you do that and internally, every framework calls these API so there is no magic in any of these frameworks
First of all, understand that no image or text can be displayed without a window. Every program uses some kind of window to display text or image. You can verify it using the Spy++ that comes with windows SDK. click the cross-hair sign, click the image or text you think is displayed without any windows. The Spy++ will show you the window it is contained in.
Now how to display such image or text that seems like not contained in any window. Well you have to perform certain steps.
Create a window with no caption bar, resize border, control box, minimize, maximize or close buttons. Use the CreateWindowEx() and see the various windows style WS_EX_XXX, WS_XXX for the desired window style.
Once the window is there you need to cut the window. Much like a cookie cutter. for this you need to define an area. This area is called region and you can define it using many functions like CreateEllipticRgn(), CreatePolygonRgn(), CreateRectRgn(), CreateRoundRectRgn() etc. all these functions return a HRGN which is the handle to the region. Elliptical or rectangle regions are OK as starter.
Now the last part. You have to cut the window like that particular region. Use the SetWindowRgn() function which requires a handle to your window and a handle to that region (HRGN). This function will cut the window into your desired shape.
Now for the image or text. Draw the image or text inside the window. I assume you must have cut the window according to your image, You just need to give window a face. so just draw the image either on WM_ERRASE BACKGROUND or WM_PAINT messages
Use the SetWindowPos() to move the window to the location you wish to on screen. If you have used correct parameters in CreateWindowEx() then this step is not necessary
You can set any further styles of windows using SetWindowLong() function.
Congratulations, you have your image displayed without using any windows ;)

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.

Image to display while dragging

I am implementing drag and drop of button on windows application.During dragging I want to display some dragging effect. I think image of the button would be appropriate to display during dragging.
Also I think cursor should be changed during dragging.
My doubts are:
How to capture the image of button and display while dragging.
What type of cursor should be displayed during dragging.
Application is in C++, win32.
Drag image:
If it is a standard button control then you should be able to use WM_PRINT or WM_PRINTCLIENT to ask it to draw itself to a GDI HDC (i.e. into a bitmap that you then use as the drag-image).
Note that not all controls support those messages and some of them support them in slightly different ways. Sometimes you have to experiment a bit or have custom code-paths for different controls.
Another way is to draw the button yourself using the visual styles (themes) API, with a fallback on DrawFrameControl for when themes are disabled. But that is much more tedious than using WM_PRINT/WM_PRINTCLIENT if you don't need it.
Cursor:
Depends what the operation is doing, really. Note that you get the copy and move cursors for free with the shell drag object, if you want them. Sometimes it makes sense to use a custom cursor, though.