home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / environ / setenv.c next >
C/C++ Source or Header  |  1988-08-10  |  1KB  |  45 lines

  1. /*
  2.  *  SetEnvironment
  3.  *  Setenv.c
  4.  *  
  5.  *  This program demonstrates the use of the function SetEnvironment.
  6.  *  This function copies the contents of the buffer specified by the second
  7.  *  parameter into the environment associated with the device attached to
  8.  *  the system port specified by the first parameter.
  9.  *
  10.  */
  11.  
  12. #include <windows.h>
  13. #include "setenv.h"
  14.  
  15. LPSTR far PASCAL lstrcpy( LPSTR, LPSTR );
  16.  
  17. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  18. HANDLE hInstance, hPrevInstance;
  19. LPSTR  lpszCmdLine;
  20. int    cmdShow;
  21. {
  22.   short nCopied;
  23.   DEVMODE devmode;
  24.  
  25.   lstrcpy ( (LPSTR) devmode.DeviceName, (LPSTR) "HP LaserJet Series II" );
  26.   devmode.orient = PORTRAIT;
  27.   devmode.cartridge = DEFAULT_CTG + CARTRIDGE;
  28.   devmode.paper = LETTER;
  29.  
  30.   MessageBox ( NULL, (LPSTR) "Setting environment", (LPSTR) "SetEnvironment",
  31.      MB_OK );
  32.  
  33.   nCopied = SetEnvironment ( (LPSTR) "LPT1:", (LPSTR) &devmode,
  34.      sizeof (DEVMODE) );
  35.  
  36.   if ( nCopied == 0 )
  37.      MessageBox (NULL, (LPSTR)"Environment not set!", (LPSTR)"SetEnvironment",
  38.         MB_OK|MB_ICONEXCLAMATION);
  39.   else
  40.      MessageBox (NULL, (LPSTR)"Environment set", (LPSTR)"SetEnvironment",
  41.         MB_OK);
  42.  
  43.   return 0;
  44. }
  45.