Thread: Create a Program with no window

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    16

    Create a Program with no window

    Hi,
    I'm trying to make a program that when it runs opens a file on an odd second and then writes to it, but I don't want the DOS like window to pop up when it starts. I figured out one way to prevent this from happening, but I think that it's probably slowing my program down a little. Right now I have it set up like a radc++ program but don't set up any forms. Is there a better way to prevent the window from opening? I'm using Dev C++ 5 and creating this program for a windows machine.
    Thanks,
    Blair

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    There are two ways of doing this off the top of my head.

    One is to create it as a "real" Windows application. You might be able to write it as a console application but just instruct your compiler to treat is as a Windows app, but that approach is not necessarily guarenteed to work AFAIK.

    Another option is to compile it as a console program and call FreeConsole() almost right away. This will throw away your console, but it will appear and be noticable, so it may not be what you want.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    With that "real" Windows applications you have 2 options:
    1. Don't create a window.
    2. Create a window but don't show it. (So your program still receives instructions from Windows like WM_CLOSE)
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    16
    Thats basically what I'm doing already with the rad c++ thing. But I'm thinking that by using the rad c++ it's slowing it down, so how would I create the window app without the window then? Code would be helpful as well.
    Thanks,
    Blair

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Making a windows app without window. Hint:
    Code:
    #include <windows.h>
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
        MessageBox(NULL, "No window. See?", "Blah", MB_OK);
        return 0;
    }
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    16
    Hey,
    That worked great! Made the file much smaller I think it's operating faster as well. Is there a way to make it so that this program will not change the cursor in any way? Since I want this program to start and end in the background of another program, it would be nice if this program does not change the cursor in any way. Like change it to the loading cursor. Is ther any way I can aviod that?
    Thanks,
    Blair

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I don't believe it's your program that is changing the cursor. That is probably Windows showing that you're starting a process if you're simply doubleclicking the .exe.

    How are you planning on starting this program in your live environment anyway?

  8. #8
    Registered User
    Join Date
    May 2007
    Posts
    16
    Another program will start it. But windows change the cursor is what I'd like to avoid. It's not a huge deal, but it would be nice if i could avoid that.
    Last edited by brconner; 05-27-2007 at 12:46 PM.

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I think you'll have to look into the first program that starts it. There is probably an option in CreateProcess() (or w/e API function used) to create it silently.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  3. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM