📄 listbox_liz.c
字号:
#include <time.h>#include <string.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <dirent.h>#include <pwd.h>#include <errno.h>#include <stdio.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#define _ID_TIMER 160#define IDC_CHS 110#define IDC_TIME 150#define IDC_STATIC2 170#define IDC_PROMPTINFO 130#define IDC_PROGRESS 140#define M_MAX 11 //array's len#define M_LINE_HEIGHT 25#define IDC_EDIT 120#define TIME_MAX 8#define MY_CTRL_INFO "companyinfo"static WNDPROC old_edit_proc;int g_page_line = 4;static BITMAP bmp1,bmp2; //map1 map2PLOGFONT disp_font, disp_font1; //fontRECT rc_list[M_MAX], rc_text; //int i_focus, pg_focus, pg_max=M_MAX/4; //focus// 列表项的字符串数组char* psz_list[M_MAX] = { "COMPANY INFO","BBB","TIME EDIT","RESOLUTION","DISPMAP","FFF","GGG","EXIT","III","JJJ","NE" };char time_date[TIME_MAX];HWND hwndcominfo;static DLGTEMPLATE DlgInitProgress ={ WS_BORDER | WS_CAPTION, WS_EX_NONE, 100, 150, 200, 200, "时间编辑", 0, 0, 4, NULL, 0};static CTRLDATA CtrlInitProgress [] ={ { "static", WS_VISIBLE | SS_SIMPLE, 10, 40, 60, 40, IDC_PROMPTINFO, "系统时间", 0 }, { "static", WS_VISIBLE | SS_SIMPLE|SS_NOTIFY, 70, 40, 120, 40, IDC_TIME, "", 0 }, { "sledit", WS_CHILD | WS_VISIBLE |ES_CENTER, 60, 80, 65, 20, IDC_PROGRESS, "00:00:00", 0 }, { "button", WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON, 60, 120, 60, 25, IDOK, "保存", 0 }};//编辑框函数static void on_down_up (HWND hwnd, int offset){ char time [10]; int caretpos; int hour, minute, second; GetWindowText (hwnd, time, 8); caretpos = SendMessage (hwnd, EM_GETCARETPOS, 0, 0); /*?*/ hour = atoi (time); minute = atoi (time + 3); second = atoi (time + 6); if (caretpos > 5) { /* change second */ second += offset; if (second < 0) second = 59; if (second > 59) second = 0; } else if (caretpos > 2) { /* change minute */ minute += offset; if (minute < 0) minute = 59; if (minute > 59) minute = 0; } else { /* change hour */ hour += offset; if (hour < 0) hour = 23; if (hour > 23) hour = 0; } sprintf (time, "%02d:%02d:%02d", hour, minute, second); SetWindowText (hwnd, time); SendMessage (hwnd, EM_SETCARETPOS, 0, caretpos);}//编辑框回调函数static int TimeEditBox (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){ if (message == MSG_KEYDOWN) { switch (wParam) { case SCANCODE_CURSORBLOCKUP: on_down_up (hwnd, 1); return 0; case SCANCODE_CURSORBLOCKDOWN: on_down_up (hwnd, -1); return 0; case SCANCODE_PAGEUP: on_down_up (hwnd, 10); return 0; case SCANCODE_PAGEDOWN: on_down_up (hwnd, -10); return 0; case EM_SETCARETPOS: ShowCaret (hwnd); break; case SCANCODE_CURSORBLOCKLEFT: case SCANCODE_CURSORBLOCKRIGHT: break; default: return 0; } } if (message == MSG_KEYUP || message == MSG_CHAR) return 0; return (*old_edit_proc) (hwnd, message, wParam, lParam);}//设置时间函数static void time_save(hwnd){ char time_dd[10]; char *hour, *min, *sec; struct tm _tm; time_t timep; struct timeval tv; GetWindowText (hwnd, time_dd, 8); hour = strtok(time_dd, ":"); min = strtok(NULL, ":"); sec = strtok(NULL, ":"); _tm.tm_sec = atoi(sec); _tm.tm_min = atoi(min); _tm.tm_hour = atoi(hour); _tm.tm_mday = 11; _tm.tm_mon = 3 - 1; _tm.tm_year = 2009 - 1900; timep = mktime(&_tm); tv.tv_sec = timep; tv.tv_usec = 0; if(settimeofday (&tv, (struct timezone *) 0) < 0) { printf("Set system datatime error!\n"); MessageBox (GetParent(hwnd), "Set system datatime error!" , "错误信息", MB_OK | MB_ICONINFORMATION); } }//显示系统时间函数 获取系统时间 设置给指定的控件static void settimetext (HWND hwnd){ time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); sprintf(time_date, "%02d:%02d:%02d", timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); SetWindowText (hwnd, time_date);}// show solutionstatic void show_resolution(HWND hwnd){ RECT rcClient,rc; char resolution[30]; int x, y; HWND hwnd1; HDC hdc; GetClientRect (hwnd, &rcClient); x = rcClient.right - rcClient.left; y = rcClient.bottom - rcClient.top; rc_text.left = 20; //显示框 当摁空格时 显示选择的项 rc_text.top = 240; rc_text.right = 385; rc_text.bottom = 330; sprintf(resolution, "resolution : %d * %d", x, y); //SetBrushColor (hdc, PIXEL_lightgray); //FillBox( hdc, rc.left, rc.top, 300, 230 ); //DrawText( hdc, resolution, -1, &rc_text, DT_NOCLIP|DT_SINGLELINE|DT_CENTER|DT_VCENTER ); printf("i ready to create window\n"); hwnd1 =CreateWindow (CTRL_STATIC, "", WS_CHILD | SS_NOTIFY | WS_VISIBLE | WS_BORDER|WS_EX_USEPARENTFONT|WS_EX_TRANSPARENT|CS_OWNDC, IDC_STATIC2, 60, 120, 280, 150, hwnd, 0); SetWindowBkColor (hwnd1, PIXEL_lightgray); InvalidateRect(hwnd1, NULL, TRUE); //刷新子控件窗口 不然显示不了颜色 hdc = GetClientDC(hwnd1); SelectFont(hdc, disp_font); TextOut(hdc, 55, 20, resolution); ReleaseDC(hdc); //SetWindowCallbackProc(hwnd, show_resolution_proc); }static void show_resolution_proc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){ if(message == MSG_CLOSE) DestroyWindow(hwnd); }static void GDIDemo_TransparentBitmaps (HWND hwnd, HDC hdc) //效果 使图片背景色不显示{ int tox = 0, toy = 200; int count; BITMAP bitmap; /* Transparent bitmap */ if (LoadBitmap (hdc, &bitmap, "res/sail.bmp")) return; bitmap.bmType = BMP_TYPE_COLORKEY|BMP_TYPE_ALPHACHANNEL; //效果 使图片背景色不显示 bitmap.bmColorKey = GetPixelInBitmap (&bitmap, 0, 0); count = 25; while (count--) { bitmap.bmAlpha = tox; tox = tox+10; FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap); } UnloadBitmap (&bitmap); }static int My_ctrl_cominfo_Proc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; switch(message){ case MSG_PAINT: hdc = BeginPaint (hwnd); SetTextColor (hdc, PIXEL_black); SetBkColor (hdc, PIXEL_lightgray); SetBkMode (hdc, BM_TRANSPARENT); TabbedTextOut (hdc, 80, 50, "welcome to jieheweitong"); EndPaint (hwnd, hdc); return 0; case MSG_CLOSE: DestroyWindow(hwnd); //UnregisterWindowClass (MY_CTRL_INFO); } return DefaultControlProc (hwnd, message, wParam, lParam);}static BOOL RegisterComInfo (void){ WNDCLASS myclasscominfo; myclasscominfo.spClassName = MY_CTRL_INFO; myclasscominfo.dwStyle = WS_BORDER | WS_CAPTION; myclasscominfo.dwExStyle = WS_EX_NONE; myclasscominfo.hCursor = GetSystemCursor (IDC_ARROW); myclasscominfo.iBkColor = COLOR_blue; myclasscominfo.WinProc = My_ctrl_cominfo_Proc; return RegisterWindowClass (&myclasscominfo);}//对话框回调函数 static int InitDialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; switch (message) { case MSG_INITDIALOG: //SetWindowCallbackProc(GetDlgItem (hDlg, IDC_TIME), my_notif_proc); //SetFocusChild (GetDlgItem (hDlg, IDC_TIME)); //set focus failel old_edit_proc = SetWindowCallbackProc (GetDlgItem (hDlg, IDC_PROGRESS), TimeEditBox); SetTimer (hDlg, _ID_TIMER, 100); settimetext(GetDlgItem (hDlg, IDC_PROGRESS)); settimetext(GetDlgItem (hDlg, IDC_TIME)); return 1; case MSG_COMMAND: switch (wParam) { case IDOK: time_save(GetDlgItem (hDlg, IDC_PROGRESS)); break; case IDCANCEL: EndDialog (hDlg, wParam); break; } break; case MSG_TIMER: settimetext(GetDlgItem (hDlg, IDC_TIME)); break; case MSG_KEYDOWN: switch (wParam) { case SCANCODE_ENTER: SetFocusChild (GetDlgItem (hDlg, IDC_TIME)); return 0; } break; case MSG_CLOSE: EndDialog (hDlg, wParam);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -