Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. checkbox check problem

checkbox check problem

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionloungelearning
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C c s

    I am a beginner in the windows programming world, and am having a bit of trouble figuring out how to determine the state of my checkbox when it's ownerdraw. If I use BM_GETCHECK it always returns 0, even if I send BM_SETCHECK a line above passing BST_CHECKED. I also tried ORing BS_CHECKBOX and/or BS_AUTOCHECKBOX with BS_OWNERDRAW but BM_GETCHECK still returned 0. I then attempted to use BM_SETIMAGE as general storage (a pointer) but BM_GETIMAGE always returns 0 as well. Is it due to the fact my checkboxes are ownerdraw, or is there some other problem I'm unaware of? thanks

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #2

    May we see a code snippet?


    "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

    C 1 Reply Last reply
    0
    • D David Crow

      May we see a code snippet?


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      C Offline
      C Offline
      c s
      wrote on last edited by
      #3

      hTempWnd = CreateWindowEx (
      0, // no extended style
      "Button",
      "Compression", // toggles chunk compression
      WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, // make a visible child window, that we draw ourself (see void DrawCheckbox)
      clientRect.right - MM_DBUTTON_WIDTH - MMPADDING_RIGHT, // create it near the top right corner
      clientRect.top + MMPADDING_TOP + MM_GROUPPADDING_BOTTOM,
      MM_DBUTTON_WIDTH, MM_DBUTTON_HEIGHT, // use our standard checkbox button height and width
      hWnd, // our parent window is this popup menu
      (HMENU) MMENU_BUTTON_COMPRESSION,
      GetModuleHandle ( NULL ),
      NULL // pass no extra parms on creation
      ) ;

      LPDRAWITEMSTRUCT lpdis from lParam in WM_DRAWITEM

      long lResult = 0;

      	lResult = SendMessage ( lpdis->hwndItem, BM\_GETCHECK, (WPARAM) 0, (LPARAM) 0 ) ;
      	if ( lResult == BST\_CHECKED ) ...
      

      When I was trying BM_GETIMAGE I used the same procedure as the second code snippet edit: It seems that BM_GETCHECK and BM_SETCHECK just don't work with ownerdraw, so that solves that issue, but I'm still unsure why BM_SETIMAGE doesn't work.

      D J 2 Replies Last reply
      0
      • C c s

        hTempWnd = CreateWindowEx (
        0, // no extended style
        "Button",
        "Compression", // toggles chunk compression
        WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, // make a visible child window, that we draw ourself (see void DrawCheckbox)
        clientRect.right - MM_DBUTTON_WIDTH - MMPADDING_RIGHT, // create it near the top right corner
        clientRect.top + MMPADDING_TOP + MM_GROUPPADDING_BOTTOM,
        MM_DBUTTON_WIDTH, MM_DBUTTON_HEIGHT, // use our standard checkbox button height and width
        hWnd, // our parent window is this popup menu
        (HMENU) MMENU_BUTTON_COMPRESSION,
        GetModuleHandle ( NULL ),
        NULL // pass no extra parms on creation
        ) ;

        LPDRAWITEMSTRUCT lpdis from lParam in WM_DRAWITEM

        long lResult = 0;

        	lResult = SendMessage ( lpdis->hwndItem, BM\_GETCHECK, (WPARAM) 0, (LPARAM) 0 ) ;
        	if ( lResult == BST\_CHECKED ) ...
        

        When I was trying BM_GETIMAGE I used the same procedure as the second code snippet edit: It seems that BM_GETCHECK and BM_SETCHECK just don't work with ownerdraw, so that solves that issue, but I'm still unsure why BM_SETIMAGE doesn't work.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #4

        What happens if you create a checkbox like:

        CreateWindowEx(..., WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, ...);

        In other words, does the owner-draw style have any affect? I wouldn't think so but I'm just trying to pare the problem down.


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        C 1 Reply Last reply
        0
        • C c s

          hTempWnd = CreateWindowEx (
          0, // no extended style
          "Button",
          "Compression", // toggles chunk compression
          WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, // make a visible child window, that we draw ourself (see void DrawCheckbox)
          clientRect.right - MM_DBUTTON_WIDTH - MMPADDING_RIGHT, // create it near the top right corner
          clientRect.top + MMPADDING_TOP + MM_GROUPPADDING_BOTTOM,
          MM_DBUTTON_WIDTH, MM_DBUTTON_HEIGHT, // use our standard checkbox button height and width
          hWnd, // our parent window is this popup menu
          (HMENU) MMENU_BUTTON_COMPRESSION,
          GetModuleHandle ( NULL ),
          NULL // pass no extra parms on creation
          ) ;

          LPDRAWITEMSTRUCT lpdis from lParam in WM_DRAWITEM

          long lResult = 0;

          	lResult = SendMessage ( lpdis->hwndItem, BM\_GETCHECK, (WPARAM) 0, (LPARAM) 0 ) ;
          	if ( lResult == BST\_CHECKED ) ...
          

          When I was trying BM_GETIMAGE I used the same procedure as the second code snippet edit: It seems that BM_GETCHECK and BM_SETCHECK just don't work with ownerdraw, so that solves that issue, but I'm still unsure why BM_SETIMAGE doesn't work.

          J Offline
          J Offline
          Jose Lamas Rios
          wrote on last edited by
          #5

          c. s. wrote: hTempWnd = CreateWindowEx ( 0, // no extended style "Button", "Compression", // toggles chunk compression WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, // make a visible child window, that we draw ourself (see void DrawCheckbox) clientRect.right - MM_DBUTTON_WIDTH - MMPADDING_RIGHT, // create it near the top right corner clientRect.top + MMPADDING_TOP + MM_GROUPPADDING_BOTTOM, MM_DBUTTON_WIDTH, MM_DBUTTON_HEIGHT, // use our standard checkbox button height and width hWnd, // our parent window is this popup menu (HMENU) MMENU_BUTTON_COMPRESSION, GetModuleHandle ( NULL ), NULL // pass no extra parms on creation ) ; According to this[^], an owner-drawn button "has no predefined appearance or usage. Its purpose is to provide a button whose appearance and behavior are defined by the application alone." Furthermore, your call to Create isn't even specifying one of the possible check box styles (BS_CHECKBOX, BS_AUTOCHECKBOX, BS_3STATE, BS_AUTO3STATE), so it's no wonder the control doesn't react to BM_SETCHECK messages. Try adding BS_CHECKBOX, and if that doesn't work (which may be due because of the owner draw style), I suggest subclassing the control so that you can handle the BM_GETCHECK and BM_SETCHECK messages yourself. Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

          D C 2 Replies Last reply
          0
          • D David Crow

            What happens if you create a checkbox like:

            CreateWindowEx(..., WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, ...);

            In other words, does the owner-draw style have any affect? I wouldn't think so but I'm just trying to pare the problem down.


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            C Offline
            C Offline
            c s
            wrote on last edited by
            #6

            I have tried using BS_AUTOCHECKBOX with BS_OWNERDRAW (I do draw them myself so I need that) but it doesn't seem to have an effect, and BM_GETCHECK still always returns 0.

            D 1 Reply Last reply
            0
            • C c s

              I have tried using BS_AUTOCHECKBOX with BS_OWNERDRAW (I do draw them myself so I need that) but it doesn't seem to have an effect, and BM_GETCHECK still always returns 0.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #7

              c. s. wrote: I have tried using BS_AUTOCHECKBOX with BS_OWNERDRAW (I do draw them myself so I need that) but it doesn't seem to have an effect... Right, but does the problem persist for non owner-drawn checkboxes?


              "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

              1 Reply Last reply
              0
              • J Jose Lamas Rios

                c. s. wrote: hTempWnd = CreateWindowEx ( 0, // no extended style "Button", "Compression", // toggles chunk compression WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, // make a visible child window, that we draw ourself (see void DrawCheckbox) clientRect.right - MM_DBUTTON_WIDTH - MMPADDING_RIGHT, // create it near the top right corner clientRect.top + MMPADDING_TOP + MM_GROUPPADDING_BOTTOM, MM_DBUTTON_WIDTH, MM_DBUTTON_HEIGHT, // use our standard checkbox button height and width hWnd, // our parent window is this popup menu (HMENU) MMENU_BUTTON_COMPRESSION, GetModuleHandle ( NULL ), NULL // pass no extra parms on creation ) ; According to this[^], an owner-drawn button "has no predefined appearance or usage. Its purpose is to provide a button whose appearance and behavior are defined by the application alone." Furthermore, your call to Create isn't even specifying one of the possible check box styles (BS_CHECKBOX, BS_AUTOCHECKBOX, BS_3STATE, BS_AUTO3STATE), so it's no wonder the control doesn't react to BM_SETCHECK messages. Try adding BS_CHECKBOX, and if that doesn't work (which may be due because of the owner draw style), I suggest subclassing the control so that you can handle the BM_GETCHECK and BM_SETCHECK messages yourself. Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #8

                Jose Lamas Rios wrote: Furthermore, your call to Create isn't even specifying one of the possible check box styles (BS_CHECKBOX, BS_AUTOCHECKBOX, BS_3STATE, BS_AUTO3STATE), so it's no wonder the control doesn't react to BM_SETCHECK messages. Did you miss this: "I also tried ORing BS_CHECKBOX and/or BS_AUTOCHECKBOX with BS_OWNERDRAW but BM_GETCHECK still returned 0."


                "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                J 1 Reply Last reply
                0
                • J Jose Lamas Rios

                  c. s. wrote: hTempWnd = CreateWindowEx ( 0, // no extended style "Button", "Compression", // toggles chunk compression WS_VISIBLE | WS_CHILD | BS_OWNERDRAW, // make a visible child window, that we draw ourself (see void DrawCheckbox) clientRect.right - MM_DBUTTON_WIDTH - MMPADDING_RIGHT, // create it near the top right corner clientRect.top + MMPADDING_TOP + MM_GROUPPADDING_BOTTOM, MM_DBUTTON_WIDTH, MM_DBUTTON_HEIGHT, // use our standard checkbox button height and width hWnd, // our parent window is this popup menu (HMENU) MMENU_BUTTON_COMPRESSION, GetModuleHandle ( NULL ), NULL // pass no extra parms on creation ) ; According to this[^], an owner-drawn button "has no predefined appearance or usage. Its purpose is to provide a button whose appearance and behavior are defined by the application alone." Furthermore, your call to Create isn't even specifying one of the possible check box styles (BS_CHECKBOX, BS_AUTOCHECKBOX, BS_3STATE, BS_AUTO3STATE), so it's no wonder the control doesn't react to BM_SETCHECK messages. Try adding BS_CHECKBOX, and if that doesn't work (which may be due because of the owner draw style), I suggest subclassing the control so that you can handle the BM_GETCHECK and BM_SETCHECK messages yourself. Hope that helps, -- jlr http://jlamas.blogspot.com/[^]

                  C Offline
                  C Offline
                  c s
                  wrote on last edited by
                  #9

                  I was hoping to avoid using my own storage, but it seems not too feasible. I will subclass it and see how it turns out, thanks all.

                  J 1 Reply Last reply
                  0
                  • D David Crow

                    Jose Lamas Rios wrote: Furthermore, your call to Create isn't even specifying one of the possible check box styles (BS_CHECKBOX, BS_AUTOCHECKBOX, BS_3STATE, BS_AUTO3STATE), so it's no wonder the control doesn't react to BM_SETCHECK messages. Did you miss this: "I also tried ORing BS_CHECKBOX and/or BS_AUTOCHECKBOX with BS_OWNERDRAW but BM_GETCHECK still returned 0."


                    "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                    J Offline
                    J Offline
                    Jose Lamas Rios
                    wrote on last edited by
                    #10

                    DavidCrow wrote: Did you miss this: "I also tried ORing BS_CHECKBOX and/or BS_AUTOCHECKBOX with BS_OWNERDRAW but BM_GETCHECK still returned 0." Yes, I missed it. Sorry. -- jlr http://jlamas.blogspot.com/[^]

                    1 Reply Last reply
                    0
                    • C c s

                      I was hoping to avoid using my own storage, but it seems not too feasible. I will subclass it and see how it turns out, thanks all.

                      J Offline
                      J Offline
                      Jose Lamas Rios
                      wrote on last edited by
                      #11

                      c. s. wrote: I was hoping to avoid using my own storage, but it seems not too feasible. I will subclass it and see how it turns out, thanks all. Well, subclassing it would have an additional benefit, since it would allow you to handle the drawing in the control, rather than doing so in the parent. That's in my opinion a better alternative because it's easier to reuse the control with different parents. Good luck :) -- jlr http://jlamas.blogspot.com/[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups