#pragma once

#include <windows.h>
#include "kpi_decoder.h"
#include "kpi_impl.h"

class KbDShowDecoderBase :  public KbKpiUnknownImpl<IKpiDecoder>
{
private:
    static bool s_bMaximized;//最大化されたとき true
public:
    struct KMP_STATUS {//本体の再生位置を取得するための構造体(非公式)
        DWORD dwStructSize;//=sizeof(KMP_STATUS) //プラグイン側で設定
        DWORD dwAccepted;  //本体が受け入れてば 1//本体側で設定(作成直後にプラグイン側で 0 にする)
        DWORD dwPosition;  //再生位置(ms)        //本体側で設定
        DWORD dwStatus;    //KPI_STATUS_STOP/KPI_STATUS_PLAYING/KPI_STATIS_PAUSE(kpi_player.h)//本体側で設定
    };
protected:
    struct{
        int    nCommand;
        WPARAM wParam;
        LPARAM lParam;
    }m_Command;
    HANDLE      m_hFileMap;  //KMP_STATUS を得るためのファイルマップハンドル
    KMP_STATUS* m_pStatus;
    KPI_MEDIAINFO        m_MediaInfo; 
    IKpiFile            *m_pFile;
    IKpiConfig          *m_pConfig;
    HWND                 m_hWnd;
    HWND                 m_hWndDraw;//描画するウィンドウ
    wchar_t              m_szClassName[128];
    HANDLE               m_hThread;
    DWORD                m_dwThreadId;
    HANDLE               m_hEvent;
    HANDLE               m_hEventDone;
    int                  m_rx;
    int                  m_ry;
    int                  m_nStopMode;
    int                  m_nStatus;
    UINT64               m_qwCurSample;
    int                  m_nRestoredLeft;
    int                  m_nRestoredTop;
    int                  m_nRestoredWidth;
    int                  m_nRestoredHeight;
    bool                 m_bRestoredTopMost;
    bool                 m_bFullScreen;
    void __fastcall RegisterWndClass(void);
    void __fastcall UnregisterWndClass(void);
    void __fastcall UpdateWindowPosition(void);
    void __fastcall SendCommand(int nCommand, WPARAM wParam, LPARAM lParam);
    void __fastcall CreateKmpStatus(void);
    void __fastcall CreateThread(void);
    void __fastcall CreateVideoWindow(int X, int Y, int nWidth, int nHeight);
    void  WINAPI GetWindowPosition(int* pLeft, int* pTop,
        int* pVideoWidth, int* pVideoHeight);
    static unsigned __stdcall ThreadProc(void* pvParam);
    static LRESULT CALLBACK VideoWindowProc(HWND hWnd,
        UINT message,
        WPARAM wParam, LPARAM lParam);
    virtual void __stdcall ThreadProc(void) = 0;
    virtual LRESULT CALLBACK VideoWindowProcInternal(HWND hWnd,
        UINT message,
        WPARAM wParam, LPARAM lParam);
    void __fastcall SetFullScreen(bool bFullScreen);
public:
    KbDShowDecoderBase(void);
    ~KbDShowDecoderBase(void);
};
