1

I have code to make a screenshot, but here is what my program produces:

screenshot with control program blocking some of the screen http://imageshack.us/a/img27/7387/71240043.png

My program's console pops up and gets in the way. This is a split-second pop-up as the program takes the screen shot the split-second you double-click it.

I did some searching for information for how to hide it, and found a forum with the following recommendation:

change the application type from "console" to "GUI application" in the target options (project properties -> tab "build targets").

But setting it to GUI application didn't get rid of the split-second console.

I tried looking for code to hide the console with, and found an example:

HWND hWnd = GetConsoleWindow();
ShowWindow( hWnd, SW_HIDE );

However, writing code to hide the console still has the console pop up and block the screenshot in the split second it appears.

What can I do to stop the console from appearing in that split second? I'm not bothered if the console is simply minimised, so long as it doesn't block the shot.

Community
  • 1
  • 1
user1433767
  • 645
  • 2
  • 6
  • 14

3 Answers3

3

I don't think just switching the type is enough, since you need to change the entry point form main to WinMain too. Look at this example of how to make a windowless application ( http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/82f506c4-ac1f-48c1-a5dc-51bfe99cf850 ), I'd suggest making a new Win32 project and then copying over the code you have.

Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71
  • Where would I get the current working directory from in API instance? – user1433767 Oct 30 '12 at 17:06
  • That doesn't really have anything to do with the question at hand, @User. You can use Google for that, or even [Stack Overflow's own search](http://stackoverflow.com/search?q=%5Bc%2B%2B%5D+current+working+directory+API). It would show you a previous question here: [How do I find the current directory?](http://stackoverflow.com/q/4807629/33732) – Rob Kennedy Oct 30 '12 at 17:54
1

Using Rudolf's suggestion, I did the research and can answer the question specifically:

Change int main() to int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd). (Correction) This will only work if the settings are graphical.

And to deal with the issue of not having access to int main's argc/argv options, use __argc and __argv, which is an external variable found in stdlib.h.

See also http://support.microsoft.com/kb/126571

ctype.h
  • 1,470
  • 4
  • 20
  • 34
user1433767
  • 645
  • 2
  • 6
  • 14
1

Hacky, but... after hiding the window you can delay long enough for that to take effect on-screen. Here I use C++11 (#include <thread> for this_thread and #include <chrono> for milliseconds) so you'd need to use VS2012 to use this exact code to delay.

HWND console = GetConsoleWindow();
if (!console)
    ; // handle error
BOOL was_visible = ShowWindow(console, SW_HIDE);

// delay for a fraction of a second...
std::this_thread::sleep_for(std::chrono::milliseconds(100));

// ... take screen shot

if (was_visible)
    ShowWindow(console, SW_SHOW);
bames53
  • 86,085
  • 15
  • 179
  • 244