📄 displaywindow.cpp
字号:
/*
* DisplayWindow.cpp
*
* Create a window
*
* DirectDraw YUV420P project
*
* Copyright (c) 2004-2005 for Cyansoft Studio.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Log: DisplayWindow.cpp,v $
* Revision 1.1 2005/01/17 13:43:00 jin.bai
* Initial revision
*
*
*/
#include <windows.h>
#include <ddraw.h>
#include "DisplayWindow.h"
#define DISPLAY_CLASS_NAME TEXT("Display Window Class")
#define DD_OVERLAY_COLORKEY_16BPP 0x00000001 // 16 bpp only
#define DD_OVERLAY_COLORKEY_32BPP 0x0000000F // 24 & 32 bpp
#define DD_OVERLAY_COLORREF 0x000F0000 // 32, 24, and 16 bpp
//
// DisplayWindow class
//
DisplayWindow::DisplayWindow() : m_hWnd (NULL), m_lpszClsName (DISPLAY_CLASS_NAME)
{
}
DisplayWindow::~DisplayWindow()
{
Close();
}
BOOL DisplayWindow::Create(LPCTSTR lpszWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hwndParent/* = NULL */,
BOOL bOverlay/* = FALSE */,
LPDIRECTDRAWSURFACE lpPrimary/* = NULL */,
LPDIRECTDRAWCLIPPER lpClipper/* = NULL */)
{
WNDPROC lpfnWndProc = DefWindowProc;
if (bOverlay)
{
if (!lpPrimary || !lpClipper) return FALSE;
lpfnWndProc = WindowProc;
m_lpPrimary = lpPrimary;
m_lpClipper = lpClipper;
}
// Register class
if (!RegWindowClass(m_lpszClsName, lpfnWndProc))
{
if (::GetLastError() != ERROR_CLASS_ALREADY_EXISTS)
{
return FALSE;
}
}
// Create window
m_hWnd = CreateWindow(m_lpszClsName,
lpszWindowName,
dwStyle,
x,
y,
nWidth,
nHeight,
hwndParent,
NULL, NULL, this);
return m_hWnd != NULL;
}
HWND DisplayWindow::GetHwnd()
{
return m_hWnd;
}
BOOL DisplayWindow::RegWindowClass(LPCTSTR lpszClsName, WNDPROC lpfnWndProc)
{
WNDCLASS WndCls;
memset(&WndCls, 0, sizeof (WNDCLASS));
WndCls.lpszClassName = lpszClsName;
WndCls.lpfnWndProc = lpfnWndProc;
WndCls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
return ::RegisterClass(&WndCls);
}
LRESULT DisplayWindow::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HRESULT ddrval;// Return value from DirectDraw API calls
static DisplayWindow *s_pDisplay = NULL;
switch (uMsg)
{
case WM_CREATE:
LPCREATESTRUCT lpCS;
lpCS = (LPCREATESTRUCT) lParam;
if (!lpCS) return -1;
s_pDisplay = (DisplayWindow *) lpCS->lpCreateParams;
if (!s_pDisplay) return -1;
return 0;
case WM_PAINT:
/****************************************************************/
/* Attach the clipper to the primary surface for this operation */
/****************************************************************/
ddrval = IDirectDrawSurface_SetClipper(s_pDisplay->m_lpPrimary, s_pDisplay->m_lpClipper);
if(ddrval != DD_OK) break;
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hWnd, &ps);
/* Fill the client area with colour key */
POINT ptClient;
ptClient.x = ps.rcPaint.left;
ptClient.y = ps.rcPaint.top;
ClientToScreen(hWnd, &ptClient);
RECT rectBlt;
rectBlt.left = ptClient.x;
rectBlt.top = ptClient.y;
ptClient.x = ps.rcPaint.right;
ptClient.y = ps.rcPaint.bottom;
ClientToScreen(hWnd, &ptClient);
rectBlt.right = ptClient.x;
rectBlt.bottom = ptClient.y;
DDBLTFX ddbfx;
ddbfx.dwSize = sizeof(DDBLTFX);
ddbfx.dwFillColor = DD_OVERLAY_COLORKEY_16BPP;
IDirectDrawSurface_Blt (s_pDisplay->m_lpPrimary,
&rectBlt,
NULL,
&rectBlt,
DDBLT_COLORFILL | DDBLT_WAIT,
&ddbfx);
EndPaint(hWnd, &ps);
IDirectDrawSurface_SetClipper(s_pDisplay->m_lpPrimary, NULL);
return 0;
default: break;
}
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
BOOL DisplayWindow::Close()
{
if (m_hWnd)
{
::DestroyWindow(m_hWnd);
m_hWnd = NULL;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -