MFC Dialogue based application - mfc

Good day, I am trying to add a bitmap image to my dialogue-based application using MFC ( VSTUDIO 2019 ). I wish to position my image at the center of the application. How do I get the size of the current rectangle so that it can be given as an input to BitBlt() function? Thanks in advance

As mentioned in the comments, you can use GetClientRect to get the dimensions use refer to. My answer here provides some additonal information about GetClientRect and the other variants.

Related

MFC picture control changes size when DPI awareness disabled or running on Win7

I made an MFC app for my friend using VS2015 in Win10. It looks like this, which is exactly the same as in resource editor.
.
But when he ran the app on his computer in Win7, the Bitmap image in Picture Control enlarges and covers up some text boxes below, which looks like this.
.
After I searched and realized it may be related with DPI awareness. I disabled DPI-Awareness in property page of Manifest Tool and rebuilt. The same thing happened even when it runs in Win10.
Could someone help me explain the cause of this and find a solution to fix the size of the image control? Thanks.
The main problem is that a dialog from a resource is always measured in DLUs.
And DLUs are calculated from the size of the font, that is used for the dialog.
See this article how dialog base units are calculated.
Now you have a static picture control that is sized in DLUs. The bitmap is just scaled in pixels and is never resized, when you assign it to a static dialog control. And because the real size of the static control depends on the used font, you get different layouts for your dialog and your bitmap.
And because just the font changes when you choose no DPI awareness and because the font changes from windows version to windows version your dialog always look different.
Advice: Paint you picture your own and stretch it accordingly.
Also this stackoverflow question is nice documents and shows the effect of DLUs.
And here some code for auto sizeing picture controls.
An auto-sizing bitmap picture control
A simple image preview class using GDI+
CxImage
Normally, I prefer to keep control in my hand by using SetWindowPos() to set the size of image I want in different situations. You can use below two lines to control/set position and size of your image.
Assume ID of the Picture Control is IDC_STATIC2 then you can use like:
CStatic * pStatic = (CStatic *) GetDlgItem(IDC_STATIC2);
pStatic->SetWindowPos(NULL,20,20,50,50,0);

c++ win32 change trackbar background color

I have a win32 API, developed in c++ and i can't find any useful information regarding how can i change the background color of a Trackbar component in windows Vista and above?
I am looking for a equivalent to .NET attribute called BackColor.
Winforms implements it by handling WM_CTLCOLORSTATIC for a TrackBar control. The example code in the linked SDK article should do the trick.
Not done that one before, but try using NM_CUSTOMDRAW for trackbar and then setting the background brush and text colour of the DC for that control when its being drawn (probably in the CDRF_NOTIFYPOSTERASE stage).

Function to retrieve the size of an element

What I need is a function to retrieve the size of an element, be it a Java Applet window in a browser, text boxes in programs, applications window and so on.
Now I don't know what this kind of function is called, but I uploaded an example from an application that had that functionality.
Example (The red box)
What I need to be able to with this is get its size and its coordinates on the screen. This needs to be in C++.
So ff anyone could give an example, or atleast the name of that kind of function, I would be grateful.
I found a program that has the function I seek: It is called Scar Divi, which is a scriptable tool to perform repetitive actions, mostly uses for cheating in a game called Runescape it seems. Unfortunately it is closed source.
Are you looking for Window Geometry or desktop widget?
After getting an image of the screen (there will be somethign in Qt to do this)
You need an image processing library like openCV to find the rectangle - look for "Hough Transform"
I found the solution!
POINT p;
HWND wnd;
RECT rec;
GetCursorPos(&p);
wnd = WindowFromPoint(p);
GetWindowRect(wnd, &rec);
This will give you the coordinates for the box (extract from rec).

Get resolution of DirectX device

Where should I be looking for resolution of DirectX (3D) device? getViewport seems to have Width and Height, yet as far as I know viewport is supposed to be an area, not 2D "canvas" with these attributes.
(I hope "resolution" applies to the device, not D3D directly. Please correct me if this part is wrong.)
Simple MSDN link will be good answer as well, however I already browsed it through and couldn't find it.
Edit: it seems like getDisplayMode will work for fullscreen apps that changes resolution since it returns the display adapter mode, yet I'd like to be able to get the size of d3d window too.
DirectX doesn't actually own a window. If you remember when you initialise the device, you give it a handle to a window. It takes this and displays to its viewports within this window.
So if your looking specifically for the window size then you'll want to get it at the OS level.
This question discusses how to deal with it.
Namely GetWindowRect/GetClientRect(HWND, LPRECT)
If for some reason you only have the d3d interface, you can use getcreationparameters to get the original hwnd and then you can use GetWindowRect or GetClientRect as suggested before.
D3DDEVICE_CREATION_PARAMETERS cparams;
RECT rect;
device->GetCreationParameters(&cparams);
GetWindowRect(cparams.hFocusWindow, &rect);
//rect.width
//rect.height
Perhaps this is what you need: IDirect3D9::GetAdapterDisplayMode Method
http://msdn.microsoft.com/en-us/library/bb174316%28v=VS.85%29.aspx
If you want the window size then call "GetClientRect" on the hWnd you are setting up with.

How to show Iplmage format on the GUI of C++ instead of showing it in another windows?

I'm trying to display the output image onto the C++ interface instead of creating another window to display the image.
For example: cvNameWindow("Window A",0);
cvShowImage("Window A", imgA);
This will create an window and display the imgA on it.
My question is that can i display my imgA onto my C++ interface together with all my other button and textbox.
I'm using Borland C++ Builder 6 and OpenCV.
For one thing, since it's open source, you can have a look at the cvShowImage implementation for Windows here.
My C++ Builder memories are a bit fuzzy but I guess you can skip all the CvWindow calls and use any control's (a PaintBox?) GetDeviceContext() to its the DC and GetClientRect() to get its size.
Hope this helps.
You will need to convert the IplImage to a Graphics::TBitmap with this. Then you can draw it as here.