Is it necessary to invoke the functions "Showwindow" and "Updatewindow"?

Asked

Viewed 362 times

2

I recently made an introduction to Windows API and I’m already in the window-making part. In one of the first applications I created I had to use ShowWindow and UpdateWindow after creating a window, but even without them the window would still appear. I even created more windows to see if your invocation would be necessary and these additional windows also appeared.

So is here my question is really necessary to invoke them? Will it have any impact not to do? Or is it just a preventive measure?

P.S I put the C++ tag as it is an API also used in this language

2 answers

3


I don’t know how you wrote the application, but we can say that some functions already call these cited functions "automatically" which would actually make it redundant.

Showwindow

But note that the use of ShowWindow not only to display the window when starting a program, it has "utility" to change the state of the window you are referencing, for example, this would force you to minimize an already opened window:

 ShowWindow(hwnd, SW_FORCEMINIMIZE);
  • SW_FORCEMINIMIZE minimizes a window, even if its proprietary Thread is not responding

  • SW_HIDE - Hide the window and activate another window

  • SW_MAXIMIZE - minimizes the window

  • SW_MINIMIZE - minimizes the window and activates the next one at the highest level by order Z

  • SW_RESTORE - active and shows the window. If minimized or maximized it "restores" to the original position and sizes.

  • SW_SHOW - active and shows the window in original position and size.

  • SW_SHOWDEFAULT - Sets the window state based on the value SW_ specified in the structure STARTUPINFO passed to the CreateProcess

  • SW_SHOWMAXIMIZED - Activates and displays the maximized window

  • SW_SHOWMINIMIZED - Activates and shows the minimized window

  • SW_SHOWMINNOACTIVE - shows the minimized window, is similar to SW_SHOWMINIMIZED, except that the window is not enabled

  • SW_SHOWNA - Shows the window at current position and size, is similar to SW_SHOW, except that the window is not enabled

  • SW_SHOWNOACTIVATE - Shows the window at the most recent position and size, is similar to SW_SHOWNORMAL, except that it does not activate the window.

  • SW_SHOWNORMAL - Activates and displays the window. If the window is minimized or maximized this restores to the original size and position. An application must specify this "flag" when displaying the window for the first time.

Updatewindow

The UpdateWindow updates the client area of the window by sending a message WM_PAINT to the window if the update region is not empty. This may be useful for animations maybe, so you will use it when needed to update the rendering.

I do not know much, but it seems to me that these are the objectives, if you have any doubts too maybe new answers will appear, I hope that for now this will help.

Documentation:

  • Thank you now I realized Xp. The tutorial I am following does not explain certain things that in MSDN are also not explained :/

  • 1

    Guilherme, would you have a link to the documentation of all this? Add a lot to your answer.

  • @bfavaretto added documentation on the ShowWindow, my English is not very good, I translated the flags of the documentation from microsoft, if you have any gafe forgive me, I translated with the basic that I know of English (which is very bad by the way :p ), I did not use google-translator because often the texts lose meaning for me.

3

Just to complement what William said, if you notice, most of the time at the time the call Showwindow inside Winmain sends the nCmdShow argument, this argument is the way Windows wants its window to be displayed(since you can change the view mode of shortcuts), so basically when calling the Showwindow sending nCmdShow, you are not exactly asking function to show your window, but rather to show it the way that Windows wants.

But the window is not shown on the screen alone, it is only shown on the screen automatically if you create the window by sending the WS_VISIBLE flag, see this example:

CreateWindowW(wc.lpszClassName, L"Janela", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInstance, NULL);  

In the above case it is shown automatically, because you sent the WS_VISIBLE in the function, that is, even without calling the Showwindow it will be shown.

Now look at this case:

HWND hwnd = CreateWindowW(wc.lpszClassName, L"Janela", WS_OVERLAPPEDWINDOW, 100, 100, 250, 150, NULL, NULL, hInstance, NULL);    
ShowWindow(hwnd, SW_SHOW);

In this case the window would not appear without the Showwindow call as the WS_VISIBLE flag was not sent.

  • Ah! I thought the nCmdShow was a kind of argc. Thanks for the clarification ;D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.