PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

CommandBar question.

Is it possible to align a commandbar at the bottom (instead of the top) of the screen where the input icon is?

The reason I want to do this is because, right now I am using a CommandBar for my menubar and it shows at the top. There is still an empty bar at the bottom of the screen with the input (keyboard) icon and would like to use this space to save some for the main window.

Regards,
Kornalius
Interesting, my command bars are always (by default it seems) on the bottom of the screen. What are you doing thats different?


JJB
Oh yeah? Strange! Here is my code to create the menu bar:

Code:
HWND m = CommandBar_Create(Instance, h, Id);
CommandBar_InsertMenubarEx(m, NULL, (LPTSTR)menu, 0);


It always appear at the top. But right after I create my Window, I do this to initialize the bottom bar, since I need to keep this bar.

Code:


HWND CreateEmptyRpCommandBar(HWND hwnd)
{
SHMENUBARINFO mbi;

memset(&mbi;, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.dwFlags = SHCMBF_EMPTYBAR;
mbi.hwndParent = hwnd;
mbi.nToolBarId = 0;
mbi.hInstRes = Instance;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;

if (!SHCreateMenuBar(&mbi;))
return NULL;

return mbi.hwndMB;
}


void CreateMenuBar ()
{
HWND m = CreateEmptyRpCommandBar(h);

RECT rc;
RECT rcMenuBar;

GetWindowRect(h, &rc;);
GetWindowRect(m, &rcMenuBar;);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);

MoveWindow(h, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, false);

ShowWindow(h, SW_SHOW);
UpdateWindow(h);
}


Regards,
Kornalius
Code:

HWND m = CommandBar_Create(Instance, h, Id);
CommandBar_InsertMenubarEx(m, NULL, (LPTSTR)menu, 0);


Why are you doing this if you don't want it there to begin with? Why not just use SHCreateMenuBar to initialize an empty one, as you are doing, at the bottom. Seems to work for me. And then, when your window is created, create the menubar sometime or in WM_CREATE with your CreateMenuBar function.



JJB
I tried that but it doesn't work with the CommandBar_InsertMenubarEx. It always returns false. How can I add menus dynamicly then to the bottom bar.

Regards,
Kornalius
Aren't commandbars on top in WinCE 2.11? I remember running into a similar thing while playing with eVB.
Yes, and if you run a CE 2.11 PSPC app on Pocket PC it will move the command bar up to the top for compatibility.

Dan East
Well I use eVc 4 and an ASUS A620 with WCE2003. My problem is that I would like to use the SHCreateMenuBar and then add menus to it dynamicaly. And I cannot do it. I tried many things and nothing works. If I load the menubar from resource it works, but not if I want to use AppendMenu or something like that. Can somebody give me the steps and the right functions to do this?

This thing as been driving me nuts for a while now, I put it aside for some time but now that PPL is about to be released in beta, I really need to get this to work. You guys are pretty much my only source of information on programming the PPC.

Regards,
Kornalius
Anyone?
Here is what I am doing right now:

Code:
SHMENUBARINFO mbi;

memset(&mbi;, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.dwFlags = SHCMBF_EMPTYBAR;
mbi.hwndParent = hwnd;
mbi.nToolBarId = 0;
mbi.hInstRes = 0;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
#ifdef SHCMBF_COLORBK
mbi.clrBk = 0 ; // PocketPC2002 only
#endif

SHCreateMenuBar(&mbi;);
HWND b = mbi.hwndMB;

#define SHGetMenu(hWndMB) (HMENU)SendMessage((hWndMB), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);

HMENU newmenu = CreatePopupMenu();
HMENU menu = SHGetMenu(b);

AppendMenu(menu, MF_STRING | MF_ENABLED | MF_POPUP, 400, L"&File;");
AppendMenu(menu, MF_STRING | MF_ENABLED | MF_POPUP, 500, L"&Edit;");

CommandBar_DrawMenuBar(b);


SHGetMenu return a NULL. :cry:

Now here something else I tried (found this snippet on the internet 8) ):

Code:
void AddMenuItem(HWND bar, int iFlags, UINT iId, UINT iValue, LPTSTR sText)
{

int iLength ; // Real length of the menu item string
TBBUTTON rButton ; // Menu item "button" on the menu bar
wchar_t *lpBuffer ; // Pointer to buffer for text of menu items
int iIndex ;

iLength = wcslen(sText) ;

lpBuffer = (wchar_t *)malloc((iLength + 2) * sizeof(wchar_t)) ;
wcscpy(lpBuffer, sText) ; // Copy the string to the buffer
lpBuffer[iLength+1] = 0;

if ((iIndex = SendMessage(bar, TB_ADDSTRING, 0, (LPARAM) lpBuffer)) == -1) { // Add one string
MessageBox(GetForegroundWindow(), lpBuffer, L"Could not add menu string", MB_OK | MB_ICONHAND) ;
}

free(lpBuffer) ;

// Now add a toolbar button containing the string

rButton.iBitmap = I_IMAGENONE ; // No bitmap
rButton.idCommand = iId ; // ID for WM_COMMAND
rButton.fsState = TBSTATE_ENABLED ; // Enabled button, text
rButton.fsStyle = iFlags | TBSTYLE_AUTOSIZE ; // Autosize the button, flags indicate dropdown
rButton.dwData = iValue ; // Handle to dropdown menu
rButton.iString = iIndex ; // Use this string for text

CommandBar_AddButtons(bar, 1, &rButton;);
}

SHMENUBARINFO mbi;

memset(&mbi;, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.dwFlags = SHCMBF_EMPTYBAR;
mbi.hwndParent = hwnd;
mbi.nToolBarId = 0;
mbi.hInstRes = 0;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
#ifdef SHCMBF_COLORBK
mbi.clrBk = 0 ; // PocketPC2002 only
#endif

SHCreateMenuBar(&mbi;);
HWND b = mbi.hwndMB;

#define SHGetMenu(hWndMB) (HMENU)SendMessage((hWndMB), SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);

#define TBSTYLE_NO_DROPDOWN_ARROW 0x0080

HMENU newmenu = CreatePopupMenu();
AddMenuItem(b, TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW, 400, (UINT)newmenu, L"&File;");

HMENU newmenu = CreatePopupMenu();
AddMenuItem(b, TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW, 500, (UINT)newmenu, L"&Edit;");

CommandBar_DrawMenuBar(b);


Here, CommandBar_AddButtons(bar, 1, &rButton;); doesn't work either. :cry:

I would really like some help if anybody can. This is a crucial part for my project.

The funny thing is that if I specify a resource ID for my SHCreateMenuBar instead of an emptybar, it works.


Regards,
Kornalius
Ok, I finally figured out a way to add menus dynamicaly to the menu bar (SHCreateMenuBar). It's a trick. You cannot create an EMPTYBAR with SHCreateMenuBar, it won't let you add anything to it after. You have to include a resource ID. What I did is, create a menubar resource with only one HIDDEN menu. Then you can AppendMenu from SHGetMenu without any problems.

I hope this will help so that person is not going to have to go through what I have been through. :D

Regards,
Kornalius.

Btw, thanx all for your help (they sorted lead me to the right solution after all) even if I couldn't get much answers. :wink: