Frying my system

This is a discussion on Frying my system within the Windows Programming forums, part of the Platform Specific Boards category; I wrote this program to help play minesweeper on windows vista. It's not the most intelligent program in the world ...

  1. #1
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341

    Frying my system

    I wrote this program to help play minesweeper on windows vista. It's not the most intelligent program in the world but it handles the the trivial aspects. Anyway, after running for a bit, my computer slows down and the program eventually no longer runs.
    Code:
    #define STRICT
    #include <windows.h>
    #include <windowsx.h>
    #include <stdio.h>
    
    #define BMPX 12
    #define BMPY 9
    #define BMPWIDTH 8
    #define BMPHEIGHT 8
    #define BOARDX (38 - BMPX)
    #define BOARDY (78 - BMPY)
    #define CELLWIDTH 18
    #define CELLHEIGHT 18
    #define CELLCOUNTX 9
    #define CELLCOUNTY 9
    #define HIGHNUMBER 4
    #define SCREENWIDTH 1680
    #define SCREENHEIGHT 1050
    #define BLANK 0
    #define FLAG (HIGHNUMBER + 1)
    #define EPSILON 30
    
    #define RED24BIT(c)  (int)(((c) >> 0) & 255)
    #define GREEN24BIT(c)  (int)(((c) >> 8) & 255)
    #define BLUE24BIT(c)  (int)(((c) >> 16) & 255)
    #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 
    #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 
    
    struct INFO 
    {
    	COLORREF Color;
    	int x;
    	int y;
    };
    
    int BoardInfo[CELLCOUNTX][CELLCOUNTY];
    
    static HWND MainWindow;
    static HINSTANCE MainInstance;
    static char ClassName[] = "Minesweeper Helper";
    INFO ColorInfo[HIGHNUMBER + 2];
    int WindowX = -1, WindowY = -1;
    
    bool InitWindow(HINSTANCE Instance, int ShowCmd);
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT Message,
    							WPARAM wParam, LPARAM lParam);
    bool GetMinesweeperLocation();
    BOOL Helper_OnCreate(HWND Window, CREATESTRUCT FAR* CreateStruct);
    void Helper_OnPaint(HWND Window);
    void Helper_OnDestroy(HWND Window);
    void UpdateBoard(void);
    void FindClicks(void);
    
    int _stdcall WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine , int ShowCmd)
    {
    	MSG Msg;
    
    	if (!InitWindow(Instance, ShowCmd))
    	{
    		MessageBox(0, "Could not create the window!\nPeace Out!", "Huge Problem", MB_OK);
    		return 0;
    	}
    
    	if (!GetMinesweeperLocation())
    	{
    		MessageBox(MainWindow, "Could not find minesweeper window!\nPeaceOut", "Big Problem", MB_OK);
    		return 0;
    	}
    
    	while (true)
    	{
    		if (PeekMessage(&Msg, 0, NULL, NULL, PM_REMOVE))
    		{
    			if (Msg.message == WM_QUIT)
    				break;
    
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    		UpdateBoard();
    		FindClicks();
    		Sleep(30);
    	}
    	return Msg.wParam;
    }
    
    bool InitWindow(HINSTANCE Instance, int ShowCmd)
    {
    	WNDCLASSEX Class;
    
    	Class.cbClsExtra	= 0;
    	Class.cbSize		= sizeof(Class);
    	Class.cbWndExtra	= 0;
    	Class.hbrBackground	= GetStockBrush(WHITE_BRUSH);
    	Class.hCursor		= LoadCursor(NULL, IDC_ARROW);
    	Class.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
    	Class.hIconSm		= LoadIcon(NULL, IDI_APPLICATION);
    	Class.hInstance		= Instance;
    	Class.lpfnWndProc	= WindowProc;
    	Class.lpszClassName	= ClassName;
    	Class.lpszMenuName	= NULL;
    	Class.style			= CS_HREDRAW | CS_VREDRAW;
    
    	if (!RegisterClassEx(&Class))
    		return false;
    
    	MainInstance = Instance;
    
    	MainWindow = CreateWindowEx(NULL, ClassName, ClassName,WS_OVERLAPPEDWINDOW,
    								0, 0, 300, 300, NULL, NULL, Instance, NULL);
    
    	if (MainWindow == NULL)
    		return false;
    
    	ShowWindow(MainWindow, ShowCmd);
    	UpdateWindow(MainWindow);
    
    	return true;
    }
    
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT Message,
    							WPARAM wParam, LPARAM lParam)
    {
    	switch (Message)
    	{
    		HANDLE_MSG(hWnd, WM_CREATE, Helper_OnCreate);
    		HANDLE_MSG(hWnd, WM_PAINT, Helper_OnPaint);
    	//	HANDLE_MSG(hWnd, WM_KEYUP, Edge_OnKey);
    		HANDLE_MSG(hWnd, WM_DESTROY, Helper_OnDestroy);
    	default:
    		return DefWindowProc(hWnd, Message, wParam, lParam);
    	}
    }
    
    BOOL Helper_OnCreate(HWND Window, CREATESTRUCT FAR* CreateStruct)
    {
    	ColorInfo[0].Color = RGB(196, 207, 229);
    	ColorInfo[0].x = 9;
    	ColorInfo[0].y = 8;
    
    
    	ColorInfo[1].Color = RGB(64, 80, 191);
    	ColorInfo[1].x = 9;
    	ColorInfo[1].y = 9;
    
    	ColorInfo[2].Color = RGB(31, 104, 5);
    	ColorInfo[2].x = 8;
    	ColorInfo[2].y = 3;
    
    	ColorInfo[3].Color = RGB(166, 5, 5);
    	ColorInfo[3].x = 8;
    	ColorInfo[3].y = 8;
    
    	ColorInfo[4].Color = RGB(2, 1, 133);
    	ColorInfo[4].x = 12;
    	ColorInfo[4].y = 10;
    
    	ColorInfo[FLAG].Color = RGB(252, 3, 9);
    	ColorInfo[FLAG].x = 8;
    	ColorInfo[FLAG].y = 7;
    
    	return true;
    }
    
    bool GetMinesweeperLocation()
    {
    	HDC MainDC = GetDC(0);
    	HDC WindowDC = GetDC(MainWindow);
    	int x1, y1, x2, y2;
    	unsigned long BmpPixels[BMPWIDTH][BMPHEIGHT];
    	unsigned long *ScrnPixels = new unsigned long[SCREENWIDTH*SCREENHEIGHT];
    	char Message[100];
    	HBITMAP CornerBmp = LoadBitmap(MainInstance, "Corner");
    	HBITMAP ScreenBmp = CreateCompatibleBitmap(MainDC, SCREENWIDTH, SCREENHEIGHT);
    
    	if (!CornerBmp)
    	{
    		MessageBox(MainWindow, "Corner Bitmap is MIA", "Chillin'", MB_OK);
    		return false;
    	}
    
    	HDC BmpDC = CreateCompatibleDC(MainDC);
    	HBITMAP OldBmp = SelectBitmap(BmpDC, CornerBmp);
    	bool FoundWindow = false;
    
    	for (y1 = 0; y1 < BMPHEIGHT; y1++)
    	{
    		for (x1 = 0; x1 < BMPWIDTH; x1++)
    		{
    			BmpPixels[x1][y1] = GetPixel(BmpDC, x1, y1);
    		}
    	}
    
    	SelectBitmap(BmpDC, ScreenBmp);
    	BitBlt(BmpDC, 0, 0, SCREENWIDTH, SCREENHEIGHT, MainDC, 0, 0, SRCCOPY);
    
    	for (y1 = 0; y1 < SCREENHEIGHT; y1++)
    	{
    		for (x1 = 0; x1 < SCREENWIDTH; x1++)
    		{
    			ScrnPixels[x1 + y1 * SCREENWIDTH] = GetPixel(BmpDC, x1, y1);
    		}
    	}
    
    	SelectBitmap(BmpDC, OldBmp);
    	
    	for (y1 = 0; (y1 < SCREENHEIGHT - BMPHEIGHT) && (!FoundWindow); y1++)
    	{
    		for (x1 = 0; (x1 < SCREENWIDTH - BMPWIDTH) && (!FoundWindow); x1++)
    		{
    			FoundWindow = true;
    			for (y2 = 0; (y2 < BMPHEIGHT) && FoundWindow; y2++)
    			{
    				for (x2 = 0; (x2 < BMPWIDTH) && FoundWindow; x2++)
    				{
    					if (BmpPixels[x2][y2] != ScrnPixels[x1+x2+(y1+y2) * SCREENWIDTH])
    						FoundWindow = false;
    				}
    			}
    			if (FoundWindow)
    			{
    				WindowX = x1;
    				WindowY = y1;
    			}
    		}
    	}
    
    	if (!FoundWindow)
    		return false;
    
    	sprintf(Message, "Window location: (%d, %d)", WindowX - BMPX, WindowY - BMPY);
    	TextOut(WindowDC, 10, 10, Message, strlen(Message));
    
    	for (y1 = 0; y1 < CELLCOUNTY; y1++)
    	{
    		for (x1 = 0; x1 < CELLCOUNTX; x1++)
    		{
    			BoardInfo[x1][y1] = -1;
    		}
    	}
    	DeleteDC(BmpDC);
    	ReleaseDC(0, MainDC);
    	ReleaseDC(MainWindow, WindowDC);
    	return true;
    }
    
    void Helper_OnPaint(HWND Window)
    {
    	PAINTSTRUCT PaintStruct;
    	char Message[100];
    	HDC PaintDC = BeginPaint(Window, &PaintStruct);
    
    	if (WindowX != -1 && WindowY != -1)
    	{
    		sprintf(Message, "Window location: (%d, %d)", WindowX - BMPX, WindowY - BMPY);
    		TextOut(PaintDC, 10, 10, Message, strlen(Message));
    	}
    
    	EndPaint(Window, &PaintStruct);
    }
    
    void Helper_OnDestroy(HWND Window)
    {
    	PostQuitMessage(0);
    }
    
    void UpdateBoard(void)
    {
    	int x, y, i;
    	HDC MainDC = GetDC(0);
    	HDC WindowDC = GetDC(MainWindow);
    	char Message[100];
    	HBITMAP ScreenBmp = CreateCompatibleBitmap(MainDC, CELLWIDTH * CELLCOUNTX, CELLHEIGHT * CELLCOUNTY);
    	HDC ScreenDC = CreateCompatibleDC(MainDC);
    	HBITMAP OldBmp = SelectBitmap(ScreenDC, ScreenBmp);
    	BitBlt(ScreenDC, 0, 0, 80, 80,
    		   MainDC, WindowX + BOARDX, WindowY + BOARDY, SRCCOPY);
    	BitBlt(ScreenDC, 80, 0, 82, 80,
    			   MainDC, WindowX + BOARDX + 81, WindowY + BOARDY, SRCCOPY);
    	BitBlt(ScreenDC, 0, 80, 80, 82,
    		   MainDC, WindowX + BOARDX, WindowY + BOARDY + 81, SRCCOPY);
    	BitBlt(ScreenDC, 80, 80, 82, 82,
    			   MainDC, WindowX + BOARDX + 81, WindowY + BOARDY + 81, SRCCOPY);
    	for (y = 0; y < CELLCOUNTY; y++)
    	{
    		for (x = 0; x < CELLCOUNTX; x++)
    		{
    			BoardInfo[x][y] = -1;
    		//	if (BoardInfo[x][y] == -1)
    		//	{
    				// BOARDX/y may be wrong
    			//	if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[BLANK].x,
    			//			y * CELLHEIGHT + ColorInfo[BLANK].y) == ColorInfo[BLANK].Color)
    			//	{
    			//		BoardInfo[x][y] = BLANK;
    				COLORREF Color = GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[0].x,
    								y * CELLHEIGHT + ColorInfo[0].y);
    				if (abs(RED24BIT(Color) - RED24BIT(ColorInfo[0].Color)) < EPSILON)
    				{
    					if (abs(GREEN24BIT(Color) - GREEN24BIT(ColorInfo[0].Color)) < EPSILON)
    					{
    						if (abs(BLUE24BIT(Color) - BLUE24BIT(ColorInfo[0].Color)) < EPSILON)
    						{
    							BoardInfo[x][y] = 0;
    						}
    					}
    				}
    								
    					for (i = 0; i <= HIGHNUMBER; i++)
    					{
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x,
    								y * CELLHEIGHT + ColorInfo[i].y) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x - 1,
    								y * CELLHEIGHT + ColorInfo[i].y) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x + 1,
    								y * CELLHEIGHT + ColorInfo[i].y) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}		
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x,
    								y * CELLHEIGHT + ColorInfo[i].y - 1) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x,
    								y * CELLHEIGHT + ColorInfo[i].y + 1) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}	
    						
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x - 1,
    								y * CELLHEIGHT + ColorInfo[i].y + 1) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x + 1,
    								y * CELLHEIGHT + ColorInfo[i].y + 1) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}		
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x - 1,
    								y * CELLHEIGHT + ColorInfo[i].y - 1) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}
    						if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[i].x + 1,
    								y * CELLHEIGHT + ColorInfo[i].y - 1) == ColorInfo[i].Color)
    						{
    							BoardInfo[x][y] = i;
    							continue;
    						}	
    						
    					}
    			//	}
    				if (GetPixel(ScreenDC, x * CELLWIDTH + ColorInfo[FLAG].x,
    							y * CELLHEIGHT + ColorInfo[FLAG].y) == ColorInfo[FLAG].Color)
    				{
    					BoardInfo[x][y] = FLAG;
    				}
    		//	}
    		}
    	}
    	
    	SelectBitmap(ScreenDC, OldBmp);
    	DeleteDC(ScreenDC);
    
    	for (y = 0; y < CELLCOUNTY; y++)
    	{
    		for (x = 0; x < CELLCOUNTX; x++)
    		{
    			if (BoardInfo[x][y] >= 0 && BoardInfo[x][y] <= HIGHNUMBER)
    			{
    				sprintf(Message, "%d", BoardInfo[x][y]);
    				TextOut(WindowDC, 10 + 20 * x, 30 + 20 * y, Message, strlen(Message));
    			}
    			else if (BoardInfo[x][y] == -1)
    			{
    				sprintf(Message, "?");
    				TextOut(WindowDC, 10 + 20 * x, 30 + 20 * y, Message, strlen(Message));
    			}
    			else if (BoardInfo[x][y] == FLAG)
    			{
    				sprintf(Message, "F");
    				TextOut(WindowDC, 10 + 20 * x, 30 + 20 * y, Message, strlen(Message));
    			}
    		}
    	}
    
    	POINT pt;
    	GetCursorPos(&pt);
    
    	sprintf(Message, "Rel Pos: (%d, %d)        ", pt.x - WindowX, pt.y - WindowY);
    	TextOut(WindowDC, 10, 30 + 20 * CELLCOUNTY, Message, strlen(Message));
    
    	ReleaseDC(MainWindow, WindowDC);
    	DeleteDC(MainDC);
    }
    
    void FindClicks(void)
    {
    	bool RClick[CELLCOUNTX][CELLCOUNTY];
    	bool LClick[CELLCOUNTX][CELLCOUNTY];
    	int x, y, i, j;
    	int OpenCount, FlagCount;
    	POINT OldPos;
    
    	for (y = 0; y < CELLCOUNTY; y++)
    	{
    		for (x = 0; x < CELLCOUNTX; x++)
    		{
    			LClick[x][y] = false;
    			RClick[x][y] = false;
    		}
    	}
    
    	for (y = 0; y < CELLCOUNTY; y++)
    	{
    		for (x = 0; x < CELLCOUNTX; x++)
    		{
    			if (BoardInfo[x][y] >= 1 && BoardInfo[x][y] <= HIGHNUMBER)
    			{
    				OpenCount = 0; 
    				FlagCount = 0;
    				for (i = MAX(0, x - 1); i <= MIN(CELLCOUNTX - 1, x + 1); i++)
    				{
    					for (j = MAX(0, y - 1); j <= MIN(CELLCOUNTY - 1, y + 1); j++)
    					{
    						if (BoardInfo[i][j] == -1)
    							OpenCount++;
    						if (BoardInfo[i][j] == FLAG)
    							FlagCount++;
    					}
    				}
    				if (FlagCount == BoardInfo[x][y] && OpenCount > 0)
    				{
    					for (i = MAX(0, x - 1); i <= MIN(CELLCOUNTX - 1, x + 1); i++)
    					{
    						for (j = MAX(0, y - 1); j <= MIN(CELLCOUNTY - 1, y + 1); j++)
    						{
    							if (BoardInfo[i][j] == -1)
    								LClick[i][j] = true;
    						}
    					}
    				}
    				if (FlagCount + OpenCount == BoardInfo[x][y] && OpenCount > 0)
    				{
    					for (i = MAX(0, x - 1); i <= MIN(CELLCOUNTX - 1, x + 1); i++)
    					{
    						for (j = MAX(0, y - 1); j <= MIN(CELLCOUNTY - 1, y + 1); j++)
    						{
    							if (BoardInfo[i][j] == -1)
    								RClick[i][j] = true;
    						}
    					}
    				}
    			}
    		}
    	}
    	
    	GetCursorPos(&OldPos);
    
    	for (y = 0; y < CELLCOUNTY; y++)
    	{
    		for (x = 0; x < CELLCOUNTX; x++)
    		{
    			if (LClick[x][y])
    			{
    				SetCursorPos(WindowX + BOARDX + CELLWIDTH / 2 + CELLWIDTH * x,
    							 WindowY + BOARDY + CELLHEIGHT / 2 + CELLHEIGHT * y);
    				mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    				Sleep(10);
    				mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    				Sleep(10);
    			}
    			if (RClick[x][y])
    			{
    				SetCursorPos(WindowX + BOARDX + CELLWIDTH / 2 + CELLWIDTH * x,
    							 WindowY + BOARDY + CELLHEIGHT / 2 + CELLHEIGHT * y);
    				mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
    				Sleep(5);
    				mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
    				Sleep(5);
    			}
    		}
    	}
    
    	SetCursorPos(OldPos.x, OldPos.y);
    }
    OS: Windows Vista Ultimate 64bit
    Program: 32bit
    Compiler: MSVC++ 6.0
    Memory 2G
    Memory Usage Before: ~900MB
    Memory Usage At Crash: ~1900MB
    Processor: Intel Core 2 CPU T7200 2.00Ghz
    Graphics Card: NVIDIA GeForce Go 7600 512MB

    Judging from the memory usage, I'd guess it's using too much memory but I don't know why.
    Don't quote me on that... ...seriously

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    It's probably just a simple memory leak. This memory
    Code:
    unsigned long *ScrnPixels = new unsigned long[SCREENWIDTH*SCREENHEIGHT];
    is never freed, but the function it's in is only called once. The problem must lie in one of these functions:
    Code:
    	while (true)
    	{
    		if (PeekMessage(&Msg, 0, NULL, NULL, PM_REMOVE))
    		{
    			if (Msg.message == WM_QUIT)
    				break;
    
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		}
    		UpdateBoard();
    		FindClicks();
    		Sleep(30);
    	}
    Closer examination shows a CreateCompatibleBitmap() call in UpdateBoard(). You're supposed to call DeleteObject() on the HBITMAP returned by CreateCompatibleBitmap() when you're done with it, but you don't. This is likely the culrit. http://msdn2.microsoft.com/en-us/library/ms532287.aspx
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Would DeleteBitmap() work the same as DeleteObject()?
    Don't quote me on that... ...seriously

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    From the API help for CreateCompatibleBitmap():
    When you no longer need the bitmap, call the DeleteObject function to delete it.
    DeleteObject() is what you want.

    AFAIK, there is no function named DeleteBitmap() in Win32 API-dom. Feel free to prove me wrong and point to the MSDN page, however.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> AFAIK, there is no function named DeleteBitmap() in Win32 API-dom. Feel free to prove me wrong and point to the MSDN page, however.
    Code:
    #define DeleteBitmap DeleteObject

  6. #6
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Windowsx.h:
    Code:
    #define     DeleteBitmap(hbm)       DeleteObject((HGDIOBJ)(HBITMAP)(hbm))
    I'm still having the same problem but I don't think it is as bad. I have more time before it crashes.
    Don't quote me on that... ...seriously

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    You are leaking GDI.

    A DC must be returned to it's default state before it can delete.
    EDIT: That is you must 'catch' the default GDI objects (inside the DC when you create it) when ever you use SelectObject(), put them back when you have finished and DeleteObject() them.

    Code:
    HBITMAP   *hOrigBMP=(HBITMAP)SelectObject(hMemDC, hCornerBMP);
    //Use
    SelectObject(hMemDC, hOrigBMP);
    DeleteObject(hCornerBMP);
    //delete DC

    You load and create bitmaps but never free/delete them (ie corner and screen bitmaps).

    What compiler are you using? MSVC v6 treats GDI differently than later versions.

    Open the task manager, select 'View', then 'Select Columns'. Add 'GDI Objects'. When you run your app, find it in the task manager and ensure that the GDI count is relatively static.

    GDI count should NOT slowly increase. It should jump when you open a dlg/window and jump back once it closes again.
    Last edited by novacain; 06-14-2007 at 10:35 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Ok. Think I got the memory leak fixed but I somehow the UpdateBoard function isn't finding the right values anymore so I haven't tested to see if the leak is fixed.
    Don't quote me on that... ...seriously

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Operating System
    By Houssen in forum C Programming
    Replies: 18
    Last Post: 04-22-2008, 12:51 PM
  2. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 12:04 PM
  3. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 06:56 PM
  4. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21