Embedded C language screen operation menu

原文地址: http://www.cprogramdevelop.com/1827752/

C language the idea of object-oriented software architecture will be how to change it?

Menu menu 2 menu menu menu ..

Switch the menu to the left and right arrow keys on the keyboard focus when the user focus in a menu, tap OK on the keyboard, the CANCEL button menu corresponding processing function calls the focus. Look at the difference between the following two methods:

* Press the OK button * / 
void onOkKey () 
{ 
* To determine what the focus of the menu, press the OK button, call the appropriate handler function * / 
Switch (currentFocus) 
{ 
case menu1; 
menu1OnOk (); 
break; 
case menu2; 
menu2OnOk (); 
break; 
... 
} 
} 
* Press the Cancel key * / 
void onCancelKey () 
{ 
* To determine what the focus of the menu, press the Cancel key, call the appropriate handler function * / 
Switch (currentFocus) 
{ 
case menu1: 
menu1OnCancel (); 
break; 
case menu2; 
menu2OnCancel (); 
break; 
... 
} 
}

Compare the following method:

/ * The menu attributes and operations "Package" * / 
typedef struct tagSysMenu is 
{ 
char   * Text; / * menu text * / 
BYTE XPos; / * x coordinate of the menu on the LCD * / 
Byte ypos; / * y-coordinate of the menu on the LCD * / 
void (* onOkFun) (); / * on the menu, press the OK key processing function pointer * / 
void (* onCancelFun) (); / * on the menu, press the Cancel key processing function pointer * / 
} SysMenu, * LPSysMenu; 
When we define the menu is simply this:

static SysMenu menu [MENU_NUM] = 
{ 
{ 
"Menu1", 0, 48, menu1OnOk, menu1OnCancel 
} 
And 
{ 
Menu2, 7, 48, menu2OnOk menu2OnCancel 
} 
And 
{ 
"Menu3", 14, 48, menu2OnOk, menu2OnCancel 
} 
And 
... 
}; 
The OK button and the Cancel key processing becomes:

/ * Press the OK button * / 
void onOkKey () 
{ 
menu [currentFocusMenu]. onOkFun (); 
} 
/ * Press the Cancel key * / 
void onCancelKey () 
{ 
menu [currentFoucusMenu]. onCancelFunI (); 
}
Program do not greatly among the flowers, and also look good scalability! We just package object-oriented thinking, let the program structure clear, As a result, almost no need to modify the program in the system to add more menu, press handler for the system remains unchanged.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值