Search button without creating new file C++ - c++

I want to open a dialog to search for a filepath, without already creating the File and only saving the pathfile in a textBox.
This is what I already got, but it creates a new file:
System::IO::Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
if ( (myStream = saveFileDialog1->OpenFile()) != nullptr )
{
textBox->Text = saveFileDialog1->FileName;
myStream->Close();
}
}

Calling OpenFile is what's creating the file. Don't do it.
System::IO::Stream^ myStream;
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )
{
textBox->Text = saveFileDialog1->FileName;
}

Related

TDLib: how to send bold text in the message? (ะก++)

Using the official TDLib C++ example, I'm trying to send a message with formatted markdown text.
Here's my code:
auto send_message = td_api::make_object<td_api::sendMessage>();
send_message->chat_id_ = -1001424068198;
auto message_content = td_api::make_object<td_api::inputMessageText>();
std::string text = "Hello! **how are u?**";
message_content->text_ = td_api::make_object<td_api::formattedText>();
message_content->text_->text_ = std::move(text);
send_message->input_message_content_ = std::move(message_content);
send_query(std::move(send_message), {});
I expect to see "Hello! how are u?" but the message comes as it is written in the code, without markdown formatting applied.
I spent hours on google trying to figure out how to force TDLib to parse it.
UPDATE: SOLVED!
Thanks Azeem for help!
Using this example, the following code should send the parsed message (tested in VS 2019)
void sendMsg(INT64 chatID, INT64 ReplyTo, const char* textMsg) {
const std::string text = textMsg;
auto textParseMarkdown = td_api::make_object<td_api::textParseModeMarkdown>(2);
auto parseTextEntities = td_api::make_object<td_api::parseTextEntities>(text, std::move(textParseMarkdown));
td::Client::Request parseRequest{ 123, std::move(parseTextEntities) };
auto parseResponse = td::Client::execute(std::move(parseRequest));
if (parseResponse.object->get_id() == td_api::formattedText::ID) {
auto formattedText = td_api::make_object<td_api::formattedText>();
formattedText = td_api::move_object_as<td_api::formattedText>(parseResponse.object);
auto send_message = td_api::make_object<td_api::sendMessage>();
send_message->chat_id_ = chatID;
auto message_content = td_api::make_object<td_api::inputMessageText>();
message_content->text_ = std::move(formattedText);
send_message->input_message_content_ = std::move(message_content);
send_message->reply_to_message_id_ = ReplyTo;
send_query(std::move(send_message), {});
}
}
You can use td_api::textParseModeMarkdown, td_api::parseTextEntities and td::Client::execute() like this:
using namespace td;
const std::string text = "*bold* _italic_ `code`";
auto textParseMarkdown = td_api::make_object<td_api::textParseModeMarkdown>( 2 );
auto parseTextEntities = td_api::make_object<td_api::parseTextEntities>( text, std::move( textParseMarkdown ) );
td::Client::Request parseRequest { 123, std::move( parseTextEntities ) };
auto parseResponse = td::Client::execute( std::move( parseRequest ) );
auto formattedText = td_api::make_object<td_api::formattedText>();
if ( parseResponse.object->get_id() == td_api::formattedText::ID )
{
formattedText = td_api::move_object_as<td_api::formattedText>( parseResponse.object );
}
else
{
std::vector<td_api::object_ptr<td_api::textEntity>> entities;
formattedText = td_api::make_object<td_api::formattedText>( text, std::move(entities) );
}
std::cout << td_api::to_string( formattedText ) << '\n';
For debugging purposes, you can use td_api::to_string() to dump the contents of an object. For example, dumping parseTextEntities like this:
std::cout << td_api::to_string( parseTextEntities ) << '\n';
would give this:
parseTextEntities {
text = "*bold* _italic_ `code`"
parse_mode = textParseModeMarkdown {
version = 2
}
}

dao property from vb to mfc

