📄 old-mginit
字号:
/* ** $Id: mginit.c,v 1.20 2006/06/12 06:40:35 weiym Exp $**** Listing 31.1**** mginit.c: Sample program for MiniGUI Programming Guide** A simple mginit program.**** Copyright (C) 2003 ~ 2006 Feynman Software.**** License: GPL*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <signal.h>#include <time.h>#include <sys/types.h>#include <sys/wait.h>#include <sys/ipc.h>#include <sys/msg.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include "tryttys1.c"#define FIFO_SERVER "/tmp/fifoserver" #define SIG_CHAILL 1111static BOOL quit = FALSE;static void on_new_del_client (int op, int cli){ static int nr_clients = 0; if (op == LCO_NEW_CLIENT) { nr_clients ++; } else if (op == LCO_DEL_CLIENT) { nr_clients --; if (nr_clients == 0) { printf ("There is no any client, I will quit.\n"); quit = TRUE; } else if (nr_clients < 0) { printf ("Serious error: nr_clients less than zero.\n"); } } else printf ("Serious error: incorrect operations.\n");}static pid_t exec_app (const char* file_name, const char* app_name){ pid_t pid = 0; if ((pid = vfork ()) > 0) { fprintf (stderr, "new child, pid: %d.\n", pid); } else if (pid == 0) { execl (file_name, app_name, NULL); perror ("execl"); _exit (1); } else { perror ("vfork"); } return pid;}static unsigned int old_tick_count;static pid_t pid_scrnsaver = 0;static int my_event_hook (PMSG msg){ old_tick_count = GetTickCount (); if (pid_scrnsaver) { kill (pid_scrnsaver, SIGINT); ShowCursor (TRUE); pid_scrnsaver = 0; } if (msg->message == MSG_KEYDOWN) { switch (msg->wParam) { case SCANCODE_F1: exec_app ("./edit", "edit"); break; case SCANCODE_F2: exec_app ("./timeeditor", "timeeditor"); break; case SCANCODE_F3: exec_app ("./propsheet", "propsheet"); break; case SCANCODE_F4: exec_app ("./bmpbkgnd", "bmpbkgnd"); break; } } return HOOK_GOON;}static int ttys_pipe[2];static void child_wait (int sig){ int pid; int status; while ((pid = waitpid (-1, &status, WNOHANG)) > 0) { if (WIFEXITED (status)) printf ("--pid=%d--status=%x--rc=%d---\n", pid, status, WEXITSTATUS(status)); else if (WIFSIGNALED(status)) printf ("--pid=%d--signal=%d--\n", pid, WTERMSIG (status)); }}static char id_buf[15]; //储藏从串口读出的数据static char c[15];static int buf_key = 0;static void mes_wait (int sig){ int len = 0; //char c[15]; //MSG msg; printf("now in mes_wait haha\n"); memset(c,0,sizeof c); if(len = read(ttys_pipe[0],&c,15) < 0){ printf("read err\n"); } else{ buf_key = 1; printf("read proboly ok \n"); } printf ("the buf is %s",c); printf("\n"); //printf("before send message\n"); /* if(Send2TopMostClients( MSG_KEYUP, 75, 131200) == TRUE) printf ("send message ok\n"); else printf("send message err kuba\n"); if(Send2TopMostClients( MSG_CHAR, 75, 131200) == TRUE) printf ("send message ok\n"); else printf("send message err kuba\n"); printf("after send message \n"); */ //SendMessage(HWND_DESKTOP, MSG_KEYUP, 75, 131200);}/*监听串口,有数据发送相关信号*/static pid_t listenttys(void){ pid_t pid = 0; if ((pid = fork ()) > 0) { fprintf (stderr, "new child, pid: %d.\n", pid); } else if (pid == 0) { int ttys1_fb; int ret,res; char buf[15]; int fb,real_wnum; struct sigaction siga_mes; unsigned int num = 0; fd_set rds; siga_mes.sa_handler = mes_wait; siga_mes.sa_flags = 0; memset (&siga_mes.sa_mask, 0, sizeof(sigset_t)); sigaction (SIGUSR1, &siga_mes, NULL); ttys1_fb = initttyS1(); while(1){ FD_ZERO(&rds); FD_SET(ttys1_fb, &rds); //printf("before select\n"); //usleep(100000); ret = select(ttys1_fb + 1, &rds, NULL, NULL, NULL); //sleep(10); if (ret < 0) { perror("select"); exit(1); } if (ret == 0) { printf("Timeout.\n"); }else if (FD_ISSET(ttys1_fb, &rds)) { //usleep(100000); res = read(ttys1_fb,buf,15); buf[res] = 0; printf ("res = %d ",res); printf(":%s\n", buf); if(write(ttys_pipe[1],buf,15) < 0){ printf("ttys write err\n"); } else{ printf("ttys write okok \n"); } raise(SIGUSR1); } } _exit (1); } else { perror ("fork"); } return pid; }int MiniGUIMain (int args, const char* arg[]){ //static int ttyS1_fb; int fb; MSG msg; struct sigaction siga; siga.sa_handler = child_wait; siga.sa_flags = 0; memset (&siga.sa_mask, 0, sizeof(sigset_t)); sigaction (SIGCHLD, &siga, NULL); OnNewDelClient = on_new_del_client; if (!ServerStartup (0 , 0 , 0)) { fprintf (stderr, "Can not start the server of MiniGUI-Processes: mginit.\n"); return 1; } SetServerEventHook (my_event_hook); if (args > 1) { if (exec_app (arg[1], arg[1]) == 0) return 3; } else { if (exec_app ("./helloword", "helloworld") == 0) return 3; } old_tick_count = GetTickCount (); //memset(r_buf, 0, sizeof(r_buf));HWND_DESKTOP //memset(w_buf, 0, sizeof(w_buf)); if(pipe(ttys_pipe) == -1){ printf("open pipe error\n"); return -1; } listenttys(); //打开串口监听进程 while (!quit && GetMessage (&msg, HWND_DESKTOP)) { //SendMessage(HWND_DESKTOP, MSG_KEYDOWN, 75, 131200); //SendMessage(HWND_DESKTOP, MSG_KEYDOWN, 82, 131200); //printf("main msg.HWND = %d, msg.type=%d\n",msg.hwnd,msg.message); TranslateMessage(&msg); DispatchMessage (&msg); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -