I'm trying to redraw some text I drew on window at x and y coordinates say (100, 100) to a new location (500, 500). when I redraw the text, it doesn't erase the old text at (100, 100) until I refresh the window (like do a minimize and maximum). how can you update the window to display the current text?
InvalidateRect, UpdateWindow.
Related
First, if this isn't a great way to do this, PLEASE suggest better. I can't seem to find an exact solution to what must be a common desire (see post title).
My approach was to trap the WM_PAINT message and check whether the window position is maximized. If it is, then run this code:
SetWindowLong(hCDGWnd, GWL_STYLE, 0); // remove all styling
SetWindowPos(hCDGWnd, HWND_TOP, 0, 0, 1280, 720, SWP_SHOWWINDOW); // full screen is 1280 x 720
StretchDIBits(hdc, 0, 0, 1280, 720, CDG_XOFFSET, CDG_YOFFSET, CDG_RENDER_WIDTH, CDG_RENDER_HEIGHT,
bmBits, (LPBITMAPINFO)&bmInfo, DIB_RGB_COLORS, SRCCOPY);
What I want to see is my BITMAP stretched to fill the entire client area, which should just fill the entire screen. Actually it is a section taken out of a larger bitmap. It seems like the window is in fact full screen, but the bitmap is its normal size and not stretched. Curiously, when I was fiddling with the window positioning stuff I had all kinds of attempts leaving the styling but trying to position the title bar and frame offscreen (see below) - the bitmap was appearing stretched just fine during those close but failed attempts. Now I've got the window right, suddenly the bitmap no longer stretches. Is there something about removing the styling that would screw up the StretchDIBits function?
Also, when I attempt leaving the style in place, and use AdjustWindowRect() to have my client size be fullscreen, it returns {-3, -26, 1283, 723 } which makes sense - 3 pixel border plus 23 more for title bar on top. But, just to explore things, when I don't even test for maximized state, and just make the window have x = -3, y = -26, cx = 1286, cy = 749, then almost everything is fine except the bottom of the window is shy of fullscreen by about 4 pixels. When I make the window height much bigger - say 760 - IT STAYS THE SAME HEIGHT!? I so confused. If try this maneuver only when maximized, it seems like windows ignores my attempts to have the title bar off the top of the screen.
I'm creating a multi-window application (cross-platform (X11, macOS, Windows), unspecified window manager), where each window corresponds to a document.
When creating a new document (and thus window), the window manager should be free to put the window wherever it finds suitable.
However, if the user manually moves the window to some location, this location should be saved along with the document (so on re-opening the document, it will be at exactly the place it was last saved).
The (initial) window size is fixed.
In order to find out the current position, I can either use wm geometry or winfo geometry, which both return slightly different results (the former with decoration (like border and menu), the latter without).
As I understand it, I need the result of wm geometry if I would like to restore the position of the window.
However, when I create an initial window and resize it, winfo geometry returns the correct position (but without the decoration), whereas wm geometry does not.
# hide the default window
wm withdraw .
toplevel .my
wm geometry .my 200x100
# the following prints "1x1+0+0" for both geometries
puts "[wm geometry .my] [winfo geometry .my]"
raise .my
# this prints something like "200x100+0+0 200x100+860+542"
puts "[wm geometry .my] [winfo geometry .my]"
If I manually move the window and then call [wm geometry .my] again, it now correctly reports whatever position the window is at.
So my question is:
Is there a way to get the window position (as set by the window manager) after I resized the window using wm geometry ${w}x${h}?
Alternatively, is there a way to find out (from the window itself) whether the user has moved it to some other place? (so I can save the position as "undefined, let the WM do their thing").
Ideally, such a solution would handle the case where the user to manually moved the window to the +0+0 position differently from the case where the window was not moved at all.
I'm especially interested in getting this information without having to bind to the <<Configure>> (or some other) event, in order to detect whether the user touched the window.
sidenote: setting the window dimensions
I know that I can set the window dimensions with both wm geometry ${w}x${h} and when creating the window with toplevel .wm -width $w -height $h.
When doing the latter, wm geometry returns the correct window position, but what are there any other differences between the two?
I think a more extensive use of winfo is what you need:
https://www.tcl.tk/man/tcl8.6/TkCmd/winfo.htm
set _x [winfo rootx .my]
The command above returns the X coord of the upper-left corner
winfo rooty .my
Same as before, returns the Y coord of the upper-left corner
winfo width .my
winfo height .my
Same for these self-explaining commands.
You can save in real time the position and size of any window, to restore later on re-open.
This question was generated by a response to another question: Common Controls on a Transparent Window?.
Apparently, there is a way to only paint the background without a control painting itself again This would solve the problem of having common control buttons on a transparent background.
So my question is, how do I paint only the background around a common control after the common control has painted itself?
About how to redraw visible borders.
The rounded rectangle drawn by RoundRect is used as representative
The FrameRgn function draws a border around the specified region by using the specified brush.
Simple code demonstration:
HRGN hRegion = ::CreateRoundRectRgn (0, 0, ClientWidth, ClientHeight,12,12);
Canvas->Brush->Style = bsSolid;
Canvas->Brush->Color = RGB(96, 96, 96);
::FrameRgn(Canvas->Handle, hRegion, Canvas->Brush->Handle, 2, 2);
::DeleteObject(hRegion); // Don't leak a GDI object
Link you need: Redraw Border
I want to make a box with a hover effect (to make a bold border of the box) when a mouse moves over it. What method should I use in Gosu library?
#green rectangle that I want to give a hover effect (to become bold border)
def draw
Gosu.draw_rect(50, 50, 100, 50, Gosu::Color::GREEN, ZOrder::MIDDLE, mode=:default)
end
In the draw function use the if condition for mouse over button where the parameters are the dimensions of the button, then inside the if condition draw a rectangle slightly bigger with zorder middle (make sure the green rectangle zorder is top)
I'm have a picture box control and 2 Command Buttons. I have an image displayed inside the picture box.
Is it possible to zoom the image when the Zoom-in and Zoom out buttons are clicked?
Or I can even put a scroll bar. Is it possible to zoom the image according to the scroll bar movements?
I'm using VB 6.
I assume here that you are using BMP or JPG files here.
The simple scratch method is to place an Image control in the PictureBox, initially with the property Stretch = False. Initially, it would be in the top left hand corner. After setting the Picture property to your picture object, the Image control will be resized to fit the image. Save the original width and height of the control in variables. Now set Stretch = True. You can zoom in by resizing the image using
img.Move 0, 0, sngWidth * sngMagFactor, sngHeight * sngMagFactor
Where sngMaxFactor = 4! or however much you want to zoom by.
Restore back to original size by:
img.Move 0, 0, sngWidth, sngHeight
You can also pan the zoomed image by altering the Left and Top arguments in the Move() method.
It might be easiest to use two pic boxes, one inside the other. The 'outer' box can be thought of as a viewport into the 'inner' box, which you resize and position as needed. The effect will be the same but the coding is much simpler.