Message box: different between WM_CREATE and WM_NCCREATE?

I tried to create a button (child window) inside the WM_NCCREATE message, and its position seemed to be created taking into account the coordinates of the screen, not the coordinates of the client. At first I thought that WM_CREATE and WM_NCCREATE provide us with the same window handle, but this seems to be wrong. So can anyone explain the differences between WM_CREATE and WM_NCCREATE messages? Also, what are the differences between the window handle in WM_CREATE and WM_NCCREATE?

+8
c ++ windows
source share
4 answers

In MSDN:

WM_NCCREATE:

Sent before WM_CREATE message when a window is first created.

Return value:

If the application processes this message, it should return TRUE to continue creating the window. If the application returns FALSE, CreateWindow or the CreateWindowEx function will return a NULL handle.

WM_CREATE:

Dispatched when an application requests to create a window by calling the CreateWindowEx or CreateWindow function. (A message is sent before the function returns.) Window procedure for a new window is a message after the window is created, but before the window becomes visible.

Return value:

If the application processes this message, it should return zero in continue window creation. If the application returns -1, the window is destroyed, and the CreateWindowEx or CreateWindow function returns a NULL handle.

+4
source share

WM_NC messages are for the non-client area, that is, the border of the window and the header. For your needs, you are not interested in these non-client messages.

+8
source share

WM_NCCREATE is an example of an arms race. This seems to have been introduced in order to satisfy the need for DefWindowProc (or the base window handler in a regular subclass) to do some initialization, perhaps before WM_CREATE is processed (or to make up for the fact that many window implementations process WM_CREATE directly and return TRUE, not pass it to DefWindowProc).

WM_NCCREATE is a message that you must reply to if you are executing a standard window procedure that must initialize before the user window handler processes the WM_CREATE message. WM_NCCREATE MUST also be passed to the corresponding DefWindowProc, perhaps before you do your own processing, as some aspects of the lower level of the window are clearly in an uninitialized state before WM_NCCREATE is processed.

If an attempt to guarantee processing at a glance is not your consideration, then WM_CREATE is the appropriate place to initialize your window: all other layers that can have jist-in-time-time settings via WM_NCCREATE have been completed and the window is in a stable state with respect to to things like its odd numbers, screen position, etc.

Or: If you do not know why you should use WM_NCCREATE through WM_CREATE, you should not use WM_NCCREATE.

+8
source share

Not sure why you are creating a button in WM_NCCREATE - because the window on which the button will be displayed does not exist yet, therefore (as I assume), in the skin codes. WM_NCCREATE is sent to you when the "non-client" areas of the window are created (non-client areas, such as window border, title bar, etc.).

Do you need to place a button on a non-client area? If the answer is no, then why not create a button inside WM_CREATE.

If you need to create a button for any reason inside WM_NCCREATE, then why not save the window handle returned by calling Createwindow (). Then, inside your WM_CREATE message handler, grab this button window handle and make "MoveWindow (...)" on it using the application window, in which you should now have coordinates when you are in the WM_CREATE message handler.

I believe that one of the parameters that you can pass to the CreateWindow (...) call to create the button allows you to specify the β€œSW _...” flag, for example, β€œSW_HIDE” if the memory is correct for me. So create, but don’t show the button in processing WM_NCCREATE if you need, and then when WM_CREATE comes quickly after that, do "MoveWindow (... window coordinates ... SW_SHOW, ......), etc. p. for positioning and creating a visible button.

-one
source share

All Articles