2014年3月18日 星期二

[C#/winform] Winform Application的介面美化

測試完成示意圖


教學:   首先,下載 IrisSkin2.dll 

然後一樣 專案->加入參考->瀏覽->選擇IrisSkin2.dll

加入以後在主程式的部分寫入

namespace XXX
{
    public partial class XXX: Form
    {

        Sunisoft.IrisSkin.SkinEngine Skin = null; //這邊改Skin
        .
        .
        .
        public XXX()
        {
            InitializeComponent();

            Skin = new Sunisoft.IrisSkin.SkinEngine();
            Skin.SkinFile = @"C:\Users\Skins\MSN.ssk"; //路徑請自行更改
            Skin.SkinAllForm = true; //系統下所有Form都改為該Skin
         }
          .
          .
          .
          .
      }
  }

然後就可以了

End

2014年3月7日 星期五

[Android] Google Android APP 開發環境安裝

1.需要Java JDK

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

選擇符合自己作業系統的版本

2.下載

http://developer.android.com/sdk/index.html

installer_r20.0.1-windows.exe  + ADT bundle for windows

3.安裝installer_r20.0.1 (要調整為install for anyone using this computer ,預設為just for me)

下一步下一步......完成

4.打開Android SDK Manager 選 Android其中一個版本 然後按下install X(看有多少個) Packages...

會開始更新,很久,可以休息一下喝杯水再過來

5.改JAVA環境變數(跟linux根本一樣)

到[系統及安全性]->[系統]->[進階系統設定](在左側) 進入以後 選 [進階]->下面有{環境變數} 按鈕,進入以後


(如文字描述)

將你安裝的JDK的bin資料夾路徑ex: C:\Program Files\Java\jdk1.7.0_51\bin 加入 "系統變數"的Path值中,如果前面有東西,或後面還要加東西請用分號區隔。

然後再加入Android SDK tools & Platform-tools兩個資料夾(也在program files\android....可以找到)

所以總共是:

加入;C:\Program Files\Android\android-sdk\tools;C:\Program Files\Android\android-sdk\platform-tools

;是為了區隔前後,不是打錯(以上三個都要(編輯)加入在Path中)

選取 "系統變數"的CLASSPATH(如果沒有就新增) 按 編輯 加入  C:\Program Files\Java\jdk1.7.0_51\lib (是lib資料夾,不是bin)

6.開始->程式->Android SDK tools ->AVD Manager

按New即可新增一個模擬器,設定可以自己調。(要調整SD卡的話一定要給sdcard空間,不然權限會不足)->按下Start就會開始emulate(模擬),超級超級超級久.....然後就可以測試囉!

7.cmd 命令提式字元 先進到platform-tools目錄

adb.exe shell( root權限 Linux指令)

adb.exe push 檔案 手機內的路徑(pull為下載,push為上傳)

可以在Android SDK 下的tools 找到ddms.bat 打開可以看file explore 或是模擬傳簡訊。

End


2014年3月3日 星期一

[RS232-to-USB Driver] 分享rs232-USB轉接器的Driver

相信許多人都有買到大陸製的PL2303 USB-RS232轉接器

內附Driver無法使用,這邊給大家一個Driver,目前大部分電腦跟OS版本都適用

點我下載

End

2014年2月27日 星期四

[C#/winform] DataGridView 隨視窗大小變動/列的Header加入文字/隱藏行,列

DataGridView 隨視窗大小變動

將DataGridView放入Form中,調整Dock(選中間那個) = Fill即可。


DataGridView 列的Header加入文字

要讓Row的Header加入文字,只要輸入

DataGridView1.Rows[第幾列].HeaderCell.Value = 文字 即可。

隱藏行,列

DataGridView.Columns[第幾行].Visble = false; //行

DataGridView.Rows[第幾列].Visble = false; //列

小技巧,但有大功用喔!

End


[C#/win32 API] SendMessage() 與 PostMessage()

網路上比較少SendMessage()跟PostMessage資料

先給SendMessage範例




SendMessage會等到接收端check後才會繼續執行,而PostMessage則是丟入訊息queue,繼續做。

以下範例都要先加入 using System.Runtime.InteropServices;

SendMessage A端(控制端):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
namespace TestA
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern uint RegisterWindowMessage(string lpString);
        uint MSG_SHOW = RegisterWindowMessage("Show Message");

        [DllImport("user32.dll")]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
     

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            IntPtr form_name = FindWindow(null, "要控制的視窗元件名稱(text,不是name)");//找B的IntPtr 用來代表指標或控制代碼

            if (form_name != IntPtr.Zero)
            {
                try
                {
                    int iNum = 9527;
                    SendMessage(form_name, MSG_SHOW, iNum, IntPtr.Zero);
                }
                catch (Exception)
                {
                }
            }
        }
    }
}

SendMessage B端(接收端):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace TestB
{
    public partial class TestB_1 : Form
    {
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern uint RegisterWindowMessage(string lpString);
        uint MSG_SHOW = RegisterWindowMessage("Show Message");
        public TestB_1()
        {
            InitializeComponent();
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == MSG_SHOW)
            {
                label1.Text = (string)m.WParam.ToString();
            }
            base.WndProc(ref m);
        }
    }
}

PostMessage A端(呼叫端):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace postmessager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
 
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
 
        private void post()
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr ptr = FindWindow(null, "post messager B");
            if (ptr != IntPtr.Zero)
            {
                int msg = 9527;
                PostMessage(ptr, msg, IntPtr.Zero, IntPtr.Zero);
            }
        }
    }
}

PostMessage B端(接收端):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace PostmessagerB
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 9527)//m.Msg == MSG_SHOW
            {
                //label1.Text = (string)m.WParam.ToString();
                MessageBox.Show("9527");
            }
            base.WndProc(ref m);
        }
    }
}

至於為何可以使用SendMessage(),PostMessage(),FindWindow(),RegisterWindowMessage(),都是要先

import user32.dll (也就是[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 後面為參數)

然後接收端使用WndProc (WindowProcess,我個人理解縮寫函意)去接收。

大部分程式碼也是參考網路上的,但大家都抄來抄去,而且我有修改程式碼,所以就不註明出處了(因為也不知道原始是誰的),當然我的版本是比較精簡化。

End