CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    MFC Maximize Function

    Hi All,

    I'm using Visual Studio 2003, and MFC/C++.
    I want to simulate just the update/refresh portion of the maximize command, on an ie window. I've already managed to connect to the window and can send minimize and maximize commands to it, as well as move the window around the screen, even hide and show the window if I wish to. I just need to know what message or function I have to pass to that window to get it to do JUST the refresh portion of its maximize command.

    Here's some background info and stuff I've already tried:

    I have an internet page, that uses java applets served from a server I have no control over. The internet page loads, but none of the background graphics, or button graphics load, so you pretty much have to click on a blank screen and "guess" where the buttons are.

    However, if you minimize the window, and maximize (tested over 100 times, by multiple people, under different conditions, with a 100% success ratio), it'll redraw the window properly.

    I've tried simulating a very rapid alt+tab and it restored the buttons graphics but not the main graphic (not acceptable to my client). I've also tried the following commands:

    ::RedrawWindow(hWnd,0,0,RDW_INVALIDATE);
    ::RedrawWindow(hWnd,0,0,0);
    ::UpdateWindow(hWnd);
    ::SetFocus(hWnd);

    Any help here would be greatly appreciated.

    Thanks,
    Brian
    Last edited by bderagon; November 6th, 2007 at 12:03 PM.

  2. #2
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: MFC Maximize Function

    UpdateWindow should work, but before that you need to set whole window as invalid rect (mark for repaint) using InvalidateRect.
    Regards,
    Ramkrishna Pawar

  3. #3
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: MFC Maximize Function

    I'm not very familiar with how to do that, how would I go about setting that up? Thanks for the quick response by the way.

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: MFC Maximize Function

    It;s simple, you need to call an API,

    Code:
    InvalidateRect(hWnd_IE, NULL, 1);
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: MFC Maximize Function

    Thank you very much, I'll give this a try on the job site tonight or tomorrow, I cannot replicate the problem at home, but this seems to be giving the desired effect.

    Thanks
    Brian

  6. #6
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: MFC Maximize Function

    Appears to be working great, thank you, had to do a little more research and realized I wrote way too much code...but hey, it works, next time I know what to do.

  7. #7
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: MFC Maximize Function

    Actually, as an update to this, I'm having some slight issues now after slightly over a week.

    First, I'm using a series of timers to decide when to redraw the window, I only target IE windows opened with a specific name, once one is open, I issue an invalidate and update once, and then again 2 seconds later. Then I go into another timer waiting for that window to close, when it closes, it triggers a timer waiting for another one to open again, thus, essentially, every time a window loads with that title, I get two screen refreshes which fixes my problem.

    Unfortunately, there's a few issues, the InvalidateRect and UpdateWindow cause the screen to briefly flicker, and that was undesirable, hence going from constantly doing it on one timer, to my multiple timers. If I could find a way to redraw the window without the flicker that'd be great, but that's not the largest issue.

    The largest issue is Java, for some reason, when Java locks up, it locks my timers, and my program refuses to work from that point onward, and the windows go back to displaying their normal graphical glitch. I'm using WM_Timer messages, and was wondering if that may be causing the problem, and if so, what alternatives I should consider.

    Here's a copy of my code for those interested in helping.
    And here's a code tag with the related sections
    Code:
    BOOL CMarineFixDlg::OnInitDialog(){
    	SetTimer(1,200, NULL);					// Set Timer for IE window to open
    	return TRUE; 
    }
    
    void CMarineFixDlg::OnTimer(UINT nIDEvent){
    	if((nIDEvent==1) && bd_CheckMarine()){	// Timer to for IE window to open
    		SetTimer(2,3000, NULL);
    		KillTimer(nIDEvent);
    	}
    	if(nIDEvent==2) {						// Timer to redraw IE window
    		if(bd_CheckMarine()) 
    			SetTimer(4,2000,NULL);
    		else
    			SetTimer(1,200,NULL);			// Timer to wait for window to open
    		::InvalidateRect(NULL,NULL,FALSE);
    		::UpdateWindow(NULL);
    		KillTimer(nIDEvent);
    	}
    	if((nIDEvent==3) && !bd_CheckMarine()){	// Timer to wait for IE window to close
    		SetTimer(1,200,NULL);				// Timer to wait for window to open
    		KillTimer(nIDEvent);
    	}
    	if(nIDEvent==4) {						// Timer to redraw IE window a second time
    		if(bd_CheckMarine()) 
    			SetTimer(3,200,NULL);
    		else
    			SetTimer(1,200,NULL);			// Timer to wait for window to open
    		::InvalidateRect(NULL,NULL,FALSE);
    		::UpdateWindow(NULL);
    		KillTimer(nIDEvent);
    	}
    }
    
    bool CMarineFixDlg::bd_CheckMarine(){
    	HWND hIE = ::FindWindow(0,"US Marine Corps Museum - Windows Internet Explorer");
    	HWND hIE2 = ::FindWindow(0,"US Marine Corps Museum - Mozilla Firefox");
    	if(hIE || hIE2)
    		return true;
    	else
    		return false;
    }
    Code:
    // MarineFixDlg.h : header file
    #pragma once
    class CMarineFixDlg : public CDialog{
    // Construction
    public:
    	CMarineFixDlg(CWnd* pParent = NULL);	// standard constructor
    	afx_msg void OnTimer(UINT nIDEvent);
    	afx_msg void OnPaint();
    	enum { IDD = IDD_MARINEFIX_DIALOG };
    protected:
    	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support
    	virtual BOOL OnInitDialog();
    	HICON m_hIcon;
    	DECLARE_MESSAGE_MAP()
    private:
    	bool bd_CheckMarine();
    };
    Attached Files Attached Files

  8. #8
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    Re: MFC Maximize Function

    Still having an issue with this, couldn't figure it out last night, tried using a multimedia timer, and java locking up still screws up my timer code for some reason, as long as java doesn't lock, I'm fine. But I have to be able to get around that, cause relying on java not locking up isn't really a good solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured