Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C++CLI / VB .Net / .Net-Framework » Keyboard Hook noch aktuell?

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: [ 1 ] > 2 <
010
10.07.2006, 16:09 Uhr
der Leitman



danke, das war sehr hilfreich *gg*

Terminalserver schön und gut, aber ich hab nur mit dem Client zu tun,
das einzige was ich zurzeit brauche ist, wie ich im ganzen Programm ein schließen durch ALT F4 sperren kann.
Hab eigentlich nur gefragt, ob es eine Alternative zum Kexboardhook gibt, oder einen andern Anatz!?

Quellcode:

C++:

//
//only TestWinFormApp
//July 2006
//

#pragma once

namespace TestWinFormApp {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    ///          'Resource File Name' property for the managed resource compiler tool
    ///          associated with all .resx files this class depends on.  Otherwise,
    ///          the designers will not be able to interact properly with localized
    ///          resources associated with this form.
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  button1;
    private: System::Windows::Forms::Button^  button2;
    private: newControl::newControlControl^  newControlControl1;
    //to use CustomControl in TestWinFormApp
    private: static int flankcounter = 0;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->button2 = (gcnew System::Windows::Forms::Button());
            this->newControlControl1 = (gcnew newControl::newControlControl());
            this->SuspendLayout();
            //
            // button1
            //
            this->button1->Location = System::Drawing::Point(102, 208);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->TabStop = false;
            this->button1->Text = L"beenden";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            this->button1->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
            //
            // button2
            //
            this->button2->Location = System::Drawing::Point(102, 159);
            this->button2->Name = L"button2";
            this->button2->Size = System::Drawing::Size(75, 23);
            this->button2->TabIndex = 0;
            this->button2->TabStop = false;
            this->button2->Text = L"button2";
            this->button2->UseVisualStyleBackColor = true;
            this->button2->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
            //
            // newControlControl1
            //
            this->newControlControl1->ButtonText = L"ändern";
            this->newControlControl1->LabelText = L"Weiche 1";
            this->newControlControl1->Location = System::Drawing::Point(200, 159);
            this->newControlControl1->Name = L"newControlControl1";
            this->newControlControl1->Size = System::Drawing::Size(127, 72);
            this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusMiddle;
            this->newControlControl1->TabIndex = 0;
            this->newControlControl1->button->Click += gcnew System::EventHandler(this, &Form1::newControlControl1_Click);
            this->newControlControl1->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
            this->newControlControl1->button->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(1280, 1024);
            this->ControlBox = false;
            this->Controls->Add(this->newControlControl1);
            this->Controls->Add(this->button2);
            this->Controls->Add(this->button1);
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->TopMost = true;
            this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form1_KeyDown);
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->ResumeLayout(false);

        }
#pragma endregion

    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e)
             {
             }

    //KeyEventHandler to catch downKeys
    private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
             {

                if (e->Alt)
                {    
                    //ALT F4 Catch:
                    if (e->KeyCode == Keys::F4)
                        {
                            MessageBox::Show("Couldn`t close Program!");
                        }

                    //doesn`t work
                    /*
                    //ALT TAB Catch:
                    if (e->KeyCode == Keys::Tab)
                        {
                            MessageBox::Show("Couldn`t switch Program!");
                        }
                    */

                }
                    
                //Event Handled
                e->Handled = true;
             }

    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
             {
                this->Close();
             }

     private: System::Void newControlControl1_Click(System::Object^  sender, System::EventArgs^  e)
             {
                 switch(flankcounter%3)
                 {
                    case 0:
                        this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusLeft;
                        break;
                    case 1:
                        this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusMiddle;
                        break;
                    case 2:
                        this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusRight;
                        break;
                 }

                 this->Refresh();
                 flankcounter++;

             }


    };
}




--
Das Leben ist ein Scheiß-Spiel...
aber die Grafik ist saugeil!!!
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
011
10.07.2006, 16:31 Uhr
Th



Um ein Fenster am Schließen zu hindern, einfach OnClosing implementieren:


C++:
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
     e.Cancel = true;
}


So kann es selbst durch dein eigenes Programm nicht mehr geschlossen werden...
(wenn doch einfach eine Variable setzen bzw. OnClosing deaktivieren)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
012
11.07.2006, 14:53 Uhr
der Leitman



HAHA!!! Super

Danke nochmals, habs folgendermaßen gelöst:


C++:
#pragma once


namespace TestWinFormApp {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    ///          'Resource File Name' property for the managed resource compiler tool
    ///          associated with all .resx files this class depends on.  Otherwise,
    ///          the designers will not be able to interact properly with localized
    ///          resources associated with this form.
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }

    private: System::Windows::Forms::Button^  button1;
    private: newControl::newControlControl^  newControlControl1;
    // to use CustomControl in Testproject:
    private: static int flankcounter = 0;
             // to control ClosingEvent
             static bool closingActive = false;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->newControlControl1 = (gcnew newControl::newControlControl());
            this->SuspendLayout();
            //
            // button1
            //
            this->button1->Location = System::Drawing::Point(102, 208);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabStop = false;
            this->button1->Text = L"closing";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            //
            // newControlControl1
            //
            this->newControlControl1->ButtonText = L"change";
            this->newControlControl1->LabelText = L"Flank 1";
            this->newControlControl1->Location = System::Drawing::Point(200, 159);
            this->newControlControl1->Name = L"newControlControl1";
            this->newControlControl1->Size = System::Drawing::Size(127, 72);
            this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusMiddle;
            this->newControlControl1->TabStop = false;
            this->newControlControl1->button->Click += gcnew System::EventHandler(this, &Form1::newControlControl1_Click);
            //
            // Form1
            //
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(1600, 1200);
            // no close, maximize, minimize controls:
            this->ControlBox = false;
            this->Controls->Add(this->newControlControl1);
            this->Controls->Add(this->button1);
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
            this->Name = L"testWinApp";
            this->Text = L"form1";
            // to prevent Window switching:
            this->TopMost = true;
            this->ResumeLayout(false);
            // to prevent closing:
            this->Closing += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::form1_Closing);

        }
#pragma endregion

    // if "end"Button pressed, set closeActive = true to Close Window
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
             {
                 closingActive = true;
                 this->Close();
             }

    private: System::Void form1_Closing(System::Object^ sender, System::ComponentModel::CancelEventArgs^ e)
             {
                 // if closingActive = true ==> Close Window, if not, dont Close
                 e->Cancel = (closingActive == false) ? true : false;
             }

    // function to test CustomControl :
     private: System::Void newControlControl1_Click(System::Object^  sender, System::EventArgs^  e)
             {
                 switch(flankcounter%3)
                 {
                    case 0:
                        this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusLeft;
                        break;
                    case 1:
                        this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusMiddle;
                        break;
                    case 2:
                        this->newControlControl1->StatusFlank = newControl::newControlControl::FlankStatus::StatusRight;
                        break;
                 }

                 this->Refresh();
                 flankcounter++;

             }


    };
}




Das einzige wodurch sich das Programm noch schließen lässt
ist wenn man die Windowstaste und dann Herunterfahren drückt, aber da dann sowieso die ganze Workstation herunterfährt, ist das kein Problem *freu*
(Ja ok... und weil das nur ein Testprogramm ist, habe ich einen Button eingebaut, um das Programm wieder schließen zu können)

Danke,

der Leitman
--
Das Leben ist ein Scheiß-Spiel...
aber die Grafik ist saugeil!!!

Dieser Post wurde am 11.07.2006 um 14:57 Uhr von der Leitman editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: [ 1 ] > 2 <     [ C++CLI / VB .Net / .Net-Framework ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: