home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / DTWLPAPR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.7 KB  |  57 lines

  1. /*
  2.     DTWLPAPR.C -- Sets the desktop wallpaper .BMP using SetDeskWallpaper
  3.  
  4.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC DTWLPAPR (for Borland C++ v3.00)
  8.                  WINIOMS DTWLPAPR (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h> 
  12. #include "winio.h" 
  13.  
  14. /* undocumented function */ 
  15. BOOL (FAR PASCAL *lpfnSetDeskWallPaper)(LPSTR lpszBmpFileName); 
  16.  
  17. int main() 
  18.     {
  19.     char bmpfilename[64]; 
  20.  
  21.     winio_about("DTWLPAPR"
  22.         "\nSets the desktop wallpaper .BMP using SetDeskWallpaper"
  23.         "\n\nFrom Chapter 6 of"
  24.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  25.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  26.         );
  27.     
  28.     // Get function address
  29.     lpfnSetDeskWallPaper =
  30.         GetProcAddress(GetModuleHandle("USER"), (LPSTR) (DWORD) 285);
  31.  
  32.     for (;;)
  33.         {
  34.         /* prompt for the filename */
  35.         puts("Enter name of .BMP file to use:");
  36.         gets(bmpfilename);
  37.         
  38.         /* break on empty filename */
  39.         if (bmpfilename[0] == 0)
  40.             break;
  41.         
  42.         /* otherwise call the SetDeskWallPaper function */
  43.         if ((*lpfnSetDeskWallPaper)(bmpfilename))
  44.             {
  45.             /* Save name of bitmap in WIN.INI */
  46.             WriteProfileString("Desktop", "Wallpaper", bmpfilename);
  47.             InvalidateRect(GetDesktopWindow(), NULL, TRUE);
  48.             puts("Desktop wallpaper successfully changed.\n");
  49.             }
  50.         else
  51.             puts("Could not change desktop wallpaper...\n");
  52.         }
  53.     
  54.     puts("Program terminated");
  55.     return 0;
  56.     }
  57.