95 в двух томах Том I



Pdf просмотр
страница38/41
Дата27.11.2016
Размер4.32 Mb.
Просмотров7677
Скачиваний0
ТипРеферат
1   ...   33   34   35   36   37   38   39   40   41
Пример
Объединим теперь все эти фрагменты для элементов меню, всплывающих меню и системного меню. Ниже приведен код, иллюстрирующий то, каким образом программа GADGETS обрабатывает сообщение
WM_MENUSELECT для того, чтобы отобразить вспомогательную информацию в строке состояния:
LRESULT Statusbar_MenuSelect(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
UINT fuFlags =(UINT) HIWORD(wParam);
HMENU hMainMenu = NULL; int iMenu = 0;
// Обработка несистемных всплывающих меню if((fuFlags & MF_POPUP) &&(!(fuFlags & MF_SYSMENU)))
{ for(iMenu = 1; iMenu < MAX_MENUS; iMenu++)
{ if((HMENU) lParam == popstr[iMenu].hMenu)
{ hMainMenu =(HMENU)lParam; break;
}
}
}
// Отображение вспомогательной информации в строке состояния
MenuHelp(WM_MENUSELECT, wParam, lParam, hMainMenu, hInst, hwndStatusBar, &((UINT) popstr[iMenu].hMenu)); return 0;
}

438
Программа GADGETS
Программа GADGETS объединяет вместе три рассмотренных элемента управления: панель инструментов, подсказку, строку состояния. Как показано на рис. 12.7, программа GADGETS имеет панель инструментов, содержащую комбинированный список, и строку состояния с возможностью изменения размеров окна. Она также имеет рабочее окно, которое содержит список для отображения всех кодов уведомлений, получаемых для каждого из этих элементов управления. Для того чтобы дать вам возможность почувствовать различные стили панели инструментов и строки состояния, программа GADGETS дает вам возможность разрешить или запретить эти флаги стилей, чтобы продемонстрировать незамедлительно эффект каждого из этих флагов стиля. На рис. 12.8 приведен исходный текст программы GADGETS.
Рис. 12.7 Вывод на экран программы GADGETS
GADGETS.MAK
#-----------------------
# GADGETS.MAK make file
#----------------------- gadgets.exe : gadgets.obj notifdef.obj statbar.obj \ toolbar.obj tooltip.obj gadgets.res
$(LINKER) $(GUIFLAGS) -OUT:gadgets.exe gadgets.obj \ notifdef.obj statbar.obj toolbar.obj tooltip.obj \ gadgets.res $(GUILIBS) gadgets.obj : gadgets.c comcthlp.h gadgets.h
$(CC) $(CFLAGS) gadgets.c notifdef.obj : notifdef.c notifdef.h
$(CC) $(CFLAGS) notifdef.c statbar.obj : statbar.c comcthlp.h gadgets.h
$(CC) $(CFLAGS) statbar.c toolbar.obj : toolbar.c comcthlp.h gadgets.h notifdef.h
$(CC) $(CFLAGS) toolbar.c tooltip.obj : tooltip.c comcthlp.h gadgets.h notifdef.h
$(CC) $(CFLAGS) tooltip.c gadgets.res : gadgets.rc gadgets.ico
$(RC) $(RCVARS) gadgets.rc
GADGETS.H
// Resource definitions.
#define IDM_FILE_NEW 100 // -- Menu Commands --
#define IDM_FILE_OPEN 101
#define IDM_FILE_SAVE 102
#define IDM_FILE_SAVEAS 103
#define IDM_FILE_PRINT 104

