Bug 1241633 - Make screenshot.exe a GUI application to avoid a console window when run. r=ted
--- 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;
}