C# Make a window program in system tray, hidden in task bar, and hidden in alt-tab list

September 18th, 2009 Phanix

讓視窗程式只在 system tray 中顯示, 不會出現在工作列(task bar)中, 也不會出現在 alt-tab 清單裡頭

Read the rest of this entry / 繼續閱讀 »

C# mount / unmount UNC (network folder / drive) 連結網路磁碟機

September 8th, 2009 Phanix

有些時候為了 security 問題或者想要詳細紀錄使用者存取網路磁碟機或目錄中資料的情況, 所以會另外建立帳號並透過程式來存取網路磁碟機, 而不讓使用者直接用他的帳號密碼來存取, 這時候就需要讓程式可以建立網路磁碟機與中斷連線.

我自己比較喜歡第一個方式, 相對來說簡單許多.
Read the rest of this entry / 繼續閱讀 »

Visual Studio .Net 設定 DLL / EXE 版本編號

August 12th, 2009 Phanix

in Properties\AssemblyInfo.cs

[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]

C# UDP server sending and client receiving

August 10th, 2009 Phanix

UDP Server

private void ServerBroadcastThread()
{
    int GroupPort = 15000;

    UdpClient udp = new UdpClient();
    udp.EnableBroadcast = true;
    IPEndPoint groupEP = new IPEndPoint(IPAddress.Broadcast, GroupPort);

    string str4;
    byte[] sendBytes4;

    while (true)
    {
        str4 = "Is anyone out there?";
        sendBytes4 = Encoding.Default.GetBytes(str4);
        udp.Send(sendBytes4, sendBytes4.Length, groupEP);

        Thread.Sleep(10000);
    }
}

UDP Client

private void ClientBroadcastThread()
{
    UdpClient receivingUdpClient = new UdpClient(15000);
    IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

    string returnData;
    byte[] receiveBytes;

    while (true)
    {
        try
        {
            // Blocks until a message returns on this socket from a remote host.
            receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);

            returnData = Encoding.ASCII.GetString(receiveBytes);

            MessageBox.Show(returnData);
        }
        catch (Exception e)
        {
            //Console.WriteLine(e.ToString());
        }
    }
}

Add description to functions and parameters in .NET

August 7th, 2009 Phanix

While using some library functions in Visual Studio .NET, you can always find such kind of descriptions which help you to get some idea of parameters and functions.

csharp_function_description (by Phanix)

However, how to provide such kind of descriptions in your class libraries?

Plz refer this! http://www.codeproject.com/KB/XML/csharpcodedocumentation.aspx?msg=1643354

Allow multiple statements in MySQL ODBC

August 7th, 2009 Phanix

While using MySQL ODBC to execute sql statements, only single sql statement is allowed for execution by default. If you want to execute multiple sql statements at once, you have to enable the multiple statements setting in MySQL ODBC.

mysql setting  ODBC multiple statement (by Phanix)

[C#, .NET] Run a program in tray (minimized window and no-shown in taskbar) with right clicked pop-up menu

July 30th, 2009 Phanix

程式執行後以最小化的方式執行,即不會出現在工作列上,而會出現在tray裡頭。而在 tray icon 上可以點滑鼠右鍵來彈出功能表單(menu),進行各功能選擇(如結束等)。

Read the rest of this entry / 繼續閱讀 »

.net 無視窗背景執行的程式

July 15th, 2009 Phanix

有時候為了要偷偷做一些事情, 所以會想要讓程式以無視窗在背景執行, 而要做出這樣的程式其實方法很簡單

  1. 在建立專案的時候選擇「主控台應用程式」(console application)
  2. 設定專案屬性(properties), 將輸出類型改為「windows 應用程式」

這樣就可以了, 當發現到這樣做就搞定的時候還有點訝異怎麼這麼容易…

The recent days after back to TW

July 5th, 2009 Phanix

Just wake up from noon break, I think I have to write down some day-to-day things.

Read the rest of this entry / 繼續閱讀 »

C# 建立ODBC DSN 連線到 SQL Server

July 1st, 2009 Phanix

那個\0很重要。

using System.Runtime.InteropServices;

public bool DoDBConnect(string strDSN,string strUID,string strPWD)
{
	try
	{
		strConn = "DSN=" + strDSN + ";UID=" + strUID + ";PWD=" + strPWD + ";";
		cn = new OdbcConnection(strConn);
		cmd = new OdbcCommand();
		adp = new OdbcDataAdapter();

		cmd.CommandType = CommandType.Text;
		cmd.Connection = cn;
	}
	catch
	{
		return false;
	}

	return true;
}

[
DllImport("ODBCCP32.dll")
]
private static extern bool SQLConfigDataSource(IntPtr hwndParent, int fRequest, string lpszDriver, string lpszAttributes);

public bool CreateODBCDSN(string strDSN, string strServer, string strDB, string strDescription)
{
	string strSQL = "SERVER=" + strServer + "\0";
	strSQL += "DESCRIPTION=" + strDescription + "\0";
	strSQL += "DSN=" + strDSN + "\0";
	strSQL += "DATABASE=" + strDB + "\0";
	strSQL += "trusted_connection=no\0";
	return SQLConfigDataSource((IntPtr)0, 4, "SQL Server", strSQL);
}