先把代码粘在下面了,注释可能不是很清晰。
#include
#include
#include
#include
#include
#include
#include
#ifdef _LANG_ZHCN
#include "bmpbkgnd_res_cn.h"
#elif defined _LANG_ZHTW
#include "bmpbkgnd_res_tw.h"
#else
#include "bmpbkgnd_res_en.h"
#endif
#define IDC_SIZE_BTN_ON 100
#define IDC_SIZE_BTN_OFF 110
#define IDC_SIZE_BTN_ADD 120
#define IDC_SIZE_BTN_LES 130
//个人理解图片存放位置变量
static BITMAP bmp_bkgnd;
static BITMAP button;
//用来定义对话框
static DLGTEMPLATE DlgBoxInputLen =
{
WS_CAPTION,
WS_EX_NOCLOSEBOX | WS_EX_TRANSPARENT ,
0, 0, 800, 480,
please_input_the_length,
0, 0,
5, NULL,
0
};
//定义控件并初始化,参数手册里面都有
static CTRLDATA CtrlInputLen [] =
{
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE | WS_THINFRAME,
459, 73, 250, 123,
IDC_STATIC,
"25.8%",
0,
WS_EX_TRANSPARENT
},
{
CTRL_BUTTON,
WS_CHILD | BS_PUSHBUTTON | BS_BITMAP |BS_REALSIZEIMAGE | BS_NOTIFY | WS_VISIBLE,
95, 350, 106, 52,
IDC_SIZE_BTN_ON,
"ON",
(DWORD)&bmp_bkgnd,
0
},
{
CTRL_BUTTON,
WS_CHILD | BS_PUSHBUTTON | BS_BITMAP |BS_REALSIZEIMAGE | BS_NOTIFY | WS_VISIBLE,
270, 350, 106, 52,
IDC_SIZE_BTN_OFF,
"OFF",
(DWORD)&button,
0
},
{
CTRL_BUTTON,
WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP ,
447, 350, 106, 52,
IDC_SIZE_BTN_ADD,
"+",
0
},
{
CTRL_BUTTON,
WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP ,
619, 350, 106, 52,
IDC_SIZE_BTN_LES,
"-",
0
}
};
//回调函数,里面只有一个功能就是背景图片
static int InputLenDialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case MSG_ERASEBKGND:
{
HDC hdc = (HDC)wParam;
const RECT* clip = (const RECT*) lParam;
BOOL fGetDC = FALSE;
RECT rcTemp;
if (hdc == 0) {
hdc = GetClientDC (hDlg);
fGetDC = TRUE;
}
if (clip) {
rcTemp = *clip;
ScreenToClient (hDlg, &rcTemp.left, &rcTemp.top);
ScreenToClient (hDlg, &rcTemp.right, &rcTemp.bottom);
IncludeClipRect (hdc, &rcTemp);
}
else
GetClientRect (hDlg, &rcTemp);
FillBoxWithBitmap (hdc, 0, 0,
RECTW(rcTemp), RECTH(rcTemp), &bmp_bkgnd);
if (fGetDC)
ReleaseDC (hdc);
return 0;
}
}
return DefaultDialogProc (hDlg, message, wParam, lParam);
}
//主函数
int MiniGUIMain (int argc, const char* argv[])
{
#ifdef _MGRM_PROCESSES
JoinLayer(NAME_DEF_LAYER , "bmpbkgnd" , 0 , 0);
#endif
//装载位图 miniGUI设备相关的位图对象
if (LoadBitmapFromFile (HDC_SCREEN, &bmp_bkgnd, "/mnt/yaffs2/bkgnd.jpg"))
return 1;
if (LoadBitmapFromFile (HDC_SCREEN, &button, "/mnt/yaffs2/bkgnd.jpg"))
return 1;
//关联对话框和控件
DlgBoxInputLen.controls = CtrlInputLen;
DialogBoxIndirectParam (&DlgBoxInputLen, HWND_DESKTOP, InputLenDialogBoxProc, 0L);
//释放内存
UnloadBitmap (&bmp_bkgnd);
UnloadBitmap (&button);
return 0;
}
#ifdef _MGRM_THREADS
#include
#endif
按键添加图片首先要先创建按键(也就是控件),用 CTRLDATA ,其中属性中(DWORD)&bmp_bkgnd为图片句柄。然后在主函数中装载图片,LoadBitmapFromFile (HDC_SCREEN, &button, "/mnt/yaffs2/bkgnd.jpg")。
文本框与按键类似。
风格设定为SS_BITMAP 或者 SS_ICON,这种静态框会显示一幅位图或者图标。
最后释放内存,UnloadBitmap (&bmp_bkgnd);。
因为只是新手,只是自己的理解,希望不要误导别人,只是自己做个笔记。