嵌入式学习小组
直播中

沈家春

8年用户 224经验值
私信 关注

为什么在WM_PAINT中刷新背景图片不显示?

#if SYSTEM_SUPPORT_UCOS
#include "includes.h"                                        //ucos 使用         
#endif
#define ID_FRAMEWIN_0    (GUI_ID_USER + 0x00)
static char bmpBuffer[BMPPERLINESIZE];
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 0, 0, 0, 0x0, 0 },
};
static int BmpGetData(void * p, const U8 ** ppData, unsigned NumBytesReq, U32 Off)
{
        static int readaddress=0;
        FIL * phFile;
        UINT NumBytesRead;
        #if SYSTEM_SUPPORT_UCOS
                OS_CPU_SR cpu_sr;
        #endif
        
        phFile = (FIL *)p;
        
        if (NumBytesReq > sizeof(bmpBuffer))
        {
                NumBytesReq = sizeof(bmpBuffer);
        }
        //移动指针到应该读取的位置
        if(Off == 1) readaddress = 0;
        else readaddress=Off;
        #if SYSTEM_SUPPORT_UCOS
                OS_ENTER_CRITICAL();        //临界区
        #endif
        f_lseek(phFile,readaddress);
        
        //读取数据到缓冲区中
        f_read(phFile,bmpBuffer,NumBytesReq,&NumBytesRead);
        #if SYSTEM_SUPPORT_UCOS
                OS_EXIT_CRITICAL();        //退出临界区
        #endif
        *ppData = (U8 *)bmpBuffer;
        return NumBytesRead;//返回读取到的字节数
}
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN hItem;
  int     NCode;
  int     Id;
        static FIL BMPFile;
  u8 *BMPFileName="0:/PICTURE/ji.bmp";
  switch (pMsg->MsgId) {
        case WM_PAINT:
        f_open(&BMPFile,(const TCHAR*)BMPFileName,FA_READ);        //打开文件
        GUI_BMP_DrawEx(BmpGetData,&BMPFile,1,1);
        f_close(&BMPFile);                //关闭BMPFile文件
        break;
        case WM_NOTIFY_PARENT:     
    break;
    default:
    WM_DefaultProc(pMsg);
    break;
  }
}
WM_HWIN CreateFramewin(void) {
  WM_HWIN hWin;
  hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  return hWin;
}
在WM_PAINT中刷新背景图片不显示,不知是什么原因?(照着BMP例程显示改的,BMP例程可以正常显示)

回帖(1)

王利祥

2019-10-16 09:36:01
帮顶
举报

更多回帖

发帖
×
20
完善资料,
赚取积分