Click here to Skip to main content
15,887,371 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GetNetworkParams Pin
Richard MacCutchan8-Mar-11 23:22
mveRichard MacCutchan8-Mar-11 23:22 
GeneralRe: GetNetworkParams Pin
David Crow10-Mar-11 2:01
David Crow10-Mar-11 2:01 
Questionhow to show tooltip text as table for TreeView??? Pin
Nikhil Sisodia8-Mar-11 20:24
Nikhil Sisodia8-Mar-11 20:24 
QuestionShow tooltip text as table for TreeView Pin
Nikhil Sisodia8-Mar-11 20:20
Nikhil Sisodia8-Mar-11 20:20 
AnswerRe: Show tooltip text as table for TreeView Pin
Hans Dietrich9-Mar-11 6:15
mentorHans Dietrich9-Mar-11 6:15 
QuestionHow to deselct the text from a rich edit control when i click ( not click and move ) in the text of it. Pin
Amrit Agr8-Mar-11 0:19
Amrit Agr8-Mar-11 0:19 
AnswerRe: How to deselct the text from a rich edit control when i click ( not click and move ) in the text of it. Pin
Hans Dietrich8-Mar-11 1:09
mentorHans Dietrich8-Mar-11 1:09 
Questionprogram leaks memory when i resize [modified] Pin
leorex8-Mar-11 0:16
leorex8-Mar-11 0:16 
Hey. Basically I made a program that contains 17 * 7 number of boxes using two for loops, and they seem to work pretty well, until i resize it. Every single time i resize the window, the memory goes up by quite a bit, until the program fails with too much memory. I am pretty sure i deleted everything that i called for WM_PAINT, but I am not sure what other parts i might have overlooked. Is there any common mistakes that people would make for drawing a lot of GDI objects? Do I need to post my code to see which part went wrong?

here are the codes. sorry for asking the stupid question "do i need to post my code here" =_+;;

#include <windows.h>
COLORREF color[17][7];


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow )
{
    MSG  msg ;
    HWND hwnd;
    WNDCLASS wc;

    wc.style         = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.lpszClassName = TEXT( "Window" );
    wc.hInstance     = hInstance ;
    wc.hbrBackground = GetSysColorBrush(COLOR_INACTIVECAPTIONTEXT);
    wc.lpszMenuName  = NULL;
    wc.lpfnWndProc   = WndProc;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);

    RegisterClass(&wc);
    hwnd = CreateWindow( wc.lpszClassName,TEXT("BOXES"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                        100, 100, 800, 800, NULL, NULL,
                        hInstance,
                        NULL);

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while( GetMessage(&msg, NULL, 0, 0))
    {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    int i_row, j_column;

    switch (msg)
    {

    case WM_CREATE:
    {
       for(i_row=0; i_row<17; i_row++)
       {
           for(j_column=0; j_column<7; j_column++)
           {
               color[i_row][j_column]=RGB(255,255,255);
           }
       }
       break;
    }

    case WM_PAINT:
    {
        HDC hdc;
        PAINTSTRUCT ps;
        HPEN hPen,holdPen;
        HBRUSH hBrush_1, holdBrush;
       hdc = BeginPaint(hwnd, &ps);

       //create a pen and hold it here for a solid fill
       hPen = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
       holdPen = SelectObject(hdc, hPen);

       for(i_row=0; i_row<17; i_row++)
       {
           for(j_column=0; j_column<7; j_column++)
           {
               hBrush_1 = CreateSolidBrush(color[i_row][j_column]);
               holdBrush = SelectObject(hdc, hBrush_1);
               Rectangle(hdc, 90*j_column+100, 50+30*i_row, 90*j_column+180, 30*i_row+75); //rember is x, y, x, y

           }
       }

       DeleteDC(hdc);

       DeleteObject(hPen);
       DeleteObject(holdPen);
       DeleteObject(hBrush_1);
       DeleteObject(holdBrush);

       EndPaint(hwnd, &ps);
       break;

    }
       break;

    case WM_DESTROY:
    {
       PostQuitMessage(0);
       return 0;
    }
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}


modified on Wednesday, March 9, 2011 5:01 AM

AnswerRe: program leaks memory when i resize Pin
Code-o-mat8-Mar-11 0:32
Code-o-mat8-Mar-11 0:32 
AnswerRe: program leaks memory when i resize Pin
CPallini8-Mar-11 0:51
mveCPallini8-Mar-11 0:51 
AnswerRe: program leaks memory when i resize Pin
Hans Dietrich8-Mar-11 1:13
mentorHans Dietrich8-Mar-11 1:13 
AnswerRe: program leaks memory when i resize Pin
leorex8-Mar-11 21:00
leorex8-Mar-11 21:00 
GeneralRe: program leaks memory when i resize Pin
Richard MacCutchan8-Mar-11 21:35
mveRichard MacCutchan8-Mar-11 21:35 
AnswerRe: program leaks memory when i resize Pin
Code-o-mat8-Mar-11 23:05
Code-o-mat8-Mar-11 23:05 
GeneralRe: program leaks memory when i resize Pin
leorex9-Mar-11 0:14
leorex9-Mar-11 0:14 
GeneralRe: program leaks memory when i resize Pin
Code-o-mat9-Mar-11 0:44
Code-o-mat9-Mar-11 0:44 
GeneralRe: program leaks memory when i resize Pin
leorex9-Mar-11 10:21
leorex9-Mar-11 10:21 
GeneralRe: program leaks memory when i resize Pin
Code-o-mat9-Mar-11 10:27
Code-o-mat9-Mar-11 10:27 
AnswerRe: program leaks memory when i resize Pin
SledgeHammer019-Mar-11 13:58
SledgeHammer019-Mar-11 13:58 
Questionput image on client area of main frame windows Pin
Max++7-Mar-11 19:37
Max++7-Mar-11 19:37 
AnswerRe: put image on client area of main frame windows Pin
Hans Dietrich7-Mar-11 19:45
mentorHans Dietrich7-Mar-11 19:45 
GeneralRe: put image on client area of main frame windows Pin
Max++7-Mar-11 20:09
Max++7-Mar-11 20:09 
QuestionSmall IVR Development Pin
AmbiguousName7-Mar-11 8:35
AmbiguousName7-Mar-11 8:35 
QuestionRe: Small IVR Development Pin
Maximilien7-Mar-11 9:12
Maximilien7-Mar-11 9:12 
AnswerRe: Small IVR Development PinPopular
Chris Meech7-Mar-11 9:46
Chris Meech7-Mar-11 9:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.