none
Drawing on desktop background before background icons are drawn is difficult

    Question

  •  

    How can I do it in visual c++?

     

    I want to do it in vista and windows xp.

     

    Please help.

    Friday, August 03, 2007 5:18 AM

Answers

  •  doojin wrote:

    What if I want to display an animation on the desktop background?

    Changing background image file every frame is very inefficient.

     

    Oh! Animation. Why didn't you say so in the beginning ?

     

    Try this.

     

    Code Snippet

     

       #include <iostream>
       #include <windows.h>
      
       using namespace std;

      
       int main(int argc, char* argv[])  {
          HWND p  = FindWindow("ProgMan", NULL);
          HWND s = FindWindowEx(p, NULL, "SHELLDLL_DefView", NULL);
          HWND dtw  = FindWindowEx(s, NULL, "SysListView32", NULL);
          HDC hdc = GetDC(dtw);
          if(hdc != NULL) {
            TextOut(hdc, 10, 10, "hello world", 12);
          }
          else {
             cout<<"error"<<endl;

             return 0; 
          } 
                 
          RECT r = {0,  0, 100, 100};
          RedrawWindow(dtw, &r, NULL, RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW );
          ReleaseDC(dtw, hdc);
          return 0;
      }
     

     

     

    You need to have some icon in the top left corner to see the text being drawn under the icon.   

     

    In your animation loop you need to call RedrawWindow for each frame you draw.  Not sure if there will be any flicker. Best of luck.  :-)

    Sunday, August 05, 2007 3:28 PM

All replies

  • What do you mean by "before background icons are drawn"  ? 

     

    HDC hdc;

    hdc = CreateDC(L"DISPLAY", NULL, NULL, NULL);

    TextOut(hdc, 100, 100, L"hello world", 12);

     

    This will  draw to the desktop.  However, it will be lost when that part of the desktop is redrawn.  

    Friday, August 03, 2007 7:34 PM
  • You say you want to do it but you don't say what it is.

    Friday, August 03, 2007 10:54 PM
  •  

    I just want to draw whatever I want to draw on the desktop background, under the desktop icons.
    Sunday, August 05, 2007 6:31 AM
  •  doojin wrote:
    I just want to draw whatever I want to draw on the desktop background, under the desktop icons

     

    You can create an image file with whatever you want to draw to desktop background and call SystemParametersInfo to set that image file as desktop background.  Your drawing is in the background and the icons are on top. 

     

    Please see http://msdn2.microsoft.com/en-us/library/ms940383.aspx for description of SystemParametersInfo

     

    Regards

     

     Sahir Shah

     

    Sunday, August 05, 2007 7:05 AM
  • What if I want to display an animation on the desktop background?

    Changing background image file every frame is very inefficient.

    Sunday, August 05, 2007 7:20 AM
  •  Sahir Shah wrote:

    What do you mean by "before background icons are drawn"  ? 

     

    HDC hdc;

    hdc = CreateDC(L"DISPLAY", NULL, NULL, NULL);

    TextOut(hdc, 100, 100, L"hello world", 12);

     

    This will  draw to the desktop.  However, it will be lost when that part of the desktop is redrawn.  

     

    No...! It doesn't draw on the desktop background and under the desktop icons.

    Your code draws on the top of the screen!

    Sunday, August 05, 2007 8:16 AM
  • Unfortunately the world is not always as simple as we want it to be, and that is definitely true about the desktop. See Using the Active Desktop Object for one possible solution, but note that it is not supported by current versions and I don't know what if anything replaces it. If there is a replacement, it is probably part of the shell. so look at that documentation.

     

    It is possible to replace the shell, but that is a lot of work. I don't know anything more about that either except it should also be documented somewhere in the shell documentation.

    Sunday, August 05, 2007 8:20 AM
  • Sahir Shah did not say desktop background or under the desktop icons; Sahir Shah only said desktop. What is most important is that whatever is drawn will be drawn over.

     

    In the context of the desktop, there is not a clear definition of "screen". What you call screen is in this context what is technically refered to as the desktop.

     

    Such technical details are not important. What is important is that there is not an easy solution.

    Sunday, August 05, 2007 8:28 AM
  •  doojin wrote:

    No...! It doesn't draw on the desktop background and under the desktop icons.

    Your code draws on the top of the screen!

    Yes. I know that. I wasn't sure what your actual requirement was, hence the partial answer. 

    If you want to draw underneath the icons, the easiest way is creating an image and setting that image as the desktop background using the  SystemParametersInfo function.  Please see http://msdn2.microsoft.com/en-us/library/ms940383.aspx  for details.

     

    Sunday, August 05, 2007 10:08 AM
  •  doojin wrote:

    What if I want to display an animation on the desktop background?

    Changing background image file every frame is very inefficient.

     

    Oh! Animation. Why didn't you say so in the beginning ?

     

    Try this.

     

    Code Snippet

     

       #include <iostream>
       #include <windows.h>
      
       using namespace std;

      
       int main(int argc, char* argv[])  {
          HWND p  = FindWindow("ProgMan", NULL);
          HWND s = FindWindowEx(p, NULL, "SHELLDLL_DefView", NULL);
          HWND dtw  = FindWindowEx(s, NULL, "SysListView32", NULL);
          HDC hdc = GetDC(dtw);
          if(hdc != NULL) {
            TextOut(hdc, 10, 10, "hello world", 12);
          }
          else {
             cout<<"error"<<endl;

             return 0; 
          } 
                 
          RECT r = {0,  0, 100, 100};
          RedrawWindow(dtw, &r, NULL, RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW );
          ReleaseDC(dtw, hdc);
          return 0;
      }
     

     

     

    You need to have some icon in the top left corner to see the text being drawn under the icon.   

     

    In your animation loop you need to call RedrawWindow for each frame you draw.  Not sure if there will be any flicker. Best of luck.  :-)

    Sunday, August 05, 2007 3:28 PM
  •  Sahir Shah wrote:
    Oh! Animation. Why didn't you say so in the beginning ?

    Because we are supposed to be psychic so that people asking questions don't have to spend more time asking questions than we do answering questions.

    Sunday, August 05, 2007 7:27 PM