📄 softkey.c
字号:
/*************************************************
Copyright (C), 2007-2011, Aurine
File name: au_keybord.c
Author: 许集润
Version: 1.0
Date:
Description: 软键盘
History:
1. Date: 2007-07-01
Author:
Modification:
2. ...
*************************************************/
#include "../include/au_model_func.h"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#define IDC_EDIT 100
#define KEY_X 100
#define KEY_Y 150
#define KEY_W 30
#define KEY_H 30
static BITMAP g_back_bmp,g_JTai_bmp;
static RECT rc_text;
static char num[10]={0};
static int status[4][10];
static int g_mouse_down=0,g_mouse_up=0;
static const char *caption[4][10] =
{
{"1","2","3","4","5","6","7","8","9","0"},
{"Q","W","E","R","T","Y","U","I","O","P"},
{"A","S","D","F","G","H","J","K","L",""},
{"Z","X","C","V","B","N","M",".","",""}
};
//模板-窗体控件定义
static DLGTEMPLATE DlgInit =
{
DW_STYLE,
DW_STYLE_EX,
FORM_X, FORM_Y, 800, 480,
"",
0,
0,
0,//sizeof(Ctrls)/sizeof(CTRLDATA),
NULL,//Ctrls,
0
};
static void create_ctrl(HWND hDlg)
{
CreateWindow("edit","",
WS_VISIBLE | WS_TABSTOP | WS_BORDER ,
IDC_EDIT,
100, 50, 200, 25,
hDlg,
0);
}
static void click_form(HWND hDlg, int x, int y)
{
int i,j,len;
char char_tmp[4]={0};
RECT rc_keydown;
if((x>500 && x<(500+(int)g_back_bmp.bmWidth)) && (y>400 && y<400+(int)g_back_bmp.bmHeight))
{
printf("HIDE dialog\n");
EndDialog(hDlg,0);
}
if(x>KEY_X && x< KEY_X + KEY_W*10 && y > KEY_Y && y < KEY_Y + KEY_H*4)
{
i = (int)floor((y - KEY_Y)/KEY_H);
j = (int)floor((x - KEY_X)/KEY_W);
printf("the i is : %d \t the j is : %d \n",i,j);
len=strlen(num);
if(g_mouse_down == 1)
{
if(len<15)
{
printf("the len is : %d \n",len);
sprintf(char_tmp,"%s",caption[i][j]);
printf("the char_tmp is : %s \n",char_tmp);
num[len]=char_tmp[0];
printf("the num is : %s \n",num);
num[len+1]=0;
SetWindowText(GetDlgItem(hDlg,IDC_EDIT),num);
}
status[i][j]=1;
g_mouse_down = 0;
}
if(g_mouse_up == 1)
{
status[i][j] = 2;
printf("free mouse \n");
g_mouse_up = 0;
}
rc_keydown.left = KEY_X + KEY_W * j;
rc_keydown.top = KEY_Y + KEY_H * i + 1;
rc_keydown.right = rc_keydown.left + KEY_W;
rc_keydown.bottom = rc_keydown.top + KEY_H - 1;
printf("left:%d,top:%d,right:%d,bottom:%d",rc_keydown.left,rc_keydown.top,rc_keydown.right,rc_keydown.bottom);
InvalidateRect(hDlg,&rc_keydown, TRUE);
}
}
static void draw_text(HWND hDlg,HDC hdc)
{
int i,x,y,j;
FillBoxWithBitmap(hdc, 500, 400, 0,0,&g_back_bmp);
x = KEY_X;
y = KEY_Y;
//这是我自己写的画有立体感的矩形边框
draw_rect(hdc,KEY_X,KEY_Y,KEY_W*10,KEY_H*4,PIXEL_MAINCOLOR,
PIXEL_SHALLOWCOLOR,PIXEL_DEEPCOLOR,1,2,1,1);
SetPenColor(hdc,PIXEL_DEEPCOLOR);
for(i=0;i<3;i++)
{
y = KEY_Y + KEY_H * (i + 1);
LineEx (hdc, x,y,x+KEY_W*10,y);
}
for(i=0;i<4;i++)
{
j=0;
while (j<10)
{
if(status[i][j]==1)
{
printf ("the satus is 1\n");
SetBrushColor(hdc,PIXEL_blue);
FillBox(hdc,KEY_X + KEY_W * j,KEY_Y + KEY_H * i,KEY_W,KEY_H);
}
if(status[i][j]==2)
{
printf ("the satus is 2\n");
SetBrushColor(hdc,PIXEL_MAINCOLOR);
FillBox(hdc,KEY_X + KEY_W * j,KEY_Y + KEY_H * i,KEY_W,KEY_H);
}
j++;
}
}
SetBkMode(hdc,BM_TRANSPARENT);
for(i=0;i<40;i++)
{
if(i<10)
{
j=0;
}
else if(i<20)
{
j=1;
}
else if(i<30)
{
j=2;
}
else
{
j=3;
}
rc_text.left=KEY_X + (i%10) * 30-10;
rc_text.top = KEY_Y+ 7 + KEY_H * j;
rc_text.right = rc_text.left + KEY_W;
rc_text.bottom = rc_text.top + KEY_H;
DrawText(hdc,caption[j][i%10],-1,&rc_text,DT_VCENTER|DT_RIGHT);
}
}
static void load_res(HDC hdc)
{
LoadBitmap (hdc, &g_back_bmp, "res/back-01.gif");
}
//模板-控件事件处理函数
static void OnCommand(WPARAM id, HWND hWnd, HWND hDlg)
{
char ch_tmp[2]={0};
switch (id)
{
}
}
//模板-消息处理函数
static int WindowProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
static i=0;
switch (message)
{
case MSG_CREATE:
printf("####MSG_CREATE\n");
create_ctrl(hDlg);
break;
case MSG_INITDIALOG:
printf("####MSG_INITDIALOG\n");
break;
case MSG_ACTIVE:
printf("#####MSG_ACTIVE\n");
break;
case MSG_SHOWWINDOW:
if (wParam==0x00)//hide
{
printf("MSG_SHOWWINDOW:hide\n");
}
else//show
{
printf("MSG_SHOWWINDOW:show");
}
break;
case MSG_COMMAND:
OnCommand(wParam, (HWND)lParam, hDlg) ;
break;
case MSG_PAINT:
printf("####MSG_PAINT\n");
hdc = BeginPaint (hDlg);
load_res(hdc);
draw_text(hDlg,hdc);
EndPaint (hDlg, hdc);
return 0;
case MSG_LBUTTONDOWN:
g_mouse_down = 1;
click_form(hDlg, LOWORD(lParam), HIWORD(lParam));
break;
case MSG_LBUTTONUP :
g_mouse_up = 1;
click_form(hDlg, LOWORD(lParam), HIWORD(lParam));
break;
case MSG_CLOSE:
DestroyMainWindow(hDlg);
PostQuitMessage(hDlg);
return 0;
}
return DefaultDialogProc(hDlg, message, wParam, lParam);
}
//模板-建立窗体
GUI_FORM FrmKeyboard = {0, NULL, &DlgInit, WindowProc, -1, 0,1};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -