Respond to this messageReturn to Index
Original Message
  • Re: response
    • (Login MCalkins)
      Moderator
      Posted Jul 2, 2012 6:32 AM

      Yes, the Windows version of QB64 creates 32 bit programs that will run on 32 or 64 bit Windows. They will run on XP and later, including Vista and "7". (It is possible to jump through hoops to get it to run on Windows 2000, but it won't do so by default.)

      forums:
      http://www.qb64.net/forum/

      version 0.954 (current at this time):
      http://www.qb64.net/forum/index.php?topic=6007.0

      I recommend the .7z file, because it is significantly smaller. You can get 7-zip here:
      http://www.7-zip.org/

      -----

      QBasic, as with other DOS programs, has no knowledge of running in a window. When it switches to Screen 12, all it knows is that it just told the BIOS to switch the VGA adapter from a text mode to a graphical mode. It has no knowledge of Windows.

      Meanwhile, Windows is running QBASIC in a virtual DOS machine, sees the request to switch the graphics mode, and decides to make the program full screen.

      -----

      Here is a C++ program that will call the Windows API's SetConsoleDisplayMode() function.

      http://msdn.microsoft.com/en-us/library/ms686028%28v=vs.85%29

      Note that it requires Windows XP or 2003. (Vista/"7" don't do fullscreen consoles.)

      conwfs.cpp --------------------------------

      // public domain, 2012 july, michael calkins
      // http://www.network54.com/Forum/648955/message/1341162659/

      #include <windows.h>
      // #include <stdio.h>

      // MinGW's wincon.h seems to be missing some things...

      #if !defined CONSOLE_FULLSCREEN_MODE
       #define CONSOLE_FULLSCREEN_MODE 1
      #endif
      #if !defined CONSOLE_WINDOWED_MODE
       #define CONSOLE_WINDOWED_MODE 2
      #endif
      #if !defined SetConsoleDisplayMode
       extern "C" { WINBASEAPI BOOL WINAPI SetConsoleDisplayMode(HANDLE hConsoleOutput, DWORD dwFlags, PCOORD lpNewScreenBufferDimensions); }
      #endif

      HANDLE hsb;
      SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), 0, 0};
      COORD d;

      int main(int argc, char * argv[]) {              // MinGW does not support wmain()

       hsb = CreateFileW( L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, & sa, OPEN_EXISTING, 0, 0);
       if (hsb == INVALID_HANDLE_VALUE) {
        // printf("CreateFileW failed. 0x%x\n", GetLastError());
        return 1;                                      // CreateFileW() failed.
       }
       if (argc < 2) return 2;                         // Missing command line parameter.

       switch (*argv[1]) {
        case '1':
         if (SetConsoleDisplayMode(hsb, CONSOLE_FULLSCREEN_MODE, & d)) return 0;
         break;
        case '2':
         if (SetConsoleDisplayMode(hsb, CONSOLE_WINDOWED_MODE, & d)) return 0;
         break;
        default:
         return 3;                                     // Invalid command line parameter.
       }
       // printf("SetConsoleDisplayMode failed. 0x%x\n", GetLastError());
       // seems to fail with 0x57 if you're already in that mode...
       return 4;                                       // SetConsoleDisplayMode() failed.
      }

      --------------------------------

      You'll need a C++ compiler with Windows headers to compile it. If you have QB64, then you can execute:

      internal\c\bin\g++ -s conwfs.cpp -o conwfs.exe

      where "internal" is a subfolder of the QB64 folder.

      I could upload the executable (12KB) to my website, but I am reluctant to do so without a good reason. I would prefer that you compile it from source, if possible.

      -----

      The program expects 1 parameter, of which it checks the first character:

      conwfs.exe 1
      to go to full screen.

      conwfs.exe 2
      to go to a window.

      The program returns exit codes that you can check from a .BAT file using echo %errorlevel%. A code of 0 means success. A code of 1 means it couldn't open "CONOUT$" using CreateFileW(). A code of 2 means you forgot the parameter. A code of 3 means the first character of the parameter was something other than "1" or "2". A code of 4 means the call to SetConsoleDisplayMode() failed. If you want to see the Windows error codes, uncomment the #include <stdio> and the two printf() lines.

      -----

      Here is a QBASIC 1.1 program that SHELLs to it to alternate modes every 3 seconds:

      DO
       SHELL "conwfs.exe 1" 'full screen
       ' WIDTH 80, 25
       SLEEP 3
       IF LEN(INKEY$) THEN EXIT DO
       SHELL "conwfs.exe 2" 'windowed
       SLEEP 3
      LOOP UNTIL LEN(INKEY$)
      SYSTEM

      -----

      Regards,
      Michael
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Options Also send responses to my email address