上色

Code Block

2013年4月19日 星期五

[PHP] 區分同一個表單上的兩個按鈕

以onclick設定不同按鈕所送出的參數,例如︰

按鈕1︰
<input type="submit" name="button" value="Choose" onclick="document.form.action='sign.php?no=1' "/>

按鈕2︰
<input type="submit" name="button" value="Choose" onclick="document.form.action='sign.php?no=2' "/> 

如此即可在目的地表單(sign.php)藉由$_GET[no]方法取得此表單所送出的no變數,即可輕易分辨不同按鈕

2013年4月18日 星期四

[SQL] select指令

SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy
 
what_to_select表示要搜尋的目標,也可以「*」表示所有的列
which_table表示要搜尋的資料表
conditions_to_satisfy是選擇性參數,代表搜尋條件 

[PHP] Session無法啟用 - Cannot send session

Warning: session_start() [function.session-start]: Cannot send session ... - headers already sent (output started at .... )

發生原因
session_start() 之前不能有任何字元輸出,UTF-8 編碼裡的 BOM 也會被認為是 headers,有上述狀況 Session 將無法順利傳遞,並會顯示錯誤訊息。

解決方法1
1. 確定 <?php 和 session_start() 之間沒有其他字元,空格也要移除。
2. 若是 UTF-8 編碼,請用編輯器(例 UltraEdit、Notepad++...)將檔案裡的 BOM 移除。

解決方法2
以 ob_start() 開啟緩衝區將輸出資訊寫入緩衝區,可避免 headers 先於 session_start() 輸出,寫入緩衝區的內容可由 flush() 或 ob_end_flush() 輸出至瀏覽器,以下範例不會顯示錯誤訊息:
<?php
ob_start();
echo "test";
session_start();
ob_end_flush();
?>
Reference:
http://www.pczone.com.tw/vbb3/thread/47/73367/

2013年4月14日 星期日

[Phone] 合併vCard檔案 (*.vcf)

利用copy命令的/b參數將多個vcf檔案以二進位形式合併

copy /b *.vcf all.vcf

以上命令的意義代表將該資料夾下所有的vcf檔案(vCard檔案)合併成為all.vcf

2013年4月9日 星期二

[VB.Net] 取得視窗大小資訊

Public x0, y0, x1, y1 As Integer '視窗四角座標
Public Client_x0, Client_y0 As Integer '視窗左上座標(不含標題邊框)
Public ClientX, ClientY As Integer '視窗長寬(不含標題邊框)
Public Border As Integer '視窗邊框寬度
Public Title As Integer '視窗標題高度
Public hwnd As Integer '視窗hwnd

'取得視窗大小(含邊框,功能表)
Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Integer, ByRef rectangle As RECT) As Integer

'取得視窗大小(不含邊框,功能表,左上角為0,0)
Public Declare Function GetClientRect Lib "user32 " (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer

Structure RECT '視窗大小資料結構
    Dim x1 As Integer
    Dim y1 As Integer
    Dim x2 As Integer
    Dim y2 As Integer
End Structure

'取得特定視窗資訊
Sub GetWindowInfo(hwnd As Integer)
    Dim R As RECT
    Dim RetVal As Integer
    RetVal = GetWindowRect(hwnd, R)
    x0 = R.x1
    x1 = R.x2
    y0 = R.y1
    y1 = R.y2
    RetVal = GetClientRect(hwnd, R)
    ClientX = R.x2
    ClientY = R.y2
    Border = ((x1 - x0) - ClientX) / 2
    Title = (y1 - y0) - ClientY - Border
    Client_x0 = x0 + Border
    Client_y0 = y0 + Title
End Sub

[VB.Net] 清除無效的系統圖示

Dim hWndShell, hWndTray, hWndPager, hWndToolBar As Integer '系統用hwnd

'抹除通知區域圖示
hWndShell = FindWindow("Shell_TrayWnd", "") '取得系統圖示區hwnd

'取得通知區域hwnd
If Environment.OSVersion.Version.Major = 5 AndAlso Environment.OSVersion.Version.Minor = 0 Then
    hWndTray = FindWindowEx(hWndShell, 0, "TrayNotifyWnd", "")
    hWndToolBar = FindWindowEx(hWndTray, 0, "ToolbarWindow32", "")
Else
    hWndTray = FindWindowEx(hWndShell, 0, "TrayNotifyWnd", "")
    hWndPager = FindWindowEx(hWndTray, 0, "SysPager", "")
    hWndToolBar = FindWindowEx(hWndPager, 0, "ToolbarWindow32", "使用者升級的通知區域")
End If

'取得邊界
GetWindowInfo(hWndToolBar) '以自訂函數GetWindowInfo取得視窗資訊
Dim ibx, iby As Integer
iby = CInt(ClientY / 2) * 65536
'以WM_MOUSEMOVE消去無效圖示(將通知區域全部掃過一次)
For ibx = 1 To ClientX Step 1
    PostMessage(hWndToolBar, WM_MOUSEMOVE, 0, iby + ibx)
Next

**********以下為API宣告**********
'發送訊息到執行緒佇列
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
'定義常數
Public Const WM_KEYDOWN As Integer = &H100
Public Const WM_KEYUP As Integer = &H101
Public Const VK_C As Integer = &H43
Public Const WM_CLOSE As Integer = &H10
Public Const WM_LBUTTONDBLCLK As Integer = &H203
Public Const WM_LBUTTONDOWN As Integer = &H201
Public Const WM_LBUTTONUP As Integer = &H202
Public Const WM_MBUTTONDBLCLK As Integer = &H209
Public Const WM_MBUTTONDOWN As Integer = &H207
Public Const WM_MBUTTONUP As Integer = &H208
Public Const WM_RBUTTONDBLCLK As Integer = &H206
Public Const WM_RBUTTONDOWN As Integer = &H204
Public Const WM_RBUTTONUP As Integer = &H205
Public Const WM_MOUSEACTIVATE As Integer = &H21
Public Const WM_MOUSEWHEEL As Integer = &H20A
Public Const WM_MOUSEFIRST As Integer = &H200
Public Const WM_MOUSELAST As Integer = &H209
Public Const WM_MOUSEMOVE As Integer = &H200
Public Const WM_SETCURSOR As Integer = &H20 

2013年4月8日 星期一

[VB.Net] 將視窗影像截圖並轉存為圖片

Dim saveFileDialog1 As New SaveFileDialog() '儲存檔案公用視窗

Try  '預設錯誤處理方式
    '定義存檔格式
    saveFileDialog1.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif"
    saveFileDialog1.FilterIndex = 2  '預設為第二種(JPG)
    If saveFileDialog1.ShowDialog() = DialogResult.OK Then '使用者按下確認之後紀錄檔名
        GetWindowInfo(Me.Handle)  '以自訂函數GetWindowInfo取得視窗資訊
        '建立一個Bitmap作為存檔目標
        Dim Screenshot As Bitmap = New Bitmap(ClientX, ClientY - 50, PixelFormat.Format32bppArgb)
        Dim picOutput As Graphics = Graphics.FromImage(Screenshot) '建立儲存影像的Graphic
        Dim picSource As Graphics = Graphics.FromHdc(GetDC(Me.Handle)) '建立獲取來源影像的Graphic
        '以Bitbit將來源影像轉存到目標影像
        BitBlt(picOutput.GetHdc(), 0, 0, ClientX, ClientY - 50, picSource.GetHdc(), 0, 50, CopyPixelOperation.SourceCopy) '把來源影像複製到儲存影像中
        '釋放hdc
        picSource.ReleaseHdc()
        picOutput.ReleaseHdc()
        '存為圖片
        Screenshot.Save(saveFileDialog1.FileName)
    End If
Catch ex As Exception
    MsgBox(ex.Message) '錯誤訊息
End Try

**********以下為API宣告**********

'重繪圖檔用API
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer