将integer指向TBSAVEPARAMS?(TBSAVETB_SAVERESTORE怎么用?) (150分)

  • 主题发起人 Tomorrows
  • 开始时间
T

Tomorrows

Unregistered / Unconfirmed
GUEST, unregistred user!
TB_SAVERESTORE可以将自定义过的工具栏存到注册表中,也可以从注册表恢复。<br>请问TB_SAVERESTORE怎么用?<br><br>相关帖子:http://www.delphibbs.com/delphibbs/dispq.asp?lid=1375713
 
&nbsp; &nbsp;你的代码没有问题,这个在 delphi 5 中就有。<br>&nbsp; &nbsp; 主要是 delphi 的文档少了关键的一段话,需要Toolbar 的父窗口对“通过”消息<br>TBN_GETBUTTONINFO 进行处理!!!!<br>&nbsp; &nbsp; 其中的处理涉及 按钮 id 文本 图像等各种信息内容,比较适合VC的处理。<br>如果只是想保存工具栏的位置和状态信息还不如用自己的方式进行处理。<br><br>To save and restore a toolbar's settings using the TB_SAVERESTORE message, the parent window of the toolbar control must implement a handler for the TBN_GETBUTTONINFO notification message. The toolbar uses this notification to retrieve information about the buttons as they are read out of the registry. <br><br>以下是VC中的示例:<br><br>SBAR.CPP<br>//**************************************************************************** // &nbsp;Module: &nbsp; &nbsp; NMUI.EXE &nbsp; &nbsp; &nbsp;// &nbsp;File: &nbsp; &nbsp; &nbsp; SBAR.CPP &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;Content: &nbsp; &nbsp;Status Bar Routines // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // // &nbsp;Copyright (c) Microsoft Corporation 1995-1997 // // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF &nbsp;// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO &nbsp;// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A &nbsp;// PARTICULAR PURPOSE. //**************************************************************************** &nbsp;#include "precomp.h" &nbsp;TBBUTTON _rgtbb[] = { &nbsp; &nbsp; {0, &nbsp; 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_SEP, &nbsp; &nbsp;0, 0, &nbsp;0, 0}, &nbsp; &nbsp; {28, &nbsp;IDM_MONITOR, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_CHECK, &nbsp;0, 0, &nbsp;1, 0}, &nbsp; &nbsp; {10, &nbsp;IDM_CONF_START, &nbsp; &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;2, 0}, &nbsp; &nbsp; {6, &nbsp; IDM_CONF_STOP, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;3, 0}, &nbsp; &nbsp; {4, &nbsp; IDM_VIEW_CLEAR, &nbsp; &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;4, 0}, &nbsp; &nbsp; {5, &nbsp; IDM_CALL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;5, 0}, &nbsp; &nbsp; {1, &nbsp; IDM_VIEW_MSG, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_CHECK, &nbsp;0, 0, &nbsp;6, 0}, &nbsp; &nbsp; {0, &nbsp; IDM_VIEW_CLEAR, &nbsp; &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;7, 0}, &nbsp; &nbsp; {6, &nbsp; IDM_VIEW_FONT, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;8, 0}, &nbsp; &nbsp; {10, &nbsp;IDM_CHANNEL_DATA, &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, &nbsp;9, 0}, &nbsp; &nbsp; {11, &nbsp;IDM_CHANNEL_AUDIO, &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 10, 0}, &nbsp; &nbsp; {12, &nbsp;IDM_CHANNEL_VIDEO, &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 11, 0}, &nbsp; &nbsp; {26, &nbsp;IDM_CHANNEL_FT, &nbsp; &nbsp; &nbsp; &nbsp; TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 12, 0}, &nbsp; &nbsp; {14, &nbsp;IDM_CHANNEL_SHARE, &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 13, 0}, &nbsp; &nbsp; {3, &nbsp; IDM_FT_CANCEL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 14, 0}, &nbsp;}; &nbsp;// default ordering of toolbar buttons static char _szBtnDefault[] = "0100020304000500060007"; &nbsp;static char _szToolbar[] = "Toolbar"; &nbsp; //**************************************************************************** // // LPTBBUTTON _GetDefaultTbb(DWORD * pcTbb, BOOL fReset) // //**************************************************************************** &nbsp;LPTBBUTTON _GetDefaultTbb(DWORD * pcTbb, BOOL fReset) { DWORD iBtn, cBtn; LPSTR lpsz, lpch; LPTBBUTTON pttb; &nbsp;if (fReset) lpsz = _szBtnDefault; else lpsz = GetIniStr(_szToolbar, _szBtnDefault); &nbsp;lpch = lpsz; cBtn = lstrlen(lpsz) / 2; &nbsp;pttb = (LPTBBUTTON) LpvAlloc(sizeof(TBBUTTON) * cBtn); if (NULL == pttb) return NULL; for (iBtn = 0; iBtn &lt; cBtn; iBtn++) { CopyStruct(pttb + iBtn, &amp;_rgtbb[ChFromHex(lpch)]); lpch += 2; } &nbsp;if (!fReset) FreePlpv(&amp;lpsz); &nbsp;*pcTbb = cBtn; return pttb; } &nbsp;//**************************************************************************** // // VOID ResetToolbar(void) // // Reset the toolbar to the initial defaults // //**************************************************************************** &nbsp;VOID ResetToolbar(void) { DWORD cBtn, iBtn; LPTBBUTTON ptbb; &nbsp;ptbb = _GetDefaultTbb(&amp;cBtn, TRUE /* fReset */); if (NULL == ptbb) return; &nbsp;iBtn = SendMessage(ghwndTbar, TB_BUTTONCOUNT, 0, 0); while (iBtn != 0) { SendMessage(ghwndTbar, TB_DELETEBUTTON, (WPARAM) --iBtn, 0); } &nbsp;SendMessage(ghwndTbar, TB_ADDBUTTONS, (WPARAM) cBtn, (LPARAM) ptbb); &nbsp;FreePlpv(&amp;ptbb); } &nbsp;//**************************************************************************** // // BOOL FCreateTbar(void) // // Create the toolbar // //**************************************************************************** &nbsp;BOOL FCreateTbar(void) { DWORD cBtn; LPTBBUTTON ptbb; &nbsp;ptbb = _GetDefaultTbb(&amp;cBtn, FALSE /* fReset */); if (NULL == ptbb) return FALSE; &nbsp;ghwndTbar = CreateToolbarEx(ghwndMain, WS_CHILD | CCS_ADJUSTABLE | TBSTYLE_TOOLTIPS | TBSTYLE_ALTDRAG, // | TBSTYLE_WRAPABLE &nbsp;IDW_TBAR, NUMIMAGES, ghInst, IDC_TOOLBAR, ptbb, cBtn, BUTTONWIDTH, BUTTONHEIGHT, IMAGEWIDTH, IMAGEHEIGHT, sizeof(TBBUTTON)); &nbsp;FreePlpv(&amp;ptbb); &nbsp;return (ghwndTbar != NULL); } &nbsp;//**************************************************************************** // // LRESULT MsgNotifyTbar(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) // //**************************************************************************** &nbsp;LRESULT MsgNotifyTbar(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { LPTOOLTIPTEXT lpToolTipText; static TCHAR szBuffer[MAX_PATH]; &nbsp;lpToolTipText = (LPTOOLTIPTEXT)lparam; &nbsp;switch (lpToolTipText-&gt;hdr.code) { case TTN_NEEDTEXT: { int cb; &nbsp;cb = LoadString(ghInst, lpToolTipText-&gt;hdr.idFrom, &nbsp; // string ID == command ID szBuffer, CCHMAX(szBuffer)); if (cb == 0) { szBuffer[0] = '/0'; } &nbsp;lpToolTipText-&gt;lpszText = szBuffer; return 1; } case TBN_QUERYINSERT: return 1; // allow insert case TBN_QUERYDELETE: return 1; // allow delete case TBN_RESET: ResetToolbar(); return 1; case TBN_GETBUTTONINFO: { LPTBNOTIFY ptbn = (LPTBNOTIFY) lparam; int iBtn = ptbn-&gt;iItem+1; &nbsp;if (iBtn &gt;= (ARRAY_ELEMENTS(_rgtbb))) return 0; // all button data has been passed to the control &nbsp;LoadString(ghInst, _rgtbb[iBtn].idCommand, ptbn-&gt;pszText, ptbn-&gt;cchText); //?ptbn-&gt;tbButton = _rgtbb[iBtn]; return 1; &nbsp;} case TBN_CUSTHELP: break; case TBN_TOOLBARCHANGE: break; // changes handled when exiting default: break; } &nbsp;return 0; } &nbsp;//**************************************************************************** // // VOID SetToolbarCheck(int idm, BOOL fCheck) // // Change the status of a toolbar command to be checked // //**************************************************************************** &nbsp;VOID SetToolbarCheck(int idm, BOOL fCheck) { SendMessage(ghwndTbar, TB_CHECKBUTTON, (WPARAM) idm, (LPARAM) MAKELONG(fCheck, 0)); } &nbsp;//**************************************************************************** // // VOID CmdToolbar(HWND hwnd, WORD wCmd, WORD wNotify, HWND hwndCtrl) // //**************************************************************************** &nbsp;VOID CmdToolbar(HWND hwnd, WORD wCmd, WORD wNotify, HWND hwndCtrl) { SendMessage(ghwndTbar, TB_CUSTOMIZE, 0, 0); } &nbsp; //**************************************************************************** // // VOID WriteIniTbar(void) // //**************************************************************************** &nbsp;VOID WriteIniTbar(void) { int &nbsp; iBtn; int &nbsp; cBtn; LPSTR lpsz; LPSTR lpch; TBBUTTON tbb; &nbsp;if (NULL == ghwndTbar) return; // no toolbar? &nbsp;cBtn = SendMessage(ghwndTbar, TB_BUTTONCOUNT, 0, 0); if (0 == cBtn) return; &nbsp;lpsz = (LPSTR) LpvAlloc(cBtn*2 + 1); if (NULL == lpsz) return; &nbsp;lpch = lpsz; for (iBtn = 0; iBtn &lt; cBtn; iBtn++) { SendMessage(ghwndTbar, TB_GETBUTTON, (WPARAM) iBtn, (LPARAM) (LPTBBUTTON) &amp;tbb); wsprintf(lpch, TEXT("%02X"), LOBYTE(tbb.dwData)); lpch += 2; } WriteIniStr(_szToolbar, lpsz); FreePlpv(&amp;lpsz); } &nbsp; //**************************************************************************** // // BOOL FCreateSbar(void) // // Create the status bar. // //**************************************************************************** &nbsp;BOOL FCreateSbar(void) { ghwndSbar = CreateWindow(STATUSCLASSNAME, NULL, WS_CHILD | SBARS_SIZEGRIP, 0, 0, 0, 0, ghwndMain, (HMENU) IDW_SBAR, ghInst, NULL); &nbsp;return (ghwndSbar != NULL); } &nbsp; //**************************************************************************** // // VOID UpdateStatusBar(LPTSTR lpsz, WORD wPart, WORD wFlags) // // Update the text for part of the status bar // //**************************************************************************** &nbsp;VOID UpdateStatusBar(LPTSTR lpsz, WORD wPart, WORD wFlags) { &nbsp; &nbsp; SendMessage(ghwndSbar, SB_SETTEXT, wPart | wFlags, (LPARAM) lpsz); } &nbsp; //**************************************************************************** // // VOID StatusMsg(LPTSTR sz) // //**************************************************************************** &nbsp;VOID StatusMsg(LPTSTR sz) { UpdateStatusBar(sz, IDSBP_MSG, 0); } &nbsp; //**************************************************************************** // // VOID UpdateStatusIcon(DWORD dwId) // //**************************************************************************** &nbsp;VOID UpdateStatusIcon(DWORD dwId) { static DWORD m_idIconStatus = 0; static HICON m_hIconStatus = 0; &nbsp;if (dwId == m_idIconStatus) return; &nbsp;HICON hIcon = (HICON) LoadImage(ghInst, MAKEINTRESOURCE(dwId), IMAGE_ICON, STATUSICONSIZE, STATUSICONSIZE, LR_DEFAULTCOLOR | LR_SHARED); if (NULL == hIcon) { return; } &nbsp;m_idIconStatus = dwId; m_hIconStatus = hIcon; SendMessage(ghwndSbar, SB_SETTEXT, &nbsp;IDSBP_ICON | SBT_OWNERDRAW, (LPARAM) m_hIconStatus); } &nbsp; //**************************************************************************** // // LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) // // Change the status bar text to display the menu help. // //**************************************************************************** &nbsp;LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam) { TCHAR &nbsp;szBuffer[MAX_PATH]; UINT &nbsp; nStringID = 0; UINT &nbsp; fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) &amp; 0xffff; UINT &nbsp; uCmd &nbsp; &nbsp;= GET_WM_MENUSELECT_CMD(wparam, lparam); HMENU &nbsp;hMenu &nbsp; = GET_WM_MENUSELECT_HMENU(wparam, lparam); &nbsp;szBuffer[0] = 0; nStringID = 0; &nbsp;if (fuFlags == 0xffff &amp;&amp; hMenu == NULL) &nbsp; &nbsp; // Menu has been closed { return 0; //nStringID = IDS_DESCRIPTION; } else if (fuFlags &amp; MFT_SEPARATOR) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Ignore separators { nStringID = 0; } else if (fuFlags &amp; MF_POPUP) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Popup menu { if (fuFlags &amp; MF_SYSMENU) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // System menu nStringID = IDS_SYSMENU; } else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Must be a command item { nStringID = uCmd; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // String ID == Command ID } &nbsp;// Load the string if we have an ID if (nStringID != 0) { LoadString(ghInst, nStringID, szBuffer, CCHMAX(szBuffer)); } &nbsp;// Finally... send the string to the status bar UpdateStatusBar(szBuffer, IDSBP_MSG, 0); &nbsp;return 0; } &nbsp;<br>&nbsp;<br>祝好运!!!!<br>
 
顶部