Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS (WIN) Kernel - System.c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Kernel ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Types                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
#ifndef PBT_APMQUERYSUSPEND
#define PBT_APMQUERYSUSPEND 0x0000
#endif

#ifndef PBT_APMRESUMESUSPEND
#define PBT_APMRESUMESUSPEND 0x0007
#endif

#define GWL_STYLE           (-16)
#define GWL_EXSTYLE         (-20)

TgTYPE_STRUCT(TgMS_MINMAXINFO,)
{
    TgMS_POINT ptReserved;
    TgMS_POINT ptMaxSize;
    TgMS_POINT ptMaxPosition;
    TgMS_POINT ptMinTrackSize;
    TgMS_POINT ptMaxTrackSize;
};




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  File Local Functions and Data                                                                                                                                         */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

static TgSINTPTR                            s_uiWindow_Window_Style;
static TgSINTPTR                            s_uiWindow_Window_ExStyle;
static TgSINT32                             s_iWindow_Window_X;
static TgSINT32                             s_iWindow_Window_Y;
static TgSINT32                             s_iWindow_Window_W;
static TgSINT32                             s_iWindow_Window_H;




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgKN_Window_FullScreen ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Window_FullScreen( TgVOID )
{
    C_TgSINT32                          uiStyle = ~(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE | WS_EX_DLGMODALFRAME);
    TgSINT32                            iX, iY, iW, iH;
    TgMS_RECT                           tgRect;
    CP_TgMS_RECT                        ptgRect;

    if (tgKN_Query_FullScreen())
    {
        return;
    };

    /* Store the original window data */
    g_pfnGetWindowRect( g_hWnd, &tgRect );
    s_uiWindow_Window_Style = g_pfnGetWindowLong( g_hWnd, GWL_STYLE );
    s_uiWindow_Window_ExStyle = g_pfnGetWindowLong( g_hWnd, GWL_EXSTYLE );
    s_iWindow_Window_X = tgRect.left;
    s_iWindow_Window_Y = tgRect.top;
    s_iWindow_Window_W = tgRect.right - tgRect.left;
    s_iWindow_Window_H = tgRect.bottom - tgRect.top;

    /* Modify the window's style */
    g_pfnSetWindowLong( g_hWnd, GWL_STYLE, s_uiWindow_Window_Style & ~(WS_BORDER | WS_CAPTION | WS_THICKFRAME) );
    g_pfnSetWindowLong( g_hWnd, GWL_EXSTYLE, s_uiWindow_Window_ExStyle & (uiStyle | WS_EX_TOPMOST) );

    /* Stretch the window to the full size of the screen */
    if (nullptr != (ptgRect = tgSI_Query_Monitor_Virt_Rect( g_bKN_Monitor_Index )))
    {
        iX = ptgRect->left;
        iY = ptgRect->top;
        iW = ptgRect->right - ptgRect->left;
        iH = ptgRect->bottom - ptgRect->top;
    }
    else
    {
        iX = 0;
        iY = 0;
        iW = g_pfnGetSystemMetrics( 0 ); /* SM_CXSCREEN */
        iH = g_pfnGetSystemMetrics( 1 ); /* SM_CYSCREEN */
    };

    g_pfnSetWindowPos( g_hWnd, 0, iX, iY, iW, iH, 0x0004 );

    tgKN_Set_FullScreen( TgTRUE );
    tgKN_ReCalc_Display();
    tgKN_Display_Dimensions_In_Caption();
}


