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
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|