439
#define IDM_FILE_PREVIEW 105
#define IDM_FILE_EXIT 106
#define IDM_EDIT_UNDO 200
#define IDM_EDIT_CUT 201
#define IDM_EDIT_COPY 202
#define IDM_EDIT_PASTE 203
#define IDM_EDIT_PROP 204
#define IDM_TB_HELP 250
#define IDM_TB_DELETE 251
#define IDM_IGNORESIZE 300
#define IDM_STRINGS 301
#define IDM_LARGEICONS 302
#define IDM_SMALLICONS 303
#define IDM_NODIVIDER 400
#define IDM_WRAPABLE 401
#define IDM_TOP 402
#define IDM_BOTTOM 403
#define IDM_NOMOVEY 404
#define IDM_NOPARENTALIGN 405
#define IDM_NORESIZE 406
#define IDM_ADJUSTABLE 407
#define IDM_ALTDRAG 408
#define IDM_TOOLTIPS 409
#define IDM_TB_CHECK 500
#define IDM_TB_ENABLE 501
#define IDM_TB_HIDE 502
#define IDM_TB_INDETERMINATE 503
#define IDM_TB_PRESS 504
#define IDM_TB_BUTTONCOUNT 505
#define IDM_TB_GETROWS 506
#define IDM_TB_CUSTOMIZE 507
#define IDM_STAT_IGNORESIZE 600
#define IDM_STAT_SIZEGRIP 700
#define IDM_STAT_TOP 701
#define IDM_STAT_BOTTOM 702
#define IDM_STAT_NOMOVEY 703
#define IDM_STAT_NOPARENTALIGN 704
#define IDM_STAT_NORESIZE 705
#define IDM_ST_GETBORDERS 800
#define IDM_ST_GETPARTS 801
#define IDM_ST_SETTEXT 802
#define IDM_ST_SIMPLE 803
#define IDM_NOTIFICATIONS_CLEAR 900
#define IDM_VIEW_TOOLBAR 1000
#define IDM_VIEW_STATUS 1001
#define IDM_VIEW_NOTIFICATIONS 1002
#define IDM_COMBOBOX 4000
#define IDI_APP 101 // -- Icons --
#define IDS_MAIN_MENU 71 // -- Strings --
#define IDS_MAIN_MENU1 72
#define IDS_MAIN_MENU2 73
#define IDS_MAIN_MENU3 74
#define IDS_MAIN_MENU4 75
#define IDS_MAIN_MENU5 76
#define IDS_TOOLBAR_MENU 80
#define IDS_TOOLBAR_MENU1 81
#define IDS_TOOLBAR_MENU2 82
#define IDS_TOOLBAR_MENU3 83
#define IDS_STATUSBAR_MENU 90
#define IDS_STATUSBAR_MENU1 91
#define IDS_STATUSBAR_MENU2 92
#define IDS_STATUSBAR_MENU3 93
#define IDC_TB_COMBOBOX 2000 // -- Toolbar combo box

440
// Toolbar functions.
HWND InitToolBar(HWND hwndParent);
HWND RebuildToolBar(HWND hwndParent, WORD wFlag); void ToolBarMessage(HWND hwndTB, WORD wMsg);
LRESULT ToolBarNotify(HWND hwnd, WPARAM wParam, LPARAM lParam);
// Tooltip functions.
BOOL InitToolTip(HWND hwndToolBar, HWND hwndComboBox);
BOOL RelayToolTipMessage(LPMSG pMsg); void CopyToolTipText(LPTOOLTIPTEXT lpttt);
// Status bar functions.
HWND InitStatusBar(HWND hwndParent);
HWND RebuildStatusBar(HWND hwndParent, WORD wFlag); void StatusBarMessage(HWND hwndSB, WORD wMsg);
LRESULT Statusbar_MenuSelect(HWND, WPARAM, LPARAM);
// Notification window functions.
HWND ViewNotificationsToggle(HWND hwnd); void DisplayNotificationDetails(WPARAM wParam, LPARAM lParam); void ClearNotificationList();
NOTIFDEF.H
typedef struct tagCONTROLNOTIFICATIONS
{
UINT nCode;
LPSTR pName;
} CONTROLNOTIFICATIONS;
BOOL QueryNotifyText(UINT nNotifyCode, LPSTR *pName); void DisplayText(LPSTR pText);
GADGETS.C
/*-----------------------------------------
GADGETS.C -- Gadgets for a frame window
(c) Paul Yao, 1996
-----------------------------------------*/
#include
#include
#include
#include "comcthlp.h"
#include "gadgets.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ClientWndProc(HWND, UINT, WPARAM, LPARAM); char szAppName[] = "Gadgets";
BOOL bIgnoreSize = FALSE;
HINSTANCE hInst;
HWND hwndClient = NULL;
HWND hwndToolBar = NULL;
HWND hwndStatusBar = NULL;
HWND hwndNotify = NULL; extern DWORD dwToolBarStyles; extern BOOL bStrings; extern BOOL bLargeIcons; extern BOOL bComboBox; extern DWORD dwStatusBarStyles; extern int cyToolBar;
//------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,

441
PSTR lpszCmdLine, int cmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wc; hInst = hInstance; wc.cbSize = sizeof(wc); wc.lpszClassName = szAppName; wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_APP)); wc.lpszMenuName = "MAIN"; wc.hbrBackground =(HBRUSH)(COLOR_WINDOW + 1); wc.style = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(IDI_APP));
RegisterClassEx(&wc); wc.lpszClassName = "ClientWndProc"; wc.hInstance = hInstance; wc.lpfnWndProc = ClientWndProc; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.lpszMenuName = NULL; wc.hbrBackground =(HBRUSH)(COLOR_WINDOW + 1); wc.style = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc); hwnd = CreateWindowEx(0L, szAppName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, cmdShow);
UpdateWindow(hwnd);
InitCommonControls(); while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return msg.wParam;
}
//------------------------------------------------------------------- void MenuCheckMark(HMENU hmenu, int id, BOOL bCheck)
{ int iState; iState =(bCheck) ? MF_CHECKED : MF_UNCHECKED;
CheckMenuItem(hmenu, id, iState);
}
//-------------------------------------------------------------------

442
LRESULT CALLBACK
WndProc(HWND hwnd, UINT mMsg, WPARAM wParam, LPARAM lParam)
{ switch(mMsg)
{ case WM_CREATE :
{
// Create toolbar(source resides in toolbar.c) hwndToolBar = InitToolBar(hwnd);
// Create status bar(source resides in statbar.c) hwndStatusBar = InitStatusBar(hwnd);
// Create client window(contains notify list) hwndClient = CreateWindowEx(WS_EX_CLIENTEDGE,
"ClientWndProc", NULL,
WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd,(HMENU) 4, hInst, NULL); return 0;
} case WM_COMMAND :
{
// Toolbar button commands if(LOWORD(wParam) < 300)
{ char ach[80]; wsprintf(ach, "Got Command(%d)", wParam);
MessageBox(hwnd, ach, szAppName, MB_OK); break;
}
// Menu item commands switch(LOWORD(wParam))
{
// Toolbar settings case IDM_STRINGS : case IDM_LARGEICONS : case IDM_SMALLICONS : case IDM_NODIVIDER : case IDM_WRAPABLE : case IDM_TOP : case IDM_BOTTOM : case IDM_NOMOVEY : case IDM_NOPARENTALIGN : case IDM_NORESIZE : case IDM_ADJUSTABLE : case IDM_ALTDRAG : case IDM_TOOLTIPS : case IDM_COMBOBOX :
DestroyWindow(hwndToolBar); hwndToolBar = RebuildToolBar(hwnd,
LOWORD(wParam)); break;
// Toolbar messages case IDM_TB_CHECK : case IDM_TB_ENABLE : case IDM_TB_HIDE : case IDM_TB_INDETERMINATE : case IDM_TB_PRESS : case IDM_TB_BUTTONCOUNT : case IDM_TB_GETROWS :

443 case IDM_TB_CUSTOMIZE :
ToolBarMessage(hwndToolBar, LOWORD(wParam)); break;
// Status bar settings case IDM_STAT_SIZEGRIP : case IDM_STAT_TOP : case IDM_STAT_BOTTOM : case IDM_STAT_NOMOVEY : case IDM_STAT_NOPARENTALIGN : case IDM_STAT_NORESIZE :
DestroyWindow(hwndStatusBar); hwndStatusBar = RebuildStatusBar(hwnd,
LOWORD(wParam)); break;
// Status bar messages case IDM_ST_GETBORDERS : case IDM_ST_GETPARTS : case IDM_ST_SETTEXT : case IDM_ST_SIMPLE :
StatusBarMessage(hwndStatusBar, LOWORD(wParam)); break;
// Toggle display of toolbar case IDM_VIEW_TOOLBAR :
{
RECT r; if(hwndToolBar && IsWindowVisible(hwndToolBar))
{
ShowWindow(hwndToolBar, SW_HIDE);
} else
{
ShowWindow(hwndToolBar, SW_SHOW);
}
// Resize other windows
GetClientRect(hwnd, &r);
PostMessage(hwnd, WM_SIZE, 0,
MAKELPARAM(r.right, r.bottom)); break;
}
// Toggle display of status bar case IDM_VIEW_STATUS :
{
RECT r; if(hwndStatusBar && IsWindowVisible(hwndStatusBar))
{
ShowWindow(hwndStatusBar, SW_HIDE);
} else
{
ShowWindow(hwndStatusBar, SW_SHOW);
}
// Resize other windows
GetClientRect(hwnd, &r);
PostMessage(hwnd, WM_SIZE, 0,
MAKELPARAM(r.right, r.bottom));

444 break;
}
// Toggle display of notifications window case IDM_VIEW_NOTIFICATIONS : hwndNotify = ViewNotificationsToggle(hwndClient); break;
// Toggle ignore WM_SIZE to show auto-size/auto-move case IDM_IGNORESIZE : case IDM_STAT_IGNORESIZE :
{
RECT r; bIgnoreSize = !bIgnoreSize; if(bIgnoreSize)
{
ShowWindow(hwndClient, SW_HIDE);
} else
{
ShowWindow(hwndClient, SW_SHOW);
GetClientRect(hwnd, &r);
PostMessage(hwnd, WM_SIZE, 0,
MAKELPARAM(r.right, r.bottom));
} break;
}
// Clear contents of notification window case IDM_NOTIFICATIONS_CLEAR :
ClearNotificationList(); break;
} return 0;
} case WM_INITMENU :
{
BOOL bCheck;
HMENU hmenu =(HMENU) wParam;
MenuCheckMark(hmenu, IDM_IGNORESIZE, bIgnoreSize);
MenuCheckMark(hmenu, IDM_STAT_IGNORESIZE, bIgnoreSize);
// Toolbar menu items
MenuCheckMark(hmenu, IDM_STRINGS, bStrings);
MenuCheckMark(hmenu, IDM_LARGEICONS, bLargeIcons);
MenuCheckMark(hmenu, IDM_SMALLICONS, !bLargeIcons);
MenuCheckMark(hmenu, IDM_COMBOBOX, bComboBox); bCheck =(dwToolBarStyles & CCS_NODIVIDER);
MenuCheckMark(hmenu, IDM_NODIVIDER, bCheck); bCheck =(dwToolBarStyles & TBSTYLE_WRAPABLE);
MenuCheckMark(hmenu, IDM_WRAPABLE, bCheck); bCheck =((dwToolBarStyles & 3) == CCS_TOP);
MenuCheckMark(hmenu, IDM_TOP, bCheck); bCheck =((dwToolBarStyles & 3) == CCS_BOTTOM);
MenuCheckMark(hmenu, IDM_BOTTOM, bCheck);

445 bCheck =((dwToolBarStyles & 3) == CCS_NOMOVEY);
MenuCheckMark(hmenu, IDM_NOMOVEY, bCheck); bCheck =(dwToolBarStyles & CCS_NOPARENTALIGN);
MenuCheckMark(hmenu, IDM_NOPARENTALIGN, bCheck); bCheck =(dwToolBarStyles & CCS_NORESIZE);
MenuCheckMark(hmenu, IDM_NORESIZE, bCheck); bCheck =(dwToolBarStyles & CCS_ADJUSTABLE);
MenuCheckMark(hmenu, IDM_ADJUSTABLE, bCheck); bCheck =(dwToolBarStyles & TBSTYLE_ALTDRAG);
MenuCheckMark(hmenu, IDM_ALTDRAG, bCheck); bCheck =(dwToolBarStyles & TBSTYLE_TOOLTIPS);
MenuCheckMark(hmenu, IDM_TOOLTIPS, bCheck);
// Status bar menu items bCheck =(dwStatusBarStyles & SBARS_SIZEGRIP);
MenuCheckMark(hmenu, IDM_STAT_SIZEGRIP, bCheck); bCheck =((dwStatusBarStyles & 3) == CCS_TOP);
MenuCheckMark(hmenu, IDM_STAT_TOP, bCheck); bCheck =((dwStatusBarStyles & 3) == CCS_BOTTOM);
MenuCheckMark(hmenu, IDM_STAT_BOTTOM, bCheck); bCheck =((dwStatusBarStyles & 3) == CCS_NOMOVEY);
MenuCheckMark(hmenu, IDM_STAT_NOMOVEY, bCheck); bCheck =(dwStatusBarStyles & CCS_NOPARENTALIGN);
MenuCheckMark(hmenu, IDM_STAT_NOPARENTALIGN, bCheck); bCheck =(dwStatusBarStyles & CCS_NORESIZE);
MenuCheckMark(hmenu, IDM_STAT_NORESIZE, bCheck);
// View menu items bCheck = IsWindowVisible(hwndToolBar);
MenuCheckMark(hmenu, IDM_VIEW_TOOLBAR, bCheck); bCheck = IsWindowVisible(hwndStatusBar);
MenuCheckMark(hmenu, IDM_VIEW_STATUS, bCheck); bCheck =(hwndNotify != NULL);
MenuCheckMark(hmenu, IDM_VIEW_NOTIFICATIONS, bCheck); return 0;
} case WM_MENUSELECT : return Statusbar_MenuSelect(hwnd, wParam, lParam); case WM_DESTROY :
PostQuitMessage(0); return 0; case WM_NOTIFY :
{
LPNMHDR pnmh =(LPNMHDR) lParam; int idCtrl =(int) wParam;
// Display notification details in notify window
DisplayNotificationDetails(wParam, lParam);

446
// Toolbar notifications if((pnmh->code >= TBN_LAST) &&
(pnmh->code <= TBN_FIRST))
{ return ToolBarNotify(hwnd, wParam, lParam);
}
// Fetch tooltip text if(pnmh->code == TTN_NEEDTEXT)
{
LPTOOLTIPTEXT lpttt =(LPTOOLTIPTEXT) lParam;
CopyToolTipText(lpttt);
} return 0;
} case WM_SIZE :
{ int cx = LOWORD(lParam); int cy = HIWORD(lParam); int cyStatus; int cyTB; int x, y;
DWORD dwStyle;
RECT rWindow;
// Ignore size message to allow auto-move and auto-size
// features to be more clearly seen if(bIgnoreSize) return 0;
// Adjust toolbar size if(IsWindowVisible(hwndToolBar))
{ dwStyle = GetWindowLong(hwndToolBar, GWL_STYLE); if(dwStyle & CCS_NORESIZE)
{
MoveWindow(hwndToolBar,
0, 0, cx, cyToolBar, FALSE);
} else
{
ToolBar_AutoSize(hwndToolBar);
}
InvalidateRect(hwndToolBar, NULL, TRUE);
GetWindowRect(hwndToolBar, &rWindow);
ScreenToClient(hwnd,(LPPOINT) &rWindow.left);
ScreenToClient(hwnd,(LPPOINT) &rWindow.right); cyTB = rWindow.bottom - rWindow.top;
} else
{ cyTB = 0;
}
// Adjust status bar size if(IsWindowVisible(hwndStatusBar))
{
GetWindowRect(hwndStatusBar, &rWindow); cyStatus = rWindow.bottom - rWindow.top;
MoveWindow(hwndStatusBar, 0, cy - cyStatus, cx, cyStatus, TRUE);
}

447 else
{ cyStatus = 0;
}
// Adjust client window size x = 0; y = cyTB; cy = cy -(cyStatus + cyTB);
MoveWindow(hwndClient, x, y, cx, cy, TRUE); return 0;
} default: return(DefWindowProc(hwnd, mMsg, wParam, lParam));
}
}
//-------------------------------------------------------------------
LRESULT CALLBACK
ClientWndProc(HWND hwnd, UINT mMsg, WPARAM wParam, LPARAM lParam)
{ static COLORREF crBack; static HBRUSH hbr; switch(mMsg)
{ case WM_CREATE : hwndNotify = ViewNotificationsToggle(hwnd); crBack = GetSysColor(COLOR_APPWORKSPACE); hbr = CreateSolidBrush(crBack); return 0; case WM_DESTROY :
DeleteObject(hbr); return 0; case WM_CTLCOLORLISTBOX :
{
DefWindowProc(hwnd, mMsg, wParam, lParam);
SetBkColor((HDC) wParam, crBack);
SetBkMode((HDC) wParam, TRANSPARENT); return(LRESULT)(HBRUSH) hbr;
} case WM_SIZE :
{
HWND hwndNotify = GetWindow(hwnd, GW_CHILD); int cx = LOWORD(lParam); int cy = HIWORD(lParam);
// Ignore if notification window is absent if(hwndNotify != NULL)
{
MoveWindow(hwndNotify, 0, 0, cx, cy, TRUE);
} return 0;
} default : return(DefWindowProc(hwnd, mMsg, wParam, lParam));
}
}

