I am working on an MFC application and I am adding some error checking with the use of MessageBox
which has documentation found here.
int MessageBox(
[in, optional] HWND hWnd,
[in, optional] LPCTSTR lpText,
[in, optional] LPCTSTR lpCaption,
[in] UINT uType
);
Note: The utype parameter is a list of styles separated with |
Above is MessageBox
's implementation. My question is about the HWND parameter. When writing my call to MessageBox
, Visual Studio 2017 Professional did not ask for the HWND parameter. At first, I thought it was because it is optional, but the other two optional LPCTSTR
parameters were not as optional as they seemed, and required me to put at least ""
to satisfy them.
Currently, my call to MessageBox
only uses the last three parameters. My call is:
int BoxReturnVal = MessageBox("foo1", "foo2", MB_OK | MB_ICON);
.
My question is why is the HWND
parameter not asked for while writing the call to the function and do I need to worry about it all?
Thank you in advance ! :D
CodePudding user response:
You are not calling the MessageBox()
function that you think you are.
You are looking at the MessageBox()
function in the Win32 API, but MFC has its own MessageBox()
method in the CWnd
class. The latter one, which does not have an HWND
parameter, is the one you are actually calling.