2010年10月18日 星期一

license header template (Qt creator)

大部分的程式開頭,都有一段宣告。像是LGPL、GPL或doxygen的註譯等。
Qt creator提供一個license template的功能,當每次增加新的檔案時,都會在文件最前面加上設定好的字串。
Tools > Options... > C++ > License Template > Browse
選擇文件檔(像是gpl.txt)

以下Qt提供的特殊placeholders

  1. %YEAR%: Year
  2. %DATE%: Date
  3. %USER%: User name
  4. %FILENAME%: File name
  5. %CLASS%: Class name (if applicable)
舉個例子:
/**
* @file %FILENAME%
* @brief define %CLASS% class
*
* Define %CLASS% class.
*
* @author %USER%
*
* @date %DATE%
*/
經過Qt轉換後,就會變成
/**
* @file dictionary.h
* @brief define Dictionary class
*
* Define Dictionary class.
*
* @author http://yycking.blogspot.com/
*
* @date 2010/10/18
*/

2010年10月3日 星期日

DPInst & nsis

DPInst是驅動程式安裝架構DIFx(Driver Install Frameworks) 所提供的工具之ㄧ。使用方式很簡單。
以下說明是以FTDI的driver為例:
  1. 將ftdi的driver解壓縮到driver資料夾
  2. 到微軟下載wdk
  3. 安裝完wdk後,可在WinDDK\redist\DIFx\dpinst中看到二個資料夾MultiLin(提供多國語言),EngMui(提供特定語言,預設為英文,除非提供.mui檔)
  4. 在MultiLin提供三個資料夾x86,amd64,ia64
  5. 將x86內的dpinst.exe重新命名為x86.exe,將amd64內的dpinst.exe重新命名為x64.exe。將x86.exe和x64.exe複製到driver資料夾(現在執行x86或x64就會幫你安裝FTDI的driver了)
  6. 因為我想要安裝程式時,偷偷的替user安裝驅動(也就是不用秀出DPInst的視窗)。
  7. 所以在driver的資料夾建立一個dpinst.xml檔。
    <?xml version="1.0"?>
    <dpInst>
    <!--- 不秀出視窗 -->
    <suppressWizard/>
    <quietInstallStrict/>
    <!--- 強迫安裝 -->
    <forceIfDriverIsNotBetter/>
    </dpInst>
    
  8. 在nsis中加入下面程式,即可自動判斷安裝32還是64位元的驅動
    ; Check OS is 32bit or 64bit
    !include "x64.nsh"
    !define FTDI_32_URL "$INSTDIR\driver\x86.exe"
    !define FTDI_64_URL "$INSTDIR\driver\x64.exe"
    
    Function installFTDI
    ${If} ${RunningX64}
    StrCpy $2 ${FTDI_64_URL}
    ${Else}
    StrCpy $2 ${FTDI_32_URL}
    ${EndIf}
    ExecWait $2
    FunctionEnd
    

2010年9月7日 星期二

在Qt中整合freetype

建立字型對照表
    QSettings settings("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts",
QSettings::NativeFormat);
QStringList list = settings.allKeys();

for(int i=0;i<list.size();i++)
{
QString key = list.at(i);
QString text = settings.value(key).toString();
QStringList keys = key.split(" & ");
QString last = keys.last();
keys[keys.size()-1] = last.left(last.indexOf(" ("));
for(int j=0;j<keys.size();j++)
{
index.insert(keys[j], j);
name.insert(keys[j], text);
}
}

轉換成FT_Face
    QString family = ui->fontComboBox->currentText();
QString path("C:/WINDOWS/Fonts/");
path.append(name[family]);
int in = index[family];
FT_New_Face(library, path.toUtf8(), in, &face))

2010年8月30日 星期一

用mingw編譯freetype

下載ft242.zip,解壓縮

1.devcpp+mingw
set PATH=C:\Dev-Cpp\bin
set PATH=%PATH%;C:\Dev-Cpp\mingw\bin
set PATH=%PATH%;%SystemRoot%\System32
set make=mingw32-make
set make=%make%
make
make
copy objs\freetype.a C:\Dev-Cpp\lib\libfreetype.a /Y
xcopy include\* C:\Dev-Cpp\include /Y /S
pause

將上面的文字檔存成t.bat檔,放在解壓縮後的freetype資料夾,點擊t.bat

2.qt+mingw
set QTDIR=C:\Qt\2010.04\qt
set PATH=C:\Qt\2010.04\qt\bin
set PATH=%PATH%;C:\Qt\2010.04\bin;C:\Qt\2010.04\mingw\bin
set PATH=%PATH%;%SystemRoot%\System32
set QMAKESPEC=win32-g++
set make=mingw32-make
set make=%make%
make
make
copy objs\freetype.a C:\Qt\2010.04\mingw\lib\libfreetype.a /Y
xcopy include\* C:\Qt\2010.04\mingw\include /Y /S
pause

2010年8月16日 星期一

避免打開雙視窗

#include <windows.h>

#define Executable "test.exe"
char TITLE[] = "The SoftW";//full title name "The SoftWare"
int size;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, DWORD lParam)
{
//get hwnd title
char buffer[255];
SendMessage(hwnd,WM_GETTEXT,255,(long)buffer);

//check title is we want
if(strncmp(buffer,TITLE,size)==0)
{
//if window is iconic, show it as normal
if(IsIconic(hwnd))
ShowWindow(hwnd, SW_RESTORE);

//show it at top of desktop
SetForegroundWindow(hwnd);

//we got it
return FALSE;
}

//to check next hwnd
return TRUE;
}

int main(int argc, char** argv)
{
//check title size,remove '\0'
size = sizeof(TITLE)/sizeof(char);
size--;

//check window is show or not
if(EnumWindows((WNDENUMPROC)EnumWindowsProc,0)==TRUE)
{
//if window not show, to execute it
WinExec(Executable,SW_SHOW);
}

return 0;
}

2010年8月10日 星期二

使用glut時,不顯示控制台視窗

prevent opening a console window in addition to your GLUT window when it is run

in vc
menu option ( Project → Properties )
From the Configuration: list box, select All Configurations.
select the Linker subtree and then Command Line option in the left pane. Then add the following code to the Additional Options: text box
Copy & Paste: /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup

in mingw
click on Project and go to Project Options.
Click on the Parameters tab.
On the 3rd box, Linker, you will need to add in the following code to your project
-Wl,--subsystem,windows