Accueil > > > SIMULATION DE CONSOLE POUR WINDOWS MOBILE
SIMULATION DE CONSOLE POUR WINDOWS MOBILE
Information sur la source
Description
Pour faire court, lorsqu'on développe en .NET sous WM, on ne dispose pas des mêmes outils que sous windows: pas de console, pas de véritable chrono à se mettre sous la dent pour trouver les processus qui sont trop lents... Bref, la classe que je vous propose bien que très simple permet de remplir quelques lacunes. Je l'ai faite (baclé ?) en 2h, avec moins 2 mois d' "expérience" en C#... et pourtant elle me rend de grands services ! C'est la 2ième fois que j'essais de poster ce code... comme je n'ai pas envie de re écrire ce que j'ai déjà fait 2 fois (sur mon site et ici), voici le lien direct sur mon site internet où j'explique pourquoi et comment se servir de la classe etc... http://newprograms.free.fr/CSHARP/index.ph p
Source
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing; // Point
- using System.Runtime.InteropServices; // DllImport
- using System.Windows.Forms; // Form
- using System.IO; // StreamWriter
-
- namespace OCagenda
- {
- class ClassDebugForWM
- {
- [DllImport("coredll.dll")]
- public static extern int GetTickCount();
-
- List<long> lstart = new List<long>();
-
- Panel pchrono = new Panel();
- TextBox lchrono = new TextBox();
- int unite;
- string ini = "";
-
- public void init(Color c, string repini)
- {
- ini = repini;
- lchrono.Parent = pchrono;
- pchrono.Location = new Point(50, 100);
- pchrono.BackColor = c;
- lchrono.Multiline = true;
- lchrono.BackColor = Color.White;
- lchrono.Font = new Font("Arial", 7, FontStyle.Regular);
- lchrono.WordWrap = false;
- lchrono.ScrollBars = ScrollBars.Both;
- unite = lchrono.Height;
- pchrono.ClientSize = new Size(122, unite * 7 + 2);
- lchrono.Location = new Point(1, 1 + unite);
- lchrono.Size = new Size(120, unite * 6);
- pchrono.MouseMove += new MouseEventHandler(TitreFenetre_MouseMove);
- pchrono.MouseDown += new MouseEventHandler(TitreFenetre_MouseDown);
- pchrono.MouseUp += new MouseEventHandler(TitreFenetre_MouseUp);
- FenetreUtile = Screen.PrimaryScreen.WorkingArea;
- //
- Button b3 = new Button();
- b3.Location = new Point(1, 1);
- b3.Size = new Size(unite, unite);
- b3.Font = lchrono.Font;
- b3.Text = "-";
- b3.Parent = pchrono;
- b3.Click += delegate(Object sender, EventArgs e)
- {
- if (b3.Text == "-")
- {
- pchrono.ClientSize = new Size(122, unite * 1 + 2);
- lchrono.Height = unite * 0;
- b3.Text = "+";
- }
- else
- {
- pchrono.ClientSize = new Size(122, unite * 7 + 2);
- lchrono.Height = unite * 6;
- b3.Text = "-";
- }
- };
- //
- Button b1 = new Button();
- b1.Location = new Point(1 +unite, 1);
- b1.Size = new Size(unite, unite);
- b1.Font = lchrono.Font;
- b1.Text = "0";
- b1.Parent = pchrono;
- b1.Click += delegate(Object sender, EventArgs e)
- {
- lchrono.Text = "";
- };
- //
- Button b2 = new Button();
- b2.Location = new Point(1 + unite * 2, 1);
- b2.Size = new Size(unite, unite);
- b2.Font = lchrono.Font;
- b2.Text = "10";
- b2.Parent = pchrono;
- b2.Click += delegate(Object sender, EventArgs e)
- {
- string[] st = lchrono.Text.Split('\r');
-
- if (st.Length > 10)
- {
- lchrono.Text = st[0];
-
- for (int i = 1; i < 10; i++)
- lchrono.Text += "\r\n" + st[i].Substring(1, st[i].Length-1);
- }
- };
- //
- Button b4 = new Button();
- b4.Location = new Point(1 + unite * 3, 1);
- b4.Size = new Size(unite, unite);
- b4.Font = lchrono.Font;
- b4.Text = "s";
- b4.Parent = pchrono;
- b4.Click += delegate(Object sender, EventArgs e)
- {
- WriteIni();
- };
- }
-
- // --------------------------------------------------------------------------------------------------
-
- public void WriteIni()
- {
- try
- {
- using (StreamWriter sw = File.CreateText(ini + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"))
- {
- string[] st = lchrono.Text.Split('\r');
-
- if (st.Length > 1)
- {
- sw.WriteLine(st[0]);
-
- for (int i = 1; i < st.Length; i++)
- sw.WriteLine(st[i].Substring(1, st[i].Length - 1));
- }
- sw.Close();
- }
- }
- catch
- {
- // si l'écriture dans le mobile échoue, je ne fais rien !!!!
- }
- }
-
- // --------------------------------------------------------------------------------------------------
-
- Point MousePositionInCaption;
-
- private void TitreFenetre_MouseDown(object sender, MouseEventArgs e)
- {
- MousePositionInCaption.X = e.X;
- MousePositionInCaption.Y = e.Y;
- }
-
- Rectangle FenetreUtile;
- Boolean NouveauTraitement = true;
- Point NouvellePositionForm = new Point();
- Point AnciennePosition = new Point();
- //static Point this_Location = new Point();
-
- private void TitreFenetre_MouseMove(object sender, MouseEventArgs e)
- {
- if (NouveauTraitement)
- {
- NouveauTraitement = false;
- // e.X, e.Y = position de la souris dans le controle
- NouvellePositionForm.X = pchrono.Location.X + (e.X - MousePositionInCaption.X);
- NouvellePositionForm.Y = pchrono.Location.Y + (e.Y - MousePositionInCaption.Y);
-
- if (!AnciennePosition.Equals(NouvellePositionForm))
- {
- AnciennePosition.X = NouvellePositionForm.X;
- AnciennePosition.Y = NouvellePositionForm.Y;
- }
-
- NouveauTraitement = true;
- }
- }
-
- private void TitreFenetre_MouseUp(object sender, MouseEventArgs e)
- {
- pchrono.Top = Math.Min(Math.Max(0, NouvellePositionForm.Y), Screen.PrimaryScreen.WorkingArea.Height -24 - pchrono.Height);
- pchrono.Left = Math.Min(Math.Max(0, NouvellePositionForm.X), Screen.PrimaryScreen.WorkingArea.Width - pchrono.Width);
- }
-
- // --------------------------------------------------------------------------------------------------
-
- public void show(string t, Boolean Clear)
- {
- if (Clear || (lchrono.Text == ""))
- lchrono.Text = t;
- else
- lchrono.Text = t + "\r\n" + lchrono.Text;
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- public void show(Form f, string t, Boolean Clear)
- {
- show(t, Clear);
- pchrono.Parent = f;
- pchrono.Visible = true;
- pchrono.BringToFront();
- }
-
- // --------------------------------------------------------------------------------------------------
-
- public void start()
- {
- lstart.Add(GetTickCount());
- }
-
- // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-
- public void end(Form f, string s, Boolean Clear)
- {
- long lduree = GetTickCount() - lstart[lstart.Count - 1];
- string t = lstart.Count.ToString() + " ; " +lduree.ToString() + (s != "" ? " ; " + s : "");
- show(f, t, Clear);
- lstart.RemoveAt(lstart.Count - 1);
- }
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- public void end(string s, Boolean Clear)
- {
- long lduree = GetTickCount() - lstart[lstart.Count - 1];
- string t = lstart.Count.ToString() + " ; " + lduree.ToString() + (s != "" ? " ; " + s : "");
- show(t, Clear);
- lstart.RemoveAt(lstart.Count - 1);
- }
-
- // --------------------------------------------------------------------------------------------------
- }
- }
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing; // Point
using System.Runtime.InteropServices; // DllImport
using System.Windows.Forms; // Form
using System.IO; // StreamWriter
namespace OCagenda
{
class ClassDebugForWM
{
[DllImport("coredll.dll")]
public static extern int GetTickCount();
List<long> lstart = new List<long>();
Panel pchrono = new Panel();
TextBox lchrono = new TextBox();
int unite;
string ini = "";
public void init(Color c, string repini)
{
ini = repini;
lchrono.Parent = pchrono;
pchrono.Location = new Point(50, 100);
pchrono.BackColor = c;
lchrono.Multiline = true;
lchrono.BackColor = Color.White;
lchrono.Font = new Font("Arial", 7, FontStyle.Regular);
lchrono.WordWrap = false;
lchrono.ScrollBars = ScrollBars.Both;
unite = lchrono.Height;
pchrono.ClientSize = new Size(122, unite * 7 + 2);
lchrono.Location = new Point(1, 1 + unite);
lchrono.Size = new Size(120, unite * 6);
pchrono.MouseMove += new MouseEventHandler(TitreFenetre_MouseMove);
pchrono.MouseDown += new MouseEventHandler(TitreFenetre_MouseDown);
pchrono.MouseUp += new MouseEventHandler(TitreFenetre_MouseUp);
FenetreUtile = Screen.PrimaryScreen.WorkingArea;
//
Button b3 = new Button();
b3.Location = new Point(1, 1);
b3.Size = new Size(unite, unite);
b3.Font = lchrono.Font;
b3.Text = "-";
b3.Parent = pchrono;
b3.Click += delegate(Object sender, EventArgs e)
{
if (b3.Text == "-")
{
pchrono.ClientSize = new Size(122, unite * 1 + 2);
lchrono.Height = unite * 0;
b3.Text = "+";
}
else
{
pchrono.ClientSize = new Size(122, unite * 7 + 2);
lchrono.Height = unite * 6;
b3.Text = "-";
}
};
//
Button b1 = new Button();
b1.Location = new Point(1 +unite, 1);
b1.Size = new Size(unite, unite);
b1.Font = lchrono.Font;
b1.Text = "0";
b1.Parent = pchrono;
b1.Click += delegate(Object sender, EventArgs e)
{
lchrono.Text = "";
};
//
Button b2 = new Button();
b2.Location = new Point(1 + unite * 2, 1);
b2.Size = new Size(unite, unite);
b2.Font = lchrono.Font;
b2.Text = "10";
b2.Parent = pchrono;
b2.Click += delegate(Object sender, EventArgs e)
{
string[] st = lchrono.Text.Split('\r');
if (st.Length > 10)
{
lchrono.Text = st[0];
for (int i = 1; i < 10; i++)
lchrono.Text += "\r\n" + st[i].Substring(1, st[i].Length-1);
}
};
//
Button b4 = new Button();
b4.Location = new Point(1 + unite * 3, 1);
b4.Size = new Size(unite, unite);
b4.Font = lchrono.Font;
b4.Text = "s";
b4.Parent = pchrono;
b4.Click += delegate(Object sender, EventArgs e)
{
WriteIni();
};
}
// --------------------------------------------------------------------------------------------------
public void WriteIni()
{
try
{
using (StreamWriter sw = File.CreateText(ini + "\\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"))
{
string[] st = lchrono.Text.Split('\r');
if (st.Length > 1)
{
sw.WriteLine(st[0]);
for (int i = 1; i < st.Length; i++)
sw.WriteLine(st[i].Substring(1, st[i].Length - 1));
}
sw.Close();
}
}
catch
{
// si l'écriture dans le mobile échoue, je ne fais rien !!!!
}
}
// --------------------------------------------------------------------------------------------------
Point MousePositionInCaption;
private void TitreFenetre_MouseDown(object sender, MouseEventArgs e)
{
MousePositionInCaption.X = e.X;
MousePositionInCaption.Y = e.Y;
}
Rectangle FenetreUtile;
Boolean NouveauTraitement = true;
Point NouvellePositionForm = new Point();
Point AnciennePosition = new Point();
//static Point this_Location = new Point();
private void TitreFenetre_MouseMove(object sender, MouseEventArgs e)
{
if (NouveauTraitement)
{
NouveauTraitement = false;
// e.X, e.Y = position de la souris dans le controle
NouvellePositionForm.X = pchrono.Location.X + (e.X - MousePositionInCaption.X);
NouvellePositionForm.Y = pchrono.Location.Y + (e.Y - MousePositionInCaption.Y);
if (!AnciennePosition.Equals(NouvellePositionForm))
{
AnciennePosition.X = NouvellePositionForm.X;
AnciennePosition.Y = NouvellePositionForm.Y;
}
NouveauTraitement = true;
}
}
private void TitreFenetre_MouseUp(object sender, MouseEventArgs e)
{
pchrono.Top = Math.Min(Math.Max(0, NouvellePositionForm.Y), Screen.PrimaryScreen.WorkingArea.Height -24 - pchrono.Height);
pchrono.Left = Math.Min(Math.Max(0, NouvellePositionForm.X), Screen.PrimaryScreen.WorkingArea.Width - pchrono.Width);
}
// --------------------------------------------------------------------------------------------------
public void show(string t, Boolean Clear)
{
if (Clear || (lchrono.Text == ""))
lchrono.Text = t;
else
lchrono.Text = t + "\r\n" + lchrono.Text;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public void show(Form f, string t, Boolean Clear)
{
show(t, Clear);
pchrono.Parent = f;
pchrono.Visible = true;
pchrono.BringToFront();
}
// --------------------------------------------------------------------------------------------------
public void start()
{
lstart.Add(GetTickCount());
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
public void end(Form f, string s, Boolean Clear)
{
long lduree = GetTickCount() - lstart[lstart.Count - 1];
string t = lstart.Count.ToString() + " ; " +lduree.ToString() + (s != "" ? " ; " + s : "");
show(f, t, Clear);
lstart.RemoveAt(lstart.Count - 1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public void end(string s, Boolean Clear)
{
long lduree = GetTickCount() - lstart[lstart.Count - 1];
string t = lstart.Count.ToString() + " ; " + lduree.ToString() + (s != "" ? " ; " + s : "");
show(t, Clear);
lstart.RemoveAt(lstart.Count - 1);
}
// --------------------------------------------------------------------------------------------------
}
}
Conclusion
http://newprograms.free.fr/CSHARP/index.php
Historique
- 23 novembre 2009 17:05:38 :
- rajout d'une image
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
PB avec les application console [ par Mike ]
Salut, j'ai un probleme avec les application en mode consol ( style fenetre DOS ), lorsque je lance un de ces programmes, il s'arrete automatiquement
Pb avec mon programme - help... [ par adrien78 ]
Voici les sources de mon programme il bug :// project created on 09/11/2002 at 10:51// By Adrien HADJ SALAH// http://www.informatick.com// Pour me rem
problemes de compilation [ par clebard ]
bonjour à tous,newbie j'avais à plusieurs reprises déposé des appels au secours car mon CSC.exe n'était pas reconnu dans la console DOS.J'ai (enfin et
faire un GUI [ par raver2046 ]
Bon voila, sa fais un moment que je me creuse la tête pour essayer de faire une GUI ( comprenez par la une appli WIN32 avec des fenêtres et tout) qui
exporter les donnés d'une base dans un fichier.TXT [ par kmbmaster ]
salut , en faite voila je suis débutant en c# dailleurs meme en programmation donc je voulais vous demander SVP si possible un peu daide .voila le
Soucis avec un switch [ par zigzou ]
Voila je viens de commencer le C#, et je viens de tombé sur un problème... :(En effet je demande au user de rentré un nombre je fais mes cas et en fai
Problème de console au chargement de la form [ par Jujufouq ]
Bonjour à tous!Je ne sais pas si ce problème a déjà été posté, mais j'ai ce problème. Voici mon code :using System;using System.Windows.Forms;class fr
Enlever la console de son programme .net windows [ par ricklekebekoi ]
J'ai mon programme , tout fonctionne, mais jai toujours la *** de console derriere .. comment je peut l'enlever ?
[C#] System.Information & mode console [ par scoubidou944 ]
using System.Windows.Forms;string szComputerName = System.Windows.Forms.ComputerName;Vala, ca marche nickel, le pb, c'est qu'en mode console, 'using S
Application graphique avec Console [ par oberown ]
Comment faire une application graphique (une windows form) et qui en même temps utilise une console.Par exemple qd on utilise une fonction qu'on puiss
|
Derniers Blogs
MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril SHAREPOINT 15 TECHNICAL PREVIEW MANAGED OBJECT MODEL SOFTWARE DEVELOPMENT KITSHAREPOINT 15 TECHNICAL PREVIEW MANAGED OBJECT MODEL SOFTWARE DEVELOPMENT KIT par Matthew
http://www.microsoft.com/download/en/details.aspx?id=28768&utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+MicrosoftDownloadCenter+(Microsoft+Download+Center) ...
Cliquez pour lire la suite de l'article par Matthew
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|