Create_Set.cpp
Upload User: dq031136
Upload Date: 2022-08-08
Package Size: 802k
Code Size: 3k
Development Platform:

C++ Builder

  1. #include <genstub.c>
  2. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3. {
  4.    switch (uMsg)
  5.    {
  6.          case WM_CREATE:  // Set current directory to value passed on command line.
  7.          {
  8.                char   szMessage[MAX_PATH + 31];
  9.                char   szCommandLine[MAX_PATH + 1];
  10.                LPTSTR lpToken = NULL;
  11.                LPTSTR lpszDirName = NULL;
  12.                DWORD  dwcCurDir = MAX_PATH;
  13.                lstrcpy( szCommandLine, GetCommandLine() );
  14.                // Search for extra input after program name.
  15.                if ( ( lpToken = strstr( szCommandLine, " " ) ) )
  16.                {
  17.                   // Get first argument by itself, if there is one.
  18.                   lpszDirName = strtok( lpToken, " " );
  19.                   if ( lpszDirName )
  20.                   {
  21.                      // Use lpTemp pointer to isolate 1st arg.
  22.                      LPTSTR lpTemp = strstr(lpszDirName, " ");
  23.                      if (lpTemp)
  24.                         *lpTemp = 0;
  25.                      // Attempt to change the current directory.
  26.                      if ( !SetCurrentDirectory(lpszDirName) )
  27.                         wsprintf( szMessage,
  28.                                   "Cannot set current directory to [%s]",
  29.                                   lpszDirName );
  30.                      else
  31.                         wsprintf( szMessage, "Set current directory to [%s]",
  32.                                   lpszDirName );
  33.                      // Report result of operation.
  34.                      MessageBox( hWnd, szMessage,
  35.                                  "Result of SetCurrentDirectory()", MB_OK );
  36.                   }
  37.                }
  38.          }
  39.          return DefWindowProc( hWnd, uMsg, wParam, lParam );
  40.          case WM_COMMAND:
  41.                switch ( LOWORD( wParam ) )
  42.                {
  43.                      case IDM_TEST:
  44.                      {
  45.                            char szBuffer[MAX_PATH + 1];
  46.                            DWORD dwcNameSize = MAX_PATH + 1;
  47.                            // Now query the system for the paths.
  48.                            GetCurrentDirectory( dwcNameSize, &szBuffer );
  49.                            MessageBox( hWnd, szBuffer, "Current Directory", MB_OK );
  50.                      }
  51.                      break;
  52.                      case IDM_EXIT:
  53.                            DestroyWindow( hWnd );
  54.                            break;
  55.                }
  56.                break;
  57.          case WM_DESTROY:
  58.                PostQuitMessage( 0 );
  59.                break;
  60.          default:
  61.                return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  62.    }
  63.    return (NULL);
  64. }