WinCE的高速图形库
CEDraw 是一个用于 WinCE 的高速图形库。
引言
CEDraw 是 WinCE 中的高速图形库。 它依赖于 GAPI。 此代码使用嵌入式 VC++ 用 C++ 编写,用于编译它。 测试是在运行 WinCE 3.0 的 iPaq h3600 上进行的。 CEDraw 使用双缓冲和直接写入视频缓冲区的技术来提高绘图速度。 由于其自身的图形算法,绘图速度比 WinGDI 快得多。
CE Draw 支持以下功能
- 绘制像素
- 填充屏幕
- 绘制线条,水平线,垂直线
- 绘制折线
- 绘制多边形
- 绘制矩形
- 填充矩形(支持 Alpha 混合)
- 填充多边形
- 绘制位图(支持 Bmp、Gif、Jpg 格式,支持 Alpha 混合)
- 绘制文本(自有字体文件,支持中文,支持 GDI 文本)
如何使用
在使用 CEDraw 库之前,您必须在系统中复制一些支持文件。
a. 将 dll 复制到您的 WinCE 系统目录
- 如果在仿真模式下使用,将两个 dll 复制到 …\CEGraph\DLL\X86Em 目录(gx.dll 和 cegl.dll)到仿真 Windows 系统目录,始终位于 D:\Windows CE Tools\wce300\MS Pocket PC\emulation\palm300\windows 目录中,然后将文件 Hzk16 从 …\CEGraph\Res 目录复制到 WinCE 根目录,始终位于 D:\Windows CE Tools\wce300\MS Pocket PC\emulation\palm300
- 如果使用 Arm 系统,将两个 DLL 复制到 …\CEGraph\DLL\Arm(gx.dll 和 cegl.dll)到 Pocket PC Windows 系统目录。 然后将文件 HZK16 复制到系统根目录。
使用它有 4 个步骤
步骤 1 目录
将包含目录设置为 …\CEGraph\Include
并将 lib 目录设置为 …\CEGraph\Lib\X86Em(如果在仿真系统中使用)或 …\CEGraph\Lib\Arm(如果在 pocketpc 中使用)
打开项目设置->链接->对象/库模块
添加 CEGL.lib
步骤 2 头文件包含
包含 cedraw 图形头文件:CEGL.h
#include "stdafx.h" #include "SDKSample.h" #include <commctrl.h> #include <cegl.h> // Include CE Graphics library
步骤 3 创建 CE Draw 类
// Create the CE Draw Object: CCEDraw m_ceDraw; // Initialize after CreateWindow() BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name hInst = hInstance; // Store instance handle in our global variable // Initialize global strings LoadString(hInstance, IDC_SDKSAMPLE, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance, szWindowClass); LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } // Create the CE Grahpics Library m_ceDraw.Create( hWnd ); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; }
步骤 4:自由使用 CE Draw
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; int wmId, wmEvent; PAINTSTRUCT ps; TCHAR szHello[MAX_LOADSTRING]; switch (message) { case WM_PAINT: RECT rt; hdc = BeginPaint(hWnd, &ps); GetClientRect(hWnd, &rt); LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_SINGLELINE | DT_VCENTER | DT_CENTER); EndPaint(hWnd, &ps); Render(); // Render screen break; ... } } void Render( void ) { POINT pt[5] ={ { 140, 100 }, { 70,120 }, { 104, 150 }, { 210, 122 }, { 75, 200 } }; // Create the ce pen object... CCEPen cePen; // Convert RGB color to CE support Color cePen.CreatePen( 1, 1, m_ceDraw.ConvertColor( 255, 0, 0 ) ); // Select it to the graphics system m_ceDraw.SetGDIObject( &cePen ); // Create the ce brush object... CCEBrush ceBrush1, ceBrush2; ceBrush1.CreateBrush( 1, m_ceDraw.ConvertColor( 200, 200, 100 ), 1 ); ceBrush2.CreateBrush( 1, m_ceDraw.ConvertColor( 0, 240, 0 ), 1 ); // Select it to the graphics system m_ceDraw.SetGDIObject( &ceBrush1 ); // Begin Draw m_ceDraw.BeginDraw(); m_ceDraw.Clear( (DWORD)255 ); // Clear screen use white color m_ceDraw.DrawLine( 1, 1, 100, 100 ); // Draw line m_ceDraw.DrawRect( 10, 10, 110, 80 ); // Draw Rect m_ceDraw.FillRect( 30, 30, 50, 50 ); // Fill Rect m_ceDraw.SetGDIObject( &ceBrush2 ); // Select another color brush m_ceDraw.FillRect( 40, 40, 100, 100, 0.4 ); // fill Rect with alpha blend m_ceDraw.FillPolygon( pt, 5 ); // Draw an polygon m_ceDraw.SetGDIObject( &ceBrush1 ); // Select another color brush m_ceDraw.FillPolygon( pt, 5, 40, 40 ); // Draw an polygon CCEBitmap ceBmp1,ceBmp2; // Load Gif picture from file ceBmp1.LoadBitmap( &m_ceDraw, L"windows\\wcelogo1.gif" ); ceBmp2.LoadBitmap( &m_ceDraw, L"windows\\welcomehead.gif" ); // Draw bitmap with alpha blend ceBmp2.BitBlt( &m_ceDraw, 1, 80, 0, 0, 0, 0, SRCALPHA, 0.6f ); ceBmp1.BitBlt( &m_ceDraw, 1, 200, 0, 0, 0, 0, SRCALPHA, 0.6f ); POINT ptText = { 1, 300 }; // Draw text with pen color m_ceDraw.DrawText( &ptText, "Hello CE Graph!", 16, 1 ); // End Draw m_ceDraw.EndDraw(); m_ceDraw.Flip(); // Flip the back buffer to the video buffer }
步骤 5
不要忘记释放它
case WM_DESTROY: m_ceDraw.Release(); PostQuitMessage(0); break;
技巧
此图形库不能直接用于 MFC 应用向导生成的框架。因为它有两个窗口,一个是框架窗口,另一个是子窗口。我编写了一个支持 MFC 的框架。如果有人想在 MFC 中使用它,请给我发邮件。
- CEGLDLLPrj 是 CE 图形库的 dll 项目。如果您想使用此库,强烈建议使用该项目构建您自己的 DLL 和 Lib 文件。要构建此项目。您可以将包含目录和 lib 目录设置为 ...\CEGraph\include & lib(与 步骤 1 目录相同)
- SDKSample 项目是不使用 MFC 的示例。在设置并复制库和 DLL 文件后构建它。
注释
请将任何错误或反馈报告给 jiet@msn.com
谢谢
此代码使用 GAPI 枚举。感谢作者。