in visual studio c++ debug, how to convert scentific float value in immediate window and locals window - visual-studio-debugging

in visual studio c++ how to convert scentific float value in immediate window and locals window, e.g. 2.6784184492221229e+271
(including denomalized number).
for example, in Locals window, VS c++ would show type double as 2.6784184492221229e+271
and in immediate, if I type, ?vara, it would show as 2.6784184492221229e+271
how can we convert it to a direct readable value? 1.8 (sorry I don't know what it is called).

Related

Why this BitBlt example doesn't work anymore?

I'm currently getting back to some Windows Programming using Petzold's book (5th edition).
I compiled the following example using BitBlt and it doesn't work as it is supposed to.
It should copy the Window's icon of (CxSource, CySource) size and replicate it on the whole window's surface.
What happens, in reality, using Windows 7 is that the bitmap below the window gets sourced and copied into the drawing surface i.e. hdcClient.
I don't understand why it behaves like this knowing that it's clear the DC passed to BitBlt is hdcWindow, which refers to a device context obtained via a GetWindowDC(hwnd) of the current application.
I first thought it was due to the fact the transparency mode is enabled by default, but deactivating it doesn't change anything. BitBlt seems to always take the surface below the application Window!
I don't get it! :)
Anyone knows why it works that way and how to fix it?
Making screenshots with BitBlt() did not exactly get any easier since the addition of the DWM (Desktop Window Manager, aka Aero). Petzold's sample code suffers from a subtle timing issue, it is making the screenshot too soon. It does so while Aero is still busy animating the frame, fading it into view. So you see what is behind the window, possibly already partly faded depending on how quickly the first WM_PAINT message is generated.
You can easily fix it by disabling the effect:
#include <windows.h>
#include <dwmapi.h>
#pragma comment(lib, "dwmapi.lib")
And after the CreateWindow() call:
BOOL disabled = TRUE;
DwmSetWindowAttribute(hwnd, DWMWA_TRANSITIONS_FORCEDISABLED, &disabled, sizeof(disabled));
Another tricky detail is that the first BitBlt matters, the DWM returns a cached copy afterwards that is not correctly invalidated by the animation.
This gets grittier when you need a screenshot of a window that belongs to another process. But that was already an issue before Aero, you had to wait long enough to ensure that the window was fully painted. Notable perhaps is the perf of BitBlt(), it gets bogged-down noticeably by having to do job of composing the final image from the window back-buffers. Lots of questions about that at SO, without happy answers.
It is not supposed to copy the windows icon, it is supposed to copy the windows titlebar part where the icon is located.
There are some issues with this (now 20 year old code):
GetSystemMetrics values cannot be used for window related dimensions anymore since GetSystemMetrics returns the classic sizes, not the Visual Style sizes.
Depending on the Windows version, the DWM might define the window size as something larger than your window (where it draws the window shadow and other effects).
Your example works OK on XP:
(There is a small problem because the titlebar is not square (unlike Windows 98/2000 that this example was designed for) so you see a issue in the top left where it is just white. I also modified the example slightly so it varies the HDC source location)
On a modern version of Windows it seems like the DWM or something is not able to properly emulate a simple window DC and parts of the shadow/border/effects area is part of the DC:
I don't know how to fix this but the example is pretty useless anyway, if you want to draw the window icon you should draw the HICON with DrawIconEx. If you want to draw custom non-client area stuff then you need to find more recent examples, not something that only supports the classic theme.

Convert between dialog base units and pixels

I'm coding in raw C, using win32.
I want to change at runtime the position of a control (a button) to properly keep its relative position inside the parent dialog, which is resizable.
I defined both the dialog and the button via a resource script, where dimensions are in dialog base units.
To change the size at runtime I have to deal with the SetWindowPos function, which accepts values in pixels so, to maintain the original proportions, I need to convert in pixels the original distance (in dialog base units).
I've tried to use the value returned from the GetDialogBaseUnits funcion and follow the "conversion procedure" (which is, substantially, a multiplication and a division) reported in the reference page, using the MulDiv function but what I get is a wrong value...
In particular I obtain: LOWORD(GetDialogBaseUnits()) = 8 and HIWORD(GetDialogBaseUnits()) = 16 which, used in MulDiv, produce sizes in dialog base units which are exactly the half of the pixel ones (and this is wrong, in my system).
How I can properly perform this conversion?
Not with GetDialogBaseUnits().
If you have a dialog box, you can do this easily: use the MapDialogRect() function.
If you have a regular window, you'll have to do the calculations manually. I've asked a question related to it here and wrote a tool for testing possible calculations. The different calculations are close enough to be equally visually useful; don't stress too hard.

How do I change to a black Windows arrow cursor?

I've noticed that both Visual studio and blend change from the standard Windows white cursor to a black cursor when you hover over certain areas. I looked in the Cursors enumeration and couldn't find an equivalent black cursor. Is this a special cursor included in Visual Studio or is this part of Windows? Where do I find this cursor resource? Thanks.
Windows does have a standard black arrow cursor. It's IDC_ARROW in the "Windows Black" pointer scheme, so you wouldn't see it unless you'd changed the scheme. Note that the pointer scheme is strictly a user preference. Applications should not change it, ever.
The cursor file lives at \Windows\Cursors\arrow_r.cur. The answers to this question describe several techniques for setting a custom cursor in WPF.

displaying the middle of a large array while debugging

I'm using C# with Visual Studio 2010. I've got a large array of floats (1M floats) and need to be able to look at small chunks of data in the middle of the array during debugging.
This can be done using the locals window, however the scroll bar maps onto 1M array elements, making it difficult to adjust the scroll bar with any precision.
Is there some way to look at, say k=688392 for f[k] to f[k+100] in the debugger?
Thanks
You can use the immediate window. Just put a breakpoint after the line the values of the array are set and type f[k] in the immediate window and it will give you the value at that index.

Simplest way to extend GUI functionality in OpenCV 1.1 on Windows?

I have a large real time computer vision project in C with a gui that uses OpenCV 1.1's built-in HighGUI library. As others have pointed out, the OpenCV GUI library is very limited.
I'd like to make a slider bar (trackbar) GUI element like cvCreateTrackbar that can have values that go either negative or positive. OpenCV currently limits trackbars to positive integer values only. I don't need anything else fancy, just a sliderbar that can go negative.
What is the easiest way to get a slider bar that goes positive and negative?
I am on Windows XP using mingw and OpenCV 1.1. Ideally any solution should require minimum dependencies or libraries, and should play nice with Windows and mingw.
You could write a wrapper around the progress bar class that normalizes your values to the range of the progress bar. For example, if your range is -5 to 5, inclusive, add 5 to the value before sending to the progress widget. The "+5" adjusts the range from 0 to 10.
You may want to consider using a different widget as most definitions of progress measurements don't go negative. (Is your application actually making negative progress?) Also, most progress widgets allow for a positive increment, different than an absolute value. As the application runs, it adds an increment to the widget.
"That's just my opinion, I could be wrong." -- Dennis Miller.
[zGUI][1]https://github.com/zetapark/zGUI
I just uploaded a opencv gui toolkit. Please take a look..
This is solely dependent on opencv.
Event driven..

Resources