我的wince移植遇到的问题

1。首先是OPENFILENAME 的使用

 static OPENFILENAME ofn;
    BOOL bool_return = FALSE;
 wchar_t szFileName[_MAX_PATH];
 wchar_t szFileTitle[_MAX_PATH];
    char szFileName[_MAX_PATH];
    char szFileTitle[_MAX_PATH];
    memset(&ofn, 0, sizeof(ofn)); // initialize structure to 0/NULL
 wcscpy(&szFileName[0],_T("*.swf/0/0"));
    strcpy(&szFileName[0], "*.swf");
    szFileTitle[0] = 0;


   wchar_t *szFilter=_T("*.swf/0*.swf/0/0");

    ofn.lpstrFilter = szFilter;
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = _MAX_PATH;
    ofn.lpstrDefExt = _T("*");

    ofn.lpstrFileTitle = szFileTitle;
    ofn.nMaxFileTitle = _MAX_PATH;
    ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    ofn.nFilterIndex = 0;
    ofn.hwndOwner = suf_hwnd;
    ofn.hInstance = 0;

在添加文件过滤的时候,wince有着和windows不同的处理,这点要注意,

还有获取到的文件路径名是"/sdcard/flash/a.swf"这个样子的,其中"/"当转意字符处理,必须再写专门的字符串处理程序将"/"替换为"//"或者'/',这样才能正确的获取文件名。

2.键盘按键的处理

GetAsyncKeyState和GetKeyState是有区别的,前者返回的是消息队列中的按键状态,后者返回的是键盘实时的按键状态。

这些大部分情况下是没有问题的,但是出问题的时候让我遇到了,我的方向键没有响应了。

这个给了我一个比较大的启示,在嵌入式设备上,很多问题都是和平台有关,同样的函数,平台支持是不一样的,这次GetKeyState在windows和wince上是很不一样的,这次应该仔细领悟。

3.显示的处理:

由于gdi显示没有ddraw快,所以我改用ddraw显示,但是ddraw是独占模式,横屏显示的时候遇到点困难,我推测是驱动支持的问题。

附上我改的微软的示例代码:以后方便查看。哈哈

//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//-----------------------------------------------------------------------------
// File: DDEx1.CPP
//
// Desc: Direct Draw example program 1.  Creates a Direct Draw
//       object and then a primary surface with a back buffer.
//       Slowly flips between the primary surface and the back
//       buffer.  Press F12 to terminate the program.
//
//-----------------------------------------------------------------------------

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------
#include <windows.h>
#include <ddraw.h>
#include "resource.h"
#include "winuserm.h"

//-----------------------------------------------------------------------------
// Local definitions
//-----------------------------------------------------------------------------
#define NAME                TEXT("DDExample1")
#define TITLE               TEXT("Direct Draw Example 1")

//-----------------------------------------------------------------------------
// Default settings
//-----------------------------------------------------------------------------
#define TIMER_ID            1
#define TIMER_RATE          500

//-----------------------------------------------------------------------------
// Global data
//-----------------------------------------------------------------------------
LPDIRECTDRAW                g_pDD = NULL;            // DirectDraw object
LPDIRECTDRAWSURFACE         g_pDDSPrimary = NULL;    // DirectDraw primary surface
LPDIRECTDRAWSURFACE         g_pDDSBack = NULL;       // DirectDraw back surface
BOOL                        g_bActive = FALSE;       // Is application active?
LPCTSTR                     g_szErrorMessage = NULL; // Error message to display.

//-----------------------------------------------------------------------------
// Local data
//-----------------------------------------------------------------------------
static const TCHAR          szMsg[] = TEXT("Page Flipping Test: Press F12 to exit");
static const TCHAR          szFrontMsg[] = TEXT("Front buffer (F12 to quit)");
static const TCHAR          szBackMsg[] = TEXT("Back buffer (F12 to quit)");
static const TCHAR          szDDrawError[] = TEXT("DirectDraw Error");
static const TCHAR          szDDrawFailedMsg[] = TEXT("DirectDrawCreate failed.");
static const TCHAR          szSetCooperativeFailMsg[] = TEXT("SetCooperativeLevel failed.");
static const TCHAR          szNoBackBufferMsg[] = TEXT("Display driver doesn't support a back buffer.");
static const TCHAR          szNoFlipSurfacesMsg[] =TEXT("Display driver doesn't support flipping surfaces.");
static const TCHAR          szEnumAttachedSurfacesFailMsg[] = TEXT("EnumAttachedSurfaces failed.");
static const TCHAR          szCreateSurfaceFailMsg[] = TEXT("CreateSurface failed.");
static const TCHAR          szSetTimerFailMsg[] = TEXT("SetTimer failed.");

