I'm learning the Windows API and I have written just a plain program which opens up with a menu on the top, I have created ther menu so that there is a tools button that expands to a button which brings up a message box which then tells you the program directory. This is fine apart from when you close this message box, the whole program quits. This is not what I want. Is there some special piece of code I'm missing or is it my code thats bad I've tried substituting the hwnd in MessageBox() for NULL/0 but it still does the smae thing:
The windows procedure,
Code:
LRESULT CALLBACK WndProc( HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
switch( Msg )
{
case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case ID_FILE_EXIT:
PostMessage( hwnd, WM_CLOSE, 0, 0 );
break;
case ID_TOOLS_PROGRAMDIRECTORY:
{
HINSTANCE hInstance = GetModuleHandle( NULL );
char szFileName[MAX_PATH];
GetModuleFileName( hInstance, szFileName, MAX_PATH );
MessageBox( hwnd, szFileName, "The Directory Is:", MB_OK );
}
break;
}
case WM_CLOSE:
DestroyWindow( hwnd );
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hwnd, Msg, wParam, lParam );
}
return 0;
}