i have implemented vb functionality in c++ i have replace below logic in c++ but it is giving issue :
i have to convert from VB to c++ and the code in c++ is crashing when getting property.
Original VB code:
For Each loTDef In aoDBUser.TableDefs
Set loProp = Nothing
On Error Resume Next
Set loProp = loTDef.Properties("Description")
If Not loProp Is Nothing Then
If loProp.Value = TEMP_TABLE Then
End If
End If
Next
New C++ code:
CString test::Property()
{
//
// OVERVIEW:
// Get the value for the given Custom Property
//
DAOProperties *pColProp = NULL;
DAOProperty *pProp = NULL;
CDaoDatabase cDBase;
cDBase.Open(CV_GetUserDatabasePath(_T("TEST.mdb")));
CString strDbVer;
DAOProperties* pPrp = 0;
DAOProperty* pRev = 0;
try
{
if ( !cDBase.IsOpen() )
return(_T(""));
DAO_CHECK(cDBase.m_pDAODatabase->get_Properties(&pPrp));
if ( pPrp != 0 )
{
COleVariant varRevVal;
COleVariant varName(_T("Description"), VT_BSTRT);
DAO_CHECK(pPrp->get_Item(varName, &pRev));//crashing going to catch
if (pRev != 0)
{
DAO_CHECK(pRev->get_Value(&varRevVal));
pRev->Release();
pRev = 0;
}
pPrp->Release();
pPrp = 0;
strDbVer = V_BSTRT(&varRevVal);
}
}
catch (...)
{
}
cDBase.Close();
}
some how it is crashing in DAO_CHECK(pPrp->get_Item(varName, &pRev));
But I cannot figure out why this occurs.

How to add Shapefile to map?

What's The NameSpace for ShapeFile Class ?
my language is silverlight in Esri Map:
<esri:GraphicsLayer ShowLegend="false" ID="ResultsGraphicsLayer" />
<esri:GraphicsLayer ShowLegend="false" ID="MyGraphicsLayer" />
<esri:GraphicsLayer ShowLegend="false" ID="MySelectionGraphicsLayer" MouseEnter="GraphicsLayer_MouseEnter" MouseLeave="GraphicsLayer_MouseLeave"/>
<esri:GraphicsLayer ShowLegend="false" ID="IdentifyIconGraphicsLayer"/>
</esri:Map>
in codebehind:
private void openFileDialog_Click( object sender, RoutedEventArgs e )
{
//Create the dialog allowing the user to select the ".shp" and the ".dbf" files
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if( !( ofd.ShowDialog() ?? false ) )
return;
//Get the file info objects for the SHP and the DBF file selected by the user
FileInfo shapeFile = null;
FileInfo dbfFile = null;
foreach( FileInfo fi in ofd.Files )
{
if( fi.Extension.ToLower() == ".shp" )
{
shapeFile = fi;
}
if( fi.Extension.ToLower() == ".dbf" )
{
dbfFile = fi;
}
}
//Read the SHP and DBF files into the ShapeFileReader
ShapeFile shapeFileReader = new ShapeFile();
if( shapeFile != null && dbfFile != null )
{
shapeFileReader.Read( shapeFile, dbfFile );
}
else
{
HtmlPage.Window.Alert( "Please select a SP and a DBF file to proceed." );
return;
}
//Add the shapes from the shapefile into a graphics layer named "shapefileGraphicsLayer"
//the greaphics layer should be present in the XAML or created earlier
GraphicsLayer graphicsLayer = MyMap.Layers[ "shapefileGraphicsLayer" ] as GraphicsLayer;
foreach( ShapeFileRecord record in shapeFileReader.Records )
{
Graphic graphic = record.ToGraphic();
if( graphic != null )
graphicsLayer.Graphics.Add( graphic );
}

open desktop using QText Browser

Right now I am displaying something like /home/binary/ in QText browser. Now I want the open the folder by clicking on this text. How to do that ? Thanks in advance
Here is my sample code. I am display the result
s
bool MainWindow::displayResult(multimap<string,
string> &resultMap, string &filePath)
{
multimap::iterator iter;
bool fileStatus = false;
int noOfLocFound = 0, forAppending = 0;
QString no;
noOfLocFound = resultMap.size();
if ( noOfLocFound != 0 )
ui->textBrowser->append( "<i>File found at <b>" + no.setNum (
noOfLocFound ) + " locations");
for ( forAppending = 0,iter = resultMap.begin(); iter !=
resultMap.end(); iter++,
forAppending++ )
{
string file = iter->first;
string dir = iter->second;
if ( forAppending == 0)
filePath.append(dir);
else
filePath.append(","+dir);
QString qdir = QString::fromStdString(dir);
cout << "Display";
ui->textBrowser->append( qdir );
fileStatus = true;
}
if ( fileStatus == false )
{
ui->textBrowser->append("File not
found");
return false;
}
return true;
}
By "open the folder", do you mean, open a file dialog for the user to select something inside of the given directory?
If so, you would probably want to connect your QTextBrowser's clicked signal to a slot that looked something like:
// connect events, in MyWindow constructor, or whereever...
connect(textbrowser, SIGNAL(mousePressEvent(QMouseEvent*)), this, SLOT(openFileDialog(QMouseEvent*)));
void MyWindow::openFileDialog(QMouseEvent* event) {
Q_UNUSED(event);
QStringList files = QFileDialog::getOpenFileNames(this, "Select a file...",
textbrowser.plainText());
// do something with the files here...
}

List of windows users remotely

I would like to know how to retrieve the list of users that are logged onto a Remote machine. I can do it with qwinsta /server:xxxx, but would like to do it in C#.
check out wmi in .net under system.management.
something like:
ConnectionOptions conn = new ConnectionOptions();
conn.Authority = "ntdlmdomain:NAMEOFDOMAIN";
conn.Username = "";
conn.Password = "";
ManagementScope ms = new ManagementScope(#"\\remotecomputer\root\cimv2", conn);
ms.Connect();
ObjectQuery qry = new ObjectQuery("select * from Win32_ComputerSystem");
ManagementObjectSearcher search = new ManagementObjectSearcher(ms, qry);
ManagementObjectCollection return = search.Get();
foreach (ManagementObject rec in return)
{
Console.WriteLine("Logged in user: " + rec["UserName"].ToString());
}
You may not need the ConnectionOptions...
I ended up using the qwinsta /server:server1 command from C# -- it was much easier
thanks Ken
All this checks all 8 servers at the same time -- I put the result in sql server
but you can do what ever you want
query_citrix.bat script
cd C:.......\bin\citrix_boxes
qwinsta -server:servername or ip > servername.txt
string sAppCitrixPath = Application.StartupPath.ToString() + "\\citrix_boxes\\";
//Run Script for current citrix boxes
Process proc = new Process();
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = sAppCitrixPath + "query_citrix.bat";
proc.StartInfo = si;
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
proc.Close();
if (exitCode == 0)
{
//Execute update who is on the Citrix_Boxes Currently
DirectoryInfo dic = new DirectoryInfo(sAppCitrixPath);
FileInfo[] fic = dic.GetFiles("*.txt");
for (int i = 0; i < fic.Length; i++)
{
ParseQWinStaServerFile(fic[i].FullName.ToString(), fic[i].Name.ToString().ToUpper().Replace(".TXT",""));
File.Delete(fic[i].FullName.ToString());
}
}
private void ParseQWinStaServerFile(string sLocation,string sServer)
{
using (StreamReader sr = File.OpenText(sLocation))
{
string sRecord = String.Empty;
char[] cSep = new char[] {' '};
bool bFirst = true;
while ((sRecord = sr.ReadLine()) != null)
{
if (bFirst == false)
{
string[] items = sRecord.Split(cSep, StringSplitOptions.RemoveEmptyEntries);
//Make sure all columns are present on the split for valid records
if (sRecord.Substring(19, 1) != " ") // check position of user id to see if it's their
{
//Send the user id and server name where you want to.
//here is your user
id = items[1].ToString().ToLower().Trim()
//here is your server
};
}
else
{
bFirst = false;
}
}
}
}