Visual C++ 6.x and Windows Vista

Posted on 2008-11-10
Last Modified: 2012-05-05

I made an application in Visual C++ 6.0.

I want this application to hide its window when it's running;  i'm using the following command to do this:

ShowWindow(GetForeGroundWindow(), SW_HIDE)

This instruction works perfectly on Windows XP, but on Windows Vista sometimes it works, sometimes don't...

What can i do?


Question by:kalvillo
    LVL 30

    Expert Comment

    Hi kalvillo,

    it's not sure that 'GetForeGroundWindow' returns your application's window - see MSDN about it: 'The foreground window can be NULL in certain circumstances, such as when a window is losing activation.'

    What kind of application is it? Isn't there another way to get access to the window (I think there must be one since you create the window - easiest could be to unset the style 'WS_VISIBLE' at creation)

    Hope that helps,

    LVL 2

    Expert Comment

    If you are attempting to hide the window from within the window class that must be hidden, change to:
    The SetForeGroundWindow() instruction is attempting to put your window in the foreground which I dont think you want to do within the same instruction.

    Author Comment

    Here is the thing...

    I'm trying to make a server application, this application needs to be in the background to "listen" the port 80 and serve all the client applications.

    We tried all the expert suggestions but none of them worked (except using MFC, but it's too late to use it right now).

    This server application runs on a MS-DOS window-like, and we need to hide it (the main reason is that we don't want that the final user closes it accidentally and disrupt the functionallity of all the clients).

    Using the instruction

    HWND ghWnd = GetForegroundWindow

    works perfectly on WinXP, but on Vista sometimes works, sometimes doesn't.

    We debbuged it and never returns NULL, but i don't know if this result is provided by another window and not that of my server application...

    Is there another way to solve this problem? is there another instruction to surely detect the handler of my window and hide it and not another?

    Thank you
    LVL 2

    Accepted Solution

    Look at the CreateProcess API in MSDN. Specifically the Process Creation Flags.
    My feeling is that you should be writing a proper service.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now