display_res_icon.cpp

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> 
#include <windows.h> 
#include "Display_Res_Icon.h"


#if defined (WIN32)
 #define IS_WIN32 TRUE
#else
 #define IS_WIN32 FALSE
#endif

#define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32

HINSTANCE hInst;   // current instance

LPCTSTR lpszAppName  = "MyApp";
LPCTSTR lpszTitle    = "My Application";

BOOL RegisterWin95( CONST WNDCLASS* lpwc );

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                      LPTSTR lpCmdLine, int nCmdShow)
{
   MSG      msg;
   HWND     hWnd;
   WNDCLASS wc;

   // Register the main application window class.
   //............................................
   wc.style         = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc   = (WNDPROC)WndProc;      
   wc.cbClsExtra    = 0;                     
   wc.cbWndExtra    = 0;                     
   wc.hInstance     = hInstance;             
   wc.hIcon         = LoadIcon( hInstance, lpszAppName );
   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.lpszMenuName  = lpszAppName;             
   wc.lpszClassName = lpszAppName;             

   if ( IS_WIN95 )
   {
      if ( !RegisterWin95( &wc ) )
         return( FALSE );
   }
   else if ( !RegisterClass( &wc ) )
      return( FALSE );

   hInst = hInstance;

   // Create the main application window.
   //....................................
   hWnd = CreateWindow( lpszAppName,
                        lpszTitle,   
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, 0,
                        CW_USEDEFAULT, 0, 
                        NULL,             
                        NULL,             
                        hInstance,        
                        NULL              
                      );

   if ( !hWnd )
      return( FALSE );

   ShowWindow( hWnd, nCmdShow );
   UpdateWindow( hWnd );        

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

   return( msg.wParam );
}


BOOL RegisterWin95( CONST WNDCLASS* lpwc )
{
   WNDCLASSEX wcex;

   wcex.style         = lpwc->style;
   wcex.lpfnWndProc   = lpwc->lpfnWndProc;
   wcex.cbClsExtra    = lpwc->cbClsExtra;
   wcex.cbWndExtra    = lpwc->cbWndExtra;
   wcex.hInstance     = lpwc->hInstance;
   wcex.hIcon         = lpwc->hIcon;
   wcex.hCursor       = lpwc->hCursor;
   wcex.hbrBackground = lpwc->hbrBackground;
   wcex.lpszMenuName  = lpwc->lpszMenuName;
   wcex.lpszClassName = lpwc->lpszClassName;

   // Added elements for Windows 95.
   //...............................
   wcex.cbSize = sizeof(WNDCLASSEX);
   wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName,
                            IMAGE_ICON, 16, 16,
                            LR_DEFAULTCOLOR );
   
   return RegisterClassEx( &wcex );
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_TEST :
                        {
                           HICON hIcon;      
                           HRSRC hResource;   
                           HRSRC hMem;        
                           BYTE *lpResource;  
                           int   nID;                                                          
                           HDC   hDC;       

                           // Find the icon directory
                           // whose identifier is MYAPP.
                           //...........................
                           hResource = FindResource(hInst, "MYAPP",
                                                    RT_GROUP_ICON);

                           // Load and lock the icon directory.
                           //..................................
                           hMem = LoadResource(hInst, hResource);
                           lpResource = LockResource(hMem);

                           // Get the identifier of the icon that is most
                           // appropriate for the video display.
                           //............................................
                           nID = LookupIconIdFromDirectory((PBYTE)lpResource,
                                                            TRUE);

                           // Find the bits for the nID icon.
                           //................................
                           hResource = FindResource( hInst,
                                                   MAKEINTRESOURCE(nID),
                                                   MAKEINTRESOURCE(RT_ICON));

                           // Load and lock the icon.
                           //........................
                           hMem = LoadResource(hInst, hResource);
                           lpResource = LockResource(hMem);

                           // Create a handle to the icon.
                           //.............................
                           hIcon = CreateIconFromResource((PBYTE)lpResource,
                                           SizeofResource(hInst, hResource),
                                           TRUE,
                                           0x00030000);

                           // Draw the icon in the client area.
                           //..................................
                           hDC = GetDC( hWnd );
                           DrawIcon(hDC, 10, 20, hIcon);
                           ReleaseDC( hWnd, hDC );

                           DestroyIcon( hIcon );
                        }
                        break;

                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
     
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
}


