📄 pcdmcommander.cpp
字号:
// PCDMCommander.cpp : Implementation of CPCDMCommander
#include "stdafx.h"
#include "PCDMUI.h"
#include "PCDMCommander.h"
/////////////////////////////////////////////////////////////////////////////
// CPCDMCommander
// <BOOK_ADDON Step2: Chapter 7.1.2> ***************************************
STDMETHODIMP CPCDMCommander::CreateBar(int ID,int Styles)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#ifdef UNDER_CE
// <BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (LOWORD(m_CePlatform)==CEP_PALMPCV3)
{
if (m_hwndCB!=NULL) return S_OK;
typedef BOOL (*SHCREATEMENUBARPROC)(SHMENUBARINFO *pvParam);
SHCREATEMENUBARPROC g_hSHCreateMenuBar=NULL;
SHMENUBARINFO mbi;
HINSTANCE hAygDll;
hAygDll = LoadLibrary(TEXT("aygshell.dll"));
if (hAygDll)
{
g_hSHCreateMenuBar =(SHCREATEMENUBARPROC)
GetProcAddress(hAygDll, TEXT("SHCreateMenuBar"));
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = m_hWnd;
mbi.dwFlags = 0;
mbi.nToolBarId = IDR_MAIN_MENU;
mbi.hInstRes = _Module.m_hInst;
mbi.nBmpId = IDR_TOOLBAR;
mbi.cBmpImages = 17;
(*g_hSHCreateMenuBar)(&mbi);
m_hwndCB=mbi.hwndMB;
}
else
{ return S_FALSE; }
return S_OK;
}
// </BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (m_CmdBarType==CMDBAR) // <BOOK_ADDON Step3: Chapter 7.2.2/> *******
{
if (m_IDBAR==0)
{
m_hwndCB = CommandBar_Create(_Module.m_hInst, m_hWnd, ID);
CommandBar_AddBitmap(m_hwndCB, _Module.m_hInst,
IDR_TOOLBAR, 17, 16, 16);
m_IDBAR=ID;
m_bIsFresh=FALSE;
}
// <BOOK_ADDON Step3: Chapter 7.2.2> ***************************************
}
else
{
if (m_BandCreated==FALSE)
{
HBITMAP hBmp;
int i;
// Create an Image List for the icons of
// the Bars when they get minimized
m_hImLst=ImageList_Create(16,16,ILC_COLOR,17,0);
hBmp=LoadBitmap(_Module.m_hInst,MAKEINTRESOURCE(IDR_TOOLBAR));
ImageList_Add(m_hImLst,hBmp,NULL);
DeleteObject(hBmp);
m_hwndCBand=CommandBands_Create(_Module.m_hInst,
m_hWnd,4711,RBS_SMARTLABELS|RBS_VARHEIGHT|RBS_AUTOSIZE,
m_hImLst);
if (m_hwndCBand==NULL)
return S_FALSE;
m_BandCreated=TRUE;
// Initialize the REBARBANDINFO structure
memset(m_trbi,0,sizeof(REBARINFO)*MAXBANDS);
for (i = 0; i < MAXBANDS; i++)
{
m_trbi[i].cbSize = sizeof (REBARBANDINFO);
m_trbi[i].fMask = RBBIM_SIZE;
m_trbi[i].cx = 100;
}
}
else
{
m_CurrentBar++;
}
// Set the attributes of the new Bar
m_trbi[m_CurrentBar].fMask |= RBBIM_ID | RBBIM_STYLE | RBBIM_ID;
m_trbi[m_CurrentBar].wID = ID;
if (Styles==0) // Set NoGripper and Fixed BMP as default values
Styles=RBBS_NOGRIPPER + RBBS_FIXEDBMP;
m_trbi[m_CurrentBar].fStyle = Styles;
CommandBands_AddBands (m_hwndCBand, _Module.m_hInst, 1,
&m_trbi[m_CurrentBar]);
UINT idx=SendMessage(m_hwndCBand,RB_IDTOINDEX,(WPARAM)(UINT)ID,0);
m_hwndCB = CommandBands_GetCommandBar (m_hwndCBand, idx);
CommandBar_AddBitmap(m_hwndCB, _Module.m_hInst,IDR_TOOLBAR, 17, 16, 16);
}
// </BOOK_ADDON Step3: Chapter 7.2.2> ***************************************
#else // Code for Desktop here
#endif
return S_OK;
}
STDMETHODIMP CPCDMCommander::InsertMenu(BSTR MenuName, int Index)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// <BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (LOWORD(m_CePlatform)==CEP_PALMPCV3)
{
TBBUTTONINFO tbbi;
tbbi.cbSize = sizeof(tbbi);
tbbi.dwMask = TBIF_LPARAM;
SendMessage(m_hwndCB,
TB_GETBUTTONINFO,
ID_FILE,
(LPARAM)&tbbi);
m_MyPopup[Index]= (HMENU)tbbi.lParam;
DeleteMenu(m_MyPopup[Index],12345,MF_BYCOMMAND);
m_iMaxButtons[m_CurrentBar]=1;
return S_OK;
}
// </BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (Index<MAXMENUS && m_MyPopup[Index]==NULL)
{
if (m_MyMenu==NULL)
{
m_MyMenu=CreateMenu();
#ifdef UNDER_CE
if (m_hwndCB!=NULL)
{
CommandBar_InsertMenubarEx(m_hwndCB, NULL,
(LPTSTR)m_MyMenu, Index);
SortToolTips(Index);
}
#else // Code for Desktop here
::SetMenu(m_hWnd,m_MyMenu);
#endif
}
m_MyPopup[Index]=CreatePopupMenu();
AppendMenu(m_MyMenu,MF_STRING|MF_POPUP,
(UINT)m_MyPopup[Index],MenuName);
}
return S_OK;
}
void CPCDMCommander::SortToolTips(int index)
{
int i;
for (i=MAXBUTTONS-1;i>index;i--)
m_szTTips[m_CurrentBar][i]=m_szTTips[m_CurrentBar][i-1];
if (m_iMaxButtons[m_CurrentBar]<MAXBUTTONS) m_iMaxButtons[m_CurrentBar]++;
#ifdef UNDER_CE
if (m_hwndCB!=NULL)
CommandBar_AddToolTips(m_hwndCB,
MAXBUTTONS,m_szTTips[m_CurrentBar]);
#else // Code for Desktop here
#endif
}
STDMETHODIMP CPCDMCommander::InsertMenuItem(BSTR ItemName, int MenuNo, int Index, int ID)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
if (MenuNo<MAXMENUS)
{
if (ID==0)
::InsertMenu(m_MyPopup[MenuNo],Index,
MF_BYPOSITION|MF_SEPARATOR,NULL,NULL);
else
::InsertMenu(m_MyPopup[MenuNo],Index,
MF_BYPOSITION|MF_STRING|MF_ENABLED,ID,ItemName);
}
return S_OK;
}
STDMETHODIMP CPCDMCommander::InsertButton(int StockNo, int state, int Index, int ID, BSTR ToolTipText)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
TBBUTTON lpButtons;
lpButtons.idCommand=ID;
lpButtons.fsState=state;
if (ID==0) // If ID is 0 a Separation Space is created
{
lpButtons.iBitmap=0;
lpButtons.fsStyle=TBSTYLE_SEP;
}
else
{
lpButtons.iBitmap=StockNo;
lpButtons.fsStyle=TBSTYLE_BUTTON;
}
lpButtons.iString=0;
#ifdef UNDER_CE
if (m_hwndCB!=NULL)
{
CommandBar_InsertButton(m_hwndCB,Index,
(LPTBBUTTON)&lpButtons);
if (Index<MAXBUTTONS)
{
// <BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (LOWORD(m_CePlatform)==CEP_PALMPCV3)
{
if (ID!=0)
{
m_szTTips[m_CurrentBar][m_iMaxButtons[m_CurrentBar]]=(LPTSTR)LocalAlloc(LMEM_ZEROINIT,
sizeof(TCHAR)*(lstrlen(ToolTipText)+2));
wsprintf(m_szTTips[m_CurrentBar][m_iMaxButtons[m_CurrentBar]],ToolTipText);
m_iMaxButtons[m_CurrentBar]++;
}
}
else
{
// </BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
SortToolTips(Index);
if (ID!=0)
{
m_szTTips[m_CurrentBar][Index]=(LPTSTR)LocalAlloc(LMEM_ZEROINIT,
sizeof(TCHAR)*(lstrlen(ToolTipText)+2));
wsprintf(m_szTTips[m_CurrentBar][Index],ToolTipText);
if (Index>m_iMaxButtons[m_CurrentBar]) m_iMaxButtons[m_CurrentBar]=Index;
}
} // <BOOK_ADDON Step4: Chapter 7.3.2/> ***************
CommandBar_AddToolTips(m_hwndCB,
m_iMaxButtons[m_CurrentBar]+1,m_szTTips[m_CurrentBar]);
}
}
#else // Code for Desktop here
#endif
return S_OK;
}
STDMETHODIMP CPCDMCommander::InsertComboBox(int Size, int Index, int ID)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#ifdef UNDER_CE
// <BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (LOWORD(m_CePlatform)==CEP_PALMPCV3) return S_OK;
// </BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (m_hwndCB!=NULL)
{
m_ComboStuff.handle[m_ComboStuff.curCnt].ID=ID;
m_ComboStuff.handle[m_ComboStuff.curCnt].hWnd=
CommandBar_InsertComboBox(m_hwndCB,
_Module.m_hInst,Size,NULL,ID,Index);
SortToolTips(Index);
m_ComboStuff.curCnt++;
}
#else // Code for Desktop here
#endif
return S_OK;
}
STDMETHODIMP CPCDMCommander::AddStringToComboBox(int ID, BSTR text)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// <BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (LOWORD(m_CePlatform)==CEP_PALMPCV3) return S_OK;
// </BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
int tCombo=-1;
for (int i=0;i<m_ComboStuff.curCnt;i++)
{
if (ID==(int)m_ComboStuff.handle[i].ID)
{
tCombo=i;
break;
}
}
if (tCombo>=0)
{
if (lstrcmp(text,TEXT("<CLR>"))==0)
SendMessage(m_ComboStuff.handle[i].hWnd,
CB_RESETCONTENT,0,0);
else
SendMessage(m_ComboStuff.handle[i].hWnd,
CB_ADDSTRING,0,(LPARAM)(LPCSTR)text);
}
return S_OK;
}
STDMETHODIMP CPCDMCommander::SetAdornments(int Flags)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
#ifdef UNDER_CE
// <BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (LOWORD(m_CePlatform)==CEP_PALMPCV3) return S_OK;
// </BOOK_ADDON Step4: Chapter 7.3.2> ***************************************
if (m_CmdBarType==CMDBAR)
{
if (m_hwndCB!=NULL)
CommandBar_AddAdornments(m_hwndCB, Flags,0);
}
// <BOOK_ADDON Step3: Chapter 7.2.2> ***************************************
else
{
if (m_hwndCBand!=NULL)
CommandBands_AddAdornments(m_hwndCBand,
_Module.m_hInst,Flags,NULL);
}
// </BOOK_ADDON Step3: Chapter 7.2.2> ***************************************
#else // Code for Desktop here
#endif
return S_OK;
}
////////////////// EVENT HANDLER *********************************
LRESULT CPCDMCommander::OnCommand(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled)
{
if (HIWORD(wParam)!=0) // Caught the Combo-Box
{
int tCombo=-1,u;
for (int i=0;i<m_ComboStuff.curCnt;i++)
{
if ((HWND)lParam==m_ComboStuff.handle[i].hWnd)
{
tCombo=i;
break;
}
}
if (tCombo>=0)
{
switch (HIWORD(wParam))
{
case 5:
SendMessage((HWND)lParam,
WM_GETTEXT,(WPARAM)255,
(LPARAM)m_ComboStuff.handle[tCombo].Text);
Fire_CmdBarAction(LOWORD(wParam),
m_ComboStuff.handle[tCombo].Text);
break;
case 1:
u=SendMessage((HWND)lParam,CB_GETCURSEL,0,0);
SendMessage((HWND)lParam,CB_GETLBTEXT,
(WPARAM)u,(LPARAM)m_ComboStuff.handle[tCombo].Text);
Fire_CmdBarAction(LOWORD(wParam),m_ComboStuff.handle[tCombo].Text);
break;
default:
break;
}
}
}
else
{
Fire_CmdBarAction(wParam,TEXT(""));
}
return S_OK;
}
LRESULT CPCDMCommander::OnClose(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled)
{
Fire_CmdBarAction(IDCLOSE,TEXT(""));
return S_OK;
}
LRESULT CPCDMCommander::OnDestroy(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled)
{
int i;
for (i=0;i<MAXBUTTONS;i++)
if (!m_szTTips[m_CurrentBar][i])
LocalFree(m_szTTips[m_CurrentBar][i]);
return S_OK;
}
LRESULT CPCDMCommander::NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
if (idCtrl==m_IDBAR && m_bIsFresh==FALSE)
{
FireViewChange();
m_bIsFresh=TRUE;
}
return S_OK;
}
// </BOOK_ADDON Step2: Chapter 7.1.2> ***************************************
// <BOOK_ADDON Step2: Chapter 7.2.2> ***************************************
STDMETHODIMP CPCDMCommander::SetCmdBarType(int type)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
if (type!=0)
m_CmdBarType=CMDBAND;
else
m_CmdBarType=CMDBAR;
return S_OK;
}
// </BOOK_ADDON Step2: Chapter 7.1.2> ***************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -