#include "pch.hpp"
//===========================================================================//
// File:	 WindowsDebugging.cpp											 //
// Project:  GameOS					                                         //
// Contents: Debug Functions for Windows									 //
//---------------------------------------------------------------------------//
// Date      Who    Modification                                             //
// 01/24/98  AG     Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 1999 Microsoft Corp.						                 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//
#include "Globals.hpp"
#include "ErrorHandler.hpp"
#include "WinProc.hpp"
#include "Globals.hpp"
#include "Windows.hpp"




char* GetWM_WINDOWPOSCHANGEFlags( LPWINDOWPOS wp )
{
	static char Buffer[128];
	Buffer[0]=0;

	if( (wp->flags&SWP_NOMOVE)==0 )
		sprintf(Buffer, "Top Left = %d,%d ",wp->x,wp->y );
	if( (wp->flags&SWP_NOSIZE)==0 )
		sprintf(Buffer, "Client Size = %d,%d ",wp->cx,wp->cy );
	if( wp->flags & SWP_DRAWFRAME )
		strcat(Buffer, "DRAWFRAME ");
	if( wp->flags & SWP_FRAMECHANGED )
		strcat(Buffer, "FRAMECHANGED ");
	if( wp->flags & SWP_HIDEWINDOW )
		strcat(Buffer, "HIDEWINDOW ");
	if( wp->flags & SWP_NOACTIVATE )
		strcat(Buffer, "NOACTIVATE ");
	if( wp->flags & SWP_NOCOPYBITS )
		strcat(Buffer, "NOCOPYBITS ");
	if( wp->flags & SWP_NOMOVE )
		strcat(Buffer, "NOMOVE ");
	if( wp->flags & SWP_NOOWNERZORDER )
		strcat(Buffer, "NOOWNERZORDER ");
	if( wp->flags & SWP_NOREDRAW )
		strcat(Buffer, "NOREDRAW ");
	if( wp->flags & SWP_NOSENDCHANGING )
		strcat(Buffer, "NOSENDCHANGING ");
	if( wp->flags & SWP_NOSIZE )
		strcat(Buffer, "NOSIZE ");
	if( wp->flags & SWP_NOZORDER )
		strcat(Buffer, "NOZORDER ");
	if( wp->flags & SWP_SHOWWINDOW )
		strcat(Buffer, "SHOWWINDOW ");
	return Buffer;
}



//
// Return a string describing the WM_SIZE flags
//
char* GetWM_SIZEFlags( DWORD Flags )
{
	switch( Flags )
	{
	case SIZE_MAXHIDE:
		return "MAXHIDE";
	case SIZE_MAXIMIZED:
		return "MAXIMIZED";
	case SIZE_MAXSHOW:
		return "MAXSHOW";
	case SIZE_MINIMIZED:
		return "MINIMIZED";
	case SIZE_RESTORED:
		return "RESTORED";
	default:
		return "Unknown";
	}
}

//
// Return a string describing the WM_SYSCOMMAND flags
//
char* GetWM_SYSCOMMANDFlags( DWORD Flags )
{
	switch( Flags )
	{
	case SC_CLOSE:
		return "CLOSE";
	case SC_CONTEXTHELP:
		return "CONTEXTHELP";
	case SC_DEFAULT:
		return "DEFAULT";
	case SC_HOTKEY:
		return "HOTKEY";
	case SC_HSCROLL:
		return "HSCROLL";
	case SC_KEYMENU:
		return "KEYMENU";
	case SC_MAXIMIZE:
		return "MAXIMIZE";
	case SC_MINIMIZE:
		return "MINIMIZE";
	case SC_MONITORPOWER:
		return "MONITORPOWER";
	case SC_MOUSEMENU:
		return "MOUSEMENU";
	case SC_MOVE:
		return "MOVE";
	case SC_NEXTWINDOW:
		return "NEXTWINDOW";
	case SC_PREVWINDOW:
		return "PREVWINDOW";
	case SC_RESTORE:
		return "RESTORE";
	case SC_SIZE:
		return "SIZE";
	case SC_SCREENSAVE:
		return "SCREENSAVE";
	case SC_TASKLIST:
		return "TASKLIST";
	case SC_VSCROLL:
		return "VSCROLL";
	default:
		{
			static char Buffer[30];
			sprintf( Buffer, "Unknown 0x%x",Flags );
			return Buffer;
		}
	}
}



