BRUSH displayed wrong with vc++ but not with dev-c++?

Hi

I have a little problem with my brushes, when they display they are outside the region of the buttons like in this img: http://data.fuskbugg.se/skalman02/Brush.png

The thing is that it's the same code but compiled with different programs.
What am I doing wrong in my code:

/OLD CODE WAS HERE/

EDIT:
Im using this now, and it works fine, but am i doing it right?
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
33
34
//GLOBALS
HBITMAP CLOSE;
HBRUSH CLOSEBRUSH;

case WM_DRAWITEM:
     LPDRAWITEMSTRUCT lpDrawItem;
     lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
     switch (lpDrawItem->CtlID) {
          case IDC_CLOSE:
               if(lpDrawItem->itemState & ODS_SELECTED) {
                    CLOSE = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CLOSEDOWN));
                    if(CLOSE != NULL) {
                         CLOSEBRUSH = CreatePatternBrush( CLOSE );
                         FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, CLOSEBRUSH);
                    } else { 
                         FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, (HBRUSH)GetStockObject(BLACK_BRUSH));
                    }
               }
               else {
                    CLOSE = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CLOSE));
                    if(CLOSE != NULL) {
                         CLOSEBRUSH = CreatePatternBrush( CLOSE );
                         FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, CLOSEBRUSH);
                    } else { 
                         FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, (HBRUSH)GetStockObject(BLACK_BRUSH));
                    }
               }
          break;
     }
return true;

case WM_DESTROY:
DeleteObject(CLOSE);
DeleteObject(CLOSEBRUSH);
Last edited on
closed account (3pj6b7Xj)
Its a compiler issue, Dev-C++ uses MinGW (excuse my language "a compiler with out the BULLSHIT) while VC++ 08 is different. Microsoft changes the implementation on their compilers WAY TOO much, its like they don't liek to follow the rules of ANSI and twist and bend the code to create something that works a completely different way.

Stick with the compiler that gives you the best results, simple as that.
Try BitBllt(); in WM_PAINT
*rolls eyes*

Dev-C++ uses MinGW (excuse my language "a compiler with out the BULLSHIT) while VC++ 08 is different.


Correction: Dev-C++ uses a crazy outdated version of MinGW, which is probably why the behavior was incorrect (he probably was doing something wrong that just happened to work on MinGW when it shouldn't have been working).

Microsoft changes the implementation on their compilers WAY TOO much,


How do you figure?

Besides.. why would this matter? Does it matter how the compiler works as long as it works?

its like they don't liek to follow the rules of ANSI and twist and bend the code to create something that works a completely different way.


...such as? What's your basis for this claim?

MSVC++ tries to be as standards compliant as possible. It gets some things right that GCC gets wrong (and vice versa).

Stick with the compiler that gives you the best results, simple as that.


Horrible advice. Even if the compiler he was using wasn't criminally outdated this would still be bad advice.

Good code works on any compiler. Ideally programmers should even try to test their code on as many compilers as possible to make sure it works as expected. In fact this is even somewhat of a necessity for libraries, or really any common open source software.

Take your "all the cool kids hate MS" crap elsewhere plzkthx.

@zypronix:


Your code looks to me like it has MASSIVE memory leaks. You keep creating/loading new brushes images when controls are drawn. Each time you do so, you leak the previous one because you don't delete it.

You only delete it when the window is destroyed -- but it's only destroyed once, whereas it might be drawn several hundred/thousand times.
Last edited on
Disch, so creating and delete it within the case is better?
Why I didn't do that before was because of a tutorial that sad it was better to delete it ones in wm_destroy then create/delete every time. But with obs_selected I had the option to select a new brush to display, so it's probably not the same as only create ones gobal -> only returning the brush -> delete it ones in wm_Destroy =)

I took for granted that the old brush was deleted/replaced when it was declared with a new one...

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
case WM_DRAWITEM:
	LPDRAWITEMSTRUCT lpDrawItem;
	lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
	switch (lpDrawItem->CtlID) {
		case IDC_CLOSE:
			if(lpDrawItem->itemState & ODS_SELECTED) {
				HBITMAP CLOSE = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CLOSEDOWN));
				if(CLOSE != NULL) {
					HBRUSH CLOSEBRUSH = CreatePatternBrush( CLOSE );
					FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, CLOSEBRUSH);
				} else { 
					FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, (HBRUSH)GetStockObject(BLACK_BRUSH));
				}
				DeleteObject(CLOSE);
			}
			else {
				HBITMAP CLOSE = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CLOSE));
				if(CLOSE != NULL) {
					HBRUSH CLOSEBRUSH = CreatePatternBrush( CLOSE );
					FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, CLOSEBRUSH);
					DeleteObject(CLOSEBRUSH);
				} else { 
					FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, (HBRUSH)GetStockObject(BLACK_BRUSH));
				}
				DeleteObject(CLOSE);
			}
			break;
		}
	return true;
That's better in that it won't leak memory, but it's still bad in that you'll be loading/freeing the image every time it's drawn.

You're better off loading everything once and destroying it once. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
case WM_CREATE:  // or some other startup message
  CLOSE = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_CLOSE));
  CLOSEDOWN = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_CLOSEDOWN));

  CLOSEBRUSH = CreatePatternBrush(CLOSE);
  CLOSEDOWNBRUSH = CreatePatternBrush(CLOSEDOWN);
  break;

case WM_DRAWITEM:
  ...
  if(lpDrawItem->itemState & ODS_SELECTED)
    FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, CLOSEDOWNBRUSH);
  else
    FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, CLOSEBRUSH);
  ...
  break;

case WM_DESTROY:
  DeleteObject(CLOSEDOWNBRUSH);
  DeleteObject(CLOSEBRUSH);
  DeleteObject(CLOSEDOWN);
  DeleteObject(CLOSE);
  break;
thx, Disch,

exactly as the tutorial tried to tell me, but I insisted that I replace the one I had which is wrong =)

thx again... marked as solved
closed account (3pj6b7Xj)
Disch is right, what was I thinking. I wouldn't even come close too designing an application like VC 08 so wrong of me to speak with out knowing whats involved, I apologize for that childish behaviour, I should know better.
lol sorry I exploded at you. You didn't deserve it.

There's just this whole subculture of people that hate MS just becaues it's "cool" to do so.

Don't get me wrong there are plenty of legitimate reasons not to like MS, but 99% of the "too cool for MS" kids don't cite any of them. They just hate it because it's a successful business (ie: "M$" implying they make money). I guess it just irritates me and I snap at people.
Topic archived. No new replies allowed.