Click to See Complete Forum and Search --> : Menu with icons - Is it possible in poor Win32Api?


haiaw
September 9th, 2003, 07:49 PM
Hi,
I would like to have a menu with attached bitmaps next to menu items, on their left side (like in MSWORD - this blank page next to "new"), 16x16 at least, is there any possibility to do that?
Ofcourse i've tried to use SetMenuItemBitmaps( hMenu, ID_EDYCJA_ZAPISZDANE, MF_BYCOMMAND, hBitmap , hBitmap2);
but my 16x16 bitmaps don't fit to the place of Checked, Unchecked Style, there is too little space for them, and making 16x16 bitmap even smaller - nonsens - who will see it? So
Is there any good way to do that? And it's very important -> I use VC++6, It's clear Win32Application standard, without any MFC etc.
I the only way is to create ownerdraw menu, have anybody got some example?







By the way, i wonder what it would be , if the internationale language weren't english but polish, and microsoft were polish...
So many peoply all over the world would write to our forums.... :)

JasonD
September 9th, 2003, 08:22 PM
Since MFC is just wrapper classes around the Win32 API, it has to be possible from the Win32 API. In other words, the Win32 API is the lowest level, and MFC is a higher level built on top. If anything, MFC has less functionality as a result, just as you can do more in ASM than you can in BASIC (note that I am not talking about ease of coding). Although, whether the solution to your problem is directly supported by the Win32 API (via a single function call), or was coded themselves (ever notice how some of MS's software's menus are very slow at times? It is as if they are not standard menus available from the Win32 API) - that is another question to which I do not know the answer.

usman999_1
September 10th, 2003, 07:16 AM
I am not sure if without ownerdraw if you can display icons/bitmaps beside the normal text in menus. Theres ons API that you can try though SetMenuItemBitmaps(...) .
Hope this helps,
Regards,
Usman.

haiaw
September 10th, 2003, 09:01 AM
Hey, i would like to thank u 4 u replies and thank in advance if u answer my next wuestions. Don't smile, i am a quite begginer, and only such foreign forums can help me.
So my application is at: www.toya.net.pl/~gruapie2/Baza.rar - very simple one, only simple menu, toolbar and tooltip (tooltip doesn't work, why?) all in vc++ win32api
and one of u said that win32api is some kind of root of mfc, as i understood, is there any example of ownerdraw menu but in poor win32api? somebody must have ask 4 it before, but i can't find any examples on net. Thanks in advance

usman999_1
September 10th, 2003, 12:12 PM
Well the way owner draw goes for Menu is you specifiy MFT_OWNERDRAW when you create the menu-item. You then have to handle two messages for every-item that you marked as Owner Drawn.

WM_MEASUREITEM -> In that handler you tell the Windows how big you want your menu-item to be i.e. the width & height.
WM_DRAWITEM -> In the handler for this message you draw your menu-item, with bitmaps/icons with whatever text you want.

Actually owner draw is not very easy, you might well get some problems but you can always post them here, i am sure someone will be able to guide you.
Hope this Helps,
Regards,
Usman.

haiaw
September 10th, 2003, 12:44 PM
Thanks, and here is what i've found:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Menus/MenuReference/MenuFunctions/GetMenuItemInfo.asp
code is just over "Using Custom Check Mark Bitmaps" and it seems to me, that there is a need to create a simpple window of my app first, register WNDCLASS.
But even before that i have errors:

C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(62) : error C2065: 'MIIM_STRING' : undeclared identifier
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(75) : error C2065: 'CreateMenuItemFont' : undeclared identifier
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(75) : error C2440: '=' : cannot convert from 'int' to 'struct HFONT__ *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(80) : error C2065: 'MIIM_FTYPE' : undeclared identifier
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(89) : error C2373: 'CreateMenuItemFont' : redefinition; different type modifiers
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(95) : error C2065: 'StringCchCopy' : undeclared identifier
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(153) : error C2440: 'initializing' : cannot convert from 'void *' to 'struct HFONT__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(198) : error C2440: '=' : cannot convert from 'void *' to 'struct HFONT__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

What can i do with that?
Thanks in advance
And what about others? What do u use to create such menus?
In vc++6 ? Do u create mfc projects? Which way to create such menus do u like best? If u tell me, i'll buy some new books, and drop poor win32app so as to create menus, toolbars, tooltips cotrols etc. in the most convienient way (i suppose that poor win32api is harder and people prefer other projects?)

usman999_1
September 10th, 2003, 01:05 PM
Well for the MIIM_STRING it is define in Winuser.h as

#if(WINVER >= 0x0500)
#define MIIM_STRING 0x00000040
#define MIIM_BITMAP 0x00000080
#define MIIM_FTYPE 0x00000100


So you have to define WINVER at the begining of your program #define WINVER = 0x0500 But i would prefre not to do it. Accoding to MSDN this MIIM_STRING is only supported on Win2k and above, so its no use on lower OSes.
And the second problem 'CreateMenuItemFont' : undeclared identifier... seems to be that you are using/calling that function before declaring it. You can either place a declaration of it like


int foo (void); // function declared, so now the complier knows about it...

void main (void)
{
int nRet = foo (); // No Error,because delacred earlier/above....
}

int foo() // function definition....
{
return 1;
}



OR


int foo() // function definition....
{
return 1;
}

void main (void)
{
int nRet = foo (); // No Error,because defined earlier/above....
}

So it seems that that you have forgot to place your function declaration before using the function. So just declare that function and u'll be fine.
Hope this helps,
Regards,
Usman.

haiaw
September 10th, 2003, 01:52 PM
Great :))) msdn was my last chance.... Have anybody done such menu in poor win32api ? A thank for your code !!!! I'll see if it works :)
Sorry #define WINVER = 0x0500
throws error
c:\program files\microsoft visual studio\vc98\include\windows.h(24) : fatal error C1017: invalid integer constant expression

in line #if defined(_WIN32_WINNT) && (WINVER < 0x0400) && (_WIN32_WINNT > 0x0400)

WAIT: i wrote #define WINVER 0x0500 and some errors disappeared now they r

ling...
Main.cpp
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(42) : error C2065: 'StringCchCopy' : undeclared identifier
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(154) : error C2440: 'initializing' : cannot convert from 'void *' to 'struct HFONT__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Documents and Settings\Manager\Pulpit\TestMEnu\Main.cpp(199) : error C2440: '=' : cannot convert from 'void *' to 'struct HFONT__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

usman999_1
September 11th, 2003, 05:09 AM
Yep sorry that was a mistake with the define WINVER macro.
As for your other Error what is StringCchCopy ??? where is it defined??? there isnt any function by that name either in MFC or WIN32 API???? Is it a function or a var??? It too seem to be the same case that you are using the function before declaring it. You have to either define or declare those functions. It applies to all not just one function wether it is MFC function or WIN32 or your own ;).
Regards,
Usman.

haiaw
September 11th, 2003, 06:12 AM
All this code is from MSDN. They claim that this is working example of ownerdraw menu. I don't know what they mean by these functions which throw error iny my vc++
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Menus/MenuReference/MenuFunctions/GetMenuItemInfo.asp

And by the way i have another question connected with the toolbar. I have working toolbar, but the pictures can have only up to 256 colors, is there any possibility to put there better ones?

usman999_1
September 11th, 2003, 06:56 AM
Well yes MSDN has a smaple but you too have to do something to make those things work. As I have told you whenever you get this undefined error (for a function or var) that means that the compiler that point (where the error occured) havn't yet found a declaration or definition of function or var. Kepp that thing in mind and look at you code again and check at every undefined error can you find a either a function/var definition/ declaration if not then you have to define/declare it. Thats the only thing you have to do make that sample work.
Secondly I never tried OwenerDraw ToolBar (although I have done an ownerdrawn popup menu) i think if you Ownerdraw a control you can display whatever you want. So with ownerdraw its upto u how you paint on the device dc.
Hope this helps,
Regards,
Usman.

haiaw
September 11th, 2003, 10:20 AM
ofcourse, that helped me. Now it at least compiles. But i don't fully understand - This MSDN example (for me) changes standard menu , which i have to ownerdraw menu? - Because it takes a handler GetMenu(hwnd) and uses it, so there shuld be a menu created earlier. So i did one through this wizard in vc++6 win32pplication->Simple Project. Just by inserting resource -> menu->new i reached nothing....
I load my menu through LoadMenu(...) and then i use this functions from msnd. Nothing changes with my menu, or maybe it shouldn;t change? Thanks in advance

NOTE: I deleted 3 lines wchich threw errors, these r not as much important 4 me, that they could be a reason of my problem .
PLEASE, if somebody could take a look - it's very simple project, i just can't handle with it. I read whole article in msdn.
www.toya.net.pl/~grupaie2/TestMEnu.rar

THAANKU
Oher questions r: I there is some way to convert code from mfc to pure win32api so as to be uderstandable 4 me?
And how could i change the color of my standard listbox, again ownerdraw?