//
// Return a string describing the windows message
//
// These are found in <WinUser.h> in the VC include directory
//
char* GetWindowsMessage( DWORD uMsg,WPARAM wParam,LPARAM lParam )
{
	if( uMsg==WM_NCHITTEST ||
		uMsg==WM_SETCURSOR ||
		uMsg==WM_MOUSEMOVE )
		return 0;

	static char Buffer[256];
	switch(uMsg)
	{
//
// Messages that are too often to debug!
//
	case WM_ENTERIDLE:
	case WM_NCMOUSEMOVE:
	case WM_NCLBUTTONDOWN:
	case WM_NCLBUTTONUP:
		return 0;

	case WM_CANCELMODE:
		return "WM_CANCELMODE";
	case 0x20a:									//WM_MOUSEWHEEL:
		return "WM_MOUSEWHEEL";
	case WM_PAINT:
		return "WM_PAINT";
	case WM_ENABLE:
		return "WM_ENABLE";

	case WM_ERASEBKGND:
		return "WM_ERASEBKGND";
	case WM_KEYDOWN:
		sprintf(Buffer, "WM_KEYDOWN w=0x%4.4x l=0x%4.4x",wParam,lParam );
		break;
	case WM_KEYUP:
		sprintf(Buffer, "WM_KEYUP 0x%4.4x",wParam );
		break;
	case WM_SIZE:
		sprintf(Buffer, "WM_SIZE %dx%d %s",LOWORD(lParam),HIWORD(lParam),GetWM_SIZEFlags(wParam) );
		break;
	case WM_SYSCHAR:
		sprintf(Buffer, "WM_SYSCHAR 0x%4.4x",wParam );
		break;
	case WM_SYSKEYDOWN:
		sprintf(Buffer, "WM_SYSKEYDOWN 0x%4.4x",wParam );
		break;
	case WM_SYSKEYUP:
		sprintf(Buffer, "WM_SYSKEYUP 0x%4.4x",wParam );
		break;
	case WM_SYSCOMMAND:
		sprintf(Buffer, "WM_SYSCOMMAND %s",GetWM_SYSCOMMANDFlags(wParam) );
		break;
	case WM_DISPLAYCHANGE:
		sprintf(Buffer, "WM_DISPLAYCHANGE %dx%d %dbpp",LOWORD(lParam),HIWORD(lParam),wParam );
		break;
	case WM_SYSCOLORCHANGE:
		return "WM_SYSCOLORCHANGE";
	case WM_KILLFOCUS:
		return "WM_KILLFOCUS";
	case WM_COMMAND:
		sprintf(Buffer, "WM_COMMAND 0x%4.4x,0x%x",wParam,lParam );
		break;
	case WM_CHAR:
		if( wParam<32 || wParam>127 )
			sprintf(Buffer, "WM_CHAR code=%d",wParam );
		else
			sprintf(Buffer, "WM_CHAR \"%c\"",wParam );
		break;
	case WM_DESTROY:
		return "WM_DESTROY";
	case WM_CLOSE:
		return "WM_CLOSE";
	case WM_CREATE:
		return "WM_CREATE";
	case WM_WINDOWPOSCHANGING:
		sprintf(Buffer, "WM_WINDOWPOSCHANGING %s",GetWM_WINDOWPOSCHANGEFlags((LPWINDOWPOS)lParam) );
		break;
	case WM_SIZING:
		return "WM_SIZING";
	case WM_QUIT:
		return "WM_QUIT";
	case WM_MOVE:
		sprintf(Buffer, "WM_MOVE %dx%d",LOWORD(lParam),HIWORD(lParam) );
		break;
	case WM_ACTIVATEAPP:
		sprintf(Buffer, "WM_ACTIVATEAPP %s",LOWORD(wParam) ? "Activated" : "Deactivated" );
		break;
	case WM_TIMER:
		return "WM_TIMER";
	case WM_ACTIVATE:
		sprintf(Buffer, "WM_ACTIVATE %s",LOWORD(wParam)==WA_INACTIVE ? "Deactivated" : "Activated" );
		break;
	case WM_SETFOCUS:
		return "WM_SETFOCUS";
	case WM_PALETTECHANGED:
		return "WM_PALETTECHANGED";
	case WM_QUERYNEWPALETTE:
		return "WM_QUERYNEWPALETTE";
	case WM_MOVING:
		return "WM_MOVING";
//
// Message we do not handle, but can occur
//
	case WM_NCCREATE:
		return "WM_NCCREATE";
	case WM_NCCALCSIZE:
		return "WM_NCCALCSIZE";
	case WM_WINDOWPOSCHANGED:
		sprintf(Buffer, "WM_WINDOWPOSCHANGED %s",GetWM_WINDOWPOSCHANGEFlags((LPWINDOWPOS)lParam) );
		break;
	case WM_SHOWWINDOW:
		sprintf(Buffer, "WM_SHOWWINDOW %s",wParam==0 ? "Hide" : "Show" );
		break;
	case WM_NCACTIVATE:
		return "WM_NCACTIVATE";
	case WM_NCPAINT:
		return "WM_NCPAINT";
	case WM_NCDESTROY:
		return "WM_NCDESTROY";
	case WM_STYLECHANGING:
		return "WM_STYLECHANGING";
	case WM_STYLECHANGED:
		return "WM_STYLECHANGED";
	case WM_GETTEXT:
		return "WM_GETTEXT";
	case WM_GETMINMAXINFO:
		return "WM_GETMINMAXINFO";
	case WM_MENUSELECT:
		return "WM_MENUSELECT";
	case WM_INITMENU:
		return "WM_INITMENU";
	case WM_INITMENUPOPUP:
		return "WM_INITMENUPOPUP";
	case WM_CAPTURECHANGED:
		return "WM_CAPTURECHANGED";
	case WM_ENTERMENULOOP:
		return "WM_ENTERMENULOOP";
	case WM_EXITMENULOOP:
		return "WM_EXITMENULOOP";
	case WM_LBUTTONDOWN:
		return "WM_LBUTTONDOWN";
	case WM_LBUTTONUP:
		return "WM_LBUTTONUP";
	case WM_RBUTTONDOWN:
		return "WM_RBUTTONDOWN";
	case WM_RBUTTONUP:
		return "WM_RBUTTONUP";
	case WM_CONTEXTMENU:
		return "WM_CONTEXTMENU";
	case WM_ENTERSIZEMOVE:
		return "WM_ENTERSIZEMOVE";
	case WM_EXITSIZEMOVE:
		return "WM_EXITSIZEMOVE";
	case WM_POWERBROADCAST:
		return "WM_POWERBROADCAST";
	case WM_POWER:
		return "WM_POWER";
	case WM_SYNCPAINT:
		return "WM_SYNCPAINT";
	case WM_DEVICECHANGE:
		return "WM_DEVICECHANGE";
//
// If unknown message, display hex number
//
	default:
		sprintf(Buffer, "WM_%x",uMsg );
		break;
	}
	return Buffer;
}





