UpdateWindow()

Mar 9, 2011 at 8:58pm
Hi, could you explain to me what am i doing by putting:

UpdateWindow(hWindow);

Ive read some informatin on the internet but i dont quite follow it.

What does it do and whats its purpose?
Mar 9, 2011 at 9:22pm
closed account (zb0S216C)
It's best asking in the Windows Programming section for this.

Basically, it tells Windows which window to draw/display. It sends a WM_PAINT message to the window's procedure( which jumps in front of the message queue ). The single argument is the handle to the window you wish to draw.
Last edited on Mar 9, 2011 at 9:24pm
Mar 9, 2011 at 9:34pm
Ok, you say "it tells Windows which window to draw/display"

But i thought this function does this:

ShowWindow(hWindow, iCmdShow);

???
Mar 9, 2011 at 9:40pm
Nope, ShowWindow makes the window visible. Or, to be more precise, it sets the visibility state of the window that hWindow is the handle to to iCmdShow.
Mar 9, 2011 at 9:45pm
closed account (zb0S216C)
iCmdShow

If this isn't of type HWND then you're wrong; the argument takes a HWND instance.

My post but re-phrased: It updates the client area of the given window( argument ). It still sends a WM_PAINT message to the front of the window's message queue.

Think I'm still wrong? Tell it to Microsoft.
Last edited on Mar 9, 2011 at 9:46pm
Mar 9, 2011 at 9:47pm
Ok, just to double check:

ShowWindow() just gives the visibility state (whether its minimized or maximized and so on...)

UpdateWindow() displays the window (actually draws the windows on the screen)

?

Mar 9, 2011 at 10:00pm
closed account (zb0S216C)
ShowWindow( ) Determines how the window shall be shown. ( See the table for window display options: http://msdn.microsoft.com/en-us/library/ms633548(v=vs.85).aspx )

UpdateWindow( ) updates the client area of the given window( the argument is the handle to the window you want to update ). See here for information from Microsoft: http://msdn.microsoft.com/en-us/library/ms915501.aspx
Mar 9, 2011 at 10:04pm
when you say "updates the client area of the given window"

Is that just another way of saying it draws the window on the screen?
Mar 9, 2011 at 10:23pm
closed account (zb0S216C)
I'm sorry, I should have said this before. This image represents the client area: http://www.codemorphis.com/articles/tip1/window_client_area.jpg Where the red box is the client area of the window.
Last edited on Mar 9, 2011 at 10:24pm
Mar 9, 2011 at 11:00pm
From what im understanding UpdateWindow() does infact DRAW the window on screen.

Correct?
Mar 9, 2011 at 11:14pm
closed account (zb0S216C)
Basically, yeah. However, it doesn't draw the border, caption, window button glyphs, etc...
Mar 9, 2011 at 11:28pm
Then what draws the border, caption, window button glyphs, etc...
Last edited on Mar 9, 2011 at 11:33pm
Mar 10, 2011 at 12:26am
Ive just been reading and ive come up with a new idea of what these two do:

ShowWindow() sets the "show-state". This function also DISPLAYS the window as we are setting the show state to a state which is displayed, so the window IS displayed because of this function.

UpdateWindow() does what it says on the tin. It updates the client area to make sure things such as strings and boxs are visible when the window is first created. Another thing which tells me that the updatewindow() does NOT display the window is that my application still displays if i remove the updatewindow().

Is this correct?

If so, why do need to make sure things such as strings and boxs are visible when the window is first created, why would they not be visible?
Mar 10, 2011 at 8:32am
closed account (zb0S216C)
I think you might need to update the client area when you modify a static text element or something along those lines.

And yes, those descriptions look fine to me.
Mar 10, 2011 at 10:59am
Thanks :D.

To sum up, showwindow is the one which actually displays the window, and updatewindow is the one which updates the client area for things like if ive modified a box
Mar 10, 2011 at 11:20am
You don't really need to explicitly call UpdateWindow for the standard windows, like statics or pushbuttons, they do that themselves. Just do it once after calling ShowWindow.
Mar 10, 2011 at 3:18pm
closed account (zb0S216C)
like statics

If your static string changed, then you will need to update the client area. If nothing changes then there will be no need to update the client area. However, if you were creating custom elements, then you might have to update the client area. These are my thoughts, however.
Mar 10, 2011 at 9:16pm
Not really, if you call SetWindowText the controls handle themselves quite well.
Topic archived. No new replies allowed.