/* ---- tgKN_Window_Window ---------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Window_Window( TgVOID )
{
    if (TgFALSE == tgKN_Query_FullScreen())
    {
        return;
    };

    g_pfnSetWindowLong( g_hWnd, GWL_STYLE, s_uiWindow_Window_Style );
    g_pfnSetWindowLong( g_hWnd, GWL_EXSTYLE, s_uiWindow_Window_ExStyle );
    g_pfnSetWindowPos( g_hWnd, 0, s_iWindow_Window_X, s_iWindow_Window_Y, s_iWindow_Window_W, s_iWindow_Window_H, 0x0004 );

    tgKN_Set_FullScreen( TgFALSE );
    tgKN_ReCalc_Display();
    tgKN_Display_Dimensions_In_Caption();
}


/* ---- tgKN_PM_Base_Window_Update -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSINT64 __stdcall tgKN_PM_Base_Window_Update( TgMS_HWND hWnd, TgUINT32 uMessage, TgUINT64 wParam, TgSINT64 lParam )
{
    static TgBOOL                       bActive = TgTRUE;
    static TgBOOL                       bIn_Size_Move = TgTRUE;

    tgKN_Set_Window_Size_Fixed( TgTRUE );

    switch (uMessage)
    {
        case WM_SYSKEYDOWN:
            switch (wParam)
            {
                case VK_F10:
                    tgKN_Window_Window();
                    break;
                case VK_F11:
                    tgKN_Window_FullScreen();
                    break;
            }
        case WM_KEYDOWN:
        case WM_KEYUP:
        case WM_SYSKEYUP:
            if (g_pfnKN_GUI_Keyboard_Handler)
            {
                g_pfnKN_GUI_Keyboard_Handler( hWnd, uMessage, wParam, lParam );
                return (1);
            };
            break;

        case WM_MOUSEMOVE:
            /* Update Cursor Position */
            /* Fall through for input update */

        case WM_LBUTTONDOWN:
        case WM_LBUTTONUP:
        case WM_LBUTTONDBLCLK:
        case WM_MBUTTONDOWN:
        case WM_MBUTTONUP:
        case WM_MBUTTONDBLCLK:
        case WM_RBUTTONDOWN:
        case WM_RBUTTONUP:
        case WM_RBUTTONDBLCLK:
        case WM_XBUTTONDOWN:
        case WM_XBUTTONUP:
        case WM_XBUTTONDBLCLK:
        case WM_MOUSEWHEEL:
            if (g_pfnKN_GUI_Mouse_Handler)
            {
                g_pfnKN_GUI_Mouse_Handler( hWnd, uMessage, wParam, lParam );
                return (1);
            };
            break;

        case WM_ERASEBKGND:
            if (tgKN_Query_Clear_Display())
            {
                TgMS_HDC hdc = g_pfnGetDC( g_hWnd );
                /* g_pfnPatBlt( hdc, 0, 0, tgKN_Query_Display_Width(), tgKN_Query_Display_Height(), 0x00000042 ); */
                g_pfnReleaseDC( g_hWnd, hdc );
            };
            break;

        case WM_SIZE:
            if (SIZE_MINIMIZED == wParam)
            {
                tgKN_Set_Minimized( TgTRUE );
                tgKN_Set_Maximized( TgFALSE );
            }
            else
            {
                TgMS_RECT                           wRect;

                g_pfnGetClientRect( g_hWnd, &wRect );

                if (0 == wRect.top && 0 == wRect.bottom)
                {
                    /* Empty on Purpose */
                }
                else if (SIZE_MAXIMIZED == wParam)
                {
                    tgKN_Set_Minimized( TgFALSE );
                    tgKN_Set_Maximized( TgTRUE );

                    tgKN_ReCalc_Display();
                    if (nullptr != g_pfnDevice_Change_Check)
                    {
                        g_pfnDevice_Change_Check( g_bKN_Monitor_Index, g_iKN_Display_W, g_iKN_Display_H );
                    };
                }
                else if (SIZE_RESTORED == wParam)
                {
                    if (tgKN_Query_Maximized())
                    {
                        tgKN_Set_Maximized( TgFALSE );

                        tgKN_ReCalc_Display();
                        if (nullptr != g_pfnDevice_Change_Check)
                        {
                            g_pfnDevice_Change_Check( g_bKN_Monitor_Index, g_iKN_Display_W, g_iKN_Display_H );
                        };
                    }
                    else if (tgKN_Query_Minimized())
                    {
                        tgKN_Set_Minimized( TgFALSE );

                        tgKN_ReCalc_Display();
                        if (nullptr != g_pfnDevice_Change_Check)
                        {
                            g_pfnDevice_Change_Check( g_bKN_Monitor_Index, g_iKN_Display_W, g_iKN_Display_H );
                        };
                    }
                    else if (bIn_Size_Move)
                    {

                    }
                    else
                    {
                        tgKN_ReCalc_Display();
                        if (nullptr != g_pfnDevice_Change_Check)
                        {
                            g_pfnDevice_Change_Check( g_bKN_Monitor_Index, g_iKN_Display_W, g_iKN_Display_H );
                        };
                    };
                };
            };
            break;

        case WM_MOVING:
        {
            C_TgBOOL                            bMonitor_Landscape = tgKN_Query_Monitor_Landscape();
            C_TgSINT32                          iMonitor_Index = tgKN_Query_Monitor_Index();
            P_TgMS_RECT                         pRect = (P_TgMS_RECT)lParam;
            TgSINT32                            iW, iH;

            tgKN_ReCalc_Display();

            if (iMonitor_Index == tgKN_Query_Monitor_Index())
            {
                break;
            };

            tgKN_Display_Dimensions_In_Caption();

            if (bMonitor_Landscape != tgKN_Query_Monitor_Landscape())
            {
                iW = g_iKN_Display_H;
                iH = g_iKN_Display_W;
            }
            else
            {
                iW = g_iKN_Display_W;
                iH = g_iKN_Display_H;
            };

            if (g_pfnQuery_Render_Select_Rect)
                g_pfnQuery_Render_Select_Rect( &iW, &iH, tgKN_Query_Monitor_Index(), tgKN_Query_Monitor_Landscape() );

            pRect->right = pRect->left + iW + tgKN_Query_Window_PadX();
            pRect->bottom = pRect->top + iH + tgKN_Query_Window_PadY();

            g_pfnPostMessage( g_hWnd, WM_ERASEBKGND, 0, 0 );
        };
        break;

        case WM_SIZING:
            if (tgKN_Query_Window_Size_Fixed() && g_pfnQuery_Render_Select_Rect)
            {
                P_TgMS_RECT                         pRect = (P_TgMS_RECT)lParam;
                TgSINT32                            iW = pRect->right - pRect->left - tgKN_Query_Window_PadX();
                TgSINT32                            iH = pRect->bottom - pRect->top - tgKN_Query_Window_PadY();

                /* The way the selector works is width then height - to hack in some sizing on height only swap it to a width change */
                if (WMSZ_TOP == wParam || WMSZ_BOTTOM == wParam)
                {
                    iW = tgKN_Query_Display_Width() + iH - tgKN_Query_Display_Height();
                };

                g_pfnQuery_Render_Select_Rect( &iW, &iH, tgKN_Query_Monitor_Index(), tgKN_Query_Monitor_Landscape() );

                switch (wParam)
                {
                    case WMSZ_BOTTOMLEFT:
                    case WMSZ_LEFT:
                        pRect->left = pRect->right - iW - tgKN_Query_Window_PadX();
                        pRect->bottom = pRect->top + iH + tgKN_Query_Window_PadY();
                        break;
                    case WMSZ_BOTTOMRIGHT:
                    case WMSZ_BOTTOM:
                    case WMSZ_RIGHT:
                        pRect->right = pRect->left + iW + tgKN_Query_Window_PadX();
                        pRect->bottom = pRect->top + iH + tgKN_Query_Window_PadY();
                        break;
                    case WMSZ_TOPLEFT:
                        pRect->left = pRect->right - iW - tgKN_Query_Window_PadX();
                        pRect->top = pRect->bottom - iH - tgKN_Query_Window_PadY();
                        break;
                    case WMSZ_TOPRIGHT:
                    case WMSZ_TOP:
                        pRect->right = pRect->left + iW + tgKN_Query_Window_PadX();
                        pRect->top = pRect->bottom - iH - tgKN_Query_Window_PadY();
                        break;
                    default:
                        __assume(0);
                        break;
                };

                if (tgKN_Query_Clear_Display())
                {
                    TgMS_HDC hdc = g_pfnGetDC( g_hWnd );
                    /* g_pfnPatBlt( hdc, 0, 0, iW, iH, 0x00000042 ); */
                    g_pfnReleaseDC( g_hWnd, hdc );
                };

                tgKN_Display_Dimensions_In_Caption();
            };
            break;

        case WM_GETMINMAXINFO:
            if (tgKN_Query_Window_Size_Lock())
            {
                TgSINT32                            iW = 0, iH = 0;

                if (g_pfnQuery_Render_Display_Rect)
                {
                    g_pfnQuery_Render_Display_Rect( &iW, &iH, tgKN_Query_Monitor_Index(), tgKN_Query_Monitor_Landscape() );
                };

                ((TgMS_MINMAXINFO*)lParam)->ptMinTrackSize.m_x = iW + tgKN_Query_Window_PadX();
                ((TgMS_MINMAXINFO*)lParam)->ptMinTrackSize.m_y = iH + tgKN_Query_Window_PadY();
                ((TgMS_MINMAXINFO*)lParam)->ptMaxTrackSize.m_x = iW + tgKN_Query_Window_PadX();
                ((TgMS_MINMAXINFO*)lParam)->ptMaxTrackSize.m_y = iH + tgKN_Query_Window_PadY();
            }
            else if (tgKN_Query_Window_Size_Fixed())
            {
                TgSINT32                            iW = 0, iH = 0;

                if (g_pfnQuery_Render_Display_Min_Rect)
                {
                    g_pfnQuery_Render_Display_Min_Rect( &iW, &iH, tgKN_Query_Monitor_Index(), tgKN_Query_Monitor_Landscape() );
                }
                else
                {
                    iW = 320;
                    iH = 0;
                };

                ((TgMS_MINMAXINFO*)lParam)->ptMinTrackSize.m_x = iW + tgKN_Query_Window_PadX();
                ((TgMS_MINMAXINFO*)lParam)->ptMinTrackSize.m_y = iH + tgKN_Query_Window_PadY();

                if (g_pfnQuery_Render_Display_Max_Rect)
                {
                    g_pfnQuery_Render_Display_Max_Rect( &iW, &iH, tgKN_Query_Monitor_Index(), tgKN_Query_Monitor_Landscape() );
                }
                else
                {
                    iW = 320;
                    iH = 0;
                };

                ((TgMS_MINMAXINFO*)lParam)->ptMaxTrackSize.m_x = iW + tgKN_Query_Window_PadX();
                ((TgMS_MINMAXINFO*)lParam)->ptMaxTrackSize.m_y = iH + tgKN_Query_Window_PadY();
            };

            break;

        case WM_ENTERSIZEMOVE:
            bIn_Size_Move = TgTRUE;
            break;

        case WM_EXITSIZEMOVE:
            bIn_Size_Move = TgFALSE;
            tgKN_ReCalc_Display();
            if (nullptr != g_pfnDevice_Change_Check)
            {
                g_pfnDevice_Change_Check( g_bKN_Monitor_Index, g_iKN_Display_W, g_iKN_Display_H );
            };
            tgKN_Display_Dimensions_In_Caption();
            break;

        case WM_ACTIVATEAPP:
            /* #TODO: Handle Activate App message from WinOS */
            if (TgFALSE != wParam && TgFALSE == bActive)
            {

            }
            else if (TgFALSE == wParam && TgFALSE != bActive)
            {

            };
            break;

        case WM_MOUSEACTIVATE:
            return MA_ACTIVATE;

        case WM_POWERBROADCAST:
            switch (wParam)
            {
                case PBT_APMQUERYSUSPEND:
                    return 0x424D5144;
                case PBT_APMRESUMESUSPEND:
                    return (TgTRUE);
            }
            break;

        case WM_SYSCOMMAND:
            switch (wParam & 0xFFF0)
            {
                case SC_NEXTWINDOW:
                case SC_PREVWINDOW:
                case SC_TASKLIST:
                case SC_HOTKEY:
                case SC_MOVE:
                case SC_SIZE:
                case SC_MAXIMIZE:
                case SC_KEYMENU:
                    if (tgKN_Query_FullScreen())
                    {
                        return (0);
                    };
                    break;

                case SC_SCREENSAVE:
                case SC_MONITORPOWER:
                    return (1);
            };
            break;

        case WM_DISPLAYCHANGE:
            /* #TODO: Handle Display Change message from WinOS */
            break;

        case WM_KILLFOCUS:
            /* #TODO: Handle Kill Focus message from WinOS */
            break;

        case WM_SETFOCUS:
            /* #TODO: Handle Set Focus message from WinOS */
            break;

        case WM_PAINT:
            /* #TODO: Handle Paint message from WinOS */
            break;

        case WM_SETCURSOR:
            if (0 == (lParam & 0xFFFF))
                break;
            g_pfnSetCursor( nullptr );
            break;

        case WM_DESTROY:
        case WM_CLOSE:
            g_pfnPostMessage( g_hWnd, WM_QUIT, 0, 0 );
            return (0);

        default:
            break;
    }

    return (g_pfnDefWindowProc( hWnd, uMessage, wParam, lParam ));
}




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Private Functions                                                                                                                                                     */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgKN_Set_Monitor_Index ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Set_Monitor_Index( C_TgSINT32 iIndex )
{
    g_bKN_Monitor_Index = iIndex;
}


/* ---- tgKN_Set_Monitor_Landscape -------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Set_Monitor_Landscape( C_TgBOOL bLandscape )
{
    g_bKN_Monitor_Portrait = !bLandscape;
}


/* ---- tgKN_Set_Window_PadX -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Set_Window_PadX( C_TgSINT32 iPadX )
{
    g_iKN_Window_PadX = iPadX;
}


/* ---- tgKN_Set_Window_PadY -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Set_Window_PadY( C_TgSINT32 iPadY )
{
    g_iKN_Window_PadY = iPadY;
}


/* ---- tgKN_Query_Monitor_Index ---------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSINT32 tgKN_Query_Monitor_Index( TgVOID )
{
    return (g_bKN_Monitor_Index);
}


/* ---- tgKN_Query_Monitor_Landscape ------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgBOOL tgKN_Query_Monitor_Landscape( TgVOID )
{
    return (!g_bKN_Monitor_Portrait);
}


/* ---- tgKN_Query_Window_PadX ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSINT32 tgKN_Query_Window_PadX( TgVOID )
{
    return (g_iKN_Window_PadX);
}


/* ---- tgKN_Query_Window_PadY ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgSINT32 tgKN_Query_Window_PadY( TgVOID )
{
    return (g_iKN_Window_PadY);
}


/* ---- tgKN_ReCalc_Display --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_ReCalc_Display( TgVOID )
{
    TgMS_RECT                           tgRect;
    TgMS_HMONITOR                       hMonitor;
    CP_TgMS_RECT                        ptgRect;
    TgSINT32                            iMonitor = 0;

    /* Get the current window rect */
    g_pfnGetWindowRect( g_hWnd, &tgRect );
    tgKN_Set_Window_PosX( tgRect.left );
    tgKN_Set_Window_PosY( tgRect.top );
    tgKN_Set_Window_Width( tgRect.right - tgRect.left );
    tgKN_Set_Window_Height( tgRect.bottom - tgRect.top );

    /*Set the current monitor index */
    hMonitor = g_pfnMonitorFromRect( &tgRect, 0x00000002 );
    iMonitor = tgSI_Get_Monitor_Index_From_Handle( hMonitor );
    tgKN_Set_Monitor_Index( iMonitor );
    if (nullptr != (ptgRect = tgSI_Query_Monitor_Work_Rect( iMonitor )))
    {
        tgKN_Set_Monitor_Landscape( ptgRect->right - ptgRect->left >= ptgRect->bottom - ptgRect->top );
    };

    /* Get the current display (client) rect */
    g_pfnGetClientRect( g_hWnd, &tgRect );
    tgKN_Set_Display_Width( tgRect.right );
    tgKN_Set_Display_Height( tgRect.bottom );
}


/* ---- tgKN_Display_Dimensions_In_Caption ------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgKN_Display_Dimensions_In_Caption( TgVOID )
{
    TgCHAR                              szBuffer[KTgKN_MAX_TITLE + 128];
    TgCHAR                              szUINT[128];
    TgMS_RECT                           wRect;
    TgSINT32                            iW, iH;

    g_pfnGetClientRect( g_hWnd, &wRect );

    iW = wRect.right - wRect.left;
    iH = wRect.bottom - wRect.top;

    tgSZ_Copy( szBuffer, KTgKN_MAX_TITLE + 128, tgKN_Query_Exe_Title() );
    tgSZ_Append( szBuffer, KTgKN_MAX_TITLE + 128, tgKN_Query_Monitor_Landscape() ? TgT(" Landscape [") : TgT(" Portrait [") );
    tgSZ_From_S32( szUINT, 128, iW );
    tgSZ_Append( szBuffer, KTgKN_MAX_TITLE + 128, szUINT );
    tgSZ_Append( szBuffer, KTgKN_MAX_TITLE + 128, TgTEXT( " x " ) );
    tgSZ_From_S32( szUINT, 128, iH );
    tgSZ_Append( szBuffer, KTgKN_MAX_TITLE + 128, szUINT );
    tgSZ_Append( szBuffer, KTgKN_MAX_TITLE + 128, TgTEXT("]") );

    g_pfnSetWindowText( g_hWnd, szBuffer );
}