Bonjour j'ai un probleme avec wndproc pour intercepter les evenements. Quand j'ai un formulaire vierge, tout fonctionne niquel!
Mais quand je lui ajoute un bouton par exemple. Plus rien ne fonctionne. Je comprends pas.
Voilà ma source;
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 using System; using System.Drawing; using System.Windows.Forms; namespace csTempWindowsApplication1 { public class Form1 : System.Windows.Forms.Form { private int iChar; private System.Windows.Forms.Button button1; // Constant value was found in the "windows.h" header file. private const int WM_KEYDOWN = 0x0100; [STAThread] static void Main() { Application.Run(new Form1()); } public Form1() { InitializeComponent(); this.Size = new System.Drawing.Size(300,300); this.Text = "Form1"; this.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(48, 48); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click_1); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button1); this.Name = "Form1"; this.ResumeLayout(false); } protected override void WndProc(ref Message m) { if (m.Msg != WM_KEYDOWN) { base.WndProc(ref m); } else {MessageBox.Show("1"); iChar = m.WParam.ToInt32(); switch(iChar) { case (int)Keys.D0: this.button1.Text="1"; break; case (int)Keys.D1: MessageBox.Show("1"); break; case (int)Keys.D2: MessageBox.Show("2"); break; default: //Make sure that you pass unhandled messages back to the default message handler. base.WndProc(ref m); break; } } } private void button1_Click_1(object sender, System.EventArgs e) { MessageBox.Show("ok"); } } }
Partager