2014/01/17

[C#] winForm執行另一個WPF程序並得到回傳值

我的範例 : WinForm端 (Parent)

呼叫 RunWPF() 就會去執行叫起 WPF process
如下程式碼

106 private void RunWPF()\r
107 {\r
108 Task.Run(() => RunWPFProcess());\r
109 }\r
110 \r
111 private void RunWPFProcess()\r
112 {\r
113 int ReturnValue = -1;\r
114 Process process = new Process();\r
115 process.StartInfo.FileName = “myWPF.exe“;\r
116 \r
117 try\r
118 {\r
119 process.Start();\r
122 process.WaitForExit(Int32.MaxValue);\r
123 ReturnValue = process.ExitCode;\r
124 }\r
125 catch (System.Exception ex)\r
126 {\r
127 }\r
128 \r
129 if (ReturnValue == 1)\r
130 {\r
131 /* You can do what you want as return value is 1 */ \r
137 }\r
138 else \r
139 {\r
140 /* You can do what you want as others */ \r
146 }\r
147 }\r

另一端WPF部分: (Child)

myWPF.exe 裡面程式碼,
這裡我就直接寫出如何傳值回去給winform程序
其他一概省略..

227 Environment.ExitCode = 1;\r
228 this.Close();\r

2014/01/07

左聲道,右聲道,與雙聲道的聲音測試 自己合成一個mp3來用

這樣個測試需求, 我想是很多做產品的人會使用到的

我上網Google一下, 都是一些音樂對唱男女聲唱歌 …

檔案又大而且唱歌的mp3怎麼拿來做測試啊….

於是我轉個念頭, 找找有沒有左右聲道的mp3自己做合成吧~~

步驟1: 找左聲道,右聲道, 雙聲道的mp3
很幸運的, 這裡可以找到
還是英文發音, 很專業的感覺啊!!

步驟2: 把他們合成為一首mp3
JoinExt軟體, 小巧精美又很簡單上手
安裝後在欲合成的mp3上按右鍵, 選join files…

完成品: 下載


2013/11/22

C# 開發錄影 record vedio功能 window media player 使用DirectX.Capture與 DirectShow.NET

首先請先到這個網站, 有個強者寫好sample囉, 還有講解~
http://dashingquill.wordpress.com/2012/06/27/capturing-webcam-using-directshow-net-library/

我也是這樣完成了
但是有一天, 出現問題我在某台windows x86 device無法錄到影像
也就是有影無聲的狀況..
因此我需要 library source code
而剛才說到的網站只有 .dll檔

於是乎, 我去找src code
找到年代久遠的source code
http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library

目前正在debug中

其他參考資訊:
– .net中捕获摄像头视频的方式及对比(How to Capture Camera Video via .Net)
– DirectShowNET Library
– The Filter Graph and Its Components

2013/11/01

msbuild 入門與基本操作

msbuild 有點類似linux系統的makefile讓你可以自動透過指令編譯程式碼, 但許多地方差異滿大的!

—首先—

你要先確定command line interface 知道這個指令: msbuild
如果沒有這個指令,只需到環境變數PATH裡加入類似這樣的路徑:
C:\Windows\Microsoft.NET\Framework\v4.0.30319

Microsoft有寫簡單的操作, 可以跟著一步步做會比較有感覺
–逐步解說:從頭開始建立 MSBuild 專案檔案
http://msdn.microsoft.com/zh-tw/library/dd576348.aspx

最簡單的用法:

新增一bat檔(如 buildall.bat), 用來批次處理編譯
內文為:

msbuild xxx1.slnmsbuild xxx2.slnmsbuild xxx3.slnmsbuild xxx4.slnmsbuild xxx5.sln

如此一來, 執行 buildall.bat 就可以邊一 xxx1 ~ xxx5 這五個solutions
直接後面接專案的.sln檔案就會幫你編譯囉, 當然若要不同編譯方式請在後面接著設定參數吧

如果遇到無法編譯 發生錯誤

C:\source\xxx\MidiVol.vcxproj(22,3): error MSB4019: The imported project "C:\Program files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the  declaration is correct, and that the file exists on disk.

處理方式: (來源參考)
I’m using Win 7 64-bit, VS2013 express, I fixed the problem by setting the following before running the cocos.py publish command:

SET VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120

其他參考

MSBuild Command-Line Reference:
http://msdn.microsoft.com/en-us/library/vstudio/ms164311.aspx

Common MSBuild Project Properties:
http://msdn.microsoft.com/en-us/library/vstudio/bb629394.aspx

2013/10/29

指令找不到之 csc from command prompt - csc.exe file not found

這個指令如果找不到, 只需要去環境變數裡面將PATH加入

step1: 先找這個指令的正確路徑
像我的話是在 c:\Windows\MIcrosoft.NET\Framework\v4.xxxx;

step2: 設定環境變數的PATH
PATH = %PATH%;c:\Windows\MIcrosoft.NET\Framework\v4.xxxx;

2013/10/26

windows 7 與 win 8 開發multi-touch多點觸控重要參考範例

最近工作需求需要撰寫一款Application能夠測試多點觸控, 也就是multi-touch! 在網路上找了很久, 可能是win8太新了吧, 所以大多論壇都無法提供有效的資源, (但也有可能是我沒找到) 如果你要做的是單點觸控的話,有個比較簡單的做法,就是利用mouse-down,mouse-move的windows form application內建的事件觸發即可完成! 但這樣是把滑鼠當成觸控使用啦~

但我想要做的是多點觸控, 於是找了很多資源

我覺得最有效的是這個網址, 它有說明也有範例檔! 非常棒, 讓我可以直接依據範例做修改, 從這裡我相信可以讓你很快的入門!!

因為這個範例提供三種方式的範例:

1. Win32
2. MultitouchWinForms
3. MutlitouchWPF

而我就是衝著 windows form application 而來的,

因為我要做一個可以讓使用者介面的form application
可以下載看看囉!
網址:http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=WindowsTouch&DownloadId=5038

更多範例:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562199%28v=vs.85%29.aspx

我的討論串
http://social.msdn.microsoft.com/Forums/zh-TW/8439d517-8779-4576-a607-40f9cb57e270/c-?forum=233


後記: 卡關中-被high resolution螢幕造成部分畫面無法顯示

此兩個連結說不定是正解…
http://msdn.microsoft.com/en-us/magazine/ee336016.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd464660(v=vs.85).aspx

可內嵌執行檔exe的C#

http://www.dotblogs.com.tw/larrynung/archive/2013/02/23/91701.aspx

2013/10/21

Wordpress 發信email通知留言者 (免用外掛)

如果想要讓使用者收到信, 方便點選直接來此網站! 請修改程式碼吧~ 畢竟很多人是透過搜尋才來到這個網站, 通常走了之後就找不到了@@

我是參考這篇: http://nzbenson.com/archives/989

供您參考 ~

只是我並沒有修改 get_comment_link ()

直接找到function.php 新增程式碼於此檔案~

2013/10/20

Facebook Comments (留言外掛) 嵌入程式碼示範步驟

之前被這個功能弄得有點煩, 因為facebook改版速度有點快, 原本我設定好的程式碼變成無法使用, 於是我決定還是把步驟都寫下來好了, 雖然不知道什麼時候會過期,畢竟一切都以facebook developer Comments Plugin官方訊息為主!

步驟1.請建立屬於你這個網站的Facebook應用程式

(按這裡前往), 建立好可在此找到, 請記住 APP ID 並輸入你的網站網址 URL

步驟2. 取得你的帳號ID

再來就是要取得管理者也就是自己 Facebook帳號的 ID,方法如下:
Facebook查看個人首頁,如果網址是以下這種,那數字部分就是你的帳號ID
http://www.facebook.com/profile.php?id=數字

如果你的個人頁面網址是長的像以下這種
http://www.facebook.com/帳號名稱
代表你的個人首頁已經命名過了,那請將上面的「帳號名稱」代入以下的網址進入
https://graph.facebook.com/帳號名稱
進去後會看到「”id”:”數字”」,那串數字就是你的帳號ID。

步驟3. 修改網頁程式碼 <head>下

<meta property=’fb:admins’ content=’ 你的帳號ID ‘ />
<meta property=’fb:app_id’ content=’ 你的應用程式ID ‘/>

步驟4.加入SDK程式碼:

https://developers.facebook.com/docs/reference/javascript/

步驟5.加入Facebook留言程式碼

https://developers.facebook.com/docs/plugins/comments/

完成:

我覺得重點是SDK的加入, 還有APP裡面的網址要設定對!!

Facebook工具使用
– Facebook Debuger: 可以清除你輸入網址的cache, 得到即時的網址狀態
– Comment Moderation Tool: 你所建立的Facebook留言管理後台
– Facebook應用程式

補充:除了OG語法以外,網頁特色圖片的標籤還有一個:
<link href=”圖片連結網址” rel=”image_src” type=”image/jpeg”>

2013/10/17

visual studio專案的code base server 要怎麼設定 gitignore

其實網路上滿多資源可以參考的, 當然對於git server的愛用者來說

更有人把各種專案適合的gitignore放到網路上,A collection of useful .gitignore templates

總之我現在需要的是visual studio 的 gitignore

給大家參考:

VisualStudio.gitignore

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results

[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/

# Enable “build/” folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac crap
.DS_Store

2013/10/07

一支Perl 簡單程式, 讓使用者輸入資料後再輸出顯示

參考學習網站: Perl 學習手札 由基礎一路到各個概念都有介紹。

安裝Perl:

1. 如果使用linux (UNIX-Like)平台, 通常已內建
2. 如果使用windows平台, 請先下載安裝 ActivePerl

簡單RUN看看吧!

由於我現在使用的是Win7平台, 以下例子就都window platform囉!

立馬執行command line, 即可成功完成第一步驟 hello world !

C:\> perl -e “print \”Hello world\n\””
Hello world

接下來,
使用文字編輯器寫一個 test.pl 檔, 我是使用PSPad,或者你可以用UltraEdit
test.pl:

#!/usr/bin/perl
print “hello world\n”;

再透過執行test.pl ,又可成功完成另一種方式的第一步驟 hello world !

C:\> perl test.pl
Hello world

神奇的兩個hello world, 完成後對Perl比較有fu了吧!
接著執行本文重頭戲, 其實也不難…

使用者輸入後再輸出 (像C語言scanf/printf)

修改 test.pl 的內容如下, 要記得有<STDIN>:

print “please enter your name:”;
my $name =<STDIN> ;
print “\n”;
print “hello, $name\n”;

再執行test.pl

C:\>perl test.pl
please enter your name:5566

hello, 5566

打完收功~

2013/09/17

我要format 錯誤的USB磁碟分割!! (硬碟低階格式化工具 HDD Low Level Format Tool)

困擾好一段時間的問題, USB錯誤分割造成6G多的空間浪費掉
我試過使用windows內建的磁碟分割, 但是整個失敗! 完全沒用
過程中還打電話問過sandisk的客服人員, 而sandisk做法是直接換一支給你, 沒有啥修復程式可用
(但是如果是創見的話, 妳可以上網下載創見官方修復USB程式喔!方便多了)

後來, 在阿榮那邊找到硬碟低階格式化工具 HDD Low Level Format Tool
喔賣嘎! 莫非這個可以整個格式化USB碟~~
其實這個不只支援USB碟喔, 還有硬碟也都ok~

Let’s do it~
下圖是仔細的低階格式化, 但我覺得太慢了@@
我就取消了, 改成下下圖

這張圖表示我做“執行快速抹除(僅移除分割區與MBR)”
超快的啦!!

YES! 完成後再回windows格式化USB碟就可以使用囉

2013/09/13

安裝(執行) chrome os 於小筆電 eeepc 1005HA

一切的起因來自於想體驗看看chrome os, 稍微google了一下可以安裝於小筆電的列表, 我的eeepc 1005ha也有支援耶, 看來可以廢物利用物盡其用, 不然小筆電放家裡真的快被淘汰了~~~~

Asus Eee PC 1005HA
-Wifi : OK
-Ethernet : OK
-Trackpad : OK
-Suspend/Resume : OK


Step1: 先找到了chrome os project網站,
發現大多數跟souce code 相關的東西, 但我只是想先體驗看看, 下載source code是我下次想做的事情~

Step2: 再找到非官方但公信力頗高的網站 Hexxeh
貌似很熱情的鄉民架設的, 提供大家下載使用最新的chrome os
當然我也看到了熱心的台灣網友部落格~

Step3: 請進入Hexxeh的網站,

  1. 先下載最新的chrome os, 在最下方Nightly build links (The latest three builds are shown.), 選一個下載吧!
  2. 再來找到 Let’s get started
    > Click on your OS for instructions: 我選windows
    然後跳出細部指示:

    1. Use WinRAR or 7zip to extract IMG file from the downloaded archive. (下載7Z先吧)
    2. Use Windows Image Writer, then select the IMG file(就剛提到的chrome os image) and select the USB device(請準備個USB碟吧) from the menu. (可於此下載win32 Disk imager, 並安裝於你的電腦)
    3. Click on “Write“.
    4. Boot from the newly created Chromium OS USB stick! (確認小筆電用USB開機BOOT first)

Step4: 大致就是這樣, 所以以後只要用USB開機即可進入chrome os

2013/08/13

影片嵌入碼從資料庫撈出來 去除反斜線 - stripslashes()

我要新增一個功能就是將youtube影片的內嵌碼放到資料庫
並在前台撈出來顯示, 而發現在資料庫裏面存的語法系統已經自動將雙引號前加入反斜線
所以要去除反斜線, 我使用 stripslashes()

EX:
$txt = stripslashes($txt);

stripslashes — 去除addslashes( )引用的斜線
語法 : string stripslashes (string str)
說明 :
傳回去除反斜線後的字串,連續的二個反斜線會成為一個反斜線。

2013/08/02

處理 [Solution] Script cannot be loaded because running scripts is disabled on this system

跑window power shell時候
如果你也遇到這樣的事情, 就是”Script cannot be loaded because running scripts is disabled on this system”

找到一個方法:
Run the following statement from a Command prompt (not a PS prompt):
下面方式可成功, 請在cmd (一般command line interface)執行:
c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -command set-executionpolicy unrestricted

2013/06/25

線上製作GIF動畫圖片或BANNER 就是動態切換圖片啦!

我拉網 – 線上製作GIF動畫圖片或BANNER
http://gif.55.la/

其實仔細看看我拉網, 是一個各式工具的方便網站
很適合網頁工作者使用喔, 雖然剛測試幾項都無法使用