主要遇见的难题:
1、因为软键盘和Edit编辑框是处于同一LCD中,通过鼠标或者触摸都会是焦点改变。
2、在键盘点击事件中,无法知道之前是选择的是那个Edit编辑器。
3、在选择Edit编辑器之后,点击键盘后怎么把焦点从新锁定在之前选择的Edit上(在刚刚输入的字符后面)。
现在的源码如下:
[code=c]
#include <stddef.h>
#include "GUI.h"
#include "DIALOG.h"
#include "WM.h"
#include "BUTTON.h"
#include "CHECKBOX.h"
#include "DROPDOWN.h"
#include "EDIT.h"
#include "FRAMEWIN.h"
#include "LISTBOX.h"
#include "MULTIEDIT.h"
#include "RADIO.h"
#include "SLIDER.h"
#include "TEXT.h"
#include "PROGBAR.h"
#include "SCROLLBAR.h"
#include "LISTVIEW.h"
EDIT_Handle Cd_edit_handle; // 全局edit句柄
// 事件
void OnButton0Clicked(WM_MESSAGE * pMsg)
{
// WM_HWIN hWin = pMsg->hWin;
/*************************
此处无法锁定是之前鼠标点击的edit(编辑器),?
*************************/
WM_SetFocus(Cd_edit_handle); // 锁定光标在之前选择的edit中
EDIT_AddKey(Cd_edit_handle, '0'); // 向之前edit中输入数据
}
void OnButton1Clicked(WM_MESSAGE * pMsg)
{}
void OnButton2Clicked(WM_MESSAGE * pMsg)
{}
void OnButton3Clicked(WM_MESSAGE * pMsg)
{}
void OnButton4Clicked(WM_MESSAGE * pMsg)
{}
void OnButton5Clicked(WM_MESSAGE * pMsg)
{}
void OnButton6Clicked(WM_MESSAGE * pMsg)
{}
void OnButton7Clicked(WM_MESSAGE * pMsg)
{}
void OnButton8Clicked(WM_MESSAGE * pMsg)
{}
void OnButton9Clicked(WM_MESSAGE * pMsg)
{}
void OnButton10Clicked(WM_MESSAGE * pMsg)
{}
void OnButton11Clicked(WM_MESSAGE * pMsg)
{
WM_SetFocus(Cd_edit_handle); // 锁定光标在之前选择的edit中
GUI_SendKeyMsg(GUI_KEY_BACKSPACE, 1); // 删除edit的数据(相当于键盘上的删除键功能)
}
void OnButton12Clicked(WM_MESSAGE * pMsg)
{}
// static data
#define GUI_ID_BUTTON10 GUI_ID_USER+1
#define GUI_ID_BUTTON11 GUI_ID_USER+2
#define GUI_ID_BUTTON12 GUI_ID_USER+3
// Dialog资源管理器
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Number In", 0, 0, 0, 480,320,FRAMEWIN_CF_MOVEABLE,0},
{ BUTTON_CreateIndirect, "1", GUI_ID_BUTTON1, 199,14, 80, 65, 0,0},
{ BUTTON_CreateIndirect, "2", GUI_ID_BUTTON2, 294,14, 80, 65, 0,0},
{ BUTTON_CreateIndirect, "3", GUI_ID_BUTTON3, 389,14, 80, 65, 0,0},
{ BUTTON_CreateIndirect, "4", GUI_ID_BUTTON4, 199,85, 80, 65, 0,0},
{ BUTTON_CreateIndirect, "5", GUI_ID_BUTTON5, 294,85, 80, 65, 0,0},
{ BUTTON_CreateIndirect, "6", GUI_ID_BUTTON6, 389,85, 80, 65, 0,0},
{ BUTTON_CreateIndirect, "7", GUI_ID_BUTTON7, 199,156,80, 65, 0,0},
{ BUTTON_CreateIndirect, "8", GUI_ID_BUTTON8, 294,156,80, 65, 0,0},
{ BUTTON_CreateIndirect, "9", GUI_ID_BUTTON9, 389,156,80, 65, 0,0},
{ BUTTON_CreateIndirect, "0", GUI_ID_BUTTON0, 294,227,80, 65, 0,0},
{ BUTTON_CreateIndirect, "return", GUI_ID_BUTTON10, 12, 238,115,40, 0,0},
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT0, 12, 66, 165,40, 0,0},
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT1, 12, 170,165,40, 0,0},
{ TEXT_CreateIndirect, "First number:", GUI_ID_TEXT0, 11, 28, 166,24, 0,0},
{ TEXT_CreateIndirect, "Tail number:", GUI_ID_TEXT1, 12, 134,154,24, 0,0},
{ BUTTON_CreateIndirect, "DEL", GUI_ID_BUTTON11, 153,227,126,65, 0,0},
{ BUTTON_CreateIndirect, "SAVE", GUI_ID_BUTTON12, 389,227,80, 65, 0,0}
};
void PaintDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hWin = pMsg->hWin;
}
// 初始化Dialog
void InitDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hWin = pMsg->hWin;
//
//FRAMEWIN
//
FRAMEWIN_SetBarColor(hWin,1,0x87b8de);
FRAMEWIN_SetClientColor(hWin,0xdcdcdc);
FRAMEWIN_SetTextColor(hWin,0x000000);
FRAMEWIN_SetFont(hWin,&GUI_Font8x16);
FRAMEWIN_SetTextAlign(hWin,GUI_TA_TOP|GUI_TA_LEFT);
FRAMEWIN_SetTitleHeight(hWin,16);
//
//GUI_ID_BUTTON1
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON1),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON1),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON1),&GUI_FontD48);
//
//GUI_ID_BUTTON2
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON2),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON2),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON2),&GUI_FontD48);
//
//GUI_ID_BUTTON3
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON3),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON3),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON3),&GUI_FontD48);
//
//GUI_ID_BUTTON4
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON4),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON4),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON4),&GUI_FontD48);
//
//GUI_ID_BUTTON5
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON5),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON5),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON5),&GUI_FontD48);
//
//GUI_ID_BUTTON6
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON6),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON6),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON6),&GUI_FontD48);
//
//GUI_ID_BUTTON7
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON7),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON7),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON7),&GUI_FontD48);
//
//GUI_ID_BUTTON8
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON8),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON8),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON8),&GUI_FontD48);
//
//GUI_ID_BUTTON9
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON9),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON9),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON9),&GUI_FontD48);
//
//GUI_ID_BUTTON0
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),BUTTON_CI_UNPRESSED,0xdcdcdc);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),&GUI_FontD48);
//
//GUI_ID_BUTTON10
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON10),BUTTON_CI_UNPRESSED,0x008000);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON10),BUTTON_CI_PRESSED,0x00a5ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON10),&GUI_Font24_ASCII);
//
//GUI_ID_EDIT0
//
EDIT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_EDIT0),0,0xffffff);
EDIT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_EDIT0),0,0x0000ff);
EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT0),&GUI_Font32B_ASCII);
EDIT_SetMaxLen(WM_GetDialogItem(hWin,GUI_ID_EDIT0),9);
//
//GUI_ID_EDIT1
//
EDIT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_EDIT1),0,0x0000ff);
EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT1),&GUI_Font32B_ASCII);
EDIT_SetMaxLen(WM_GetDialogItem(hWin,GUI_ID_EDIT1),9);
//
//GUI_ID_TEXT0
//
TEXT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_TEXT0),0xdcdcdc);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT0),&GUI_Font24B_ASCII);
//
//GUI_ID_TEXT1
//
TEXT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_TEXT1),0xdcdcdc);
TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT1),&GUI_Font24B_ASCII);
//
//GUI_ID_BUTTON11
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON11),BUTTON_CI_UNPRESSED,0x0045ff);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON11),BUTTON_CI_PRESSED,0x0000ff);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON11),&GUI_Font32_ASCII);
//
//GUI_ID_BUTTON12
//
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON12),BUTTON_CI_UNPRESSED,0x0045ff);
BUTTON_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_BUTTON12),BUTTON_CI_PRESSED,0x008000);
BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON12),&GUI_Font32_ASCII);
}
// Dialog callback routine
static void _cbCallback(WM_MESSAGE * pMsg)
{
int NCode, Id;
WM_HWIN hWin = pMsg->hWin;
// 这个地方才是重点 轮询是那个edit获得了焦点
// 再将获得焦点的edit句柄保存在edit全局句柄中 功能键盘使用
// 这样就是软键盘和多edit 在一个对话框中的焦点问题解决
if(WM_HasFocus(WM_GetDialogItem(hWin,GUI_ID_EDIT1)))
{
Cd_edit_handle = WM_GetDialogItem(hWin,GUI_ID_EDIT1);
}else
if(WM_HasFocus(WM_GetDialogItem(hWin,GUI_ID_EDIT0)))
{
Cd_edit_handle = WM_GetDialogItem(hWin,GUI_ID_EDIT0);
}
switch (pMsg->MsgId)
{
case WM_PAINT:
PaintDialog(pMsg);
break;
case WM_INIT_DIALOG:
InitDialog(pMsg);
break;
// case WM_KEY:
// switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
// {
// case GUI_KEY_ESCAPE:
// GUI_EndDialog(hWin, 1);
// break;
// case GUI_KEY_ENTER:
// GUI_EndDialog(hWin, 0);
// break;
// }
// break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id)
{
// case GUI_ID_OK:
// if(NCode==WM_NOTIFICATION_RELEASED)
// GUI_EndDialog(hWin, 0);
// break;
// case GUI_ID_CANCEL:
// if(NCode==WM_NOTIFICATION_RELEASED)
// GUI_EndDialog(hWin, 0);
// break;
case GUI_ID_BUTTON1:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton1Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON2:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton2Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON3:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton3Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON4:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton4Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON5:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton5Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON6:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton6Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON7:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton7Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON8:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton8Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON9:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton9Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON0:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton0Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON10:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton10Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON11:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton11Clicked(pMsg);
break;
}
break;
case GUI_ID_BUTTON12:
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
OnButton12Clicked(pMsg);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
void MainTask(void)
{
GUI_Init();
WM_SetDesktopColor(GUI_WHITE);
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
while(1);
}
[/code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
大哥,这里是不是通过edit的通知case去调取软键盘dialog呢? 用完之后咋关闭软键盘呢?
一周热门 更多>