// fires an event when a file, or files are dropped onto the application. void __fastcall TForm1::WMDropFiles(TWMDropFiles &message) { AnsiString FileName; FileName.SetLength(MAX_PATH); FileName.SetLength(DragQueryFile((HDROP)message.Drop, 0,FileName.c_str(), MAX_PATH)); if(UpperCase(ExtractFileExt(FileName)) == ".BMP") { bmp->LoadFromFile(FileName) ; img->Picture->Bitmap->Assign(bmp) ; } else if(UpperCase(ExtractFileExt(FileName)) == ".JPG") { TJPEGImage * jpeg = new TJPEGImage(); jpeg->LoadFromFile(FileName); jpeg->DIBNeeded(); bmp->Assign(jpeg); img->Picture->Bitmap->Assign(bmp) ; delete jpeg; } preview->frmSelect->Position = 0 ; outType->ItemIndex = 1 ; if(preview->Visible) updatePreview(); int l = bmp->Width, h = bmp->Height ; transType->ItemIndex = 0 ; //preview->TransparentColor = 0 ; // auto compute frame number and frameset way if(l < 142 || h < 142) { int s ; int yyop ; int *v=&h, *vh=&l ; if(l > h*2) { v=&l ; vh=&h ; vertical=0 ; } // horizontal frameset else vertical = 1 ; flipWay->Checked = !vertical ; s = *vh + 3 ; do { yyop = (*v)/s ; } while(s && yyop*s-- != *v) ; ++s ; if(s < 4) { frmNb->Text = 1 ; sprintf(msg,"frames of %i*%i",l,h) ; LabelSize->Caption = msg ; fsx = l ; fsy = h ; } else {nb = yyop ; fsx = s ; fsy = *vh ; frmNb->Text = yyop ; sprintf(msg,"frames of %i*%i",s,*vh) ; LabelSize->Caption = msg ; } } else { frmNb->Text = 1 ; sprintf(msg,"frames of %i*%i",l,h) ; LabelSize->Caption = msg ; nb=1 ; } preview->ClientHeight = h ; preview->ClientWidth = l + (nb > 1)*15 ; preview->Caption = FileName + " (" + nb + ")" ; fname = FileName ; outTypeChange((TObject*)42) ; Form1->Button1->Enabled = 1 ; Form1->Height = 304 ; Form1->StatusBar->Visible = 1 ; // tell the OS that you're finished... DragFinish((HDROP) message.Drop); }
//--------------------------------------------------------------------------- void __fastcall TRefEditForm::WMDropFiles(TWMDropFiles &message) { AnsiString FileName; FileName.SetLength(MAX_PATH); int Count = DragQueryFile((HDROP)message.Drop, 0xFFFFFFFF, NULL, MAX_PATH); // index through the files and query the OS for each file name... for (int index = 0; index < Count; ++index) { // the following code gets the FileName of the dropped file. I know it // looks cryptic but that's only because it is. Hey, Why do you think // Delphi and C++ Builder are so popular anyway? FileName.SetLength(DragQueryFile((HDROP)message.Drop, index, FileName.c_str(), MAX_PATH)); // examine the filename's extension. // If it's a Word file then ... if (UpperCase(ExtractFileExt(FileName)) == ".DOC") { ListBox_Words->Items->Add(FileName); } } // tell the OS that we're finished... DragFinish((HDROP) message.Drop); }
//=========================================================================== void Tform_Main::ReadDataFromRegistry() { AnsiString Name; TRegistry *Reg = NULL; try { try { Reg = new TRegistry; AnsiString appName = ExtractFileName(Application->ExeName); appName.SetLength(appName.Length() - 4); Reg->RootKey = HKEY_LOCAL_MACHINE; Reg->OpenKey("Software\\InnalabsUA\\ccg_QFactor", true); DFT_DeltaFreq = Reg->ReadFloat("DFT_DeltaFreq"); DTF_InterpolationPointsCount = Reg->ReadInteger("DTF_InterpolationPointsCount"); FFT_MaxPointsCount = Reg->ReadInteger("FFT_MaxPointsCount"); SoundCardIndex = Reg->ReadInteger("SoundCardIndex"); FreqSoundCardIndex = Reg->ReadInteger("FreqSoundCardIndex"); } catch ( ... ){ Reg->CloseKey(); SaveDataToRegistry(); } } __finally { Reg->CloseKey(); if (Reg != NULL) delete Reg; } }
void Global::LoadIniFile(AnsiString asFileName) { int i; for (i = 0; i < 10; ++i) { // zerowanie pozycji kamer pFreeCameraInit[i] = vector3(0, 0, 0); // wspó³rzêdne w scenerii pFreeCameraInitAngle[i] = vector3(0, 0, 0); // k¹ty obrotu w radianach } TFileStream *fs; fs = new TFileStream(asFileName, fmOpenRead | fmShareCompat); if (!fs) return; AnsiString str = ""; int size = fs->Size; str.SetLength(size); fs->Read(str.c_str(), size); // str+=""; delete fs; TQueryParserComp *Parser; Parser = new TQueryParserComp(NULL); Parser->TextToParse = str; // Parser->LoadStringToParse(asFile); Parser->First(); ConfigParse(Parser); delete Parser; // Ra: tego jak zwykle nie by³o wczeœniej :] };
//--------------------------------------------------------------------------- void __fastcall LoadFormPos(TForm *Form, const AnsiString IniFileName, const AnsiString SectionName, const AnsiString KeyName) { TIniFile *IniFile; AnsiString sWindowPositions; if (IniFileName.Length() == 0) return; // Create inifile object => Open ini file IniFile = new TIniFile(IniFileName); // Formatage par défaut de la ligne de la section window sWindowPositions.SetLength(256); WindowPosToStr(sWindowPositions.c_str(), Form); // Get widow's position and size from ini file sWindowPositions = IniFile->ReadString(SectionName, KeyName, sWindowPositions); StrToWindowPos(sWindowPositions.c_str(), Form); // Destroy inifile object => close ini file IniFile->Free(); }
//--------------------------------------------------------------------------- void __fastcall TDllTestForm::CallDllButtonClick(TObject *Sender) { AnsiString Buffer; int BufSize; int Status; Display("Calling DLL..."); BufSize = 100; Buffer.SetLength(BufSize); Status = IcsDllDemo(AnsiString(HostnameEdit->Text).c_str(), AnsiString(PortEdit->Text).c_str(), &Buffer[1], &BufSize); Buffer.SetLength(BufSize); if (Status) Display("Error #" + IntToStr(Status)); Display(Buffer); Display("Done with DLL"); }
/** * @brief Encoding wide to multibyte std::string * @param $src UnicodeString * @param $cp code page * @return multibyte std::string */ AnsiString W2MB(const wchar_t * src, const UINT cp) { // assert(src); if (!src || !*src) { return AnsiString(""); } intptr_t reqLength = WideCharToMultiByte(cp, 0, src, -1, 0, 0, nullptr, nullptr); AnsiString Result; if (reqLength) { Result.SetLength(reqLength); WideCharToMultiByte(cp, 0, src, -1, const_cast<LPSTR>(Result.c_str()), static_cast<int>(reqLength), nullptr, nullptr); Result.SetLength(Result.Length() - 1); //remove NULL character } return Result; //.c_str(); }
String TSearchFilesFrm::GetSearchData() { AnsiString data; AnsiString content_text = edtSearchContent->Text; if(cbSearchMode->ItemIndex == 0) { data = content_text; } else if(cbSearchMode->ItemIndex == 1) { data = BinToStr(content_text.c_str(), content_text.Length()); } else if(cbSearchMode->ItemIndex == 2) { DWORD num = content_text.ToInt(); data.SetLength(4); int pos = 0; WriteDWORD(data.c_str(), pos, num); data = BinToStr(data.c_str(), data.Length()); } else if(cbSearchMode->ItemIndex == 3) { WORD num = content_text.ToInt(); data.SetLength(2); int pos = 0; WriteWORD(data.c_str(), pos, num); data = BinToStr(data.c_str(), data.Length()); } else if(cbSearchMode->ItemIndex == 4) { BYTE num = content_text.ToInt(); data.SetLength(1); int pos = 0; WriteBYTE(data.c_str(), pos, num); data = BinToStr(data.c_str(), data.Length()); } return data; }
//--------------------------------------------------------------------------- __fastcall TfrmAbout::TfrmAbout(TComponent* Owner) : TForm(Owner) { AnsiString ExaName = ExtractFileName(Application->ExeName); ProductName->Caption = ExaName.SetLength(ExaName.Length()-4); int aTopPosition = 0; // if (WhoUseProgram == wupTanjaKvant) Label22->Visible = true; if (!Label22->Visible) { BitBtn1->Top = Label22->Top; ClientHeight = BitBtn1->BoundsRect.Bottom + 4; } }
//--------------------------------------------------------------------------- __fastcall TEnumWinForm::TEnumWinForm(TComponent* Owner) : TForm(Owner) { TStringList *list = new TStringList(); list->LoadFromFile("winmsgs.txt"); AnsiString str; int k; for(int i = 0; i < list->Count; i++) { str.SetLength(100); sscanf(list->Strings[i].c_str(),"%s %X\n",str.c_str(),&k); MsgComboBox->Items->AddObject(str,(TObject *)k); } delete list; MsgComboBox->ItemIndex = 0; }
void __fastcall TTMTimeLineMainForm::DoObjectLoad(TObject* Sender, TStream* Stream, TObject *&AObject) { AnsiString S; int Count; // Get the length of the string: Stream->Read(&Count,sizeof(Count)); S.SetLength(Count); // need we read any more ? if( Count > 0 ) { Stream->Read(&S[1],Count); AObject = new TStringList(); dynamic_cast<TStringList* >(AObject)->Text = S; } }
AnsiString StringFromFile(const AnsiString FileName, __int64& FileSize) { TFileStream* fs = new TFileStream(FileName, fmOpenRead); AnsiString Result; try { FileSize = fs->Size; Result.SetLength(FileSize); if (fs->Size > 0) fs->Read(Result.c_str(), FileSize); } __finally { delete fs; } return Result; }
bool TCurve::LoadFromFile(AnsiString asName) { DecimalSeparator = '.'; TFileStream *fs; fs = new TFileStream(asName, fmOpenRead | fmShareCompat); AnsiString str = "xxx"; int size = fs->Size; str.SetLength(size); fs->Read(str.c_str(), size); str += ""; delete fs; TQueryParserComp *Parser; Parser = new TQueryParserComp(NULL); Parser->TextToParse = str; Parser->First(); Load(Parser); delete Parser; DecimalSeparator = ','; }
//=========================================================================== void Tform_Main::SaveDataToRegistry() { TRegistry *Reg = NULL; try { Reg = new TRegistry; AnsiString appName = ExtractFileName(Application->ExeName); appName.SetLength(appName.Length() - 4); Reg->RootKey = HKEY_LOCAL_MACHINE; Reg->OpenKey("Software\\InnalabsUA\\ccg_QFactor", true); Reg->WriteFloat("DFT_DeltaFreq", DFT_DeltaFreq); Reg->WriteInteger("DTF_InterpolationPointsCount", DTF_InterpolationPointsCount); Reg->WriteInteger("FFT_MaxPointsCount", FFT_MaxPointsCount); Reg->WriteInteger("SoundCardIndex", SoundCardIndex); Reg->WriteInteger("FreqSoundCardIndex", FreqSoundCardIndex); } __finally { Reg->CloseKey(); if (Reg != NULL) delete Reg; } }
//=========================================================================== //=========================================================================== //=========================================================================== //=========================================================================== void AddNewFileToMainMenu(TPopupMenu *PopupMenu, AnsiString FileName, TNotifyEvent NotifyEvent) { TRegistry *Reg = new TRegistry; bool FirstInput = false; bool FileExist = false; int Counter = 0; int posFileNameInMenu = -1; AnsiString appName = ExtractFileName(Application->ExeName); appName.SetLength(appName.Length() - 4); try { Reg->RootKey = HKEY_LOCAL_MACHINE; /// ---- Находитться в Uses Windows Reg->OpenKey("Software\\Digital Systems & Technologies\\" + appName, true); //create a new key >> .ext //------------------- if (FileName == "Load") { for ( int i = 0; i < CountFileName; i++){ FileNameStackArray[i] = ""; FileNameStackArray[i] = Reg->ReadString("FileName"+IntToStr(i+1)); if (FileNameStackArray[i] != "") { Counter = Counter + 1; addMenuItem (Counter, PopupMenu, "&"+IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent); FirstInput = true; } } if (FirstInput) addMenuItem (Counter + 1,PopupMenu,"-", NULL); } else { // --- Проверка на повтор файла ----------- for ( int i = 0; i < CountFileName; i++) if (FileName == FileNameStackArray[i]) { FileExist = true; FileNameStackArray[i] = ""; posFileNameInMenu = i; } // -------- Если файл уже существует то удаляем его из списка, сортируем список if (FileExist) { for ( int i = posFileNameInMenu; i < CountFileName - 1; i++ ) { FileNameStackArray[i] = FileNameStackArray[i+1]; } FileNameStackArray[CountFileName - 1] = ""; } // ----- Добавляем в "Стек" --------- for ( int i = CountFileName - 1; i > 0; i--) if (FileNameStackArray[i-1].data() != NULL) FileNameStackArray[i] = FileNameStackArray[i-1]; FileNameStackArray[0] = FileName; // ---- Удаляю все файлы с менюхи --------- for ( int i = PopupMenu->Items->Count-1; i >= 0; i--) if (PopupMenu->Items->Items[i]->Name[1] == 'F') delete PopupMenu->Items->Items[i]; // ---- Добавляю новые файлы в менюху ------ Counter = 0; for ( int i = 0; i < CountFileName - 1; i++ ) { if (FileNameStackArray[i] != "") { Counter = Counter + 1; addMenuItem (Counter, PopupMenu, "&" + IntToStr(Counter) + ". " + GetShortFileName(FileNameStackArray[i]), NotifyEvent); } } // ---- Добавляю черту ------ addMenuItem (Counter + 1,PopupMenu,"-", NULL); } // ---- Записываю в Реестр ------- for ( int i = 0; i < CountFileName; i++) Reg->WriteString("FileName" + IntToStr(i+1), FileNameStackArray[i]); //------------------- Reg->CloseKey(); } __finally { delete Reg; } }
//--------------------------------------------------------------------------- bool __fastcall TFile::ReadString(AnsiString & data, DWORD maxsize) { data.SetLength(maxsize); return ReadString(data.c_str(), maxsize); }
//=========================================================================== // ファイルからSHA-1ハッシュ値を取得する //=========================================================================== bool __fastcall TForm1::GetSHA1HashFromFile( String FilePath, // パスワードファイルパス AnsiString &HashDataVer2, // ver.2.* ~:SHA-1ハッシュ値(20byte + 12byte) AnsiString &HashDataVer1 ) // ver.1.* ~:ヘッダデータ(先頭文字列32文字) { int i; int fh; int bytes, rest; char buffer[255]; //読み込みバッファ char sha1_hash_data_mixed_padding[BUF_HASH_DATA];// 32byte for (i = 0; i < BUF_HASH_DATA; i++) { sha1_hash_data_mixed_padding[i] = NULL; } if ( !FileExists(FilePath) ) return(false); try{ if ( (fh = FileOpen(FilePath, fmShareDenyNone)) == -1 ){ //パスワードファイルが開けない? return(false); } //ヘッダ先頭の255byteを読む(ver.1.* ~) FileRead(fh, buffer, 255); HashDataVer1 = (AnsiString)buffer; //SHA-1ハッシュの計算 FileSeek(fh, 0, 0); SHA1Context sha; unsigned char Message_Digest[20]; ZeroMemory(Message_Digest, 20); //初期化(リセット) if ( SHA1Reset(&sha)){ return(false); } //ファイルを読み出してSHA-1へ入力していく while ((bytes = FileRead (fh, buffer, 255)) != 0){ rest = bytes; if ( SHA1Input(&sha, (const unsigned char *)buffer, bytes) ){ return(false); } } if ( FileSeek(fh, -rest, 2) > 0 ){ FileRead(fh, buffer, 255); } else{ FileSeek(fh, 0, 0); FileRead(fh, buffer, 255); } //出力 if(SHA1Result(&sha, Message_Digest)){ return(false); } for (i = 0; i < BUF_SHA1_SIZE; i++){ // 20byte sha1_hash_data_mixed_padding[i] = Message_Digest[i]; } //残りの12byteを補填 for (i = 0; i < 12; i++) { // 12byte sha1_hash_data_mixed_padding[BUF_SHA1_SIZE+i] = buffer[i]; } HashDataVer2 = ""; for (i = 0; i < BUF_HASH_DATA; i++){ // 32byte //適切にキャストされるように1byteずつ代入 HashDataVer2 += (AnsiString)sha1_hash_data_mixed_padding[i]; } HashDataVer2.SetLength(32); } __finally{ FileClose(fh); } return(true); }
//--------------------------------------------------------------------------- void __fastcall TMainForm::DataGridDrawCell(TObject *Sender, int Col, int Row, TRect &Rect, TGridDrawState State) { char buf [100]; const char* s = buf; if (Col > 0) { int c = _colNum >= 0 ? _colNum : Col - 1; if (c >= _data.NumProperties()) return; // empty storage c4_Property prop (_data.NthProperty(c)); char type = prop.Type(); if (Row > 0) { c4_RowRef r = _data[Row-1]; switch (type) { case 'I': wsprintf(buf, "%ld", (long) ((c4_IntProp&) prop)(r)); break; case 'F': gcvt(((c4_FloatProp&) prop)(r), 6, buf); break; case 'D': gcvt(((c4_DoubleProp&) prop)(r), 12, buf); break; case 'S': s = ((c4_StringProp&) prop)(r); //{ static c4_String t; t = s; s = t; } //wsprintf(buf, "%ld", strlen(s)); s = buf; break; case 'B': case 'M': wsprintf(buf, "(%db)", prop(r).GetSize()); break; case 'V': wsprintf(buf, "[#%d]", ((c4_View) ((c4_ViewProp&) prop)(r)).GetSize()); break; } } else { strcpy(buf, (c4_String) prop.Name() + ":" + (c4_String) type); } } else if (Row > 0) { wsprintf(buf, "%ld", Row - 1); // "poor man's right alignment" int n = strlen(s); if (n < 5) // tricky, because two spaces is the width of one digit strcpy(buf, c4_String (' ', 10 - 2 * n) + s); } else { s = ""; } AnsiString as (s); if (as.Length() > 1000) // TextRect seems to crash with huge strings as.SetLength(1000); DataGrid->Canvas->TextRect(Rect, Rect.Left + 3, Rect.Top, as); }
//--------------------------------------------------------------------------- bool TShortCuts::ChangeShortCut(const TShortCutOwner *sco, TShortCut shortcut, AnsiString &error) { error.SetLength(0); if(!sco) return false; TMenuItem *mi=sco->mi; if(!mi) return false; if(mi->ShortCut==shortcut) return true; int oldshortcut=mi->ShortCut; TBasicAction *act=mi->Action; int groupindex=-2; AnsiString prefix=sco->prefix; int pgroupindex=-2; if(shortcut) for(TShortCutOwner *sco=shortcutowners.begin().operator ->(),*endsco=shortcutowners.end().operator ->();sco<endsco;sco++) { TMenuItem *mi2=sco->mi; if(!mi2) continue; if(mi2->ShortCut!=shortcut) continue; if(mi2==mi) continue; if(mi2->Action&&mi2->Action==act) continue; if(groupindex<0) groupindex=GetEqualGroupIndex(mi); if(groupindex>=0) { int groupindex2=GetEqualGroupIndex(mi2); if(groupindex==groupindex2) continue; } if(pgroupindex<0) pgroupindex=GetPrefixGroupIndex(prefix); if(pgroupindex>=0) { int pgroupindex2=GetPrefixGroupIndex(sco->prefix); if(IsEqualPrefixGroups(pgroupindex,pgroupindex2)) continue; } error=sco->name; return false; } TCustomAction *act2=dynamic_cast<TCustomAction*>(act); if(act2) { act2->ShortCut=shortcut; for(TShortCutOwner *sco=shortcutowners.begin().operator ->(),*endsco=shortcutowners.end().operator ->();sco<endsco;sco++) { TMenuItem *mi2=sco->mi; if(!mi2) continue; if(!mi2->Action||mi2->Action!=act) continue; if(sco->node) sco->node->Text=sco->GetNameStr(); AnsiString pref=sco->GetPrefixedStr(); ClearShortCut(oldshortcut,pref); SetShortCut(shortcut,pref); } }else{ sco->mi->ShortCut=shortcut; if(sco->node) sco->node->Text=sco->GetNameStr(); AnsiString pref=sco->GetPrefixedStr(); ClearShortCut(oldshortcut,pref); SetShortCut(shortcut,pref); } return true; }