【网通】点击这里下载PjWebApps源代码 【电信、网通】点击这里下载PjWebApps源代码
【网通】点击这里下载PjWebApps演示程序 【电信、网通】点击这里下载PjWebApps演示程序
【下载说明】
1、单击上面这个地址,打开下载页面。
2、点普通下载--等待30秒--点“下载”按钮--保存
控制台程序,调用Windows的API实现了移动控制台窗口、调整控制台窗口的大小和将控制台窗口置顶(置于所有窗口最前端)等。
源代码:
/*
* Created by SharpDevelop.
* User: PJ
* Date: 2012-9-25
* Time: 10:23
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.IO;
using System.Collections.Generic;
using PjConsoleUtilsLib;
using System.Threading;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace PjWebApps
{
class Program
{
static string windowTitle = "PjWebApps";
static int windowWidth = 10;
static int windowHeight = 25;
static Dictionary<string,string> webApps = new Dictionary<string,string>();
static void InputThread(){
bool isExit = false;
while(!isExit){
ConsoleKeyInfo key = Console.ReadKey(true);
switch(key.KeyChar){
case 'B':
case 'G':
case 'L':
Process.Start(FindWebAppsByKey(key));
break;
default:
// isExit = true;
break;
}
}
}
static string FindWebAppsByKey(ConsoleKeyInfo key){
foreach(KeyValuePair<string, string> k in webApps){
if(k.Key.ToLower()[0].ToString() == key.KeyChar.ToString().ToLower())
return k.Value;
}
return string.Empty;
}
static void ReadWebAppsText(string fileName){
using(StreamReader sr = new StreamReader(fileName)){
while(!sr.EndOfStream){
string line = sr.ReadLine();
string[] parts = line.Split(',');
webApps.Add(parts[0],parts[1]);
}
}
}
static void PrintWebApps(){
foreach(KeyValuePair<string,string> k in webApps){
PjConsoleUtils.PrintMenuItem(k.Key);
Console.WriteLine();
}
}
public static void Main(string[] args){
Console.Title = windowTitle;
Console.WindowWidth = windowWidth;
Console.WindowHeight = windowHeight;
Console.CursorVisible = false;
// move the console window to the right
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
IntPtr consoleHandle = PjConsoleUtils.FindWindowByCaption(IntPtr.Zero,windowTitle);
if(consoleHandle != IntPtr.Zero){
int x,y,width,height;
if(PjConsoleUtils.GetWindowRect(consoleHandle,out x,out y,out width,out height)){
PjConsoleUtils.SetWindowTopMost(consoleHandle);
PjConsoleUtils.MoveWindow(consoleHandle,screenWidth-width,
(screenHeight-height)/2,width,height,true);
}
}
webApps.Clear();
ReadWebAppsText(Environment.CurrentDirectory + "\\WebApps.txt");
PrintWebApps();
Thread inputThread = new Thread(new ThreadStart(InputThread));
inputThread.Start();
}
}
}
【更多阅读】