InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Hi,

    I'm Getting Real-time Data and Display the image in main screen. Using the InvalidateRect() method, I'm refresh the main screen(Image Area only - 768 * 256) continuously.

    Now I opened a child screen . It was display the back side of main screen.

    If i press ALT key means it appear in front.

    With out Alt key press, how can I display the child screen?

    Please Help me.
    Regards,

    SaraswathiSrinath

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    SetWindowPos function

    SetForegroundWindow function

    BringWindowToTop function

    ... or just specify your main window as a parent for your child.
    Best regards,
    Igor

  3. #3
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Thankyou MR.Igor. I refer these pages and come back.
    Regards,

    SaraswathiSrinath

  4. #4
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Hi,

    I tryed, but i don't know how to use correctly.

    Pls, find the attached project sample and clear me.
    Attached Files Attached Files
    Regards,

    SaraswathiSrinath

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    See the attach.

    Code:
    BOOL CDaveDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    
    
    	
    	//Cretae Bitmap Object
    	pDC=GetDC();
    	CompatibleDeviceContextHandle = CreateCompatibleDC(*pDC);
    	ReleaseDC(pDC);
    . . .
    Code:
    void CDaveDlg::OnPaint() 
    {
    	CPaintDC dc(this);
    
    	char Str[100] = "Refresh Rate:";
    . . .
    	BitBlt(dc, 0, 0, ClientWidth, ClientHeight, CompatibleDeviceContextHandle, 0, 0, SRCCOPY);
    Code:
    void CDaveDlg::OnBnClickedChildopen()
    {	
     	CChild1 cobj(this);
    	cobj.DoModal();
    }
    And please read about the changes on MSDN to avoid confusions in future.
    Attached Files Attached Files
    Last edited by Igor Vartanov; June 2nd, 2013 at 11:06 AM.
    Best regards,
    Igor

  6. #6
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Hi,

    I'm getting realtime data and plot that data in my main window continously (minimum one second once painting the data).

    At this time i opened any child window means, it won't appear. if i press ALT key means then it appear in front.

    The above attached zip code is a sample code only.

    you are changed this code. Now it painting when window moving. so the child window appear in front.

    But in my case, I'm draw the data contiously.

    pls clear me and give more details.
    Regards,

    SaraswathiSrinath

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Okay, I'll clear you.

    First of all, your app breaks all thinkable rules of GUI app. You think you draw data continuously, but in fact you draw without calling EndPaint, and this way you never let your window be aware of proper WM_PAINT handling. This causes WM_PAINT be sent again and again, which in it's turn results in 100% CPU load. You GetDC and never release it. You do calculations (potentially heavy ones in future) in WM_PAINT handler. This is not how decent GUI app behaves. Due to the WM_PAINT effect your app never makes it to redraw Client and Exit buttons once the window gets moved. Summarizing, your app is all mess. You really need to find some good book on Windows programming and work it through, from cover to cover. Besides, I would definitely recommend you to read something on good C programming styles.

    I've made some more changes to demonstrate how some of the issues could be solved by moving data processing to a worker thread. Please see the attachment.
    Attached Files Attached Files
    Best regards,
    Igor

  8. #8
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Now I cleared Little more, but not fully. Sure I will study the Window Programming books.

    Now, I'm useing the SetWindowPos method. It worked.

    I will release my GetDC like you tell in the above example.

    But, I don't know its working correct or not in real time data capture & plot (B'cos of my card Problem - Getting real time data) .
    I will check and tell you the feed back.

    Thank you Mr.Igor.
    Regards,

    SaraswathiSrinath

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Quote Originally Posted by saraswathisrinath View Post
    But, I don't know its working correct or not in real time data capture & plot (B'cos of my card Problem - Getting real time data)
    Have no idea about capture, but to be sure the plot is working alright you need to build and run my last project.
    Best regards,
    Igor

  10. #10
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Quote Originally Posted by Igor Vartanov View Post
    you need to build and run my last project.
    I run it. Its working good. You are indexing and plot the every line data which contains 1000 pixels (width of data) per line.

    So 256 line data, every line contains 1000 pixels.

    Indexing data like:
    Code:
    for (int y = 0; y < ClientHeight; y++)
    		{
    			Index = y * NumberOfBytesPerRow;  // 0,999,1998
    			for (int x = 0; x < ClientWidth; x++)
    			{
    				ImageData[Index] = (y + add) % ClientHeight;
    				Index = Index + 1;
    			}
    		}
    But in my project the ploting area is same. 1000*256 or 768*256.

    But I'm plot the data vertically. I'm getting 768 line data & every line contain 256 pixels.

    sample indexing data like:
    Code:
    for (int y = 0; y < width; y = y + 1)
    		{
    			iIndex = y + (width * height) - width;  //getting every line index vertically
    			for (int x = 0; x < height ; x = x + 1)
    			{ 
    				OfflineImageData[iIndex] = (byte)(*(pBitmapData + iIndex));
    				OfflineData[y][x] = OfflineImageData[iIndex];
    				iIndex = iIndex - width; //Indexing vertically
    			}
    		}
    and also in your code
    Code:
    NumberOfBytesPerRow = (ClientWidth + 3) & 0xFFFFFFFC; //Your code
    NumberOfBytesPerRow = (ClientHeight + 3) & 0xFFFFFFFC; // mine
    your getting NumberOfBytesPerRow = 1000 & I'm getting 256 only.

    If i release my dc and plot (786*256) the data means the image size is lessthan 786*256.

    please find the attachment ChildDlgToTop.rar in post #4.

    Hope you rectify where i held.

    Please clear me little much. Sorry for the late reply and also i never ignore your valuable comments.

    I take too much time to clear myself.
    Regards,

    SaraswathiSrinath

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,962

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Okay, indexing vertically:

    Code:
    DWORD CALLBACK UpdateWndThread(LPVOID pVoid)
    {
    	HWND hwnd = (HWND)pVoid;
    	while(1)
    	{
    		static int add = 0;
    		add += 1;
    		for (int y = 0; y < ClientWidth; y++)
    		{
    			int val = (y + add) % 256;
    			for (int x = 0; x < ClientHeight; x++)
    			{
    				ImageData[x * NumberOfBytesPerRow + y] = val;
    			}
    		} 
    
    		InvalidateRect(hwnd, NULL, FALSE);
    		Sleep(10);
    	}
    	return 0;
    }
    Besides, this is where you're wrong:
    NumberOfBytesPerRow = (ClientHeight + 3) & 0xFFFFFFFC; // mine
    It's kinda number of bytes per column, but number of bytes per row still remains
    NumberOfBytesPerRow = (ClientWidth + 3) & 0xFFFFFFFC; // Your code
    And please note that my sample was not about plotting data, but it's about organizing interaction between your worker thread and main GUI dialog. I don't care about how you plot your data, this business is all yours. What matters now is how you invoke your picture painting and handle device context.
    Attached Files Attached Files
    Last edited by Igor Vartanov; June 26th, 2013 at 04:40 PM.
    Best regards,
    Igor

  12. #12
    Join Date
    Nov 2011
    Location
    India
    Posts
    147

    Re: InvlidateRect() Doesn't Allow to Display My Child Screen in MFC?

    Quote Originally Posted by Igor Vartanov View Post
    but it's about organizing interaction between your worker thread and main GUI dialog.
    Its working. The worker thread & main GUI dialog interact correctly.

    But if i remove the worker thread & using timer means problem occured.

    Thanks Mr.Igor.
    Regards,

    SaraswathiSrinath

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center