// =============================================
// 建立 string table
0. 說明: string table 實際上是用 ID 的方式進行 string 之替換
但需經過 LoadString 之函數
1. 工具列 Insert -> Resource(Ctrl + R)
2. 快點二下 string table
3. 在 ID 處輸入 IDS_APP_NAME, Caption 輸入 Fundamentals of Windows Resources
按下 Enter 後再看 string table, 會自動帶出 value 值
4. 重覆 2.3.步驟, 輸入以下之 ID 及 Caption
IDM_ARROW 105 No tool selected
IDM_DRAW_LINE 106 Selects the Line tool\nLine
IDM_DRAW_RECTANGLE 107 Selects the Rectangle tool\nRectangle
IDM_DRAW_ELLIPSE 108 Selects the Ellipse tool\nEllipse
5. 加入全域變數 char AppCaption[40];
6. WinMain 一開始便呼叫函式:LoadString(hInstance, IDS_APP_NAME, AppCaption, 40);
7. CreateWindowEx 第三個參數改為 AppCaption
8. 完成. 之後的 Window title 便變成了 Fundamentals of Windows Resources
// =============================================
// 建立 tool bar
0. 說明: toolbar 可視為多個 button 所構成, 每一個 button pixel size = 16*16
這裡的 button 圖案可自行繪製, 若要產生 4 個 button 之 toolbar
則需要高 16 pixels, 寬 16*4 = 64 pixels 之 bmp. toolbar 上每個 button
都屬於 TBBUTTON 結構.
1. 加入 Drive:\Program Files\Microsoft Visual Studio\VC98\Lib\comctl32.lib
(程式中於一開始加入 #pragma comment(lib, "comct132.lib") )
2. 加入 resource - bitmap, 設定 96*16 (寬*高)
3. 繪製 6 個 16*16 toolbar 上 item 圖案
4. 將其 ID 改為 IDB_TOOLBARBMP
*5.
(1) 加入 #include <commctrl.h>
(2) 定義 NUMBUTTONS = 7
(3) 於 CreateWindowEx 後加入以下程式碼
INITCOMMONCONTROLSEX InitCtrlEx;
InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCtrlEx.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&InitCtrlEx);
TBBUTTON tbrButtons[7];
tbrButtons[0].iBitmap = 0;
tbrButtons[0].idCommand = IDM_FILE_NEW;
tbrButtons[0].fsState = TBSTATE_ENABLED;
tbrButtons[0].fsStyle = TBSTYLE_BUTTON;
tbrButtons[0].dwData = 0L;
tbrButtons[0].iBitmap = 0;
tbrButtons[0].iString = 0;
tbrButtons[1].iBitmap = 1;
tbrButtons[1].idCommand = IDM_FILE_OPEN;
tbrButtons[1].fsState = TBSTATE_ENABLED;
tbrButtons[1].fsStyle = TBSTYLE_BUTTON;
tbrButtons[1].dwData = 0L;
tbrButtons[1].iString = 0;
tbrButtons[2].iBitmap = 0;
tbrButtons[2].idCommand = 0;
tbrButtons[2].fsState = TBSTATE_ENABLED;
tbrButtons[2].fsStyle = TBSTYLE_SEP;
tbrButtons[2].dwData = 0L;
tbrButtons[2].iString = 0;
tbrButtons[3].iBitmap = 2;
tbrButtons[3].idCommand = IDM_ARROW;
tbrButtons[3].fsState = TBSTATE_ENABLED;
tbrButtons[3].fsStyle = TBSTYLE_BUTTON;
tbrButtons[3].dwData = 0L;
tbrButtons[3].iString = 0;
tbrButtons[4].iBitmap = 3;
tbrButtons[4].idCommand = IDM_DRAW_LINE;
tbrButtons[4].fsState = TBSTATE_ENABLED;
tbrButtons[4].fsStyle = TBSTYLE_BUTTON;
tbrButtons[4].dwData = 0L;
tbrButtons[4].iString = 0;
tbrButtons[5].iBitmap = 4;
tbrButtons[5].idCommand = IDM_DRAW_RECTANGLE;
tbrButtons[5].fsState = TBSTATE_ENABLED;
tbrButtons[5].fsStyle = TBSTYLE_BUTTON;
tbrButtons[5].dwData = 0L;
tbrButtons[5].iString = 0;
tbrButtons[6].iBitmap = 5;
tbrButtons[6].idCommand = IDM_DRAW_ELLIPSE;
tbrButtons[6].fsState = TBSTATE_ENABLED;
tbrButtons[6].fsStyle = TBSTYLE_BUTTON;
tbrButtons[6].dwData = 0L;
tbrButtons[6].iString = 0;
HWND hWndToolbar;
hWndToolbar = CreateToolbarEx(hWnd,
WS_VISIBLE | WS_CHILD | WS_BORDER,
IDB_TOOLBARBMP,
NUMBUTTONS,
hInst,
IDB_STANDARD,
tbrButtons,
NUMBUTTONS,
16, 16, 16, 16,
sizeof(TBBUTTON));
6. 完成
** TBUTTON 結構定義 **
typedef struct _TBBUTTON {
int iBitmap;
int idCommand;
BYTE fsState;
BYTE fsStyle;
#ifdef _WIN64
BYTE bReserved[6] // padding for alignment
#elif defined(_WIN32)
BYTE bReserved[2] // padding for alignment
#endif
DWORD_PTR dwData;
INT_PTR iString;
} TBBUTTON, NEAR *PTBBUTTON *LPTBBUTTON;
** CreateToolbarEx **
HWND CreateToolbarEx(HWND hwnd, // toolbar 屬於哪個 window
DWORD ws, //toolbar 顯示方示, windows styles and toolbar styles 之組合
UINT wID, // toolbar 之識別ID
int nBitmaps, // 使用圖片數量
HINSTANCE hBMInst, //管理toolbar 之 instance
UINT_PTR wBMID, //bitmap 之識別 ID
LPCTBBUTTON lpButtons, //指向已定義之 TBBUTTON array
int iNumButtons, // 已建立之 button 數量
int dxButton, // 每個 button 之 x軸 pixel 數
int dyButton, // 每個 button 之 y軸 pixel 數
int dxBitmap, // 每個 bitmap 之 x軸 pixel 數
int dyBitmap, // 每個 bitmap 之 y軸 pixel 數
UINT uStructSize // TBBUTTON 結構大小
);