commdlg.cpp

来自「这是一个在正实际应用当中运行的电力监控系统软件源代码」· C++ 代码 · 共 1,742 行 · 第 1/5 页

CPP
1,742
字号
	  if (siono>=24&&siono<=31) 	 lpctk->BaudRate[5] = 3072/tmp;
	  if (siono>=32&&siono<=35)      lpctk->BaudRate[6] = 3072/tmp;
	  if (siono>=36&&siono<=39)      lpctk->BaudRate[7] = 3072/tmp;
	  if (siono>=40&&siono<=47)      lpctk->BaudRate[8] = 3072/tmp;
	  if (siono>=48&&siono<=51) 	 lpctk->BaudRate[9] = 3072/tmp;
	  if (siono>=52&&siono<=55) 	 lpctk->BaudRate[10] = 3072/tmp;
	  if (siono>=56&&siono<=63) 	 lpctk->BaudRate[11] = 3072/tmp;


	  tmp =(UINT) SendDlgItemMessage(HWindow, ID_SyncWCBox, CB_GETCURSEL, 0, 0);
      if (tmp==1) tmp = 0xd709;
        else tmp = 0xeb90;
      lpctk->SIOWriteReg[siono][6]=0x4600+(tmp/256);
      lpctk->SIOWriteReg[siono][7]=0x8700+(tmp&0xff);
//	  lpctk->SIOWriteReg[siono][4] = 0x0410; //jgx 98.8.20
	 }
    else if (IsDlgButtonChecked(HWindow,ID_SyncBRd2)==1)
     {   
	  if (IsDlgButtonChecked(HWindow, ID_DataBitBRd1)==1)
		  {lpctk->StopDataBits[siono]=1;
//		   lpctk->SIOWriteReg[siono][3]=0x1301;   //jgx
		  }
	  else if (IsDlgButtonChecked(HWindow, ID_DataBitBRd2)==1) {lpctk->StopDataBits[siono]=2;lpctk->SIOWriteReg[siono][3]=0x1341;}
	  else if (IsDlgButtonChecked(HWindow, ID_DataBitBRd3)==1) {lpctk->StopDataBits[siono]=3;lpctk->SIOWriteReg[siono][3]=0x1381;}
	  else if (IsDlgButtonChecked(HWindow, ID_DataBitBRd4)==1) {lpctk->StopDataBits[siono]=4;lpctk->SIOWriteReg[siono][3]=0x13c1;}
//	  lpctk->SIOWriteReg[siono][3]=0x13c1;
//      lpctk->BaudRate[siono/4] = 3072/tmp;

	  if (siono>=0 &&siono<=3)       lpctk->BaudRate[0] = 3072/tmp;
	  if (siono>=4 &&siono<=7)       lpctk->BaudRate[1] = 3072/tmp;
	  if (siono>=8 &&siono<=15)      lpctk->BaudRate[2] = 3072/tmp;
	  if (siono>=16&&siono<=19) 	 lpctk->BaudRate[3] = 3072/tmp;
	  if (siono>=20&&siono<=23) 	 lpctk->BaudRate[4] = 3072/tmp;
	  if (siono>=24&&siono<=31) 	 lpctk->BaudRate[5] = 3072/tmp;
	  if (siono>=32&&siono<=35)      lpctk->BaudRate[6] = 3072/tmp;
	  if (siono>=36&&siono<=39)      lpctk->BaudRate[7] = 3072/tmp;
	  if (siono>=40&&siono<=47)      lpctk->BaudRate[8] = 3072/tmp;
	  if (siono>=48&&siono<=51) 	 lpctk->BaudRate[9] = 3072/tmp;
	  if (siono>=52&&siono<=55) 	 lpctk->BaudRate[10] = 3072/tmp;
	  if (siono>=56&&siono<=63) 	 lpctk->BaudRate[11] = 3072/tmp;

	  tmp = lpctk->SIOWriteReg[siono][4]&0xff0f;
	  if (IsDlgButtonChecked(HWindow, ID_RatioBRd1)==1) { tmp |=0;  br=1; }
        else if (IsDlgButtonChecked(HWindow, ID_RatioBRd2)==1)  { tmp |= 0x40;  br=16; }
        else if (IsDlgButtonChecked(HWindow, ID_RatioBRd3)==1)  { tmp |= 0x80;  br=32; }
        else if (IsDlgButtonChecked(HWindow, ID_RatioBRd4)==1)  { tmp |= 0xc0;  br=64; }
//      lpctk->BaudRate[siono/4] /= br;
//--------------------jgx 99.1-------------------------------------
	  if (siono>=0 &&siono<=3)       lpctk->BaudRate[0] /= br;
	  if (siono>=4 &&siono<=7)       lpctk->BaudRate[1] /= br;
	  if (siono>=8 &&siono<=15)      lpctk->BaudRate[2] /= br;
	  if (siono>=16&&siono<=19) 	 lpctk->BaudRate[3] /= br;
	  if (siono>=20&&siono<=23) 	 lpctk->BaudRate[4] /= br;
	  if (siono>=24&&siono<=31) 	 lpctk->BaudRate[5] /= br;
	  if (siono>=32&&siono<=35)      lpctk->BaudRate[6] /= br;
	  if (siono>=36&&siono<=39)      lpctk->BaudRate[7] /= br;
	  if (siono>=40&&siono<=47)      lpctk->BaudRate[8] /= br;
	  if (siono>=48&&siono<=51) 	 lpctk->BaudRate[9] /= br;
	  if (siono>=52&&siono<=55) 	 lpctk->BaudRate[10]/= br;
	  if (siono>=56&&siono<=63) 	 lpctk->BaudRate[11]/= br;
//--------------------jgx 99.1-------------------------------------
	  tmp &= 0xfff3;
      if (IsDlgButtonChecked(HWindow, ID_StopBRd1)==1)  tmp |= 4;
        else if (IsDlgButtonChecked(HWindow, ID_StopBRd2)==1)  tmp |= 8;
        else if (IsDlgButtonChecked(HWindow, ID_StopBRd3)==1)  tmp |= 0xc;
      tmp &= 0xfffc;
      if (IsDlgButtonChecked(HWindow, ID_VerifyBRd1)==1)  tmp |= 1;
        else if (IsDlgButtonChecked(HWindow, ID_VerifyBRd2)==1)  tmp |= 3;
	  lpctk->SIOWriteReg[siono][4] = tmp;
	 }
 }


void TSetCTKSIODialog::SetEnable(BOOL flag)
{
     EnableWindow(GetDlgItem(HWindow,ID_SyncWCBox),!flag);
     for (int i=ID_RatioBRd1; i<=ID_StopBRd3; i++)
          EnableWindow(GetDlgItem(HWindow,i),flag);
	 for (i=ID_DataBitBRd1; i<=ID_DataBitBRd4; i++)
          EnableWindow(GetDlgItem(HWindow,i),flag);//FALSE);
}

void TSetCTKSIODialog::WMCommand(RTMessage msg)
{
 TDialog::WMCommand(msg);

 switch(msg.WParam)
   {
    case ID_SyncBRd1:
		 lpctk->SIOWriteReg[siono][3]=0x13d1;
//		 lpctk->SIOWriteReg[siono][4]=0x0410;  //jgx 98.8.20
         SetSIOInitData();
         break;
    case ID_SyncBRd2:
		 if (lpctk->StopDataBits[siono]==1) lpctk->SIOWriteReg[siono][3]=0x1301;
		 else if (lpctk->StopDataBits[siono]==2) lpctk->SIOWriteReg[siono][3]=0x1341;
		 else if (lpctk->StopDataBits[siono]==3) lpctk->SIOWriteReg[siono][3]=0x1381;
		 else if (lpctk->StopDataBits[siono]==4) lpctk->SIOWriteReg[siono][3]=0x13c1;
//		 lpctk->SIOWriteReg[siono][3]=0x13c1;
         SetEnable(TRUE);
         break;
	case ID_SioList:
		 GetSIOData();
		 siono =(UINT) SendDlgItemMessage(HWindow, ID_SioList, LB_GETCURSEL, 0, 0);
         if (siono!=LB_ERR)
		 SetSIOInitData();
		 break;
	case ID_InitPBt:
         GetSIOData();
         if (HardwareInstallFlag[CTKBOARD])  InitSIO(siono);
         break;
    case ID_ExitPBt:
    case IDOK:
         GetSIOData();
		 CloseWindow(IDOK);
         break;
    case ID_WritePBt:
         GetSIOData();
         GetApplication()->ExecDialog(new TWriteRegDialog(this, lpctk, siono));
         break;
    case IDCANCEL:  //tzc
         ReadCTKSIO(lpctk);
         break;
         
   }
}

//-------------------------------------------------------------------------------------------//
TBaudRateDialog::TBaudRateDialog (PTWindowsObject AParent, CTKSIO FAR *lpCTK)
                : TDialog(AParent, "BAUDRATE_DLG")
{
  lpctk = lpCTK;
}

void TBaudRateDialog::WMInitDialog(RTMessage msg)
{
 TDialog::WMInitDialog(msg);
 for (int i=0; i<12; i++)
     SetDlgItemInt(HWindow, ID_BaudEdit1+i, lpctk->BaudRate[i], FALSE);
}
//tzc
void TBaudRateDialog::WMCommand(RTMessage msg)
{
 TDialog::WMCommand(msg);

 switch(msg.WParam)
   {
    case    IDOK:
			char s[5];
            int  temp;
            for (int i=0;i<12;i++)
                {
                    s[0]=s[1]=s[2]=s[3]=0;
                    int k=GetDlgItemText(HWindow,ID_WriteEdit1+i,s,5);
                    temp=0;                    
                    for (int j=0;j<k;j++)
                       {
                         if (s[j]>'9' || s[j]<'0') {j=100;break;}
                         else s[j]-='0';
                         temp=temp*10+s[j];
                       }
                    if (j!=100) lpctk->BaudRate[i]=temp;
                }

            break;
    case    IDCANCEL:
            break;
   }
}




//-------------------------------------------------------------------------------------------//
TWriteRegDialog::TWriteRegDialog (PTWindowsObject AParent, CTKSIO FAR *lpCTK, int SIONo)
                : TDialog(AParent, "WRITEREG_DLG")
{
  lpctk = lpCTK;
  siono = SIONo;

  hbr = CreateSolidBrush (RGB(255, 0, 0));
}

TWriteRegDialog::~TWriteRegDialog()
{
  DeleteObject(hbr);
}

void TWriteRegDialog::WMInitDialog(RTMessage msg)
{
 TDialog::WMInitDialog(msg);

 char wr[8];
 for (int i=0; i<8; i++)
     {
      sprintf(wr, "%04x", lpctk->SIOWriteReg[siono][i]);
      SetDlgItemText(HWindow, ID_WriteEdit1+i, (LPSTR)wr);
	 }
}

HBRUSH TWriteRegDialog::WMCtrlColor(RTMessage msg)
{
//  if (HIWORD(msg.LParam)==CTLCOLOR_EDIT)
//     {
      SetTextColor((HDC) msg.WParam, RGB(255, 255, 255));
      SetBkColor((HDC) msg.WParam, RGB(255, 0, 0));

      return hbr;
//     }
//  return NULL;
}
//tzc
void TWriteRegDialog::WMCommand(RTMessage msg)
{
 TDialog::WMCommand(msg);

 switch(msg.WParam)
   {
    case    IDOK:
            char s[10];
            int  temp;
            for (int i=0;i<8;i++)
                {
                    s[0]=s[1]=s[2]=s[3]=0;
                    int k=GetDlgItemText(HWindow,ID_WriteEdit1+i,s,5);
                    temp=0;                    
                    for (int j=0;j<k;j++)
                       {
                         if (s[j]<='9')  s[j]=s[j]-'0';
                         else if (s[j]>'9' &&s[j]<'g') s[j]=s[j]-'a'+10;
                         else if (s[j]>'f' || s[j]<'0') {j=100;break;}
                         temp=temp*16+s[j];
                       }
					if (j!=100) lpctk->SIOWriteReg[siono][i]=temp;
                }

            break;
    case    IDCANCEL:
            break;
   }
}

void    DecServerStatus::WMInitDialog(RTMessage msg)
{

}
void    DecServerStatus::WMCommand(RTMessage msg)
{
TDialog::WMCommand(msg);

}
void    CommStatus::WMInitDialog(RTMessage msg)
{
 TDialog::WMInitDialog(msg);
 int ii,cards;
 cards=syscfg->GetCommCardNums();
 SetDlgItemInt(HWindow, ID_CommNums, cards, FALSE);
 char chr[20],temp[4];
 for(ii=1; ii<=cards*8+2;ii++)
		{
        sprintf (chr," %d%d%d",ii/100,ii%100/10,ii%10);
		SendDlgItemMessage(HWindow,ID_CommList,CB_ADDSTRING,0,(LONG)(LPSTR)chr);
		}
 for (ii=0; ii<TotalChNum; ii++)
     {
      wsprintf (chr,"%d号通道",ii);
      SendDlgItemMessage(HWindow, ID_CHANEL1, CB_ADDSTRING, ii, (LONG)(LPSTR)chr);
      SendDlgItemMessage(HWindow, ID_CHANEL2, CB_ADDSTRING, ii, (LONG)(LPSTR)chr);
     }
 for (ii=0;ii<80;ii++) CommPara1[ii]=CommPara[ii];
SendDlgItemMessage(HWindow,ID_CommList,CB_SETCURSEL,0,0);
CheckRadio(0);
Radio=0;
}
void    CommStatus::WMCommand(RTMessage msg)
{
 TDialog::WMCommand(msg);
 WORD temp;
 switch(msg.WParam)
     {   
        case    ID_Open:
                break;
        case    ID_CommList:       case    ID_Used:
        case    ID_CommCardBaud+0: case    ID_CommCardBaud+1:  case    ID_CommCardBaud+2:
        case    ID_CommCardBaud+3: case    ID_CommCardBaud+4:  case    ID_CommCardBaud+5:
        case    ID_CommCardBaud+6: case    ID_CommCardBaud+7:
        case    ID_CHANEL1:        case    ID_CHANEL2:
		        UINT tmp=(UINT)SendDlgItemMessage(HWindow, ID_CHANEL1, CB_GETCURSEL, 0, 0);
                CommPara1[Radio].CHANEL1 = tmp;
		        tmp=(UINT)SendDlgItemMessage(HWindow, ID_CHANEL2, CB_GETCURSEL, 0, 0);
                CommPara1[Radio].CHANEL2 = tmp;

                for(int Button=0;Button<8;Button++)
                {
                    if (msg.WParam-ID_CommCardBaud<=7 && msg.WParam-ID_CommCardBaud>=0)
                    if(Button==(msg.WParam-ID_CommCardBaud))  SendDlgItemMessage(HWindow,ID_CommCardBaud+Button,BM_SETCHECK,1,0l);
                    else SendDlgItemMessage(HWindow,ID_CommCardBaud+Button,BM_SETCHECK,0,0l);
                }
                SaveCommData();
              	temp=SendDlgItemMessage(HWindow, ID_CommList, CB_GETCURSEL, 0, 0);
                if (temp==(WORD)LB_ERR) break;
                Radio=temp;
                CheckRadio(Radio);
                break;
        case    IDOK:
                                        
                for (int i=0;i<80;i++)  CommPara[i]=CommPara1[i];
                SaveCommBaudFile();
                BYTE cards=syscfg->GetCommCardNums();
                for (i=1;i<=cards*8+2;i++)
                    {
                        if (idComDev[i]>=0) CloseComm(idComDev[i]);
                        if (InputCommMem[i]) GlobalFree(InputCommMem[i]);
                        if (OutputCommMem[i]) GlobalFree(OutputCommMem[i]);
                    }
                    InitAllComm();
                    InitAllModem();
                for (int ii=0;ii<TotalChNum;ii++)    InitOneModem(ii);
                break;
        case    IDCANCEL:
                break;

     }
}
void SaveCommBaudFile()
{
 OFSTRUCT OfS;

 HFILE hf = OpenFile ((LPSTR)"c:\\TCZ\\Commcard.dat", (LPOFSTRUCT)&OfS, OF_CREATE);
 if (hf != HFILE_ERROR)
    {
     _lwrite(hf, &CommPara[0], 80*sizeof (COMMPARA));
     _lclose(hf);
    }

}
void CommStatus::SaveCommData()
{
BYTE    temp,i;
for (i=0;i<8;i++) if (IsDlgButtonChecked(HWindow,ID_CommCardBaud+i)==1) break; temp=i;
CommPara1[Radio].COMMBAUD=temp;
CommPara1[Radio].Used =(BOOL)IsDlgButtonChecked(HWindow, ID_Used);
CommPara1[Radio].CHANEL1=SendDlgItemMessage(HWindow, ID_CHANEL1, CB_GETCURSEL, 0, 0);
CommPara1[Radio].CHANEL2=SendDlgItemMessage(HWindow, ID_CHANEL2, CB_GETCURSEL, 0, 0);
}
void CommStatus::CheckRadio(BYTE COMMNO)
{
SendDlgItemMessage(HWindow, ID_CHANEL1,CB_SETCURSEL,CommPara1[COMMNO].CHANEL1,0);
SendDlgItemMessage(HWindow, ID_CHANEL2,CB_SETCURSEL,CommPara1[COMMNO].CHANEL2,0);

⌨️ 快捷键说明

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