Menu

#71 WCE useful commandbar

closed
nobody
5
2007-07-22
2007-07-03
Anonymous
No

Hi,

I am a windows ce developper and I had a look at code commandbar.
From what I saw the code is pretty useless and cannot be used for complex UI.
First from WM5 and when aygshell is available the preferred way of creating commandbar is SHCreatemenuBar.
MFC is a good resource to implement a useful CCommandBar.

I would like to be able to do something like like with MFC:

if(!m_wndCommandBar.Create(this->m_hWnd) || !m_wndCommandBar.InsertMenuBar(IDR_MAINFRAME) ||!m_wndCommandBar.AddAdornments() ||!m_wndCommandBar.LoadToolBar(IDR_MAINFRAME)||
!m_wndCommandBar.SendMessage(TB_SETTOOLTIPS, (WPARAM)(6), (LPARAM)(&m_ToolTipsTable[1])))
{
ATLTRACE2( _T("Failed to create CommandBar\n") );
return -1; // fail to create
}

I have started to modify the class :

HWND Create(HWND hWndParent, int nCmdBarID = 13)
{
#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
m_hWnd = AtlCreateEmptyMenuBar(hWndParent);
#else
m_hWnd = ::CommandBar_Create(ModuleHelper::GetModuleInstance(), hWndParent, nCmdBarID);
#endif
ATLASSERT(::IsWindow(m_hWnd));

return m_hWnd;
}

BOOL AddAdornments(DWORD dwFlags = 0)
{
ATLASSERT(::IsWindow(m_hWnd));

#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
return TRUE;
#else
return ::CommandBar_AddAdornments(m_hWnd, dwFlags, 0);
#endif
}

BOOL InsertMenubar(WORD wMenuID, WORD wButton = (WORD)-1)
{
ATLASSERT(::IsWindow(m_hWnd));

#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
return InsertMenubarEx(wMenuID, wButton);
#else
return ::CommandBar_InsertMenubar(m_hWnd, ModuleHelper::GetResourceInstance(), wMenuID, wButton);
#endif
}

BOOL InsertMenubarEx(ATL::_U_STRINGorID menu, WORD wButton = (WORD)-1)
{
ATLASSERT(::IsWindow(m_hWnd));

#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)

HWND hParent = GetParent();
ASSERT(hParent != NULL);
DestroyWindow();

HINSTANCE hInstance = ModuleHelper::GetResourceInstance();
ASSERT(hInstance != NULL);

SHMENUBARINFO mbi;
ZeroMemory(&mbi, sizeof(SHMENUBARINFO));

mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hParent;
mbi.nToolBarId = (UINT)menu.m_lpstr;
mbi.hInstRes = hInstance;

HRSRC hRsrc = NULL;
if ((hRsrc = ::FindResource(hInstance, (LPCTSTR)menu.m_lpstr, RT_RCDATA)) == NULL)
{
mbi.dwFlags |= SHCMBF_HMENU;
}

return ((BOOL) (WTL::AtlCreateMenuBar(mbi) != NULL) );

#else
return ::CommandBar_InsertMenubarEx(m_hWnd, ModuleHelper::GetResourceInstance(), (LPTSTR)menu.m_lpstr, wButton);
#endif
}

#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC MenuBar
typedef CCECommandBarCtrlT<CToolBarCtrl> CCECommandBarCtrl;
#else
typedef CCECommandBarCtrlT<CToolBarCtrl> CCECommandBarCtrl;
#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)

struct CToolBarData
{
WORD wVersion;
WORD wWidth;
WORD wHeight;
WORD wItemCount;

WORD* items()
{ return (WORD*)(this+1); }
};

BOOL LoadToolBar(ATL::_U_STRINGorID menu)
{
// determine location of the bitmap in resource fork
/*AfxFindResourceHandle(lpszResourceName, RT_TOOLBAR)*/

HINSTANCE hInst = ModuleHelper::GetResourceInstance();
HRSRC hRsrc = ::FindResource(hInst, menu.m_lpstr, RT_TOOLBAR);
if (hRsrc == NULL)
return FALSE;

HGLOBAL hGlobal = LoadResource(hInst, hRsrc);
if (hGlobal == NULL)
return FALSE;

CToolBarData* pData = (CToolBarData*)LockResource(hGlobal);
if (pData == NULL)
return FALSE;
ASSERT(pData->wVersion == 1);

UINT* pItems = new UINT[pData->wItemCount];
for (int i = 0; i < pData->wItemCount; i++)
pItems[i] = pData->items()[i];
BOOL bResult = SetButtons(pItems, pData->wItemCount);
delete[] pItems;

if (bResult)
{
// set new sizes of the buttons
CSize sizeImage(pData->wWidth, pData->wHeight);
CSize sizeButton(pData->wWidth + 7, pData->wHeight + 7);
SetSizes(sizeButton, sizeImage);

// load bitmap now that sizes are known by the toolbar control
bResult = LoadBitmap((UINT)menu.m_lpstr);
}

UnlockResource(hGlobal);
FreeResource(hGlobal);

return bResult;
}

// Still need to port ...
void CToolBar::SetSizes(SIZE sizeButton, SIZE sizeImage)
{
ASSERT_VALID(this);

// sizes must be non-zero and positive
ASSERT(sizeButton.cx > 0 && sizeButton.cy > 0);
ASSERT(sizeImage.cx > 0 && sizeImage.cy > 0);

// button must be big enough to hold image
// + 7 pixels on x
// + 6 pixels on y
ASSERT(sizeButton.cx >= sizeImage.cx + 7);
ASSERT(sizeButton.cy >= sizeImage.cy + 6);

if (::IsWindow(m_hWnd))
{
// set the sizes via TB_SETBITMAPSIZE and TB_SETBUTTONSIZE
VERIFY(SendMessage(TB_SETBITMAPSIZE, 0, MAKELONG(sizeImage.cx, sizeImage.cy)));
#ifdef _WIN32_WCE
int aygshellUIModel = AfxGetAygshellUIModel();
if (aygshellUIModel != PocketPC && aygshellUIModel != Smartphone)
#endif // _WIN32_WCE
{
VERIFY(SendMessage(TB_SETBUTTONSIZE, 0, MAKELONG(sizeButton.cx, sizeButton.cy)));
#ifndef _WIN32_WCE
if (_afxComCtlVersion >= VERSION_6)
{
DWORD dwSize = (DWORD)SendMessage(TB_GETBUTTONSIZE, 0, 0);
m_sizeButton.cx = LOWORD(dwSize);
m_sizeButton.cy = HIWORD(dwSize);
}
#endif // !_WIN32_WCE
}
#ifdef _WIN32_WCE
if (m_hWndOwner != NULL)
DefWindowProc(TB_SETPARENT, (WPARAM)m_hWndOwner, 0);
DefWindowProc(TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
#endif // _WIN32_WCE
Invalidate(); // just to be nice if called when toolbar is visible
}
else
{
// just set our internal values for later
m_sizeButton = sizeButton;
m_sizeImage = sizeImage;
}
}

Discussion

  • Anonymous

    Anonymous - 2007-07-06
    • status: open --> pending
     
  • Anonymous

    Anonymous - 2007-07-06

    Logged In: YES
    user_id=1041244
    Originator: NO

    Hi,

    The relevant class is CCECommandBarCtrlT<> in atlctrls.h #9846 and next.

    You can use it directly with the typedefed CMenuBarCtrl for Mobile devices and CCECommandBarCtrl for other WinCE devices.

    What problem are you facing?
    cheers,
    AR

     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending --> closed
     

Anonymous
Anonymous

Add attachments
Cancel