Programm mit Button starten (?)



  • Beim Kompilieren exakt dieses Quellcodes, zeigt er mir einen Fehler an. Der lautet wie folgt:

    Fehler	1	error C2872: 'Timer': Mehrdeutiges Symbol
    

    Ich kann mir das eigentlich nicht erklären...



  • Entferne

    using namespace System::Threading;
    


  • Danke, es funkioniert! 🙂



  • Aber jetzt kommt das, wenn ich Timer(5000); [man muss doch einen Wert angeben, oder?] schriebe:

    **error C2440: '<function-style-cast>': 'int' kann nicht in 'System::Windows::Forms::Timer' konvertiert werden
    **

    Form1.h

    #pragma once
    
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    namespace TastendruckSimulation 
    {
    
    public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    
    		}
    
    	protected:
    
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::Timer^  timer1;
    
    	private: System::ComponentModel::IContainer^  components;
    	protected: 
    
    	private:
    
    #pragma region Windows Form Designer generated code
    
    		void InitializeComponent(void)
    		{
    			this->components = (gcnew System::ComponentModel::Container());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Cursor = System::Windows::Forms::Cursors::Hand;
    			this->button1->DialogResult = System::Windows::Forms::DialogResult::Yes;
    			this->button1->FlatAppearance->MouseOverBackColor = System::Drawing::Color::DeepSkyBlue;
    			this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->button1->Location = System::Drawing::Point(206, 79);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(64, 33);
    			this->button1->TabIndex = 1;
    			this->button1->Text = L"Start";
    			this->button1->UseVisualStyleBackColor = true;
    			// 
    			// textBox1
    			// 
    			this->textBox1->Location = System::Drawing::Point(43, 87);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(148, 20);
    			this->textBox1->TabIndex = 1;
    			// 
    			// label1
    			// 
    			this->label1->AutoSize = true;
    			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Underline)), 
    				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
    			this->label1->Location = System::Drawing::Point(20, 9);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(250, 31);
    			this->label1->TabIndex = 2;
    			this->label1->Text = L"Tasten-Simulation";
    			// 
    			// timer1
    			// 
    			this->timer1->Enabled = true;
    			this->timer1->Interval = 5000;
    			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->BackColor = System::Drawing::Color::SlateGray;
    			this->ClientSize = System::Drawing::Size(290, 120);
    			this->Controls->Add(this->label1);
    			this->Controls->Add(this->textBox1);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Tasten-Simulation";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->ResumeLayout(false);
    			this->PerformLayout();
    
    		}
    #pragma endregion
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    			 }
    
    };
    }
    

    .cpp

    // Tastendruck-Simulation.cpp: Hauptprojektdatei.
    
    #pragma comment(lib, "user32.lib")
    #include <windows.h>
    #include "Form1.h"
    #include "stdafx.h"
    
    using namespace TastendruckSimulation;
    
    void SetNumlock(BOOL bState)
    
    {	  Timer(keyb_event);
    
          BYTE keyState[256];
    
          GetKeyboardState((LPBYTE)&keyState);
          if( (bState && !(keyState[VK_NUMPAD3] & 1)) ||
              (!bState && (keyState[VK_NUMPAD3] & 1)) )
          {
    
    	  Timer(5000);
    
          // Simulate a key press
             keybd_event( VK_NUMPAD3,
                          0x63,
                          KEYEVENTF_EXTENDEDKEY | 0,
                          0 );
    
          // Simulate a key release
             keybd_event( VK_NUMPAD3,
                          0x63,
                          KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                          0);
          }
    
    }
    
    int main()
    
    {	
        SetNumlock( TRUE );
    	// Aktivieren visueller Effekte von Windows XP, bevor Steuerelemente erstellt werden
    
    	Application::EnableVisualStyles();
    	Application::SetCompatibleTextRenderingDefault(false); 
    
    	// Hauptfenster erstellen und ausführen
    	Application::Run(gcnew Form1());
    	return 0;
    }
    


  • Irgendwie hat das alles keinen Sinn...

    Kauf Dir ein Buch.. oder noch besser kauf Dir ein Buch zu C# und mach das ganze mit C#...



  • 👍


Anmelden zum Antworten