IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage C++ Discussion :

Utiliser Panel de windows form avec HWND


Sujet :

Langage C++

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2020
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 27
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2020
    Messages : 1
    Points : 2
    Points
    2
    Par défaut Utiliser Panel de windows form avec HWND
    Bonjour c'est mon première poste j'espère que j'aurai des réponses je travail sur un projet, je dois créer une interface homme machine en windows form de Visual Studio j'ai besoin d'afficher des images, pour cela j'utilise un Panel, une fois j'appuie sur un Button je lance l'affichage des image, dans le fichier.h j'ai la fonction qui se lance une fois j'appuie sur le button, à l'interieur de ce dernier je lance une fichier.cpp la où je mis le traitement d'image et je veux ajouter l'affichage des image aussi, j'utilise la bibliothèque MIL de Matrox, il ont une fonction "MdispSelectWindow(UserHookDataPtr->Disp, ModifiedBufferId, monHandle);" pour l'affichage des résultats dans le troisième paramètre je dois mettre le Handle de mon panel où je veux afficher. pour créer le Handle j'utilise la méthode suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        HWND monHandle;
     
        monHandle = (HWND)panel1->Handle.ToPointer();
        MdispSelectWindow(UserHookDataPtr->Disp, ModifiedBufferId, monHandle);
    mais j'ai une erreur, le "panel1" non défini, je sais pas comment le déclarer dans ce fichier.cpp, normalement il est déclaré dans le fichier.h, comment je peux l'utiliser dans le fichier.cpp ?
    fichier.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
     
    #pragma once
    #include <iostream>
     
     
    namespace test {
     
        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>
        /// Description résumée de MyForm
        /// </summary>
        public ref class MyForm : public System::Windows::Forms::Form
        {
        public:
            MyForm(void)
            {
                InitializeComponent();
                //
                //TODO: ajoutez ici le code du constructeur
                //
            }
     
        public:
            /// <summary>
            /// Nettoyage des ressources utilisées.
            /// </summary>
            ~MyForm()
            {
                if (components)
                {
                    delete components;
                }
            }
        public: System::Windows::Forms::Panel^ panel1;
        private: System::Windows::Forms::Button^ button1;
        private: System::Windows::Forms::Button^ button2;
        private: System::Windows::Forms::Panel^ panel2;
        protected:
     
        private:
            /// <summary>
            /// Variable nécessaire au concepteur.
            /// </summary>
            System::ComponentModel::Container ^components;
     
    #pragma region Windows Form Designer generated code
            /// <summary>
            /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
            /// le contenu de cette méthode avec l'éditeur de code.
            /// </summary>
            void InitializeComponent(void)
            {
                std::cout << "Hello world!" << std::endl;
                this->panel1 = (gcnew System::Windows::Forms::Panel());
                this->button1 = (gcnew System::Windows::Forms::Button());
                this->button2 = (gcnew System::Windows::Forms::Button());
                this->panel2 = (gcnew System::Windows::Forms::Panel());
                this->SuspendLayout();
                //
                // panel1
                //
                this->panel1->AccessibleDescription = L"pan";
                this->panel1->AccessibleName = L"pan";
                this->panel1->BackColor = System::Drawing::SystemColors::ControlDark;
                this->panel1->Location = System::Drawing::Point(385, 83);
                this->panel1->Name = L"panel1";
                this->panel1->Size = System::Drawing::Size(384, 273);
                this->panel1->TabIndex = 0;
                this->panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::panel1_Paint);
                //
                // button1
                //
                this->button1->Location = System::Drawing::Point(118, 155);
                this->button1->Name = L"button1";
                this->button1->Size = System::Drawing::Size(89, 32);
                this->button1->TabIndex = 1;
                this->button1->Text = L"scan code";
                this->button1->UseVisualStyleBackColor = true;
                this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
                //
                // button2
                //
                this->button2->Location = System::Drawing::Point(118, 219);
                this->button2->Name = L"button2";
                this->button2->Size = System::Drawing::Size(89, 34);
                this->button2->TabIndex = 2;
                this->button2->Text = L"test2";
                this->button2->UseVisualStyleBackColor = true;
                //
                // panel2
                //
                this->panel2->Location = System::Drawing::Point(926, 83);
                this->panel2->Name = L"panel2";
                this->panel2->Size = System::Drawing::Size(263, 198);
                this->panel2->TabIndex = 3;
                this->panel2->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::panel2_Paint);
                //
                // MyForm
                //
                this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(1383, 548);
                this->Controls->Add(this->panel2);
                this->Controls->Add(this->button2);
                this->Controls->Add(this->button1);
                this->Controls->Add(this->panel1);
                this->Name = L"MyForm";
                this->Text = L"MyForm";
                this->ResumeLayout(false);
     
            }
    #pragma endregion
        public: System::Void panel1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
     
     
     
     
        }
        private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
     
            int code(void);
                code();
     
        }
        private: System::Void panel2_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
     
     
     
        }
    };
    }
    fichier.cpp

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
     
     
    #include "mil.h"
    #include <iostream>
    #include <windows.h>
    #include <string>
    #include <iostream>
    #include "MyForm.h"
     
    #include <algorithm>
     
     
    using namespace System;
    using namespace std;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
     
     
    const MIL_INT32 NbFrames = 4;
     
    // User's processing function hook data object
    MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType, MIL_ID HookId, void* HookDataPtr);
    typedef struct
    {
        MIL_ID Code_Context;
        MIL_ID Code_Result;
        MIL_ID Disp;
        MIL_ID McodeRead_Block_graphicContext;
        MIL_ID McodeRead_Block_graphicList;
    } HookDataStruct;
     
    int code(void)
    {
        MIL_ID MilApplication = M_NULL;
        MIL_ID* GrabBuffers = new MIL_ID[NbFrames];
        MIL_INT Digsizex = 0;
        MIL_INT Digsizey = 0;
        MIL_INT Digsizeband = 0;
        MIL_INT Digtype = 0;
        MIL_ID Codemodel0 = M_NULL;
        MIL_ID MilSystem = M_NULL;
        MIL_ID AIMDPMGrading = M_NULL;
        MIL_ID Code_Context = M_NULL;
        MIL_ID Code_Result = M_NULL;
        MIL_ID Disp = M_NULL;
        MIL_ID McodeRead_Block_graphicContext = M_NULL;
        MIL_ID McodeRead_Block_graphicList = M_NULL;
        HookDataStruct UserHookData;
     
     
     
        /////////////////////////////
     
     
     
     
        /////////////////////////
     
     
     
        MappAlloc(M_NULL, M_DEFAULT, &MilApplication);
        MsysAlloc(M_DEFAULT, MIL_TEXT("M_SYSTEM_HOST"), M_DEFAULT, M_DEFAULT, &MilSystem);
        MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &Disp);
     
        // Control Block for Disp
        MdispControl(Disp, M_TITLE, MIL_TEXT("Disp"));
     
        MdigAlloc(MilSystem, M_DEFAULT, MIL_TEXT("D:\\STPGroup\\Matrox\\MIL\\Matrox Imaging\\Images\\Full\\AIMDPMGrading"), M_DEFAULT, &AIMDPMGrading);
     
        // Post-Alloc Block for AIMDPMGrading
        MdigInquire(AIMDPMGrading, M_SIZE_X, &Digsizex);
        MdigInquire(AIMDPMGrading, M_SIZE_Y, &Digsizey);
        MdigInquire(AIMDPMGrading, M_SIZE_BAND, &Digsizeband);
        MdigInquire(AIMDPMGrading, M_TYPE, &Digtype);
     
        // MbufAllocColor loop
        for (int t = 0; t < NbFrames; t++)
        {
            GrabBuffers[t] = MbufAllocColor(MilSystem, Digsizeband, Digsizex, Digsizey, Digtype, M_IMAGE + M_PROC + M_GRAB + M_DISP, M_NULL);
        }
     
        MgraAlloc(MilSystem, &McodeRead_Block_graphicContext);
        MgraAllocList(MilSystem, M_DEFAULT, &McodeRead_Block_graphicList);
        McodeAlloc(MilSystem, M_DEFAULT, M_IMPROVED_RECOGNITION, &Code_Context);
     
        // Post-Alloc Block for Code Context
        McodeModel(Code_Context, M_ADD, M_DATAMATRIX, M_NULL, M_DEFAULT, &Codemodel0);
     
        McodeAllocResult(MilSystem, M_DEFAULT, &Code_Result);
     
        // Initialize the user's processing function data structure.
        UserHookData.Code_Context = Code_Context;
        UserHookData.Code_Result = Code_Result;
        UserHookData.Disp = Disp;
        UserHookData.McodeRead_Block_graphicContext = McodeRead_Block_graphicContext;
        UserHookData.McodeRead_Block_graphicList = McodeRead_Block_graphicList;
     
        // MdigProcess operation Block
        MdigProcess(AIMDPMGrading, GrabBuffers, NbFrames, M_START, M_ASYNCHRONOUS + M_REGION_DELETE_AT_EACH_FRAME, ProcessingFunction, &UserHookData);
        MosPrintf(MIL_TEXT("Press enter to stop grabbing\n"));
        MosGetch();
        MdigProcess(AIMDPMGrading, GrabBuffers, NbFrames, M_STOP, M_DEFAULT, ProcessingFunction, &UserHookData);
     
        MosPrintf(MIL_TEXT("Press <ENTER> to continue\n"));
        MosGetch();
     
        // MbufFree loop
        for (int t = 0; t < NbFrames; t++)
        {
            MbufFree(GrabBuffers[t]);
        }
     
        McodeFree(Code_Result);
        McodeFree(Code_Context);
        MgraFree(McodeRead_Block_graphicList);
        MgraFree(McodeRead_Block_graphicContext);
        MdigFree(AIMDPMGrading);
        MdispFree(Disp);
        MsysFree(MilSystem);
        MappFree(MilApplication);
     
        delete[] GrabBuffers;
     
        return 0;
    }
     
    // User's processing function called every time a grab buffer is ready.
    MIL_INT MFTYPE ProcessingFunction(MIL_INT /*HookType*/, MIL_ID HookId, void* HookDataPtr)
    {
        MIL_TEXT_CHAR* String0 = 0;
        MIL_DOUBLE CodeType = 0.0;
        MIL_INT Stringsize9 = 0;
        MIL_DOUBLE Score = 0.0;
        MIL_TEXT_CHAR* EscapeSequence = 0;
        MIL_INT Stringsize10 = 0;
        MIL_DOUBLE EscapeSequenceStringSize = 0.0;
        HookDataStruct* UserHookDataPtr = (HookDataStruct*)HookDataPtr;
        MIL_ID ModifiedBufferId;
     
        // Retrieve the MIL_ID of the grabbed buffer.
        MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId);
        McodeRead(UserHookDataPtr->Code_Context, ModifiedBufferId, UserHookDataPtr->Code_Result);
     
        // Display Block for McodeRead Block
        MgraControl(UserHookDataPtr->McodeRead_Block_graphicContext, M_COLOR, M_COLOR_GREEN);
        McodeDraw(UserHookDataPtr->McodeRead_Block_graphicContext, UserHookDataPtr->Code_Result, UserHookDataPtr->McodeRead_Block_graphicList, M_DRAW_BOX, M_DEFAULT, M_DEFAULT);
        MdispControl(UserHookDataPtr->Disp, M_ASSOCIATED_GRAPHIC_LIST_ID, UserHookDataPtr->McodeRead_Block_graphicList);
        MgraControl(UserHookDataPtr->McodeRead_Block_graphicContext, M_FIXTURE, M_USE_SOURCE_FIRST);
     
        ////////////////////////////////////////////////////////////////////////////////////////
     
        //private: System::Windows::Forms::Panel^ panel1;
        //void InitializeComponent();
     
        //System::Void panel1_Paint(System::Object ^ sender, System::Windows::Forms::PaintEventArgs ^ e);
        //System::Windows::Forms::Panel^ panel1;
        //void panel1();
     
        HWND monHandle;
     
        monHandle = (HWND)panel1->Handle.ToPointer();
        MdispSelectWindow(UserHookDataPtr->Disp, ModifiedBufferId, monHandle);
     
        //MdispSelectWindow(UserHookDataPtr->Disp, ModifiedBufferId, M_NULL);
     
     
     
        McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_STRING_SIZE + M_TYPE_MIL_INT, &Stringsize9);
        if (Stringsize9 > 1)
        {
            String0 = new MIL_TEXT_CHAR[Stringsize9];
            McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING, String0);
        }
        McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_CODE_TYPE + M_TYPE_MIL_DOUBLE, &CodeType);
        McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_SCORE + M_TYPE_MIL_DOUBLE, &Score);
        McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_ESCAPE_SEQUENCE + M_STRING_SIZE + M_TYPE_MIL_INT, &Stringsize10);
        if (Stringsize10 > 1)
        {
            EscapeSequence = new MIL_TEXT_CHAR[Stringsize10];
            McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_ESCAPE_SEQUENCE, EscapeSequence);
        }
        McodeGetResultSingle(UserHookDataPtr->Code_Result, 0, M_STRING + M_ESCAPE_SEQUENCE + M_STRING_SIZE + M_TYPE_MIL_DOUBLE, &EscapeSequenceStringSize);
     
        std::cout << "type de code : " << CodeType << std::endl;
        std::cout << "String : " << String0 << std::endl;
        std::cout << "Score : " << Score << std::endl;
        std::cout << "EscapeSequence : " << EscapeSequence << std::endl;
        std::cout << "EscapeSequenceStringSize : " << EscapeSequenceStringSize << std::endl;
     
        //String^ str3 = gcnew String(String0);
        //string ini = System::Convert::ToBase64String(String0);
     
        //std::cout << "Score : " << str3 << std::endl;
     
     
     
        Sleep(2000);
     
     
        MgraClear(UserHookDataPtr->McodeRead_Block_graphicContext, UserHookDataPtr->McodeRead_Block_graphicList);
     
        delete[] String0;
        delete[] EscapeSequence;
        return 0;
    }

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Bonjour,
    HookDataStruct est une structure que tu contrôles (ou contient un pointeur vers une structure que tu contrôles) ? Si oui, le plus simple, c'est que ta fonction code() prenne directement le HWND en paramètre et le mette dans la HookDataStruct.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

Discussions similaires

  1. [Débutant] WPF window form avec des boutons de réduire et fermeture
    Par midou256 dans le forum C#
    Réponses: 2
    Dernier message: 29/04/2013, 20h20
  2. WPF window form avec des boutons de réduire et fermeture
    Par midou256 dans le forum Windows Presentation Foundation
    Réponses: 3
    Dernier message: 18/04/2013, 21h12
  3. Réponses: 2
    Dernier message: 27/08/2007, 16h37
  4. Réponses: 3
    Dernier message: 20/03/2007, 13h30
  5. Réponses: 3
    Dernier message: 27/07/2006, 09h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo