C++ example
#include
#include
int main() { float m = 10; // mass (kg): integer number float a = 9.81; // gravity (m/s2): floating point number float F; // Force (Nt): floating point number std::string str = "LearnCPlusPlus.org"; // string F = m*a; // Force = mass x accelaration std::cout << "Mass:" << m << std::endl; std::cout << "Gravity:" << a << std::endl; std::cout << "Weight of mass=" << F << " Nt" << std::endl; std::cout << std::endl; std::cout << str << std::endl; system("pause"); return 0; }
Use array
#include
#include
class emp { char name[20]; float age; public: void getdata( ); void putdata( ); }; void emp::getdata( ) { cout<<"\n\nEnter name and age of employee"; cin>>name>>age; } void emp::putdata( ) { cout<<"\n\n\t"<
"<
"<
getdata( ); } cout<<"\n\tInformation about of employee"; for(i=0;i<3;i++) { lect[i]->putdata( ); } getch( ); }
Use javascrit functions
#pragma once #include
namespace YourNamespace { using namespace System; using namespace System::Windows::Forms; public ref class Form1 : public System::Windows::Forms::Form { public: Form1() { InitializeComponent(); // Load an HTML file or set the DocumentText property with your HTML content webBrowser1->DocumentText = ""; } private: void button1_Click(System::Object^ sender, System::EventArgs^ e) { // Execute the JavaScript function and retrieve the return value Object^ result = webBrowser1->Document->InvokeScript("addNumbers", gcnew array
{5, 10}); if (result != nullptr) { MessageBox::Show("Result from JavaScript function: " + result->ToString(), "JavaScript Result"); } else { MessageBox::Show("No result from JavaScript function", "JavaScript Result"); } } #pragma region Windows Form Designer generated code private: void InitializeComponent(void) { this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser()); this->button1 = (gcnew System::Windows::Forms::Button()); this->SuspendLayout(); // // webBrowser1 // this->webBrowser1->Location = System::Drawing::Point(12, 12); this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20); this->webBrowser1->Name = L"webBrowser1"; this->webBrowser1->Size = System::Drawing::Size(776, 400); this->webBrowser1->TabIndex = 0; // // button1 // this->button1->Location = System::Drawing::Point(12, 418); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 1; this->button1->Text = L"Invoke JS"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click); // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(800, 450); this->Controls->Add(this->button1); this->Controls->Add(this->webBrowser1); this->Name = L"Form1"; this->Text = L"JavaScript Function Invocation"; this->ResumeLayout(false); } #pragma endregion private: System::Windows::Forms::WebBrowser^ webBrowser1; System::Windows::Forms::Button^ button1; }; }
How get text from another windows
#include
#include
int main() { // Find the window by its class name (replace "Notepad" with the target window's class name) HWND targetWindow = FindWindow(L"Notepad", nullptr); if (targetWindow == nullptr) { std::cerr << "Window not found!" << std::endl; return 1; } // Get the length of the text in the target window int textLength = SendMessage(targetWindow, WM_GETTEXTLENGTH, 0, 0); if (textLength == 0) { std::cerr << "No text in the window!" << std::endl; return 1; } // Allocate memory to store the text wchar_t* buffer = new wchar_t[textLength + 1]; // Get the text from the target window SendMessage(targetWindow, WM_GETTEXT, textLength + 1, reinterpret_cast
(buffer)); // Output the retrieved text std::wcout << "Text in the window: " << buffer << std::endl; // Clean up delete[] buffer; return 0; }