Results 1 to 15 of 15

Thread: Attempting to save current screen

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Attempting to save current screen

    Here is the code that I can not get to work to save the current screen and to restore it. What did I do incorretly?


    Code:
    HDC SaveScn;
    
    // other variables in code
    
    	 tx=GetSystemMetrics(SM_CXFULLSCREEN);
    	 ty=GetSystemMetrics(SM_CYFULLSCREEN);
    
    void SaveScreen()
    {
    HDC CurScn;
    
    	 // Save all graphics on screen
    	
    	 SaveScn = CreateCompatibleDC(0);
    	 CurScn = GetDC(OrghWnd);
         BitBlt(SaveScn, 0, 0, tx, tx+360, CurScn, 0, 0, SRCCOPY);
    	 ReleaseDC(OrghWnd,CurScn);
     	 GetKey(OrghWnd);
    }
    
    void RestoreScreen()
    {
    HDC CurScn;
    
    	 // Restore saved screen
    	
     	 CurScn = GetDC(OrghWnd);
    //     SelectObject(CurScn, SaveScn);
         BitBlt(CurScn, 0, 0, tx, ty+360, SaveScn, 0, 0, SRCCOPY);
     	 ReleaseDC(OrghWnd,CurScn);
    	 GetKey(OrghWnd);
    }
    Last edited by randem; Jul 10th, 2003 at 02:18 PM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Well, what is the problem (beside that it "doesn't work" )?

    You should pass a real DC to CreateCompatibleDC.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    Corned Bee,

    The problem may be my understanding of the DC. I get no errors but the if I call SaveScreen() then change the screen then call RestoreScreen()... nothing appears to happen.

    I would expect the old screen to reappear. I can load an image and put that to the screen (other code) but I can not save the current screen then restore it later with the posted code. Since I am not getting any errors I have to assume that it is a logic problem (me).

    I was hoping someone could shed some light on this (for it is dark in this tunnel).

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Why are you saving and restoring the whole screen? Is your app window cover everything?

    If you want to restore the desktop window and the windows in it, you may try the below,

    Code:
    RedrawWindow (NULL, NULL, NULL, RDW_ERASE+ RDW_INVALIDATE+ RDW_ALLCHILDREN+ RDW_ERASENOW);

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    |, not +
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    transcendental,

    I shall try this, I'll let you know and thanks Corned Bee for the correction. Now how does RedrawWindow know which window to redraw or does it just redraw the window that is active at the moment?

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by CornedBee
    |, not +
    Does the same thing in this case.

    Z.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Lucky then...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    And still... What is wrong with my posted code????

  10. #10
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Originally posted by randem
    transcendental,

    I shall try this, I'll let you know and thanks Corned Bee for the correction. Now how does RedrawWindow know which window to redraw or does it just redraw the window that is active at the moment?
    All the windows in the Desktop will be redrawn.

    Originally posted by CornedBee

    Lucky then...
    It is not a matter of luck. I know my C++ well.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I know, I do too. Actually it was bound to work in this case.

    Other matter if you accidentally write
    WS_OVERLAPPEDWINDOW + WS_POPUP

    randem: which, the saving code? Windows simply doesn't work that way. Every window is supposed to draw itself, not be drawn by someone else.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    CornedBee,

    Well, suppose I want to save a current window (unknown to what is in it) then paint it into another location or window etc... How would be the senario there?


    Save the windows data
    Paint the windows data elsewhere (another window or memory DC).
    Do something with it

    What is the best way for this?

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    That depends on what you actually want to do with the data. Screenshots work that way.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    Hey Guys,

    I placed the RedrawWindow function (as posted) in my WM_ACTIVATEAPP message section, it fires and my windows are not redrawn. I am switching between apps and want the windows to refresh when the program is selected again.

    There is no error in the RedrawWindow functions return.

    Any clue?
    Last edited by randem; Jul 14th, 2003 at 09:48 AM.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Try InvalidateRect to invalidate all windows, thus forcing redraw? Pass NULL as the RECT*.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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