⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alert.c

📁 采用MINIGUI开发的一套GUI界面
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/mgext.h>#include "common.h" #include "alert.h" LVSUBITEM subdata; LVITEM item;char date[20]; LVCOLOUM lvcol; int i;       	int  EventProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){        HWND alertList, reportList, reportTime, reportBack, reportForward ;	  HDC hdc;      PLSTVWDATA pLVInternalData;   	 RECT rect, rcClient;	    static char * alarm_caption [ALARM_LIST] =     {         "序号", "型式", "来源", "发生时间","清除时间","数值"     };     static char * report_caption [REPORT_LIST] =     {         "No", "型式", "名称", "数值","单位"      };     int width1[6] = {45,90,75,130,130,80};     int width2[6] = {50,110,90,220,80};    switch (message)    {      case MSG_CREATE:					  	break;    case MSG_INITDIALOG:    {        alertList = GetDlgItem (hDlg, IDC_ALERT_LIST);    reportList = GetDlgItem (hDlg, IDC_REPORT_LIST);    reportTime = GetDlgItem (hDlg, IDC_DATE);    reportBack = GetDlgItem (hDlg, IDC_LAST);    reportForward = GetDlgItem (hDlg, IDC_NEXT);   	 /*write listview headline*/	 		    alarm_number = 1;    period =  DAY;    alarm_table.num=1;    alarm_table.type="LoLo警报";    alarm_table.from="AI18";    alarm_table.value=1.2;		       	InitAlert(hDlg);	    InvalidateRect (GetDlgItem (hDlg, IDC_ALERT_LIST), NULL, FALSE);		for (i = 1; i <= ALARM_LIST; i++) {            lvcol.nCols = i;	     lvcol.pszHeadText = alarm_caption[i-1];	     lvcol.width = width1[i-1];        SendMessage (GetDlgItem (hDlg, IDC_ALERT_LIST), LVM_ADDCOLUMN, 0, (LPARAM) &lvcol);		} 	for (i = 1; i <= REPORT_LIST; i++) {            lvcol.nCols = i;	     lvcol.pszHeadText = report_caption[i-1];	     lvcol.width = width2[i-1];        SendMessage (GetDlgItem (hDlg, IDC_REPORT_LIST), LVM_ADDCOLUMN, 0, (LPARAM) &lvcol);		}     }    break;  case MSG_PAINT:  {    hdc = BeginPaint (GetDlgItem (hDlg, IDC_ALERT_LIST));     Draw (GetDlgItem (hDlg, IDC_ALERT_LIST), hdc);    EndPaint (GetDlgItem (hDlg, IDC_ALERT_LIST), hdc);   }break;   case MSG_COMMAND:    {        int id ;	  int rowNum;	 id= LOWORD (wParam);        if(IsWindowVisible (GetDlgItem (hDlg, IDC_ALERT_LIST))) {  	 switch (id){	  /*convert between eventAlert page and Report page*/		  case IDC_MODE:	  {	   ShowWindow(GetDlgItem (hDlg, IDC_ALERT_LIST),SW_HIDE) ;		   ShowWindow(GetDlgItem (hDlg, IDC_REPORT_LIST),SW_SHOW) ;	   ShowWindow(GetDlgItem (hDlg, IDC_DATE),SW_SHOW) ;	   ShowWindow(GetDlgItem (hDlg, IDC_LAST),SW_SHOW) ;	   ShowWindow(GetDlgItem (hDlg, IDC_NEXT),SW_SHOW);	   SetDlgItemText(hDlg, IDC_MODE,"模式\n报告"); 	   SetDlgItemText(hDlg, IDC_FIRST,"每日"); 	  }	 break;        case IDC_UP:	    	          /*             pLVInternalData = (PLSTVWDATA) GetWindowAdditionalData2 (GetDlgItem (hDlg, IDC_ALERT_LIST));             InvalidateRect (GetDlgItem (hDlg, IDC_ALERT_LIST), &rect, FALSE);              pLVInternalData->pItemSelected->bSelected = FALSE;	 sendmessage(GetDlgItem (hDlg, IDC_ALERT_LIST),LVM_SELECTITEM,rowNum -1,0);*/	 break;			 case IDC_DOWN:	 alarm_happen (GetDlgItem (hDlg, IDC_ALERT_LIST) ,&alarm_table);break;	      	 break;	 case IDC_ENTER:  	alarm_solve(GetDlgItem (hDlg, IDC_ALERT_LIST),1);break;	 break;	 case IDC_BACK:	 		 break;	alarm_over(GetDlgItem (hDlg, IDC_ALERT_LIST) ,3);break;	 	 break;	 case IDC_CLEAR :        alarm_clear(GetDlgItem (hDlg, IDC_ALERT_LIST));break;	 break;	 	 case IDC_DOWNLOAD :	  	// download_item(GetDlgItem (hDlg, IDC_ALERT_LIST));	        break;        case  IDC_CLOSE :              EndDialog (hDlg, 0);	 break;         }    }else {  	 switch (id){	  /*convert between eventAlert page and Report page*/		 case IDC_MODE:	  	{		       //  ShowWindow(GetDlgItem (hDlg, IDC_REPORT_LIST),SW_HIDE) ;		   ShowWindow(GetDlgItem (hDlg, IDC_ALERT_LIST),SW_SHOW) ;	   SetDlgItemText(hDlg, IDC_MODE,"模式\n事件");	 }	  		break;	 case IDC_NEXT : 	         forwardDate(hDlg);	 	  break;        case IDC_LAST : 	         backDate(hDlg);		  break;	 /*convert report period */	 case IDC_REPORT:	 {	   	 	if (period == DAY)	      {		period = WEEK;		SetDlgItemText(hDlg, IDC_FIRST,"报告\n每周");		}		else if(period == WEEK)		{              period = MONTH;              SetDlgItemText(hDlg, IDC_FIRST,"报告\n每月");              sprintf(date, "%04d年%02d月",report_date.year,report_date.month);	       SetDlgItemText(hDlg, IDC_DATE,date); 		}		else		{              period = DAY;              SetDlgItemText(hDlg, IDC_FIRST,"报告\n每日");              sprintf(date, "%02d/%02d/%04d",report_date.month,report_date.day,report_date.year);               SetDlgItemText(hDlg, IDC_DATE,date);		 }	 	 break;         }         }    }      break;   }  case MSG_CLOSE:    {		 	    EndDialog (hDlg, 0);    }    break;    }     return DefaultDialogProc (hDlg, message, wParam, lParam);}static intsGetSubItemWidth1 (int nCols, PLSTVWDATA pLVInternalData){  PLSTHDR p;  int nPosition;  nPosition = nCols;  if ((nCols < 1) || (nCols > pLVInternalData->nCols))    {      return -1;    }  p = pLVInternalData->pLstHead;  while (nPosition != 1)    {      nPosition--;      p = p->pNext;    }  return p->width;}static intsGetSubItemX1 (int nCols, PLSTVWDATA pLVInternalData){  PLSTHDR p;  int nPosition;  nPosition = nCols;  if ((nCols < 1) || (nCols > pLVInternalData->nCols))    {      return -1;    }  p = pLVInternalData->pLstHead;  while (nPosition != 1)    {      nPosition--;      p = p->pNext;    }  return p->x;}static intsGetItemWidth1 (PLSTVWDATA pLVInternalData){  PLSTHDR p;  int width;  p = pLVInternalData->pLstHead;  width = 0;  while (p != NULL)    {      width += p->width;      p = p->pNext;    }  return width;}static voidsDrawText1 (HDC hdc, int x, int y, int width, int height, const char *pszText){  RECT rect;  SIZE size;  rect.left = x + 2;  rect.top = y + 2;  rect.right = x + width;  rect.bottom = y + height;  if (pszText != NULL)    {      GetTextExtent (hdc, pszText, -1, &size);      if (width > size.cx)        {          DrawText (hdc, pszText, -1, &rect, DT_SINGLELINE | DT_LEFT);        }      else        {          DrawText (hdc, pszText, -1, &rect, DT_SINGLELINE | DT_LEFT);        }    }}static voidsDrawTextToSubItem1 (HDC hdc, const char *pszText, int nRows, int nCols,                    PITEMDATA pItem, PLSTVWDATA pLVInternalData){  int nOldBrushColor;  int x;  int y;  int temp1, temp2 = 0;  /*     char pszTemp[20]; */  int fit_char;  int *pos_char, *dx_char;  SIZE size;  int i;  RECT rect, rect1;  //RECT rect1;  if (!pItem->bSelected)    {      nOldBrushColor = SetBrushColor (hdc, GetBkColor (hdc));    }  else    {      nOldBrushColor = SetBrushColor (hdc, RGB2Pixel (hdc, 0, 0, LIGHTBLUE));    }  y =    (nRows - 1) * pLVInternalData->nItemHeight - pLVInternalData->nOriginalY;  x = sGetSubItemX1 (nCols, pLVInternalData) - pLVInternalData->nOriginalX;  FillBox (hdc, x, y + pLVInternalData->nHeadHeight,           sGetSubItemWidth1 (nCols, pLVInternalData),           pLVInternalData->nItemHeight);  SetBrushColor (hdc, nOldBrushColor);  if (pszText != NULL)    {      i = sGetSubItemWidth1 (nCols, pLVInternalData);      GetTextExtent (hdc, pszText, -1, &size);      rect.left = x + 2;      rect.right = x + i - 2;      rect.top = y + pLVInternalData->nHeadHeight + 2;      rect.bottom =        y + pLVInternalData->nItemHeight + pLVInternalData->nHeadHeight;      temp1 = SetTextColor (hdc, pItem->nTextColor);      if (pItem->bSelected)        {          temp2 = SetBkColor (hdc, RGB2Pixel (hdc, 0, 0, LIGHTBLUE));          SetTextColor (hdc, PIXEL_lightwhite);        }      if (i > size.cx)        {          DrawText (hdc, pszText, -1, &rect, DT_SINGLELINE | DT_LEFT);        }      else        {          pos_char = (int *) malloc (sizeof (int) * strlen (pszText));          dx_char = (int *) malloc (sizeof (int) * strlen (pszText));          GetTextExtent (hdc, "...", -1, &size);          GetTextExtentPoint (hdc,                              pszText, strlen (pszText), i - 4 - size.cx,                              &fit_char, pos_char, dx_char, &size);          rect.left = x + 2;          rect.right = x + 2 + size.cx;          rect.top = y + pLVInternalData->nHeadHeight + 2;          rect.bottom =            y + pLVInternalData->nItemHeight + pLVInternalData->nHeadHeight;          DrawText (hdc, pszText, -1, &rect, DT_SINGLELINE | DT_LEFT);          rect1.left = x + 2;          rect1.right = x + i - 2;          rect1.top = y + pLVInternalData->nHeadHeight + 2;          rect1.bottom =            y + pLVInternalData->nItemHeight + pLVInternalData->nHeadHeight;          DrawText (hdc, "...", -1, &rect1, DT_SINGLELINE | DT_RIGHT);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -