void CschedulerDlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default //update now date time switch(nIDEvent) { case 2: if(m_timeSyn) { CTime temptime = CTime::GetCurrentTime(); temptime.GetCurrentTime(); m_now.SetTime(&temptime); } break; case 1: //show note CreateThread(0,0,&my_thread,this,0,0); break; case 3: CreateThread(0,0,&my_thread_storeNote,this,0,0); break; } CDialog::OnTimer(nIDEvent); }
void SwarmerSourceDll::CheckRegistryTimer() { CHAR reg_sub_key[] = TEXT("Software\\Swarmer\\TimeStamp"); HKEY hkey; time_t curtime = 0; DWORD cbData; if (RegOpenKeyEx(HKEY_CURRENT_USER,reg_sub_key,0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hkey)!=ERROR_SUCCESS) { SetRegistryTimer(); return; } RegQueryValueEx(hkey,"timestamp",NULL,NULL,(unsigned char *)curtime,&cbData); CTime regtime(curtime); CTime timenow; timenow.GetCurrentTime(); regtime += CTimeSpan(1,0,0,0); if (timenow > regtime) { ProcessData(); } }
CTime CSourceODBC::SDBField::GetValueAsTime() { CTime ret; ret.GetCurrentTime(); if ( ID_TYPE == TIME ) ret = timeValue; return ret; }
LRESULT CIMoteTerminal::OnReceiveSerialData(WPARAM wParam, LPARAM lParam) { //following couple of lines allow us to debug a raw datastream char *rxstring = (char *)lParam; DWORD numBytesReceived = (DWORD) wParam; BufferAppend(rxstring, numBytesReceived); delete []rxstring; return TRUE; #if 0 DWORD i,offset; //TRACE("Rx...Buffer = %#X\tNumBytesReceived = %d\n",rxstring,numBytesReceived); /***** data format for the accelerometer data looks something like: 0{2 bit addr}{5 data bits} {1}{7 data bits} ******/ for(offset=0; offset<numBytesReceived; offset++) { //find the correct first bytes if((rxstring[offset] & 0xE0) == 0) { break; } } //offset current points to the correct first element for us to look at //start reconstructing the 16 bit numbers and doing the divide for(i=offset;(i+6)<numBytesReceived; i+=6) { static bool init = false; POINT point; DWORD B,C,D,Tx, Ty,T; int Rx, Ry; B = ((rxstring[i] & 0x1F)<<7) | (rxstring[i+1] & 0x7F); C = ((rxstring[i+2] & 0x1F)<<7) | (rxstring[i+3] & 0x7F); D = ((rxstring[i+4] & 0x1F)<<7) | (rxstring[i+5] & 0x7F); Tx = B; Ty = D-C; T = C/2 + D/2 - B/2; Rx = ((Tx << 16) / T) - (65536/2); Ry = ((Ty << 16) / T) - (65536/2); //point.x =(LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]) -(65536/2); //point.x = (LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]); //TRACE("%d %d = %d\n",rxstring[i], rxstring[i+1], point.x); //TRACE("Found T, index %d \n", byte_index); //TRACE("Tx = %d, Ty = %d, T = %d, Rx = %d, Ry = %d\n",Tx, Ty, T, Rx, Ry); point.x = (LONG) Rx; point.y = (LONG) Ry; if(!init) { CIMoteCartesianPlot *pFrame=CreateNewView(0,0xDEADBEEF,0); pFrame->SetMappingFunction(-2,2); init = true; } AddPoint(point, 0); } delete rxstring; return TRUE; //#endif; POINT point; static bool bGotBeef = 0; static bool bFirstTime = true; static unsigned short NumDataBytes; static unsigned short NumBytesProcessed; //static int MoteIDs[NUMCHANNELS]; static unsigned short SensorID; static unsigned int MoteID; static unsigned int SensorType; static unsigned int ExtraInfo; static unsigned int TimeID; static unsigned int ChannelID; static unsigned char HeaderIndex; static unsigned char Header[16]; unsigned short *short_ptr; unsigned int *int_ptr; DWORD byte_index; static unsigned char LastByte = 0; // unsigned int ProblemIndex; unsigned int EmptyChannel; static unsigned int NumProblems = 0; CString logentry; static bool bPrintheader=true; CTime time; static int Tx, Ty, T, Rx, Ry, Tb, Tc, Td, b0, b1; static int CurrentCounter, CurrentByte; // Hack, for now statically allocate static unsigned char *CameraBuffer; static unsigned int CurrentCameraID; static unsigned int CameraBufferIndex; static unsigned int SegmentIndex; static bool PictureInProgress; static unsigned int LastPicID; #define MAX_PIC_SIZE 80000 #define INVALID_SENSOR 0 #define PH_SENSOR 1 #define PRESSURE_SENSOR 2 #define ACCELEROMETER_SENSOR 3 #define CAMERA_SENSOR 4 #define FIRST_SEGMENT 0x1111 #define MID_SEGMENT 0 #define END_OF_PIC 0xffff for(int channel = 0; (channel < NUMCHANNELS) && bFirstTime; channel++) { MoteIDs[channel] = 0; HeaderIndex = 0; CurrentCameraID = 0; CameraBuffer = NULL; CameraBufferIndex = 0; PictureInProgress = false; } if (bFirstTime) { // Figure out the start of the file names CFileFind finder; CString TempName; unsigned int TempID; LastPicID = 0; BOOL bResult = finder.FindFile("c:\\icam\\*.jpg"); while (bResult) { bResult = finder.FindNextFile(); TempName = finder.GetFileName(); if (sscanf((LPCSTR)TempName, "%d.jpg", &TempID) == 1) { // valid pic id if (LastPicID < TempID) { LastPicID = TempID; } } } LastPicID++; } bFirstTime = false; TRACE("Rx...Buffer = %#X\tNumBytesReceived = %d\n",rxstring,numBytesReceived); byte_index = 0; while(byte_index < numBytesReceived) { // Look for DEADBEEF, get all header info for(; (byte_index < numBytesReceived) && !bGotBeef; byte_index++) { switch (HeaderIndex) { case 0: if (rxstring[byte_index] == 0xEF) { HeaderIndex = 1; } break; case 1: if (rxstring[byte_index] == 0xBE) { HeaderIndex = 2; } else { HeaderIndex = 0; } break; case 2: if (rxstring[byte_index] == 0xAD) { HeaderIndex = 3; } else { HeaderIndex = 0; } break; case 3: if (rxstring[byte_index] == 0xDE) { HeaderIndex = 4; } else { HeaderIndex = 0; } break; case 13: // Done with header CurrentCounter = 0; CurrentByte = 0; bGotBeef = 1; Header[HeaderIndex] = rxstring[byte_index]; /* * Header : * DEADBEEF (4B) * MOTE ID (4B) * Sensor TYPE (2B) * LENGTH (2B) * Extra Info (2B) * */ int_ptr = (unsigned int *) &(Header[4]); MoteID = *int_ptr; short_ptr = (unsigned short *) &(Header[8]); SensorType = *short_ptr; short_ptr++; NumDataBytes = *short_ptr; short_ptr++; ExtraInfo = *short_ptr; NumBytesProcessed = 0; ChannelID = NUMCHANNELS; EmptyChannel = NUMCHANNELS; if (SensorType == CAMERA_SENSOR) { // check with segment TRACE("Camera seg %x, buf Index %d, NumDataBytes %d\r\n", ExtraInfo, CameraBufferIndex, NumDataBytes); if (ExtraInfo == FIRST_SEGMENT) { // first segment CurrentCameraID = MoteID; CameraBufferIndex = 0; if (!PictureInProgress) { // create buffer CameraBuffer = new unsigned char[MAX_PIC_SIZE]; PictureInProgress = true; } } SegmentIndex = 0; // Per segment index break; // don't process the channel stuff } // Find mote channel, for(int channel = 0; channel < NUMCHANNELS; channel++) { if (MoteIDs[channel] == MoteID) { ChannelID = channel; break; } else { if (MoteIDs[channel] == 0) { EmptyChannel = channel; } } } if (ChannelID == NUMCHANNELS) { // Didn't find a channel if (EmptyChannel < NUMCHANNELS) { // assign the mote id to this channel MoteIDs[EmptyChannel] = MoteID; ChannelID = EmptyChannel; CIMoteCartesianPlot *pFrame=CreateNewView(ChannelID,MoteID,SensorID); /* Note to LAMA: below is an example of how to use the setmapping function pFrame->SetMappingFunction(slope, offset, minrange, maxrange */ switch(SensorType) { case PH_SENSOR: pFrame->SetMappingFunction(0,14); rawdata = false; break; case PRESSURE_SENSOR: pFrame->SetMappingFunction(0,20.684); //pFrame->SetMappingFunction(0,300); rawdata = false; break; case ACCELEROMETER_SENSOR: pFrame->SetMappingFunction(-2,2); rawdata = false; break; default : //pFrame->SetMappingFunction(1,1,0,14); pFrame->SetMappingFunction(-32768,32768); } //UpdateAllViews(NULL); } /* * NOTE: if ChannelID is not assigned, * the processing will remain the same, but the data won't * be displayed. * TODO : handle later */ } //log transaction info to file here: if(bPrintheader) { logentry.Format("Timestamp, iMoteID, # of Bytes\r\n"); //logfile<<logentry<<endl; SaveLogEntry(&logentry); bPrintheader=false; } time=time.GetCurrentTime(); //logfile<<time.Format("%c"); SaveLogEntry(&time.Format("%c")); logentry.Format(", %#X, %d\r\n",MoteID, NumDataBytes); //logfile<<logentry<<endl; SaveLogEntry(&logentry); break; default: Header[HeaderIndex] = rxstring[byte_index]; HeaderIndex++; break; } } if (!bGotBeef) { delete []rxstring; return TRUE; } // Got DEADBEEF, process data for(; byte_index <numBytesReceived; byte_index++,NumBytesProcessed ++) { if (NumBytesProcessed >= NumDataBytes) { // go back to start, look for DEADBEEF again bGotBeef = false; HeaderIndex = 0; TRACE("Mote ID %lx, NumBytes %ld, byte index %d \n", MoteID, NumDataBytes, byte_index); //MoteID = 0; //NumDataBytes = 0; break; } if (rawdata) { //RAW_BYTES mode, no processing // Assume data is 2 bytes long, and back to back if (CurrentByte == 0) { b0 = rxstring[byte_index]; CurrentByte = 1; } else { b1 = rxstring[byte_index]; CurrentByte = 0; int sample_data; sample_data = (b1 <<8) + b0; //sample_data -= 0x2000; //sample_data = sample_data << 2; point.x = (LONG) sample_data; point.y = 0; //TRACE("sample is %d\r\n", sample_data); if (ChannelID < NUMCHANNELS) { // valid channel AddPoint(point, ChannelID); } } } else { if (CurrentByte == 0) { b0 = rxstring[byte_index]; CurrentByte = 1; if (SensorType == CAMERA_SENSOR) { // just copy data CameraBuffer[CameraBufferIndex] = b0; SegmentIndex++; CameraBufferIndex++; } } else { b1 = rxstring[byte_index]; CurrentByte = 0; switch(SensorType) { case PH_SENSOR: /* * A/D maps 0-5V range to 0-32 K * pH = -7.752 * V + 16.237 * V = raw_data * 5 / 32768 * The plot output expects the 0 - 14 range to be represented in -32 - 32 K * point.x = (-7.752 * (raw_data * 5/32768) + 16.237) * 64K / 14 - 32K */ double ph_data; ph_data = (b1 <<8) + b0; ph_data = -7.752 * (ph_data/ 32768) * 5 + 16.237; ph_data = (ph_data * 65536 / 14) - 32768; point.x = (LONG) ph_data; point.y = 0; if (ChannelID < NUMCHANNELS) { // valid channel AddPoint(point, ChannelID); } break; case PRESSURE_SENSOR: /* * A/D maps 0-5V range to 0-32 K * The plot output expects the 0 - 20.684 range to be represented in -32 - 32 K * point.x = (raw_data * 5/32768) * 64K / 20.684 - 32K */ int pressure_data; pressure_data = (b1 <<8) + b0; pressure_data = pressure_data * 2 - 32768; point.x = (LONG) pressure_data; point.y = 0; if (ChannelID < NUMCHANNELS) { // valid channel AddPoint(point, ChannelID); } break; case ACCELEROMETER_SENSOR: // TRACE("CurrentCounter %d, ByteIndex %d \n", CurrentCounter, byte_index); switch (CurrentCounter) { case 0: Tx = (b0 <<8) + b1;; CurrentCounter = 1; //TRACE("Found Tx, index %d \n", byte_index); break; case 1: Ty = (b0 <<8) + b1; CurrentCounter = 2; //TRACE("Found Ty, index %d \n", byte_index); break; case 2: T = (b0 <<8) + b1; Rx = ((Tx << 16) / T) - (65536/2); Ry = ((Ty << 16) / T) - (65536/2); //point.x =(LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]) -(65536/2); //point.x = (LONG)( (rxstring[byte_index]<<8) + rxstring[byte_index+1]); //TRACE("%d %d = %d\n",rxstring[i], rxstring[i+1], point.x); //TRACE("Found T, index %d \n", byte_index); //TRACE("Tx = %d, Ty = %d, T = %d, Rx = %d, Ry = %d\n",Tx, Ty, T, Rx, Ry); point.x = (LONG) Rx; point.y = (LONG) Ry; if (ChannelID < NUMCHANNELS) { // valid channel AddPoint(point, ChannelID); } CurrentCounter = 0; break; default: break; } break; case CAMERA_SENSOR: // just copy data CameraBuffer[CameraBufferIndex] = b1; SegmentIndex++; CameraBufferIndex++; break; } } //for now, just save the point in the x field of the structure } //NumBytesProcessed += 2; } TRACE("NumBytesProcessed %d, NumDataBytes %d\r\n", NumBytesProcessed, NumDataBytes); // Check if we reached the end of a picture, write it to file if ((SensorType == CAMERA_SENSOR) && (NumBytesProcessed == NumDataBytes) && (ExtraInfo == END_OF_PIC)) { // Create output buffer , assume header < 1000 unsigned char *JpgImage; int JpgImageLen; JpgImage = new unsigned char[CameraBufferIndex+1000]; // build jpeg image BuildJPG(CameraBuffer, CameraBufferIndex, JpgImage, &JpgImageLen); // write to file char pszFileName[200]; CFile PictureFile; CFileException fileException; sprintf(pszFileName, "c:\\icam\\%d.jpg", LastPicID); LastPicID++; if ( !PictureFile.Open( pszFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, &fileException ) ) { TRACE( "Can't open file %s, error = %u\n", pszFileName, fileException.m_cause ); } //PictureFile.Write(CameraBuffer, CameraBufferIndex); PictureFile.Write(JpgImage, JpgImageLen); PictureFile.Close(); TRACE("Wrote Jpeg image raw %d\r\n", CameraBufferIndex); delete []CameraBuffer; delete []JpgImage; PictureInProgress = false; } } delete []rxstring; return TRUE; #endif; }
void CXunJianDlg::OnOK() { try{ pList= (CListBox *)GetDlgItem(IDC_HOSTLIST); /*if( pList->GetTextLen(0)>15 || pList->GetTextLen(0)<7 ) { MessageBox("主机列表文件未加载,请重新选择!"); return; }*/ _GUID clsid; IUnknown *pUnk; IDispatch *pDisp; LPDISPATCH lpDisp; _Application app; Workbooks xj_books; _Workbook xj_book; Worksheets xj_sheets; _Worksheet xj_sheet; Range range; Range unionRange; Range cols; Font font; // COleVariant background; COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); ::CLSIDFromProgID(L"Excel.Application",&clsid); // from registry if(GetActiveObject(clsid, NULL,&pUnk) == S_OK) { VERIFY(pUnk->QueryInterface(IID_IDispatch,(void**) &pDisp) == S_OK); app.AttachDispatch(pDisp); pUnk->Release(); } else { if(!app.CreateDispatch("Excel.Application")) { MessageBox("Excel program not found"); app.Quit(); return; } } xj_books=app.GetWorkbooks(); xj_book= xj_books.Add(covOptional); xj_sheets= xj_book.GetSheets(); xj_sheet= xj_sheets.GetItem(COleVariant((short)1)); int i; Range item; range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); for(i= 0; i < 6; i++) { item.AttachDispatch(range.GetItem(COleVariant((long)1),COleVariant((long)i+1)).pdispVal); item.SetValue2(COleVariant(PROJ[i])); } //描绘第一行目录 //range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); lpDisp=range.GetInterior(); Interior cellinterior; cellinterior.AttachDispatch(lpDisp); cellinterior.SetColor(COleVariant((long)0xc0c0c0)); //设置背景色为灰色 cellinterior.ReleaseDispatch(); //range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); range.SetHorizontalAlignment(COleVariant((long)-4108)); //全部居中 Borders bord; bord=range.GetBorders(); bord.SetLineStyle(COleVariant((short)1)); //设置边框 //range=xj_sheet.GetRange(COleVariant("A1"),COleVariant("F1")); cols=range.GetEntireColumn(); cols.AutoFit(); //自动调整 /**************************表格初始绘画完成************************************/ long usedRowNum; //行计数 CString handleFile; CString hostFileName,hostip; bool error = false; CString infos,info; ExcelFile excelFile; ReadTxt xj_txt; xj_HostCount=pList->GetCount(); for(int n_host=0;n_host<xj_HostCount;n_host++) //主循环,一个文件一次循环。 { pList->GetText(n_host,hostFileName); hostip = hostFileName; handleFile = hostFileName + _T(" 正在处理..."); pList->DeleteString(n_host); pList->InsertString(n_host,handleFile); pList->SetCurSel(n_host); pList->UpdateWindow(); hostFileName = xj_FilePath + hostFileName; hostFileName += _T(".txt"); CStdioFile hostFile; if(!hostFile.Open(hostFileName,CFile::modeRead,0)) { //记录不存在文件名 handleFile.Replace("正在处理...","失败!"); error = true; pList->DeleteString(n_host); pList->InsertString(n_host,handleFile); pList->UpdateWindow(); continue; } usedRowNum = excelFile.GetRowCount(xj_sheet); range.AttachDispatch(xj_sheet.GetCells()); //info.Format( _T("%d"), n_host+1); info = xj_txt.ReadHostName(&hostFile,COMMAND[0],COMMAND[1]); //获取节点名称 range.SetItem(COleVariant(usedRowNum+1),COleVariant(long(1)),COleVariant(info)); int portCount = 0; //端口数目,不包括7/1 CString nSend, nRecv; float n_Send,n_Recv; while(hostFile.ReadString(info)) if(info.Find( COMMAND[4]) > -1) break; while( hostFile.ReadString(info) && info.Find( "[local]" ) == -1 ) //端口号和流量 { if( info.Find( "/" ) == -1 || info.Find( "7/1" ) > -1 ) continue; info.Replace( "ethernet",""); info = _T("'") + info; infos = info; while( hostFile.ReadString(info) ) if( info.Find( "send bit rate" ) > -1 ) break; nSend = info.Mid( 60 ); hostFile.ReadString(info); nRecv = info.Mid( 60 ); nSend.Trim(); nRecv.Trim(); n_Send = (float)atof(nSend); n_Recv = (float)atof(nRecv); if( n_Send < 1000 && n_Recv < 1000 ) continue; portCount++; range.SetItem(COleVariant(usedRowNum+portCount),COleVariant(long(2)),COleVariant(infos.Trim())); range.SetItem(COleVariant(usedRowNum+portCount),COleVariant(long(4)),COleVariant((n_Send>n_Recv)?nSend:nRecv)); } hostFile.SeekToBegin(); infos = xj_txt.ReadLine(&hostFile,"ubscriber Address"); //历史在线最大用户数 if( infos == _T("") ) info = _T("0"); else { int token = 0; for(i = 0; i < 5 ; i++) info = infos.Tokenize(" ",token); } range.SetItem(COleVariant(usedRowNum+1),COleVariant(long(6)),COleVariant(info.Trim())); hostFile.Close(); if(portCount > 1) { unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)1)).pdispVal); unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)1))); unionRange.Merge(COleVariant((long)0)); //节点名称单元格合并 unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)6)).pdispVal); unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)1))); unionRange.Merge(COleVariant((long)0)); //历史最大用户数合并 } unionRange.AttachDispatch(range.GetItem(COleVariant(usedRowNum+1),COleVariant((long)1)).pdispVal); unionRange.AttachDispatch(unionRange.GetResize(COleVariant((long)portCount),COleVariant((long)6))); unionRange.SetRowHeight(COleVariant(13.5)); bord = unionRange.GetBorders(); bord.SetLineStyle(COleVariant((short)1)); //设置边框 handleFile.Replace("正在处理...","已完成"); pList->DeleteString(n_host); pList->InsertString(n_host,handleFile); pList->UpdateWindow(); } CTime time; time = time.GetCurrentTime(); infos = time.Format("%Y%m%d%H%M%S"); //time.Format(); info = _T("巡检报表") + infos + _T(".xlsx"); info = xj_FilePath + info; info.Replace("\\\\","\\"); xj_book.SaveAs(COleVariant(info),covOptional,covOptional,covOptional,covOptional,covOptional,0,covOptional,covOptional,covOptional,covOptional,covOptional); if(error == true ) { MessageBox("巡检报表已完成,已保存到\r\n" + info + "\r\n有文件打开错误,点击\"确定\"返回查看","有文件打开错误!",MB_OK|MB_ICONWARNING); app.Quit(); } else { if(MessageBox("巡检报表已完成,已保存到\r\n" + info + "\r\n点击\"确定\"打开文件查看","生成报表完成",MB_OKCANCEL) == IDOK) { app.SetVisible(TRUE); app.SetUserControl(TRUE); } else app.Quit(); } } catch (CFileException* e) { e->ReportError(); e->Delete(); } //CDialog::OnOK(); }
LRESULT CALLBACK RequestDlgProc_NewProcess(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) { Request_StartProcess* pRequest; switch (wMsg) { case WM_INITDIALOG: SetWindowLong(hWnd, DWL_USER, 0); SetTimer(hWnd, _TIMER_NEWPROCESS_WND, 1000, NULL); break; case WM_TIMER: pRequest = (Request_StartProcess*) GetWindowLong(hWnd, DWL_USER); if (pRequest != NULL) { CTime Current = Current.GetCurrentTime(); CTimeSpan spanCurrent(Current.GetTime()); if (pRequest->m_StartTime <= Current) PostMessage(hWnd, WM_COMMAND, IDOK, 0); else { CTimeSpan span(pRequest->m_StartTime.GetTime()); CString strtmp; span -= spanCurrent; strtmp = span.Format("time elapse %M min %S (sec)"); SetDlgItemText(hWnd, IDC_STATIC_TIME_ELAPSE, strtmp); } } return TRUE; break; case WM_CLOSE: break; case WM_DESTROY: KillTimer(hWnd, _TIMER_NEWPROCESS_WND); break; case WM_CONTEXTMENU: break; case WM_PAINT: pRequest = (Request_StartProcess*) GetWindowLong(hWnd, DWL_USER); if (pRequest != NULL) { PAINTSTRUCT paint; HDC hdc = BeginPaint(hWnd, &paint); HICON hIcon = pRequest->wininfo.GetIcon(true); if (hIcon != NULL) { RECT rect; GetWindowRect(GetDlgItem(hWnd, IDC_STATIC_FILEICON), &rect); MapWindowPoints(0, hWnd, (LPPOINT) &rect, 2); DrawIcon(hdc, rect.left, rect.top, hIcon); } EndPaint(hWnd, &paint); } return TRUE; break; case WU_REQUESTUPDATE: SetWindowLong(hWnd, DWL_USER, wParam); SendMessage(hWnd, WM_TIMER, _TIMER_NEWPROCESS_WND, 0); pRequest = (Request_StartProcess*) wParam; { CString strInfo; CString strtmp; strInfo = *pRequest->m_pstrInfo; strInfo += _T("\r\n\r\n"); if (pRequest->wininfo.QueryInfo(pRequest->m_pwchImagePath)) { strtmp.Format(_T("Image path: %s\r\nVersion: <unknown>\r\nDescription: <not present>"), pRequest->m_pwchImagePath); } else { strtmp.Format(_T("Image path: %s\r\nVersion: %s\r\nDescription: %s"), pRequest->m_pwchImagePath, pRequest->wininfo.GetProductVersion(), pRequest->wininfo.GetFileDescription()); } strInfo += strtmp; SetDlgItemText(hWnd, IDC_EDIT_INFO, strInfo); if (pRequest->m_bSandBoxed) EnableWindow(GetDlgItem(hWnd, IDOK), FALSE); } ShowWindow(hWnd, SW_SHOW); SetForegroundWindow(hWnd); SetFocus(hWnd); UpdateWindow(hWnd); return TRUE; break; case WM_COMMAND: { switch (LOWORD (wParam)) { case IDCANCEL: { ShowWindow(hWnd, SW_HIDE); pRequest = (Request_StartProcess*) GetWindowLong(hWnd, DWL_USER); if (pRequest != 0) { pRequest->m_Verdict = _start_disabled; SetWindowLong(hWnd, DWL_USER, 0); SetEvent(pRequest->m_hEventComplete); } } return TRUE; case IDOK: { ShowWindow(hWnd, SW_HIDE); pRequest = (Request_StartProcess*) GetWindowLong(hWnd, DWL_USER); if (pRequest != 0) { pRequest->m_Verdict = _start_allowed; SetWindowLong(hWnd, DWL_USER, 0); SetEvent(pRequest->m_hEventComplete); } } return TRUE; case IDC_BUTTON_ALLOWONCE: { ShowWindow(hWnd, SW_HIDE); pRequest = (Request_StartProcess*) GetWindowLong(hWnd, DWL_USER); pRequest->m_Verdict = _start_allowed_once; SetWindowLong(hWnd, DWL_USER, 0); SetEvent(pRequest->m_hEventComplete); } return TRUE; } break; } break; } return FALSE; }
/* µ±nStyle=1ʱ Éú³ÉÊý×Ö±àºÅ µ±nStyle=2ʱ Éú³ÉÁ÷Ë®ÕʺŠµ±nStyle=3ʱ Éú³ÉÈÕÆÚʱ¼ä±àºÅ */ CString RxADO::AutoNumber(CString sTable, CString sFieldName, CString sCode, int nStyle) { _RecordsetPtr AutoNumberrst; CString sTempNewNumber,sNewNumber,sSQL,sMaxNumber,sOldNumber; AutoNumberrst.CreateInstance(__uuidof(Recordset)); sSQL.Format("SELECT MAX(%s) as ×î´ó±àºÅ FROM %s",sFieldName,sTable); try{ AutoNumberrst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText); } catch(_com_error & e) { GetADOErrors(e); } if(nStyle==1) //Êý×Ö±àºÅ { if(GetRecordCount(AutoNumberrst)<1) sNewNumber.Format("1"); else { AutoNumberrst->MoveFirst(); _variant_t vtext; vtext=AutoNumberrst->GetCollect("×î´ó±àºÅ"); if(vtext.vt==VT_EMPTY||vtext.vt==VT_NULL) { sNewNumber.Format("1"); goto end; } sMaxNumber=(char*)(_bstr_t)AutoNumberrst->GetCollect("×î´ó±àºÅ"); sNewNumber.Format("%d",atoi(sMaxNumber)+1); } } if(nStyle==2)//Á÷Ë®ÕʺŠ{ if(GetRecordCount(AutoNumberrst)<1) sNewNumber.Format("%s00000001",sCode); else { AutoNumberrst->MoveFirst(); _variant_t _bOldNumber=AutoNumberrst->GetCollect("×î´ó±àºÅ"); if(_bOldNumber.vt==VT_NULL || _bOldNumber.vt==VT_EMPTY) { sNewNumber.Format("%s00000001",sCode); goto end; } sOldNumber=(char*)(_bstr_t) _bOldNumber; sMaxNumber=sOldNumber.Mid(3); sTempNewNumber.Format("%d",atoi(sMaxNumber)+1); sNewNumber.Format("%s%s",sCode,Padl(sTempNewNumber,8,"0",1)); } } if(nStyle==3)//ÈÕÆÚʱ¼ä±àºÅ { int nYear,nDay,nMonth; CString sYear,sDay,sMonth; CTime tTime; tTime=tTime.GetCurrentTime(); nYear=tTime.GetYear(); nDay=tTime.GetDay(); nMonth=tTime.GetMonth(); sYear.Format("%d",nYear); sDay.Format("%d",nDay); sMonth.Format("%d",nMonth); sYear=sYear.Mid(2); sDay=Padl(sDay,2,"0",1); sMonth=Padl(sMonth,2,"0",1); if(GetRecordCount(AutoNumberrst)<1) sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay); else { _variant_t bh=AutoNumberrst->GetCollect("×î´ó±àºÅ"); if(bh.vt==VT_EMPTY||bh.vt==VT_NULL) { sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay); goto end; } CString sOldDate,sNewDate; AutoNumberrst->MoveFirst(); sOldNumber=(char*)(_bstr_t)AutoNumberrst->GetCollect("×î´ó±àºÅ"); sOldDate=sOldNumber.Mid(2,6); sNewDate.Format("%s%s%s",sYear,sMonth,sDay); if(sOldDate==sNewDate) { sMaxNumber=sOldNumber.Mid(9); sTempNewNumber.Format("%d",atoi(sMaxNumber)+1); sNewNumber.Format("%s%s%s%s-%s",sCode,sYear,sMonth,sDay,Padl(sTempNewNumber,6,"0",1)); } else sNewNumber.Format("%s%s%s%s-000001 ",sCode,sYear,sMonth,sDay); } } end: return sNewNumber; }