//-----------------------------------------------------------------------------
// Name: ReleaseAllObjects()
// Desc: Finished with all objects we use; release them
//-----------------------------------------------------------------------------
#define  HENG
#define BACKBUFFER
unsigned short *g_buf;
int g_width;
int g_height;
static void
ReleaseAllObjects(void)
{
    if (g_pDDSBack != NULL)
    {
        g_pDDSBack->Release();
        g_pDDSBack = NULL;
    }
    if (g_pDDSPrimary != NULL)
    {
        g_pDDSPrimary->Release();
        g_pDDSPrimary = NULL;
    }
    if (g_pDD != NULL)
    {
        g_pDD->Release();
        g_pDD = NULL;
    }
}

//-----------------------------------------------------------------------------
// Name: InitFail()
// Desc: This function is called if an initialization function fails
//-----------------------------------------------------------------------------
HRESULT
InitFail(HWND hWnd, HRESULT hRet, LPCTSTR szError,...)
{
    ReleaseAllObjects();
    DestroyWindow(hWnd);
    g_szErrorMessage = szError;
    return hRet;
}

//-----------------------------------------------------------------------------
// Name: UpdateFrame()
// Desc: Displays the proper text for the page
//-----------------------------------------------------------------------------
void MySetPixel(unsigned short * buf,int x, int y ,unsigned short value)
{
 *(buf + y*g_width + x) = value;
}
static void
UpdateFrame(HWND hWnd, unsigned short* buf)
{
 //memset(g_buf, 0xf0, 480*640);
 //划线;
 for(int x=10 ; x<210; x++)
 {
  for (int y=10; y<210;y++)
   MySetPixel(buf, x, y, 0xfc08);
 }
 

#ifdef  TEST
    static BYTE phase = 0;
    HDC hdc;
    RECT rc;
    SIZE size;
    int nMsg;
    DDBLTFX ddbltfx;

    // Use the blter to do a color fill to clear the back buffer
    memset(&ddbltfx, 0, sizeof(ddbltfx));
    ddbltfx.dwSize = sizeof(ddbltfx);
    ddbltfx.dwFillColor = 0;
    g_pDDSBack->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &ddbltfx);

    if (g_pDDSBack->GetDC(&hdc) == DD_OK)
    {
        SetBkColor(hdc, RGB(0, 0, 255));
        SetTextColor(hdc, RGB(255, 255, 0));
        GetClientRect(hWnd, &rc);
        if (phase)
        {
            nMsg = lstrlen(szMsg);
            GetTextExtentPoint(hdc, szMsg, nMsg, &size);
            ExtTextOut(hdc,
               (rc.right - size.cx) / 2,
               (rc.bottom - size.cy) / 2,
               0,                        // fuOptions
               NULL,                     // lprc
               szMsg,
               nMsg,
               NULL);                    // lpDx

            nMsg = lstrlen(szFrontMsg);
            GetTextExtentPoint(hdc, szFrontMsg, nMsg, &size);
            ExtTextOut(hdc,
               (rc.right - size.cx) / 2, // Center horz. for tv reasons
               0,
               0,                        // fuOptions
               NULL,                     // lprc
               szFrontMsg,
               nMsg,
               NULL);                    // lpDx
            phase = 0;
        }
        else
        {
            nMsg = lstrlen(szBackMsg);
            GetTextExtentPoint(hdc, szBackMsg, nMsg, &size);
            ExtTextOut(hdc,
               (rc.right - size.cx) / 2, // Center horz. for tv reasons
               0, 
               0,                        // fuOptions
               NULL,                     // lprc
               szBackMsg,
               nMsg,
               NULL);                    // lpDx
            phase = 1;
        }
        g_pDDSBack->ReleaseDC(hdc);
    }
#endif
}


//-----------------------------------------------------------------------------
// Name: WindowProc()
// Desc: The Main Window Procedure
//-----------------------------------------------------------------------------
long FAR PASCAL
WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HRESULT                     hRet;

    switch (message)
    {
#ifdef UNDER_CE
        case WM_ACTIVATE:
#else
        case WM_ACTIVATEAPP:
#endif
            // Pause if minimized or not the top window
            g_bActive = (wParam == WA_ACTIVE) || (wParam == WA_CLICKACTIVE);
            return 0L;

        case WM_DESTROY:
            // Clean up and close the app
            ReleaseAllObjects();
            PostQuitMessage(0);
            return 0L;

        case WM_KEYDOWN:
            // Handle any non-accelerated key commands
            switch (wParam)
            {
                case VK_ACTION:
                    PostMessage(hWnd, WM_CLOSE, 0, 0);
                    return 0L;
            }
            break;

        case WM_SETCURSOR:
            // Turn off the cursor since this is a full-screen app
            SetCursor(NULL);
            return TRUE;

        case WM_TIMER:
            // Update and flip surfaces
            if (g_bActive && TIMER_ID == wParam)
            {
                UpdateFrame(hWnd ,g_buf);
    int ret;
#ifdef BACKBUFFER
    ret = g_pDDSPrimary->Blt(NULL, g_pDDSBack, NULL, NULL, NULL);
    if(ret != DD_OK)
     InitFail(hWnd, hRet, _T("blt field/n"));
#endif
                /*while (TRUE)
                {
                    hRet = g_pDDSPrimary->Flip(NULL, 0);
                    if (hRet == DD_OK)
                        break;
                    if (hRet == DDERR_SURFACELOST)
                    {
                        hRet = g_pDDSPrimary->Restore();
                        if (hRet != DD_OK)
                            break;
                    }
                    if (hRet != DDERR_WASSTILLDRAWING)
                        break;
                }*/
            }
            break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

//-----------------------------------------------------------------------------
// Name: EnumFunction()
// Desc: Enumeration callback for surfaces in flipping chain. We expect this
//          function to be called once with the surface interface pointer of
//          our back buffer (we only ask for a single back buffer.)
//-----------------------------------------------------------------------------
static HRESULT PASCAL
EnumFunction(LPDIRECTDRAWSURFACE pSurface,
             LPDDSURFACEDESC lpSurfaceDesc,
             LPVOID  lpContext)
{
    static BOOL bCalled = FALSE;

    if (!bCalled) {

        *((LPDIRECTDRAWSURFACE *)lpContext) = pSurface;
        bCalled = TRUE;
        return DDENUMRET_OK;
    }
    else {

        OutputDebugString(L"DDEX1: Enumerated more than surface?");
        pSurface->Release();
        return DDENUMRET_CANCEL;
    }
}


/*******************************************************
*  函数名:  ModeEnumRecord (...)
*  功能:    记录检测到的显示模式
*           IDirectDraw7::EnumDisplayModes方法的回调函数
********************************************************/
static HRESULT WINAPI ModeEnumRecord( DDSURFACEDESC * pNewMode,
                                      VOID * pRecordInfo )
{
    //DISPLAYMODE * pAllModes = NULL;
    //DDSURFACEDESC2 * pddsdNewAllModes = NULL;

    获取整个记录的指针
    //pAllModes = ( DISPLAYMODE * )pRecordInfo;

    重新为模式列表分配空间,同时也为新找到的模式分配空间
    //pddsdNewAllModes = new DDSURFACEDESC2 [pAllModes->dwNumMode+1];

    ///*
    //将原来的模式列表空间直接复制到新分配的空间。目前,列表空
    //间的最后一项没有记录数据*/
    //DWORD dwSize = pAllModes->dwNumMode * sizeof(DDSURFACEDESC2);
    //memcpy( pddsdNewAllModes, pAllModes->pddsdMode, dwSize );

    删除不用了的空间,将指针指向新的空间
    //delete pAllModes->pddsdMode;
    //pAllModes->pddsdMode = pddsdNewAllModes;

    将找到的显示模式记录下来(记录在列表空间的最后一项)
    //pAllModes->pddsdMode[pAllModes->dwNumMode] = (*pNewMode);

    更新模式列表索引值
    //++pAllModes->dwNumMode;

    return DDENUMRET_OK;
}

//-----------------------------------------------------------------------------
// Name: InitApp()
// Desc: Do work required for every instance of the application:
//          Create the window, initialize data
//-----------------------------------------------------------------------------
static HRESULT
InitApp(HINSTANCE hInstance, int nCmdShow)
{
    HWND                        hWnd;
    WNDCLASS                    wc;
    DDSURFACEDESC               ddsd;
    HRESULT                     hRet;

    // Set up and register window class
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON));
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = NAME;
    RegisterClass(&wc);

    // Create a window
    hWnd = CreateWindowEx(WS_EX_TOPMOST,
                          NAME,
                          TITLE,
                          WS_POPUP,
                          0,
                          0,
                          GetSystemMetrics(SM_CXSCREEN),
                          GetSystemMetrics(SM_CYSCREEN),
                          NULL,
                          NULL,
                          hInstance,
                          NULL);
    if (!hWnd)
        return FALSE;
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    SetFocus(hWnd);

    ///
    // Create the main DirectDraw object
    ///
   
#ifdef HENG
 //横屏
 DEVMODE devmode = {0};
 devmode.dmSize = sizeof(DEVMODE);
 devmode.dmDisplayOrientation = DMDO_270; //水平模式
 devmode.dmFields = DM_DISPLAYORIENTATION;
 ChangeDisplaySettingsEx(NULL, &devmode, NULL, 0, NULL);
#else
 //横屏
 DEVMODE devmode = {0};
 devmode.dmSize = sizeof(DEVMODE);
 devmode.dmDisplayOrientation = DMDO_0; //水平模式
 devmode.dmFields = DM_DISPLAYORIENTATION;
 ChangeDisplaySettingsEx(NULL, &devmode, NULL, 0, NULL);
#endif


    hRet =  DirectDrawCreate(NULL, &g_pDD, NULL);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, szDDrawFailedMsg);

    // Get exclusive mode
    hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_FULLSCREEN);
    if (hRet != DD_OK)
        return InitFail(hWnd, hRet, szSetCooperativeFailMsg);

     //Create the primary surface with 1 back buffer
    memset(&ddsd, 0, sizeof(ddsd));
    ddsd.dwSize = sizeof(ddsd);
 //hRet = g_pDD->EnumDisplayModes( 0, 0, 0 ,ModeEnumRecord ) ;//第一个参数表示列举所有的显示模式
 //hRet = g_pDD->GetDisplayMode(&ddsd);
 
 /*hRet = g_pDD->SetDisplayMode(640, 480, 16, 0, 0);
 
 if (hRet != DD_OK)
 {
  return InitFail(hWnd, hRet, _T("set display mode field!"));
 }*/

 ddsd.dwFlags = DDSD_CAPS ;//| DDSD_PITCH |DDSD_XPITCH ;//|DDSD_WIDTH |DDSD_HEIGHT ;
 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE ;//| DDSCAPS_VIDEOMEMORY;
 hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
 if (hRet != DD_OK)
 {
  return InitFail(hWnd, hRet, szCreateSurfaceFailMsg);
 }
#ifdef BACKBUFFER
 //CREATE BUF
 
 int systemWidth = GetSystemMetrics(SM_CXSCREEN);
 int systemHeight = GetSystemMetrics(SM_CYSCREEN);
 ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT ;//|DDSD_CAPS ;//| DDSD_CAPS;
 //mini_suf_dds_desc.ddsCaps.dwCaps =  ;
 ddsd.dwWidth = systemWidth; //mini_suf_dds_desc.dwWidth;
 ddsd.dwHeight = systemHeight; //mini_suf_dds_desc.dwHeight;
 hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSBack ,NULL);
 if(hRet != DD_OK)
  InitFail(hWnd, hRet, _T("g_pDDSBack field/n"));


 //lock
 hRet = g_pDD->RestoreAllSurfaces();
 if (hRet != DD_OK)
 {
  return InitFail(hWnd, hRet, _T("restore add surfaces field/n"));
 }
 g_pDDSBack->Lock(0, &ddsd, DDLOCK_WAITNOTBUSY, 0);
 g_buf = (unsigned short*)ddsd.lpSurface;
 g_width = ddsd.dwWidth;
 g_height = ddsd.dwHeight;
 g_pDDSBack->Unlock(0);
#else
 //lock
 hRet = g_pDD->RestoreAllSurfaces();
 if (hRet != DD_OK)
 {
  return InitFail(hWnd, hRet, _T("restore add surfaces field/n"));
 }
 g_pDDSPrimary->Lock(0, &ddsd, DDLOCK_WAITNOTBUSY, 0);
 g_buf = (unsigned short*)ddsd.lpSurface;
 g_width = ddsd.dwWidth;
 g_height = ddsd.dwHeight;
 g_pDDSPrimary->Unlock(0);

#endif
    // Create a timer to flip the pages
    if (TIMER_ID != SetTimer(hWnd, TIMER_ID, TIMER_RATE, NULL))
        return InitFail(hWnd, hRet, szSetTimerFailMsg);


    return DD_OK;
}

 


//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Initialization, message loop
//-----------------------------------------------------------------------------
int PASCAL
WinMain(HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPWSTR lpCmdLine,
        int nCmdShow)
{
    MSG        msg;

    InitApp(hInstance, nCmdShow);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    if (g_szErrorMessage != NULL){
        MessageBox(NULL, g_szErrorMessage, szDDrawError, MB_OK | MB_ICONEXCLAMATION);
        return FALSE;
    }

    return msg.wParam;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值