terça-feira, 28 de maio de 2013
C++ | Usar Arrays no Visual C++
//Array para guardar Nomes
array<String^>^ strArrayNomes = gcnew array<String^>(3);
strArrayNomes[0] = gcnew String("Maria");
strArrayNomes[1] = gcnew String("Manuel");
strArrayNomes[2] = gcnew String("José");
//Mostrar os nomes guardados no Array
MessageBox::Show(strArrayNomes[0]);
MessageBox::Show(strArrayNomes[1]);
MessageBox::Show(strArrayNomes[2]);
segunda-feira, 27 de maio de 2013
C++ | Um bom programa para iniciantes: Conversão Fahrenheit para Celsius
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if (this->tbTempF->Text == String::Empty) {
MessageBox::Show("Por favor preencha o primeiro campo!!!");
}
else {
// Converter Fahrenheit para Celsius
double temp;
temp = Convert::ToDouble(tbTempF->Text) - 32.0;
temp = temp / 9.0;
temp = temp * 5.0;
tbTempC->Text = Convert::ToString(temp.ToString(".000"));
//Resultado numa Messagebox
MessageBox::Show(Convert::ToString(temp.ToString(".000")),
"My Application", MessageBoxButtons::OK,
MessageBoxIcon::Asterisk);
}
} // fim btnConvert_Click
if (this->tbTempF->Text == String::Empty) {
MessageBox::Show("Por favor preencha o primeiro campo!!!");
}
else {
// Converter Fahrenheit para Celsius
double temp;
temp = Convert::ToDouble(tbTempF->Text) - 32.0;
temp = temp / 9.0;
temp = temp * 5.0;
tbTempC->Text = Convert::ToString(temp.ToString(".000"));
//Resultado numa Messagebox
MessageBox::Show(Convert::ToString(temp.ToString(".000")),
"My Application", MessageBoxButtons::OK,
MessageBoxIcon::Asterisk);
}
} // fim btnConvert_Click
domingo, 26 de maio de 2013
C++ | MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
Resolvi o erro da seguinte forma:
If you want to keep the Windows subsystem you can just hint at what your entry point is, because you haven't defined
Retirado daqui:
If you want to keep the Windows subsystem you can just hint at what your entry point is, because you haven't defined
___tmainCRTStartup
. You can do this by adding the following to Properties -> Linker -> Command line:
/ENTRY:"mainCRTStartup"This way you get rid of the console window.
Retirado daqui:
quarta-feira, 22 de maio de 2013
C++ | Outra forma de obter a letras das drives (discos) ligados
//Função para devolver as letras dos discos no Windows
void DevolveLetrasDrives()
{
try
{
array<String^>^drives = System::IO::Directory::GetLogicalDrives();
//array<String^>^drivetype = GetDriveType();
for ( int i = 0; i < drives->Length; i++ )
{
//System::Console::WriteLine( drives[ i ] );
MessageBox::Show(drives[ i ],
"My Application", MessageBoxButtons::OKCancel,
MessageBoxIcon::Asterisk);
}
}
catch ( System::IO::IOException^ )
{
System::Console::WriteLine( "An I/O error occurs." );
}
catch ( System::Security::SecurityException^ )
{
System::Console::WriteLine( "The caller does not have the HelloServer' required permission." );
}
}
Veja aqui outra forma semelhante para obter as drives do Windows.
terça-feira, 21 de maio de 2013
C++ | Devolver todas as letras dos discos físicos (fixos) e removíveis em Windows
//Todos os discos físicos, com message box:
for each (DriveInfo ^drive in DriveInfo::GetDrives()) {
if (drive->DriveType == DriveType::Fixed)
//Mensagem
MessageBox::Show(drive->Name,
"My Application", MessageBoxButtons::OKCancel,
MessageBoxIcon::Asterisk);
}
//Todos os discos removíveis, com mensagem na consola:
for each (DriveInfo ^drive in DriveInfo::GetDrives()) {
if (drive->DriveType == DriveType::Removable)
//Mensagem
Console::WriteLine("{0} this is a fixed drive...", drive->Name);
}
//Não se esqueçam dos namespaces no início. Estes são os que estou a usar:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
C++ | Apresentar uma mensagem numa messagebox (caixa de mensagens ou popup)
//Sem variável:
MessageBox::Show("Olá Mundo!!!,
"My Application", MessageBoxButtons::OKCancel,
MessageBoxIcon::Asterisk);
//Com variável:
String^ texto="Olá Mundo!!!";
MessageBox::Show(VARIAVEL,
"My Application", MessageBoxButtons::OKCancel,
MessageBoxIcon::Asterisk);
//Não se esqueçam dos namespaces no início. Estes são os que estou a usar:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
Intro
Este é o blog das rapidinhas no que respeita a programação. Vou colocar aqui dificuldades, pesquisas, porções de código, ou seja, coisas que me vou aventurando e experimentando a fazer.
Essencialmente vão ser artigos simples e diretos.
Subscrever:
Mensagens (Atom)