checkbox check problem
-
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
May we see a code snippet?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
May we see a code snippet?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
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.
-
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.
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
-
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.
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/[^]
-
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
-
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.
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
-
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/[^]
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
-
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/[^]
-
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
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/[^]
-
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.
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/[^]