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

Windows Forms Discussion :

[c#][debutant] erreur gdi32


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de orelero
    Étudiant
    Inscrit en
    Novembre 2004
    Messages
    389
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2004
    Messages : 389
    Par défaut [c#][debutant] erreur gdi32
    Bonjour, j'ai recupérer le code de cet page:http://www.developerfusion.co.uk/show/4712/
    ca me sert à faire une copie image de la page web chargée dans un composant webbrowser, seulement lorsque je veux generer la solution (sous vs net2003),j'ai cette erreur:C:\Documents and Settings\[...](171): Le type ou le nom d'espace de noms 'GDI32' est introuvable (une directive using ou une référence d'assembly est-elle manquante*?),
    et voici le code:

    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
    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices; 
    using SHDocVw; 
    using mshtml; 
     
    namespace tmwebb
    {	
    	[Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"),
    	InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
    	ComVisible(true),
    	ComImport]
    	interface IHTMLElementRender
    			{
    				void DrawToDC([In] IntPtr hDC);
    				void SetDocumentPrinter([In, MarshalAs(UnmanagedType.BStr)] string bstrPrinterName, [In] IntPtr hDC);
    			};
     
    	/// <summary>
    	/// Description résumée de Form1.
    	/// </summary>
    	public class Form1 : System.Windows.Forms.Form
    	{
    		public AxSHDocVw.AxWebBrowser axWebBrowser1;
    		private System.Windows.Forms.Button button1;
    		private System.Windows.Forms.TextBox textBox1;
    		private System.Windows.Forms.PictureBox pictureBox1;
    		/// <summary>
    		/// Variable nécessaire au concepteur.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
     
    		public Form1()
    		{
    			//
    			// Requis pour la prise en charge du Concepteur Windows Forms
    			//
    			InitializeComponent();
     
    			//
    			// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
    			//
    		}
     
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if (components != null) 
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
     
    		#region Code généré par le Concepteur Windows Form
    		/// <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>
    		private void InitializeComponent()
    		{
    			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
    			this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
    			this.button1 = new System.Windows.Forms.Button();
    			this.textBox1 = new System.Windows.Forms.TextBox();
    			this.pictureBox1 = new System.Windows.Forms.PictureBox();
    			((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit();
    			this.SuspendLayout();
    			// 
    			// axWebBrowser1
    			// 
    			this.axWebBrowser1.Enabled = true;
    			this.axWebBrowser1.Location = new System.Drawing.Point(8, 24);
    			this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxState")));
    			this.axWebBrowser1.Size = new System.Drawing.Size(312, 416);
    			this.axWebBrowser1.TabIndex = 0;
    			this.axWebBrowser1.Enter += new System.EventHandler(this.axWebBrowser1_Enter);
    			// 
    			// button1
    			// 
    			this.button1.Location = new System.Drawing.Point(8, 0);
    			this.button1.Name = "button1";
    			this.button1.Size = new System.Drawing.Size(80, 24);
    			this.button1.TabIndex = 1;
    			this.button1.Text = "button1";
    			this.button1.Click += new System.EventHandler(this.button1_Click);
    			// 
    			// textBox1
    			// 
    			this.textBox1.Location = new System.Drawing.Point(96, 0);
    			this.textBox1.Name = "textBox1";
    			this.textBox1.Size = new System.Drawing.Size(536, 20);
    			this.textBox1.TabIndex = 2;
    			this.textBox1.Text = "textBox1";
    			// 
    			// pictureBox1
    			// 
    			this.pictureBox1.Location = new System.Drawing.Point(336, 32);
    			this.pictureBox1.Name = "pictureBox1";
    			this.pictureBox1.Size = new System.Drawing.Size(312, 408);
    			this.pictureBox1.TabIndex = 3;
    			this.pictureBox1.TabStop = false;
    			// 
    			// Form1
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(656, 454);
    			this.Controls.Add(this.pictureBox1);
    			this.Controls.Add(this.textBox1);
    			this.Controls.Add(this.button1);
    			this.Controls.Add(this.axWebBrowser1);
    			this.Name = "Form1";
    			this.Text = "Form1";
    			((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
    			this.ResumeLayout(false);
     
    		}
    		#endregion
     
     
    		/// <summary>
    		/// Point d'entrée principal de l'application.
    		/// </summary>
    		[STAThread]
    		static void Main() 
    		{
    			Application.Run(new Form1());
    		}
    		private void OnDocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
    		{
    			IHTMLDocument2 document = (IHTMLDocument2) this.axWebBrowser1.Document;
    			if (document != null)
    			{
    				IHTMLElement element = (IHTMLElement) document.body;
    				if (element != null)
    				{
    					IHTMLElementRender render = (IHTMLElementRender) element;
    					if (render != null)
    					{
    						using (Graphics graphics = this.pictureBox1.CreateGraphics())
    						{
    							IntPtr hdcDestination = graphics.GetHdc();
    							render.DrawToDC(hdcDestination);
    							IntPtr hdcMemory = GDI32.CreateCompatibleDC(hdcDestination);
    							IntPtr bitmap = GDI32.CreateCompatibleBitmap(
    								hdcDestination,  
    								this.axWebBrowser1.ClientRectangle.Width, this.axWebBrowser1.ClientRectangle.Height
    								);
     
    							if (bitmap != IntPtr.Zero)
    							{
    								IntPtr hOld = (IntPtr) GDI32.SelectObject(hdcMemory, bitmap);
    								GDI32.BitBlt(
    									hdcMemory,
    									0, 0,
    									this.axWebBrowser1.ClientRectangle.Width, this.axWebBrowser1.ClientRectangle.Height,
    									hdcDestination,
    									0, 0,
    									(int) GDI32.TernaryRasterOperations.SRCCOPY
    									);
    								GDI32.SelectObject(hdcMemory, hOld);
    								GDI32.DeleteDC(hdcMemory);
    								graphics.ReleaseHdc(hdcDestination);
     
    								this.pictureBox1.Image = Image.FromHbitmap(bitmap);
    							}
    						}
    					}
    				}
    			}
    		}
     
    		private void axWebBrowser1_Enter(object sender, System.EventArgs e)
    		{
     
    		}
     
    		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
    		{
     
    		}
     
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    			System.Object nullObject = 0;
    			string str = "";
    			System.Object nullObjStr = str;
    			Cursor.Current = Cursors.WaitCursor;
    			axWebBrowser1.Navigate(textBox1.Text, ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr);
    			Cursor.Current = Cursors.Default;
     
     
    		}
    	}
    }
    je suppose que je dois referencer gdi32.dll ? J'ai essayé de voir sur google et je suis tombé sur des trucs que je pige pas comme d'hab ... J'espere que dans mon explication je n'oublie rien, voilà merci

  2. #2
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut Re: [c#][debutant] erreur gdi32
    Essayes par l'importation directe de l'API gdi32.dll, j'ai récupéré les signatures des méthodes que je connaissais mais va falloir que tu definisses toi mêmeTernaryRasterOperations que je connais pas dans la librairie gdi32.dll mais comme une Enumération
    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
     
    //...
          [DllImport("gdi32.dll")]
          static extern IntPtr CreateCompatibleDC(IntPtr hdc);
          [DllImport("gdi32.dll")]
          static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
          [DllImport("gdi32.dll")]
          static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
          [DllImport("gdi32.dll")]
          static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
          [DllImport("gdi32.dll")]
          static extern bool DeleteDC(IntPtr hdc);
     
          private void OnDocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
           {
             IHTMLDocument2 document = (IHTMLDocument2)
             this.axWebBrowser1.Document;
             if (document != null)
             {
               IHTMLElement element = (IHTMLElement) document.body;
               if (element != null)
               {
                 IHTMLElementRender render = (IHTMLElementRender) element;
                 if (render != null)
                 {
                   using (Graphics graphics = this.pictureBox1.CreateGraphics())
                   {
                     IntPtr hdcDestination = graphics.GetHdc();
                     render.DrawToDC(hdcDestination);
                     IntPtr hdcMemory = CreateCompatibleDC(hdcDestination);
                     IntPtr bitmap = CreateCompatibleBitmap( hdcDestination, this.axWebBrowser1.ClientRectangle.Width, this.axWebBrowser1.ClientRectangle.Height);
                     if (bitmap != IntPtr.Zero)
                     {
                       IntPtr hOld = (IntPtr) SelectObject(hdcMemory, bitmap);
                       BitBlt(hdcMemory,0, 0, this.axWebBrowser1.ClientRectangle.Width, this.axWebBrowser1.ClientRectangle.Height,hdcDestination,0, 0,(int)TernaryRasterOperations.SRCCOPY);
                       SelectObject(hdcMemory, hOld);
                       DeleteDC(hdcMemory);
                       graphics.ReleaseHdc(hdcDestination);
                       this.pictureBox1.Image = Image.FromHbitmap(bitmap);
                     }
                  }
                }
              }
            }
          }
    //...
    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
     
    public enum TernaryRasterOperations
    {
        SRCCOPY     = 0x00CC0020, /* dest = source*/
        SRCPAINT    = 0x00EE0086, /* dest = source OR dest*/
        SRCAND      = 0x008800C6, /* dest = source AND dest*/
        SRCINVERT   = 0x00660046, /* dest = source XOR dest*/
        SRCERASE    = 0x00440328, /* dest = source AND (NOT dest )*/
        NOTSRCCOPY  = 0x00330008, /* dest = (NOT source)*/
        NOTSRCERASE = 0x001100A6, /* dest = (NOT src) AND (NOT dest) */
        MERGECOPY   = 0x00C000CA, /* dest = (source AND pattern)*/
        MERGEPAINT  = 0x00BB0226, /* dest = (NOT source) OR dest*/
        PATCOPY     = 0x00F00021, /* dest = pattern*/
        PATPAINT    = 0x00FB0A09, /* dest = DPSnoo*/
        PATINVERT   = 0x005A0049, /* dest = pattern XOR dest*/
        DSTINVERT   = 0x00550009, /* dest = (NOT dest)*/
        BLACKNESS   = 0x00000042, /* dest = BLACK*/
        WHITENESS   = 0x00FF0062, /* dest = WHITE*/
    };

  3. #3
    Membre éclairé Avatar de orelero
    Étudiant
    Inscrit en
    Novembre 2004
    Messages
    389
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2004
    Messages : 389
    Par défaut
    merci bien neguib, par contre je ne comprends à quoi sert TernaryRasterOperations et aussi pourquoi on est obligé de recupérer les signatures (ca ne peut pas se faire automatiquement?) .

  4. #4
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    il ne s'agit pas de recupérer une signature mais d'importer la dll non managée, je te renvoie à la doc .Net de MSDN à ce sujet, il y a aussi je crois quelquechose du côté de la Faq il me semble.
    TernaryRasterOperations

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XSL] [debutant] erreur bete avec choose
    Par enigma dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 21/07/2005, 17h58
  2. [langage] [Débutant] Erreur scalar found
    Par bartmarley dans le forum Langage
    Réponses: 5
    Dernier message: 30/05/2005, 11h50
  3. debutant: erreur LNK2001 avec la librairie GSL
    Par drill3 dans le forum MFC
    Réponses: 6
    Dernier message: 25/04/2005, 13h58
  4. [Debutant] Erreur "Unhandled event loop exception"
    Par pilz dans le forum Eclipse Platform
    Réponses: 14
    Dernier message: 08/12/2004, 15h19
  5. [Debutant]erreur lors de la sauvegarde d un code.
    Par Mr_Chut dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 27/04/2004, 19h42

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