448
TOOLBAR.C
/*----------------------------------------
TOOLBAR.C -- Toolbar helper functions
(c) Paul Yao, 1996
----------------------------------------*/
#include
#include
#include "comcthlp.h"
#include "gadgets.h"
#include "notifdef.h"
HWND hwndCombo;
HWND hwndEdit;
HWND hwndToolTip;
HWND hwndTB; int cyToolBar;
BOOL bComboBox = FALSE;
BOOL bStrings = FALSE;
BOOL bLargeIcons = FALSE;
DWORD dwToolBarStyles = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
CCS_TOP | CCS_NODIVIDER | TBSTYLE_TOOLTIPS; extern HINSTANCE hInst; char szTbStrings[] = "New\0Open\0Save\0Print\0Preview\0"
"Cut\0Copy\0Paste\0Undo\0Properties\0"
"Help\0Delete\0";
TBBUTTON tbb[] =
{
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
STD_FILENEW, IDM_FILE_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 0,
STD_FILEOPEN, IDM_FILE_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 1,
STD_FILESAVE, IDM_FILE_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 2,
STD_PRINT, IDM_FILE_PRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 3,
STD_PRINTPRE, IDM_FILE_PREVIEW, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, 0, 0, 4,
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0, 0,
STD_CUT, IDM_EDIT_CUT, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, 0, 5,
STD_COPY, IDM_EDIT_COPY, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, 0, 6,
STD_PASTE, IDM_EDIT_PASTE, TBSTATE_ENABLED, TBSTYLE_CHECKGROUP, 0, 0, 0, 7,
STD_UNDO, IDM_EDIT_UNDO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 8,

449
STD_PROPERTIES, IDM_EDIT_PROP, TBSTATE_ENABLED, TBSTYLE_CHECK, 0, 0, 0, 9,
STD_HELP, IDM_TB_HELP, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 10,
STD_DELETE, IDM_TB_DELETE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0, 11,
}; int nCust[] = { 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, -1};
TBADDBITMAP tbStdLarge[] =
{
HINST_COMMCTRL, IDB_STD_LARGE_COLOR,
};
TBADDBITMAP tbStdSmall[] =
{
HINST_COMMCTRL, IDB_STD_SMALL_COLOR,
};
//-------------------------------------------------------------------
LPSTR GetString(int iString)
{ int i, cb;
LPSTR pString;
// Cycle through to requested string pString = szTbStrings; for(i = 0; i < iString; i++)
{ cb = lstrlen(pString); pString +=(cb + 1);
} return pString;
}
//-------------------------------------------------------------------
LRESULT ToolBarNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
LPNMHDR pnmh =(LPNMHDR) lParam; int idCtrl =(int) wParam;
// Allow toolbar to be customized if((pnmh->code == TBN_QUERYDELETE) ||
(pnmh->code == TBN_QUERYINSERT))
{ return 1; // We always say "yes"
}
// Provide details of allowable toolbar buttons if(pnmh->code == TBN_GETBUTTONINFO)
{
LPTBNOTIFY ptbn =(LPTBNOTIFY) lParam; int iButton = nCust[ptbn->iItem]; if(iButton != -1)
{ lstrcpy(ptbn->pszText, GetString(ptbn->iItem)); memcpy(&ptbn->tbButton, &tbb[iButton], sizeof(TBBUTTON)); return 1;
}
} return 0;
}
//-------------------------------------------------------------------

450
HWND InitToolBar(HWND hwndParent)
{ int iNumButtons;
LPTBBUTTON ptbb; if(bComboBox)
{ ptbb = &tbb[0]; iNumButtons = 31;
} else
{ ptbb = &tbb[21]; iNumButtons = 10;
}
UINT uiBitmap =(bLargeIcons) ? IDB_STD_LARGE_COLOR :
IDB_STD_SMALL_COLOR; hwndTB = CreateToolbarEx(hwndParent, dwToolBarStyles,
1, 15,
HINST_COMMCTRL, uiBitmap, ptbb, iNumButtons,
0, 0, 0, 0, sizeof(TBBUTTON));
// If requested, add to string list if(bStrings)
ToolBar_AddString(hwndTB, 0, szTbStrings);
// Store handle to tooltip control hwndToolTip = ToolBar_GetToolTips(hwndTB);
// Insert combo box into toolbar if(bComboBox)
{
RECT r; int x, y, cx, cy;
// Calculate coordinates for combo box
ToolBar_GetItemRect(hwndTB, 0, &r); x = r.left; y = r.top; cy = 100;
ToolBar_GetItemRect(hwndTB, 18, &r); cx = r.right - x + 1; hwndCombo = CreateWindow("combobox",
NULL,
WS_CHILD | WS_VISIBLE |
CBS_DROPDOWN, x, y, cx, cy, hwndParent,
(HMENU) IDC_TB_COMBOBOX, hInst,
0);
// Set toolbar as combo box window parent
SetParent(hwndCombo, hwndTB);
SendMessage(hwndCombo, CB_ADDSTRING, 0,(LPARAM) "One");
SendMessage(hwndCombo, CB_ADDSTRING, 0,(LPARAM) "Two");

451
SendMessage(hwndCombo, CB_ADDSTRING, 0,(LPARAM) "Three");
// Calculate toolbar height
GetWindowRect(hwndCombo, &r); cyToolBar = r.bottom - r.top + 1; cyToolBar += y; cyToolBar +=(2 * GetSystemMetrics(SM_CYBORDER));
ToolBar_GetItemRect(hwndTB, 0, &r); cyToolBar = max(cyToolBar, r.bottom+5);
// If toolbar has tooltips, initialize if(dwToolBarStyles & TBSTYLE_TOOLTIPS)
InitToolTip(hwndTB, hwndCombo);
} return hwndTB;
}
//------------------------------------------------------------------- void static FlipStyleFlag(LPDWORD dwStyle, DWORD flag)
{ if(*dwStyle & flag) // Flag on -- turn off
{
*dwStyle &=(
flag);
} else // Flag off -- turn on
{
*dwStyle |= flag;
}
}
//-------------------------------------------------------------------
HWND RebuildToolBar(HWND hwndParent, WORD wFlag)
{
HWND hwndTB;
RECT r; switch(wFlag)
{ case IDM_STRINGS : bStrings = !bStrings; break; case IDM_LARGEICONS : bLargeIcons = TRUE; break; case IDM_SMALLICONS : bLargeIcons = FALSE; break; case IDM_NODIVIDER :
FlipStyleFlag(&dwToolBarStyles, CCS_NODIVIDER); break; case IDM_WRAPABLE :
FlipStyleFlag(&dwToolBarStyles, TBSTYLE_WRAPABLE); break; case IDM_TOP : dwToolBarStyles &= 0xFFFFFFFC; dwToolBarStyles |= CCS_TOP; break;

452 case IDM_BOTTOM : dwToolBarStyles &= 0xFFFFFFFC; dwToolBarStyles |= CCS_BOTTOM; break; case IDM_NOMOVEY : dwToolBarStyles &= 0xFFFFFFFC; dwToolBarStyles |= CCS_NOMOVEY; break; case IDM_NOPARENTALIGN :
FlipStyleFlag(&dwToolBarStyles, CCS_NOPARENTALIGN); break; case IDM_NORESIZE :
FlipStyleFlag(&dwToolBarStyles, CCS_NORESIZE); break; case IDM_ADJUSTABLE :
FlipStyleFlag(&dwToolBarStyles, CCS_ADJUSTABLE); break; case IDM_ALTDRAG :
FlipStyleFlag(&dwToolBarStyles, TBSTYLE_ALTDRAG); break; case IDM_TOOLTIPS :
FlipStyleFlag(&dwToolBarStyles, TBSTYLE_TOOLTIPS); break; case IDM_COMBOBOX : bComboBox =(!bComboBox);
} hwndTB = InitToolBar(hwndParent);
// Post parent a WM_SIZE message to resize children
GetClientRect(hwndParent, &r);
PostMessage(hwndParent, WM_SIZE, 0,
MAKELPARAM(r.right, r.bottom)); return hwndTB;
}
//------------------------------------------------------------------- void ToolBarMessage(HWND hwndTB, WORD wMsg)
{ switch(wMsg)
{ case IDM_TB_CHECK :
{ int nState = ToolBar_GetState(hwndTB, 1);
BOOL bCheck =(!(nState & TBSTATE_CHECKED));
ToolBar_CheckButton(hwndTB, 1, bCheck ); break;
} case IDM_TB_ENABLE :
{ int nState = ToolBar_GetState(hwndTB, 2);
BOOL bEnabled =(!(nState & TBSTATE_ENABLED));
ToolBar_EnableButton(hwndTB, 2, bEnabled); break;
}

453 case IDM_TB_HIDE :
{ int nState = ToolBar_GetState(hwndTB, 3);
BOOL bShow =(!(nState & TBSTATE_HIDDEN));
ToolBar_HideButton(hwndTB, 3, bShow); break;
} case IDM_TB_INDETERMINATE :
{ int nState = ToolBar_GetState(hwndTB, 4);
BOOL bInd =(!(nState & TBSTATE_INDETERMINATE));
ToolBar_Indeterminate(hwndTB, 4, bInd); break;
} case IDM_TB_PRESS :
{ int nState = ToolBar_GetState(hwndTB, 5);
BOOL bPress =(!(nState & TBSTATE_PRESSED));
ToolBar_PressButton(hwndTB, 5, bPress); break;
} case IDM_TB_BUTTONCOUNT :
{ int nButtons = ToolBar_ButtonCount(hwndTB); char ach[80]; wsprintf(ach, "Button Count = %d", nButtons);
MessageBox(GetParent(hwndTB), ach,
"TB_BUTTONCOUNT", MB_OK); break;
} case IDM_TB_GETROWS :
{ int nRows = ToolBar_GetRows(hwndTB); char ach[80]; wsprintf(ach, "Row Count = %d", nRows);
MessageBox(GetParent(hwndTB), ach,
"TB_GETROWS", MB_OK); break;
} case IDM_TB_CUSTOMIZE :
// ToolBar_Customize(hwndTB);
SendMessage(hwndTB, TB_CUSTOMIZE,(LPARAM) &tbb[25], 5); break;
}
}



Поделитесь с Вашими друзьями:
1   ...   33   34   35   36   37   38   39   40   41


База данных защищена авторским правом ©nethash.ru 2019
обратиться к администрации

войти | регистрация
    Главная страница


загрузить материал