论坛元老
- 积分
- 4133
- 金钱
- 4133
- 注册时间
- 2018-5-14
- 在线时间
- 902 小时
|
发表于 2023-6-28 12:31:25
|
显示全部楼层
给按钮添加附加内存,可以是自定义结构体,传入附加字节的大小
{ BUTTON_CreateIndirect, "Button DM", ID_BUTTON_RIGHT, 335, 640, 120, 80, 0, 0x0, sizeof(GUI_BITMAP) },
创建后初始化
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_RIGHT);
给按钮设置附加内存里的内容
BUTTON_SetUserData(hItem, &bmimage_nobutton, sizeof(GUI_BITMAP));
WM_SetCallback(hItem, _cb_Button);
WM_ShowWindow(hItem);
按钮自定义回调函数
static void _cb_Button(WM_MESSAGE* pMsg)
{
int xsize;
int ysize;
GUI_BITMAP image;
xsize = WM_GetWindowSizeX(pMsg->hWin);
ysize = WM_GetWindowSizeY(pMsg->hWin);
switch (pMsg->MsgId)
{
case WM_PAINT:
//这里获取到附加内存的内容,我这里是一张图片
BUTTON_GetUserData(pMsg->hWin, &image, sizeof(GUI_BITMAP));
if (BUTTON_IsPressed(pMsg->hWin))
{
GUI_DrawBitmap(&image, (xsize - image.XSize) / 2, (ysize - image.YSize) / 2+5);
}
else
{
GUI_DrawBitmap(&image, (xsize - image.XSize) / 2, (ysize - image.YSize) / 2);
}
break;
default:
BUTTON_Callback(pMsg);
}
}
原理是附加内存后,emwin会多申请内存给这个控件,多余的内存可以通过 SetUserData和GetUserData获取(实质是memcpy)
|
|