Thread: check mark in menu

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    check mark in menu

    hey, i know how to get a menuitem checked to start off with...but how do i add a check next to an item in the menu while the program is running? my brain is failing as i type this, but like in your menu, if you clicked on a property that sets something, such as bold (random example), then it would put a checkmark next to it to indicated its selected / clicked / active / whatever.

    how do i set the check mark when the menuitem it clicked while the program is running? lol thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    ....how bout the CheckMenuItem Function ?

    *slaps forehead*
    but some usage is always nice. anyone have that?


    also - the default font for static controls (created with CreateWindowEx) its like..big and kinda bold. is that changeable? then lastly, if i have a static control (again, created with CreateWindowEx) and i dont add any text when i create it, can i add text when something happens? if so, how? thanks guys.
    Last edited by willc0de4food; 08-03-2005 at 06:57 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  3. #3
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    If you want to add text or modify text of a static control and you don't want to keep it's handle in memory you must give it an id so you can retrieve it with GetDlgItem, send a WM_SETTEXT message to the control. To set the font of a static control send it a WM_SETFONT message and to make it easy you are usually safe using GetStockObject ( DEFAULT_GUI_FONT ) ;

    For menu stuff you can also use InsertMenuItem which is much more flexible, MENUITEMINFO .fState should have MF_CHECKED set. To modify the state and information of a menu item call SetMenuItemInfo.
    Code:
    MENUITEMINFO itemInfo ;
    itemInfo.cbSize = sizeof ( MENUITEMINFO ) ;
    itemInfo.fMask = MIIM_ID | MIIM_STATE | MIIM_STRING | MIIM_FTYPE ;
    itemInfo.fType = MFT_STRING ;
    itemInfo.fState = MF_ENABLED | MF_CHECKED ;
    itemInfo.wID = IDM_MENUITEM1 ;
    itemInfo.dwTypeData = "Item String" ;
    InsertMenuItem (
    					hMenu,
    					0,
    					TRUE,
    					&itemInfo
    				) ;

  4. #4
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm...the menu code, adds "Item String" in the first spot of the menu, so then it jumps in the "File" menu's position and moves everything down. i just want to add a check mark, lol here's the code for my menu:
    Code:
    ID_TEMPCONV_MENU MENU
    BEGIN
         POPUP "&File"
         BEGIN
              MENUITEM "C&lear", ID_FILE_CLEAR
              MENUITEM SEPARATOR
              MENUITEM "&Close", ID_FILE_CLOSE
         END
         POPUP "&Units"
         BEGIN
              POPUP "&Fahrenheit"
              BEGIN
                   MENUITEM "to Cel&sius", ID_UNITS_FTOC
                   MENUITEM "to Kel&vin", ID_UNITS_FTOK
              END
              POPUP "&Celcius"
              BEGIN
                   MENUITEM "to F&ahrenheit", ID_UNITS_CTOF
                   MENUITEM "to Kel&vin", ID_UNITS_CTOK
              END
              POPUP "&Kelvin"
              BEGIN
                   MENUITEM "to F&ahrenheit", ID_UNITS_KTOF
                   MENUITEM "to Cel&sius", ID_UNITS_KTOC
              END
         END
         POPUP "&Help"
         BEGIN
              MENUITEM "&About...", ID_HELP_ABOUT
         END
    END
    i just want to add a check mark to the "to ..." part, but if theres a check mark somewhere else, it has to go away. thanks for the help!
    i'm prly staring at the answer but dont know it..*shrug* any more help? its greatly appreciated thanks


    also - this is the stuff with the fonts i was talking about. the first screeny is of the program i made in VB .Net, the second the program made in C. i would like the C program's fonts to be like those of the program in VB .Net and am hopeing its not very complicated? :-[ thanks^2!
    http://img.photobucket.com/albums/v4...5/vbdotnet.jpg (13.69 kB)
    http://img.photobucket.com/albums/v48/anarchy85/c.jpg (15.88 kB)
    Last edited by willc0de4food; 08-08-2005 at 04:40 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Use CheckMenuItem like so:-
    Code:
    CheckMenuItem(hmenu, ID_UNITS_FTOC, MF_CHECKED);
    Use MF_UNCHECKED to remove check.

    For default GUI font, as in your VB.NET example:-
    Code:
    HFONT hfont;
    
    hfont = GetStockObject(DEFAULT_GUI_FONT);
    // Send this message to each control
    SendMessage(hwnd, WM_SETFONT, 0, (LPARAM)hfont);
    And when you want to change the text displayed by a control:-
    Code:
    SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)"Hello");

  6. #6
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    idk why..but uh, checkmenuitem doesn't check the menu item. lol

    hfont doesn't change the font. maybe i can create one? like 10 pt times new roman (weight) thin ?

    thanks i found that out...along with SendDlgItemMessage()


    also, this code does nothing
    Code:
                  HFONT hfont;
                  int nHeight = 10, nWidth, nEscapement = 0, nOrientation = 0, fnWeight = 100;
                  hfont = CreateFont (
                          nHeight,                 // height of font
                          0,                       // average character width
                          nEscapement,             // angle of escapement
                          nOrientation,            // base-line orientation angle
                          fnWeight,                // font weight
                          FALSE,                   // italic attribute option
                          FALSE,                   // underline attribute option
                          FALSE,                   // strikeout attribute option
                          DEFAULT_CHARSET,         // character set identifier
                          OUT_DEFAULT_PRECIS,      // output precision
                          CLIP_DEFAULT_PRECIS,     // clipping precision
                          DEFAULT_QUALITY,         // output quality
                          DEFAULT_PITCH,           // pitch and family
                          null               // typeface name
                          );
                  // Send this message to each control
                  SendMessage(hwnd, WM_SETFONT, 0, (LPARAM)hfont);
                  DeleteObject(hfont);
    *is clueless*
    Last edited by willc0de4food; 08-08-2005 at 06:29 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  7. #7
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    They should work (I use them all on a regular basis), how are you using CheckMenuItem?

    Try using this:-
    Code:
    CheckMenuItem(GetMenu(hwnd), ID_UNITS_FTOC, MF_CHECKED);
    Just to make sure that you're passing the window's menu handle.

    And where I say "send this message to each control", you have to ensure that you're changing the window handle for each control, i.e.:-
    Code:
    SendMessage(hwndEdit1, WM_SETFONT, 0, (LPARAM)hfont);
    SendMessage(hwndEdit2, WM_SETFONT, 0, (LPARAM)hfont);
    ...

  8. #8
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    mm..i'm giving up for now and going to bed so i can try working on it later because i think that may be prohibiting it from working right. but i still couldn't get things to work right.

    haha...yea..oops. i was putting the code for FTOC in the case for FTOK..*slaps forehead*
    ..ouch..
    anyways, the font thing - i'm still clueless about that i'll upload my code in a min. as a zip file (for the .c, .h, and .rc files) but the location will be: http://www.angelfire.com/linux/shibb...converter.html

    thanks for the help


    also..whats the easiest way to keep track of which menu items are checked? i dont think it would be good coding to uncheck every menu item when you check one..?
    Last edited by willc0de4food; 08-08-2005 at 07:09 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 09:21 PM
  2. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  3. dos menu....
    By Drake in forum Game Programming
    Replies: 10
    Last Post: 01-15-2006, 10:16 AM
  4. menu items check
    By Devil Panther in forum Windows Programming
    Replies: 19
    Last Post: 12-10-2004, 03:03 AM
  5. quick question about C Dos text menu pgm i was doing
    By Shadow in forum C Programming
    Replies: 2
    Last Post: 09-16-2001, 10:26 AM