15,980
社区成员




//创建工具条
HWND CreateToolBar(HWND hWndParent)
{
HWND hWndTB;
TBBUTTON tbb[4];
HIMAGELIST hImageList,hHotImageList,hDisableImageList;
HBITMAP hBitmap;
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
hWndTB = CreateWindowEx(0,
TOOLBARCLASSNAME,TEXT(""),
WS_CHILD|WS_VISIBLE|WS_BORDER|TBSTYLE_FLAT|TBSTYLE_LIST|TBSTYLE_AUTOSIZ
E,
0,0,0,0,
hWndParent,
(HMENU)IDR_TOOLBAR,
g_hInst,
NULL);
if(!hWndTB)
return 0;
SendMessage(hWndTB, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON),
0);
hImageList = ImageList_Create(20,20,ILC_COLOR24,3,1);
hBitmap = LoadBitmap(g_hInst,MAKEINTRESOURCE(IDR_TOOLBAR));
ImageList_Add(hImageList,hBitmap,NULL);
DeleteObject (hBitmap);
SendMessage(hWndTB,TB_SETIMAGELIST,0,(LPARAM)hImageList);
hHotImageList = ImageList_Create(20,20,ILC_COLOR24,3,1);
hBitmap = LoadBitmap(g_hInst,MAKEINTRESOURCE(IDR_TOOLBARHOT));
ImageList_Add(hHotImageList,hBitmap,NULL);
DeleteObject (hBitmap);
SendMessage(hWndTB,TB_SETHOTIMAGELIST,0,(LPARAM)hHotImageList);
hDisableImageList = ImageList_Create(20,20,ILC_COLOR24,3,1);
hBitmap = LoadBitmap(g_hInst,MAKEINTRESOURCE(IDR_TOOLBARDISABLE));
ImageList_Add(hDisableImageList,hBitmap,NULL);
DeleteObject (hBitmap);
SendMessage(hWndTB,TB_SETDISABLEDIMAGELIST,0,(LPARAM)
hDisableImageList);
ZeroMemory(tbb, sizeof(tbb));
tbb[0].iBitmap =MAKELONG(0,0) ;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[0].idCommand = ID_MENU_NEW;
//tbb[0].iString = (INT_PTR)TEXT("查找");
tbb[1].iBitmap =MAKELONG(1,0);
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[1].idCommand = ID_MENU_OPEN;
//tbb[1].iString = (INT_PTR)TEXT("后退");
tbb[2].iBitmap =MAKELONG(2,0);
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[2].idCommand = ID_MENU_SAVE;
//tbb[2].iString = (INT_PTR)TEXT("向前");
tbb[3].iBitmap =MAKELONG(3,0);
tbb[3].fsState = TBSTATE_ENABLED;
tbb[3].fsStyle = TBSTYLE_BUTTON|BTNS_AUTOSIZE;
tbb[3].idCommand = ID_MENU_EXIT;
//tbb[3].iString = (INT_PTR)TEXT("视图");
SendMessage(hWndTB, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON),
(LPARAM)&tbb);
SendMessage(hWndTB,WM_SIZE,0,0);
return hWndTB;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
int nWidth;
switch (message)
{
case WM_CREATE:
hToolBar=CreateToolBar(hWnd);
hStatusBar=CreateStatusToolBar(hWnd); // 注意这里
hTreePanel=CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_DIALOG_TREE),hWnd,TreePanel_DialogFun);
ShowWindow(hTreePanel,SW_SHOW);
hCommandPanel=CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_DIALOG_COMMAND),hWnd,CommandPanel_DialogFun);
ShowWindow(hCommandPanel,SW_SHOW);
return 0;
case WM_SIZE:
GetClientRect(hWnd,&rect);
nWidth=rect.right-rect.left;
MoveWindow(hTreePanel,0,30,Splitter_x,rect.bottom-rect.top-50,TRUE);
MoveWindow(hCommandPanel,Splitter_x,30,rect.right-rect.left,150,TRUE);
/*
GetClientRect(hToolBar,&rect);
MoveWindow(hToolBar,0,0,nWidth,rect.bottom-rect.top,TRUE);
*/
SendMessage(hToolBar,WM_SIZE,0,0);
SendMessage(hStatusBar,WM_SIZE,0,0);
return 0;
case WM_PAINT:
hdc = BeginPaint (hWnd, &ps);
GetClientRect(hWnd,&rect);
SetBkColor(hdc, RGB(128,128,128));
ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
EndPaint (hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_MENU_NEW:
MessageBox(hWnd,"Ok","Ok",MB_OK);
return TRUE;
case IDOK:
return TRUE;
}
return FALSE;
return 0;
}
return DefWindowProc (hWnd, message, wParam, lParam);
}