473,804 Members | 3,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'Gui-less' windows executable

I want to create a GUI-less windows executable (i.e. an executable that
has no gui) and no console. The idea is to have this running as a kind
of daemon (it can't be a service, for reasons I wont go into here ..).

I can't seem to find any code that shows how to do this which is
probably not suprising since Windows is essentially GUI oriented.

One possible hack is to go to the trouble of creating a window and then
making it invisible, but that seems aterrible waste of resources - is
there a cleaner way to do this?

Apr 19 '06 #1
11 1755
You have to have at least one window somewhere, so that Windows can process
messages sent to your application by the system.

However, in Windows 2000 and later, you can make this window a message-only
window. A message-only window has no UI, but can send and receive messages.

You create a message-only window by calling CreateWindowEx and passing in
the value HWND_MESSAGE for the hWndParent parameter.

Sean
"Bit byte" wrote:
I want to create a GUI-less windows executable (i.e. an executable that
has no gui) and no console. The idea is to have this running as a kind
of daemon (it can't be a service, for reasons I wont go into here ..).

I can't seem to find any code that shows how to do this which is
probably not suprising since Windows is essentially GUI oriented.

One possible hack is to go to the trouble of creating a window and then
making it invisible, but that seems aterrible waste of resources - is
there a cleaner way to do this?

Apr 19 '06 #2

"Sean M. DonCarlos" <se********@new sgroups.nospam> escreveu na mensagem
news:FA******** *************** ***********@mic rosoft.com...
You have to have at least one window somewhere, so that Windows can
process
messages sent to your application by the system.
There is no need to create a window if you don't need a message loop...
However, in Windows 2000 and later, you can make this window a
message-only
window. A message-only window has no UI, but can send and receive
messages.

You create a message-only window by calling CreateWindowEx and passing in
the value HWND_MESSAGE for the hWndParent parameter.

Great tip! Thanks!
Sean

"Bit byte" wrote:
I want to create a GUI-less windows executable (i.e. an executable that
has no gui) and no console. The idea is to have this running as a kind
of daemon (it can't be a service, for reasons I wont go into here ..).


[]s
Fred
Apr 19 '06 #3

"Bit byte" <fl**@flop.co m> escreveu na mensagem
news:se******** ************@bt .com...
I want to create a GUI-less windows executable (i.e. an executable that has
no gui) and no console. The idea is to have this running as a kind of
daemon (it can't be a service, for reasons I wont go into here ..).

I can't seem to find any code that shows how to do this which is probably
not suprising since Windows is essentially GUI oriented.

One possible hack is to go to the trouble of creating a window and then
making it invisible, but that seems aterrible waste of resources - is
there a cleaner way to do this?


It's perfectly possible to write non console applications GUIless.... just
don't create any window!

There are some problems, f.i:: Timer will not work properly, because it
needs a message loop;

-----------%<------------%<----------
#define WIN32_LEAN_AND_ MEAN
#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
/* Example: Write a text file */
FILE *f;

f = fopen("test.txt ", "w");
fprintf(f, "Hello\n");
fclose(f);

return 0;
}

-----------%<------------%<----------

[]s
Fred
Apr 19 '06 #4

"Frederico Pissarra" <me@nowhere.net > wrote in message
news:ux******** ******@TK2MSFTN GP05.phx.gbl...

It's perfectly possible to write non console applications GUIless.... just
don't create any window!


Here is another way, but it is more complicated. You can use the
FreeConsole() API. But then you have to write some kind of controller
program that starts the server with CreateProcess() and communicates with
that process through some IPC mechanism to shut it down or send other
commands.

Apr 19 '06 #5

Bit byte wrote:
I want to create a GUI-less windows executable (i.e. an executable that
has no gui) and no console. The idea is to have this running as a kind
of daemon (it can't be a service, for reasons I wont go into here ..).

I can't seem to find any code that shows how to do this which is
probably not suprising since Windows is essentially GUI oriented.

One possible hack is to go to the trouble of creating a window and then
making it invisible, but that seems aterrible waste of resources - is
there a cleaner way to do this?


Create a GUI subsystem app (ie, one where the start function is
WinMain. With Visual C++, you create such an exe by using the flag
"/subsystem:windo ws" for the linker).

Simply do NOT create any window in WinMain : just put your processing
stuff here.

Arnaud
MVP - VC

Apr 19 '06 #6
"Bit byte" <fl**@flop.co m> wrote in message
news:se******** ************@bt .com...
I want to create a GUI-less windows executable (i.e. an executable that has
no gui) and no console. The idea is to have this running as a kind of
daemon (it can't be a service, for reasons I wont go into here ..).


As others have mentioned, an option is simply to create a windowed
application (check teh docs for WinMain) and simply choose to create no
windows.

Alternatively, you can create a console application - it's useful to have a
console for debugging - and then to create the process that runs it with
CreateProcess() with the DETACHED_PROCES S or CREATE_NO_WINDO W flag. Check
the docs for the details.

Regards,
Will
Apr 19 '06 #7
> > You have to have at least one window somewhere, so that Windows can
process messages sent to your application by the system.


There is no need to create a window if you don't need a message loop...


Perhaps I should make sure to wake up fully before answering posts! :)

Yes, if you don't need a message loop, then you don't need a window. Thanks
for catching my mistake, Fred.

Sean
Apr 19 '06 #8


William DePalo [MVP VC++] wrote:
"Bit byte" <fl**@flop.co m> wrote in message
news:se******** ************@bt .com...
I want to create a GUI-less windows executable (i.e. an executable that has
no gui) and no console. The idea is to have this running as a kind of
daemon (it can't be a service, for reasons I wont go into here ..).

As others have mentioned, an option is simply to create a windowed
application (check teh docs for WinMain) and simply choose to create no
windows.

Alternatively, you can create a console application - it's useful to have a
console for debugging - and then to create the process that runs it with
CreateProcess() with the DETACHED_PROCES S or CREATE_NO_WINDO W flag. Check
the docs for the details.

Regards,
Will

Hi Will,

I like your approach the best. I have looked up the docu (and searched
Google), but all examples so far seem generic and not specific to the
scenario I described here. Could you please provide me with a 'boiler
plate' sample that I can start from.

This could be as simple as :

//Parent
int main(int argc, char* argv[]){
CreateProcess(/*RequiredParams */); //It would be very useful if you
could show the parent passing some data to the child
}
//child
int main(int argc, char* argv[]){
fprintf(fp,"I was started succesfully\n") ;
return ;
}
Thanks

Apr 20 '06 #9
"Bit byte" <fl**@flop.co m> wrote in message
news:uI******** ************@bt .com...
I like your approach the best.
:-)
I have looked up the docu (and searched Google), but all examples so far
seem generic and not specific to the scenario I described here. Could you
please provide me with a 'boiler plate' sample that I can start from.


OK. This example starts the built-in messenger application to pop-up a
message box on the workstation where the user "william" is logged in

char szDir[MAX_PATH + 1];
STARTUPINFO si = { 0 };
PROCESS_INFORMA TION pi = { 0 };

GetSystemDirect ory(szDir, MAX_PATH);

si.cb = sizeof(si);

if ( CreateProcess(" c:\\windows\\sy stem32\\cmd.exe ", // executable
"/C net send william hello", //
arguments
NULL, NULL, FALSE,
NORMAL_PRIORITY _CLASS | CREATE_NO_WINDO W,
NULL,
szDir,
// default directory
&si,
&pi) )
{
// Don't leak handles

CloseHandle(pi. hProcess);
CloseHandle(pi. hThread);
}

My quick hack is an ANSI application. In a UNICODE build, you'd be better
off not using string literals but rather wide-character string buffers
because (at least one of ) the parameters need to be writable.

Regards,
Will
Apr 20 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

50
5537
by: Edward K. Ream | last post by:
I would like to say a few (actually more than a few) words here about some recent discoveries I have made concerning the interaction of Leo and Python. If you don't want to hear an inventor enthuse about his work, please feel free not to read further :-) There are at least three, no four, no five, no six, no seven reasons why Leo and Python work so well together. Most are new (in my mind) with the 4.1 release of Leo. The first several...
0
1477
by: BW | last post by:
Please ignore the rest of the code, except for the highlighted part (or the line 'ent1=Entry(topf, width=25)' to line 'ent1.insert(INSERT, wrong, if you cannot see the color). You can copy this into Python and make sure you have the GIF file in the same dir. Also, make sure that you have PIL installed. I cannot get this to work. I get an error after running it and what I'm trying to do it to evaluate what the person enters in the box for the...
1
3274
by: MM | last post by:
Hi, First off, I'm just beginning .NET and GUI stuff and am very inexperienced. I have worked through a number of GUI tuts in books but all the GUI code to handle events for all the controls in these examples is always in the single file of the main form. What is the correct way to 'sub-divide' various GUI sections into differnet files? For instance, with all my anticipated controls, this one file would be hundreds if not thousands of...
4
2385
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for my own tool (http://openswarm.sourceforge.net). I already started restructuring my code to separate the actual command implementations from the command-line scripts (which is optparser-based now) and have some ideas how to proceed. But probably...
59
2536
by: Kevin Walzer | last post by:
From the introduction to PyObjC, the Python-Objective-C bridge on Mac OS X: "As described in Objective-C for PyObjC users the creation of Objective-C objects is a two-stage process. To initialize objects, first call a class method to allocate the memory (typically alloc), and then call an initializer (typically starts with init). Some classes have class methods which perform this behind the scenes, especially classes that create cached,...
31
2485
by: sdoty044 | last post by:
Just wondering on what peoples opinions are of the GUIs avaiable for Python? All I am doing is prompting users for some data (listbox, radio buttons, text box, ect...). Then I will have some text output, maybe a scrolling text message as things are happening. I have some minor things I need to do, for example, if Checkbutton X is clicked, I need to disable TextBox Y, and I would like to display the scrolling text (output)
4
3086
by: Perl Beginner | last post by:
I have created a GUI window using Perl Win32::XMLBuilder. This window has several buttons on it, that when a button is clicked another Perl script will execute. When the script is complete, the GUI window is still open and another button can be clicked to execute another Perl script. However, after the first Perl script executes, when I go back to the GUI, the font on my labels goes all wackey and also when I click a button to run a second ...
46
2140
by: Chris Stewart | last post by:
I've always had an interest in Python and would like to dabble in it further. I've worked on a few very small command line programs but nothing of any complexity. I'd like to build a really simple GUI app that will work across Mac, Windows, and Linux. How painful is that going to be? I used to be really familiar with Java Swing a few years ago. I imagine it will be similar. Next, what would you say is the best framework I should...
0
178
by: Marc 'BlackJack' Rintsch | last post by:
On Fri, 23 May 2008 07:14:08 -0400, inhahe wrote: The logic part has the rules how you may move the pieces. The GUI shouldn't have to know how a knight, bishop, or queen can move or what castling is. No it isn't! The size is independent from the GUI. Most 2D strategy games have maps that are way large than the GUI displays at once. You
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9569
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.