LRESULT CALLBACK About( HWND hDlg,          
                        UINT message,       
                        WPARAM wParam,      
                        LPARAM lParam)
{
   switch (message)
   {
       case WM_INITDIALOG:
               return (TRUE);

       case WM_COMMAND:                             
               if (   LOWORD(wParam) == IDOK        
                   || LOWORD(wParam) == IDCANCEL)   
               {
                       EndDialog(hDlg, TRUE);       
                       return (TRUE);
               }
               break;
   }

   return (FALSE);
}

/********************** * MACROS **********************/ lv_disp_drv_t *lv_port_disp_init() { static lv_disp_draw_buf_t draw_buf_dsc_3; static lv_color_t buf_3_1[LVGL_HOR_RES * LVGL_VER_RES]; /*A screen sized buffer*/ static lv_color_t buf_3_2[LVGL_HOR_RES * LVGL_VER_RES]; /*Another screen sized buffer*/ lv_disp_draw_buf_init(&draw_buf_dsc_3, buf_3_1, buf_3_2, LVGL_VER_RES * LVGL_HOR_RES); /*Initialize the display buffer*/ /*----------------------------------- * Register the display in LVGL *----------------------------------*/ static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/ lv_disp_drv_init(&disp_drv); /*Basic initialization*/ /*Set up the functions to access to your display*/ /*Set the resolution of the display*/ disp_drv.hor_res = LVGL_HOR_RES; disp_drv.ver_res = LVGL_VER_RES; disp_drv.physical_hor_res = LVGL_HOR_RES; disp_drv.physical_ver_res = LVGL_VER_RES; disp_drv.screen_transp = LV_COLOR_SCREEN_TRANSP; disp_drv.dpi = LV_DPI_DEF; disp_drv.color_chroma_key = LV_COLOR_CHROMA_KEY; /*Used to copy the buffer's content to the display*/ disp_drv.flush_cb = disp_flush; /*Set a display buffer*/ disp_drv.draw_buf = &draw_buf_dsc_3; #if ROTATE_SCREEN disp_drv.rotated = 1; disp_drv.sw_rotate = 1; #endif /*Required for Example 3)*/ disp_drv.full_refresh = 0; /* Fill a memory array with a color if you have GPU. * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL. * But if you have a different GPU you can use with this callback.*/ //disp_drv.gpu_fill_cb = gpu_fill; /*Finally register the driver*/ lv_disp_drv_register(&disp_drv); return &disp_drv; } 把他转成lv_display_create的函数。
最新发布
03-14
<think>好的,我现在需要帮助用户将现有的lv_port_disp_init函数转换为使用lv_display_create的方式,同时保持原有功能,包括缓冲区初始化、分辨率设置和显示刷新回调配置。首先,我得回顾一下LVGL的显示驱动接口变化。根据用户提供的引用内容,LVGL的新版本推荐使用lv_display_create来替代旧的初始化方法,这可能涉及到显示设备的注册和定时器的绑定,如引用[1]中提到的disp->refr_timer的设置。 首先,旧的lv_port_disp_init函数可能包含几个关键步骤:初始化显示缓冲区、设置分辨率、注册刷新回调函数,以及可能的其他配置如旋转或像素格式。用户提到需要将这些功能迁移到新的lv_display_create方法中。我需要确认lv_display_create的参数和所需配置步骤。 根据引用[1],显示设备注册时会在链表头部插入节点,并创建定时器绑定到disp结构体,定时器回调是_lv_disp_refr_timer。新的API可能将这些步骤封装在lv_display_create内部,但用户需要显式设置缓冲区、回调和分辨率。 接下来,缓冲区初始化部分。旧代码可能使用静态或动态分配的缓冲区,并调用类似lv_disp_draw_buf_init的函数。新方法可能需要使用lv_display_set_buffers来设置前后缓冲区。 分辨率设置方面,旧代码可能通过disp_drv.hor_res和ver_res来设置,而新方法可能需要调用lv_display_set_resolution函数。 刷新回调函数需要注册到显示驱动,旧代码可能通过disp_drv.flush_cb设置,而新方法可能通过lv_display_set_flush_cb来实现。 另外,引用[2]提到lv_task_handler处理定时任务、动画、界面刷新和事件,这可能影响显示刷新的定时器设置。需要确保新的显示驱动正确配置刷新周期,可能与LV_DISP_DEF_REFR_PERIOD相关,这个宏可能在lv_conf.h中定义。 可能的步骤是:使用lv_display_create创建显示对象,设置其分辨率,初始化缓冲区并关联到显示对象,设置刷新回调,以及处理旋转和像素格式。同时,确保定时器正确创建,如引用[1]中的disp->refr_timer,但新API可能自动处理这部分。 需要检查LVGL的官方文档或头文件,确认lv_display_create的参数和相关的设置函数。例如,lv_display_create可能需要输入驱动参数,如旋转方向或像素格式,然后通过其他函数设置缓冲区、回调和分辨率。 可能遇到的错误包括缓冲区未正确关联、回调函数签名不匹配、分辨率设置遗漏等。需要确保所有必要的配置步骤都迁移到新API中,并测试显示刷新是否正常,没有画面撕裂或延迟。 总结转换步骤: 1. 替换lv_port_disp_init为lv_display_create,创建显示对象。 2. 使用lv_display_set_resolution设置分辨率。 3. 初始化缓冲区并关联到显示对象,可能需要lv_disp_draw_buf_init和lv_display_set_buffers。 4. 设置刷新回调函数,使用lv_display_set_flush_cb。 5. 配置其他参数,如旋转、像素格式,使用相应的新函数。 6. 确保定时器正确设置,刷新周期由LV_DISP_DEF_REFR_PERIOD定义,可能自动处理。 需要参考LVGL的最新文档或示例代码,确认这些步骤的正确性,并调整代码结构,确保兼容性和功能完整性。</think>将`lv_port_disp_init`转换为使用`lv_display_create`的步骤如下,需重点关注缓冲区、分辨率及回调的配置: ### 1. 替换显示设备创建方式 旧代码通过`lv_disp_drv_register`注册驱动,新方法需用`lv_display_create`创建显示对象: ```c // 旧代码片段示例(用户原有逻辑) static lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); disp_drv.flush_cb = flush_cb; lv_disp_drv_register(&disp_drv); // 新代码实现 lv_display_t* disp = lv_display_create(hor_res, ver_res); // 直接设置分辨率 lv_display_set_flush_cb(disp, flush_cb); // 绑定刷新回调 ``` ### 2. 初始化显示缓冲区 旧代码可能使用`lv_disp_draw_buf_init`,新方法需显式关联缓冲区: ```c // 旧代码示例 static lv_disp_draw_buf_t draw_buf; lv_disp_draw_buf_init(&draw_buf, buf1, buf2, buf_size); // 新代码实现 lv_display_set_buffers(disp, buf1, buf2, buf_size, LV_DISPLAY_RENDER_MODE_PARTIAL); // 若使用双缓冲模式,需设置LV_DISPLAY_RENDER_MODE_DIRECT或_FULL ``` ### 3. 配置分辨率与旋转 旧代码通过`disp_drv.hor_res`设置,新方法需调用专用函数: ```c lv_display_set_resolution(disp, 320, 240); // 设置物理分辨率 lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_90); // 旋转配置 ``` ### 4. 设置像素格式与DPI 新增参数需显式声明(旧代码可能通过宏定义隐式配置): ```c lv_display_set_pixel_format(disp, LV_PIXEL_FORMAT_RGB565); lv_display_set_dpi(disp, 130); // 根据屏幕实际DPI调整 ``` ### 5. 刷新定时器配置 引用[1]指出刷新定时器由`lv_display_create`内部自动创建,其周期通过`LV_DISP_DEF_REFR_PERIOD`宏定义(默认30ms)。如需修改: ```c // 在lv_conf.h中修改: #define LV_DISP_DEF_REFR_PERIOD 33 // 改为30Hz刷新率 ``` ### 完整代码示例 ```c void lv_port_disp_init(void) { // 1. 初始化缓冲区 static lv_color_t buf1[DISP_BUF_SIZE]; static lv_color_t buf2[DISP_BUF_SIZE]; // 双缓冲 uint32_t buf_size = DISP_BUF_SIZE; // 2. 创建显示设备 lv_display_t* disp = lv_display_create(320, 240); // 3. 关联缓冲区 lv_display_set_buffers(disp, buf1, buf2, buf_size, LV_DISPLAY_RENDER_MODE_DIRECT); // 4. 设置回调与参数 lv_display_set_flush_cb(disp, flush_cb); lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_0); lv_display_set_pixel_format(disp, LV_PIXEL_FORMAT_RGB565); } ``` ### 关键差异说明 - **定时器管理**:旧版本需手动绑定`disp->refr_timer`,新版本通过`lv_display_create`自动完成[^1] - **驱动注册**:`lv_disp_drv_register`被拆分为`lv_display_create`和属性设置函数 - **缓冲区模式**:渲染模式(`PARTIAL`/`FULL`)需显式指定,影响性能与内存占用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值