Bug 1241633 - Make screenshot.exe a GUI application to avoid a console window when run. r=ted draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 21 Jan 2016 13:33:37 -0800
changeset 324052 1e94593c3f6f3fed44a4c1a4b0eb137a622cdb18
parent 324022 1292ce950e07d6d0f2a2cb16c6dda930ed176668
child 324099 52d9e2fe3402958fd5ef17d29463f5cf3bc1f720
push id9839
push usermozilla@noorenberghe.ca
push dateThu, 21 Jan 2016 21:35:11 +0000
reviewersted
bugs1241633
milestone46.0a1
Bug 1241633 - Make screenshot.exe a GUI application to avoid a console window when run. r=ted
testing/tools/screenshot/win32-screenshot.cpp
--- a/testing/tools/screenshot/win32-screenshot.cpp
+++ b/testing/tools/screenshot/win32-screenshot.cpp
@@ -23,28 +23,32 @@
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * Contributors:
  *   Ted Mielczarek <ted.mielczarek@gmail.com>
  */
 /*
- * screenshot.cpp : Save a screenshot of the Windows desktop in .png format.
+ * win32-screenshot.cpp: Save a screenshot of the Windows desktop in .png format.
  *  If a filename is specified as the first argument on the commandline,
  *  then the image will be saved to that filename. Otherwise, the image will
  *  be saved as "screenshot.png" in the current working directory.
  */
 
  // VS2015: Platform SDK 8.1's GdiplusTypes.h uses the min macro
 #undef NOMINMAX
 #undef WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <gdiplus.h>
 
+// Link w/ subsystem windows so we don't get a console when executing
+// this binary.
+#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:wmainCRTStartup")
+
 using namespace Gdiplus;
 
 // From http://msdn.microsoft.com/en-us/library/ms533843%28VS.85%29.aspx
 static int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
 {
   UINT  num = 0;          // number of image encoders
   UINT  size = 0;         // size of the image encoder array in bytes
 
@@ -62,17 +66,17 @@ static int GetEncoderClsid(const WCHAR* 
 
   for(UINT j = 0; j < num; ++j)
     {
       if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
         {
           *pClsid = pImageCodecInfo[j].Clsid;
           free(pImageCodecInfo);
           return j;  // Success
-        }    
+        }
     }
 
   free(pImageCodecInfo);
   return -1;  // Failure
 }
 
 #ifdef __MINGW32__
 extern "C"
@@ -97,16 +101,16 @@ int wmain(int argc, wchar_t** argv)
   Bitmap* b = Bitmap::FromHBITMAP(mybmp, nullptr);
   CLSID  encoderClsid;
   Status stat = GenericError;
   if (b && GetEncoderClsid(L"image/png", &encoderClsid) != -1) {
     stat = b->Save(filename, &encoderClsid, nullptr);
   }
   if (b)
     delete b;
-  
+
   // cleanup
   GdiplusShutdown(gdiplusToken);
   ReleaseDC(desktop, desktopdc);
   DeleteObject(mybmp);
   DeleteDC(mydc);
   return stat == Ok ? 0 : 1;
 }