invalidate

This is a discussion on invalidate within the Windows Programming forums, part of the Platform Specific Boards category; can somebody tell me what invalidate(); really does because i heard its used to call the paint event, thing is ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    103

    invalidate

    can somebody tell me what invalidate(); really does because i heard its used to call the paint event, thing is if i put my code to resize an image on the window as a background it doesn't wanna draw it i see the the old pixels mixed with the new drawed ones..
    so if i use invalidate before that it will make all other controls from the window flicker for some reason so is there another function i can use ?
    and another thing how can i get a pixel color from the center of cbitmap and draw that color with a width and height ? :P
    btw im using MFC, thanks.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Cwnd::Invalidate justs makes sure that the client area is painted the next time a WM_PAINT message is received; it doesn't 'force' a repaint. If you're rendering the background of a window then you might consider handling the WM_ERASBKGROUND message (CWnd::OnEraseBkgnd) and doing any background drawing there. To reduce the flickering of controls you should make sure that the parent of those controls has the WS_CLIPCHILDREN window style. To reduce flicker in the drawing itself then you might consider using double buffering - search the boards as there have been many discussions/examples regarding this.

    >>how can I get the pixel colour<<

    CDC:GetPixel

    >>draw that color with a width and height<<

    Not sure what you mean so I'll guess you're looking to fill a rectangle, in which case CDC::FillRect or CDC::FillSolidRect may be of some interest.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    wow thx alot man exactly what i was lookin for i never knew that a simple thing like setting the window style causes that whole flickering problem lol...

    ah 1 last thing please whenever i import a custom icon it looks bad as quality, the icon itself is 16x16, 32x32, 48x48 and 32bit colors i have no idea why it doesn't display correctly and when the app is loading i can see the mfc icon changing to my icon any ideas ? :P thanks.
    heres a screenshot..
    Attached Images Attached Images  
    Last edited by eXistenZ; 01-02-2005 at 03:27 PM.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,853
    How are you drawing the icon (post some code)?

    Could be that 32bit icons have a mask and an image, both have to be drawn to get the full effect. Or that the system has defaulted back to a 16/256 colour image for the icon.

    Without knowing how you are drawing / setting the icon we would have to guess.
    "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

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    im using mfc on visual c++ 6.0 and im using the default drawing..
    Code:
    void CXDlg::OnPaint() 
    {
    if (IsIconic())
    	{
    		CPaintDC dc(this); // device context for painting
    
    		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
    
    		// Center icon in client rectangle
    		int cxIcon = GetSystemMetrics(SM_CXICON);
    		int cyIcon = GetSystemMetrics(SM_CYICON);
    		CRect rect;
    		GetClientRect(&rect);
    		int x = (rect.Width() - cxIcon + 1) / 2;
    		int y = (rect.Height() - cyIcon + 1) / 2;
    
    		// Draw the icon
    		dc.DrawIcon(x, y, m_hIcon);
    	}
    ...
    oh and the icon is true color on 16x16 32x32 48x48
    well the icon quality is one thing but i can't figure out why it shows that mfc icon when its loading and switches fast to my icon and when i have too many windows in the taskbar the group icon is the mfc one.. lol

    edit: ok nvm i fixed the icon problem looks like the default mfc thing has some weird probs

    Code:
    //on init..
    SetIcon(m_hIcon, TRUE);			// Set big icon
    SetIcon(m_hIcon, FALSE);		// Set small icon - so i just removed this line and looks perfect
    but the mfc icon is still displaying..
    Last edited by eXistenZ; 01-03-2005 at 09:00 AM.

Popular pages Recent additions subscribe to a feed

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