Windows API

This is a discussion on Windows API within the C++ Programming forums, part of the General Programming Boards category; Do I have to create a window in a Windows API application (with WinMain)? What if my application runs in ...

  1. #1
    Newbie Crilston's Avatar
    Join Date
    Jun 2005
    Location
    Montreal, Canada
    Posts
    8

    Windows API

    Do I have to create a window in a Windows API application (with WinMain)? What if my application runs in the background (a server)?

  2. #2
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    You can use the WinAPI functions while running the program in a standard console, that is, you don't need to make a window. If you want to run in background, you can use handles and then the ShowWindow() function to hide the console.

    You could have simply tried it, of course And this would have been better posted under Windows Programming, if I'm not mistaken.

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    windows application run on several windows subsystems: console, windows, posix, whatever
    http://msdn.microsoft.com/library/de...mplref_135.asp
    http://msdn.microsoft.com/library/de...locconsole.asp

    to run a application with main you have to specify subsystem console (it's the default to most compilers). To work with a gui, specify windows. With a gui, you can call AllocConsole() to create a console for your process.
    http://msdn.microsoft.com/library/de...locconsole.asp
    with a console app... itīs a bit harder to get rid of the console. I donīt know why

    where's a small example - of course this syntax for pragma coment is Ms specific. I don't know the gcc version. Never tried it

    A console app
    Code:
    #pragma comment(linker, "/SUBSYSTEM:CONSOLE")
    #include <iostream>
    
    int main(){
        std::cout<<"Hllo world!"<<std::endl;
        return 0;
    }
    a gui app
    Code:
    #pragma comment(linker, "/SUBSYSTEM:WINDOWS")
    #include <windows.h>
    int WinMain(HINSTANCE hc, HINSTANCE hp, LPSTR cmdln, int guicmd){
        MessageBox(GetDesktopHandle(),"hello world","hello world",0);
        return 0;
    }
    any process can run without any console or window.
    Of course to kill it you have to go to Task Manager

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. win32 api MDI windows
    By TheNewOne in forum Windows Programming
    Replies: 5
    Last Post: 03-20-2009, 10:11 PM
  2. Use windows API functions in a GTK+ program?
    By Jake.c in forum Windows Programming
    Replies: 19
    Last Post: 01-23-2009, 06:40 AM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. Windows messenger API
    By GanglyLamb in forum Windows Programming
    Replies: 0
    Last Post: 07-10-2005, 03:52 AM
  5. Future of Windows API programming ?
    By Dev in forum Windows Programming
    Replies: 7
    Last Post: 04-23-2003, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21