各位大大,本人在
STM32上使用ucgui+ucos编写程序,在使用按钮的时候,发现点击按钮,GUI_GetKey()无法得到按钮ID(偶尔一次可以得到)。程序代码如下:
void MainTask(void)
{
GUI_Init();
while(1)
{
//WM_Exec1();
APP_main();
}
}
void APP_main(void)//用户主函数
{
GUI_Clear(); while(1) {
_Menu();
OS
timeDlyHMSM(0,0,0,20);//按时分秒延时函数
}
}
static void _Menu(void) {
BUTTON_Handle hM1, hM2;//hM3, hM4;
int sKey;
static u8 Kf1=0, Kf2=0;
GUI_RECT rText = {340,8, 460,24};
GUI_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_LIGHTGRAY);
GUI_SetFont( amp;GUI_Font16_ASCII);
GUI_DispStringInRect( quot;CH1 quot;, amp;rText, GUI_TA_VCENTER|GUI_TA_HCENTER);
hM1 = BUTTON_Create( 340, 26, 120, 25, 1, BUTTON_CF_SHOW );
BUTTON_SetText(hM1, quot;通道选择 quot;);
BUTTON_SetFont(hM1, amp;GUI_FontHZ_SimHei_19);
BUTTON_SetBkColor(hM1, 0, GUI_DARKGRAY);
BUTTON_SetTextColor(hM1, 0, GUI_WHITE);
hM2 = BUTTON_Create( 340, 76, 120, 25, 2, BUTTON_CF_SHOW );
BUTTON_SetText(hM2, quot;探头 quot;);
BUTTON_SetFont(hM2, amp;GUI_FontHZ_SimHei_19);
BUTTON_SetBkColor(hM2, 0, GUI_DARKGRAY);
BUTTON_SetTextColor(hM2, 0, GUI_WHITE);
WM_Exec();//WM_Exec1();
sKey = GUI_GetKey();获取按钮ID
if(sKey==1){//按钮处理
if(Kf1==0) Kf1=1;
else Kf1=0;
}
else if(sKey==2) {
if(Kf2==0) Kf2=1;
else Kf2=0;
}
rText.y0 = 52; rText.y1 = 75;
GUI_SetFont( amp;GUI_FontHZ_SimHei_19);
if(Kf1==0) GUI_DispStringInRect( quot;直流 quot;, amp;rText, GUI_TA_VCENTER|GUI_TA_HCENTER);
else GUI_DispStringInRect( quot;交流 quot;, amp;rText, GUI_TA_VCENTER|GUI_TA_HCENTER);
rText.y0 = 100; rText.y1 = 125;
GUI_SetFont( amp;GUI_Font16_ASCII);
if(Kf2==0) { GUI_GotoXY(360, 102); GUI_DispCEOL();
GUI_DispStringInRect( quot;X1 quot;, amp;rText, GUI_TA_VCENTER|GUI_TA_HCENTER); }
else GUI_DispStringInRect( quot;X10 quot;, amp;rText, GUI_TA_VCENTER|GUI_TA_HCENTER);
BUTTON_Delete(hM1);
BUTTON_Delete(hM2);
}