📄 setphsch.c
字号:
#include "setphsch.h"#include "fillbox.h"#include "softkb.h"#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <fcntl.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <pwd.h>#include <errno.h>//extern void fill_box(HWND hdlg, const char* path, int boxid);//extern HWND NovaSKBWindow(HWND hosting, int x, int y);typedef struct tagphno{ int num; int light;}PHNO;typedef struct tagphfile{ char schname[12]; int phtotal; }HEADFILE;DLGTEMPLATE setphdlg={ WS_BORDER | WS_CAPTION , WS_EX_NONE, 50,50,440,162, SETPHDLG_STR_SET_SCHEME, 0,0,10,NULL, 0};CTRLDATA setphctrl[]={ { CTRL_LISTVIEW, WS_VISIBLE | WS_BORDER | WS_VSCROLL | LVS_AUTOCHECKBOX | LVS_NOTIFY , 10,10,340,86, IDL_SCH_FILE, "", 0 }, { CTRL_BUTTON, WS_VISIBLE | BS_DEFPUSHBUTTON, 360,16,50,26, IDB_DEL_BTN, STR_DEL_BTN, 0, WS_EX_NONE }, { CTRL_BUTTON, WS_VISIBLE | BS_DEFPUSHBUTTON, 10,106,50,26, IDB_NEW_BTN, STR_NEW_BTN, 0, WS_EX_NONE }, { CTRL_STATIC, WS_VISIBLE | SS_LEFT, 70,112,50,26, IDS_PHN_STATIC, STR_IDS_PHN, 0, WS_EX_NONE }, { CTRL_COMBOBOX, WS_VISIBLE | WS_CHILD | CBS_READONLY | CBS_AUTOSPIN | CBS_AUTOLOOP | CBS_EDITBASELINE, 130,112,40,20, IDE_PHN_EDIT, "", 0 }, { CTRL_STATIC, WS_VISIBLE | SS_LEFT, 180,112,50,26, IDS_SCHNO_STATIC, STR_IDS_SCHNO, 0, WS_EX_NONE }, { CTRL_EDIT, WS_VISIBLE | ES_LEFT, 240,112,40,20, IDE_PHNAME_EDIT, "4", 0, WS_EX_NONE }, { CTRL_BUTTON, WS_VISIBLE | BS_DEFPUSHBUTTON, 290,106,50,26, IDB_SAVE_BTN, STR_SAVE_BTN, 0, WS_EX_NONE }, { CTRL_BUTTON, WS_VISIBLE | BS_DEFPUSHBUTTON, 350,106,25,26, IDB_IME_BTN, STR_IME_BTN, 0, WS_EX_NONE }, { CTRL_BUTTON, WS_VISIBLE | BS_DEFPUSHBUTTON, 360,58,50,26, IDCANCEL, SETPHDLG_STR_IDCANCEL, 0, WS_EX_NONE }};int splitstr(char* src, char* dest, int index, char flag){ int i = 0; int j = 0; int k = 0; int m = 0; while(src[i] != 0) { if(src[i] == flag && (j+1) == index) { while( k<i) { dest[m] = src[k]; m++; k++; } j++; k = i+1; } else if( src[i] == flag ) { j++; k = i+1; } i++; } return j;}void save(HWND hdlg){ HEADFILE head; memset(head.schname, 0, 12); GetDlgItemText(hdlg, IDE_PHNAME_EDIT, head.schname, 11); head.phtotal = SendDlgItemMessage(hdlg, IDE_PHN_EDIT,CB_GETSPINVALUE, 0, 0); char path[18]; strcpy(path, "./ph/"); strcat(path, head.schname); int file = open(path, O_CREAT | O_WRONLY | O_TRUNC, 0600); write(file, &head, sizeof(HEADFILE)); PHNO phno; phno.light = 0; int j; char phstr[16]; memset(phstr, 0, 16); char temp[3]; memset(temp, 0, 3); int n = 0; int i = 0; int bit = 0; for(j=0; j<head.phtotal; j++) { phno.num=j+1; GetDlgItemText(hdlg, IDE_P1+j, phstr, 15); n = splitstr(phstr, temp, 1, ','); for(; i< n; i++) { splitstr(phstr, temp, i+1, ','); bit = atoi(temp); phno.light |= (1<<(bit-1)); memset(temp, 0, 3); } write(file, &phno, sizeof(PHNO)); memset(phstr, 0, 16); i = 0; printf("== %d \n\r", phno.light); phno.light = 0; } close(file); }void myread(){ HEADFILE head; int file = open("./ph/aaa", O_RDONLY, 0666); int n; n = read(file, &head, sizeof(HEADFILE));// printf("n=%d", n); printf("%d", head.phtotal); close(file);}int setphschproc(HWND hdlg, int message, WPARAM wParam, LPARAM lParam){ HWND btn = NULL; switch(message){ case MSG_INITDIALOG: { char cwd[MAX_PATH+4]; getcwd(cwd, MAX_PATH); strcat(cwd, "/ph"); fill_box(hdlg, cwd,IDL_SCH_FILE); btn = GetDlgItem(hdlg, IDB_SAVE_BTN); EnableWindow(btn, FALSE); SendDlgItemMessage(hdlg, IDE_PHN_EDIT, CB_SETSPINRANGE, 0,18); SendDlgItemMessage(hdlg, IDE_PHN_EDIT, CB_SETSPINFORMAT, 0,(LPARAM)"%02d"); SendDlgItemMessage(hdlg, IDE_PHN_EDIT, CB_SETSPINVALUE, 4, 0); SendDlgItemMessage(hdlg, IDE_PHN_EDIT, CB_SETSPINPACE, 0, 1); LVCOLUMN p; p.nCols = 0; p.width = 80; p.pszHeadText = STR_FILE_NAME; p.nTextMax = 10; p.image = NULL; p.pfnCompare = NULL; p.colFlags = NULL; SendDlgItemMessage(hdlg, IDL_SCH_FILE, LVM_ADDCOLUMN, 0, (LPARAM)&p); p.nCols = 0; p.width = 80; p.pszHeadText = STR_PH_NUM; p.nTextMax = 10; p.image = NULL; p.pfnCompare = NULL; p.colFlags = NULL; SendDlgItemMessage(hdlg, IDL_SCH_FILE, LVM_ADDCOLUMN, 1, (LPARAM)&p); p.nCols = 0; p.width = 80; p.pszHeadText = STR_TIME; p.nTextMax = 10; p.image = NULL; p.pfnCompare = NULL; p.colFlags = NULL; SendDlgItemMessage(hdlg, IDL_SCH_FILE, LVM_ADDCOLUMN, 2, (LPARAM)&p); return 1; } case MSG_COMMAND: switch(wParam){ case IDB_NEW_BTN: { btn = GetDlgItem(hdlg, IDB_NEW_BTN); EnableWindow(btn, FALSE); btn = GetDlgItem(hdlg, IDB_SAVE_BTN); EnableWindow(btn, TRUE); char phno[3]; char num[3]; int i=SendDlgItemMessage(hdlg, IDE_PHN_EDIT,CB_GETSPINVALUE, 0, 0); MoveWindow(hdlg, 50, 50, 440, 162+20*i, TRUE); int j=0; for(; j<i;j++) { memset(phno, '\0', 3); phno[0]='p'; memset(num, '\0', 3); strcat(phno, itoa(j+1, num)); int x,y; if(j%2 == 0) { x=20; y=162+32*(int)(j/2); } else { x=200; y=162+32*(int)(j/2); } CreateWindow(CTRL_STATIC, phno,WS_CHILD | WS_VISIBLE, IDS_P1+j, x, y, 20, 20, hdlg, 0); CreateWindow(CTRL_EDIT, phno,WS_CHILD | WS_VISIBLE, IDE_P1+j, x+20, y, 120, 20, hdlg, 0); } break; } case IDB_SAVE_BTN: { save(hdlg); break; } case IDB_DEL_BTN: { NovaSKBWindow(hdlg, 0, 0); break; } case IDOK: case IDCANCEL: EndDialog(hdlg, wParam); break; } break; } return DefaultDialogProc(hdlg, message, wParam, lParam);}void setphschdlg(HWND hparent){ setphdlg.controls=setphctrl; DialogBoxIndirectParam(&setphdlg, hparent, setphschproc, 0L); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -