how to handle CBN_SELCHANGE

i'm trying to cahnge pen's color with combobox
in WM_COMMAND i handled this ID IDDT_COMBO (ID for my combobox) and then i handled CBN_SELCHANGE
code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
case IDDT_COMBO:
			switch(HIWORD(wParam)){
			case CBN_SELCHANGE:{
				int selection = SendMessage (g_combo,CB_GETCURSEL,NULL,NULL);
				if (selection!=CB_ERR){
					switch (selection){
					case 0:
						r=255; g=255; b=255;
						break;
					case 1:
						r=0; g=0; b=255;
						break;
					case 2:
						r=0; g=255; b=0;
						break;
					case 3:
						r=200; g=0; b=200;
						break;
					case 4:
						r=255; g=0; b=0;
						break;
					case 5:
						r=0; g=255; b=255;
						break;
					}
				}
				else
					MessageBox(NULL,L"Error during selection occured",NULL,NULL);
				break;
			}
			}
			break;


r,g,b are ints that do their job in this code
1
2
SelectObject(hdc,(HGDIOBJ)DC_PEN);
SetDCPenColor(hdc,RGB(r,g,b));



tiny problem: it doesn't work
i guess im not handling CBN_SELCHANGE correctly
how to do that?
Last edited on
Try handling CBN_SELENDOK instead.
I think your code is correct. What I don't know is if your drawing code is. It seems that SelectDCPenColor() only works with the stock DC_PEN pen. See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162970(v=vs.85).aspx .

So you must first select DC_PEN before you can change the color. Otherwise I guess you need to use CreatePen().
^lulz, i was so confused when i was reading urs post, but i used CreatePen() and selected it, and after that it worked

lulz, thx again
Topic archived. No new replies allowed.