|
Hello,
I'm making an application, that should use console, when started from a command line and windows otherwise. It has to work in UNIX too, so it must have main().
The way I've done it, works, but I'm not satisfied with it. When I start it from a command line it works properly, but when starting it as GUI it makes a console window first and then GUI. I would like to get rid of the console in GUI version. I've tried to make console disappear using FreeConsole(), but even though I use it as early as possible the console flashes in the beginning. The other solution I've tried is to use linker options '/entry:"main" /subsystem:windows'. This works fine with GUI, but the console version doesn't do anything.
I hope someone knows a better way to do it.
-Janetta
|
|
|
|
|
I think that the console creation is perfomed during the C library initialization that is performed by mainCRTStartup before your main function is called. You can found mainCRTStartup code into CRT0.C under /crt/src subdir of VC++ installation (if you installed the C library source code, of course).
I never tried to remove the window (I looked at this code only to reduce the size of executables) but you can check the routines called during program startup.
There's a good article about C library initialization by Matt Pietrek:
http://www.microsoft.com/msj/defaulttop.asp?page=/msj/archive/s569.htm
It explain how to reduce executable size but I think it could be helpful also for your pourpouses.
Good luck
--
Looking for a new screen-saver?
Try FOYD:
http://digilander.iol.it/FOYD
|
|
|
|
|
Basically, you're screwed. Seriously.
The only way to get the stdio handles connected to the console starting the app is by having a main() and the app "tagged" as a console app by the PE flags (linker option /subsystem:console). This is one parts of the baggage we carry from Win16.
The default behaviour for a console app to be started is that Windows (I don't know if its the module loader, but I guess it is) allocates a console for a console-tagged app. The only way I know about to change this is to change the flags passed to CreateProcess (to inhibit the creation of the console window). When you have an app that is started by another process (such as Explorer.exe when double-clocking an executable) I can only come to think of hooking (system-wide, loading your DLL for every created process and changing the import translation table) the CreateProcess call to stop it from doing this on a per-application basis.
As I initially wrote, you're basically screwed. Sorry...
|
|
|
|
|
Thanks for both of you for your advice. I haven't found a solution yet, but I'll keep on fighting
-Janetta
|
|
|
|
|
how to change the stock backcolor property of ocx to window background color by default.. i changed it.. it works but the property browser in vb shows application backcolor under systems Tab... for ex. if vb form background is windowtitle... control shows windowtitle in the property browser... but i am getting the correct color in the control....
now my questiong is how to set windowback ground color as default color in my control?
|
|
|
|
|
Hi there, how do I have my application just to run single instance of it. er....eg. Restore the previous instance of the app and then exits.
|
|
|
|
|
When the app starts up, do a check for a mutex. if it doesn't exist create one, and if not then find the existing app and restore it..
something like:
CString strMutexName = _T("MyApp"); // can also use a GUID here
if (!m_hMutex) {
m_hMutex = CreateMutex(NULL, FALSE, strMutexName);
} else {
/* go through all the current windows and restore the existing version of your app. i can't remember how to do this now.. something to do with EnumWindow i'm sure, just don't use FindWindow (heard bad things about it ). */
}
hope this helps.
|
|
|
|
|
|
Using mutex is one way to do so, see MSKB: Q243953
|
|
|
|
|
Look at CSingleInstance in http://www.codeproject.com/library/pj.asp and the other related articles in the "Threads Processes & IPC" section.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
sometimes its nice to pass off the command line from the second
instance to the first. I usually do this with a control struct
in shared memory. First instance creates the control struct and
records its information there. Other instances, read the control
struct and record their command line there, then activate the
first instance, and notify it that their command line has been
recorded before exiting. The first instance handles these as
appropriate, perhaps opening another file, etc.
|
|
|
|
|
Hi all,
Here is a small description of my project:
Users shall be able to send print jobs to a print server. On the print server, the print jobs arrived shallt be managed.
My question/problem:
I need to find a way to restrain a print job from being automatically printed when it arrives to the print server. I am thinking about using “FindFirstPrinterNotification” and “FindNextPrinterNotification” to catch “PRINTER_CHANGE_ADD_JOB” and then immediately ask the print job to delete. Is this the correct approach?
Thank you,
zhu xiao yun
c++
|
|
|
|
|
Hello,
I am using OpenDocument in the Doc class to Load in a DIB. The Load function is in a Dib class I made. After I get this DIB, I want to draw it. I need to call the OnDraw function in the View class to call teh DIb class' Draw function.
I do not know how to send a message from the Doc class to the Load class, saying, "hey, we loaded a DIB, now Draw it"
Can someone please help me out?
Thanks
NickOne
|
|
|
|
|
|
im trying to open a file that is on a web server how can i do it?, i did this but it fails
CFile Arch;
Arch.Open("www.mypage/file.zip",CFile::modeRead);
|
|
|
|
|
use CHttpFile which can fetch files from the web
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Hey all.
I'm not a newbie to Windows programming or multi-threading, but I've been wondering: how exactly does the implementation of ::MessageBox(...) work?
I have a simple single-threaded application.
I call ::MessageBox(...) somewhere in the code. The message box APPEARS to be blocking the code execution, since the line after the "::MessageBox(...)" will only be executed after the message box is dismissed. However, my single-threaded application is still processing messages!
How is this magic performed behind the scenes?
Thanks!
|
|
|
|
|
Probably because your message loop continues to process messages such as WM_PAINT.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Actually, Cristian (and correct me if im wrong) but i dont see how yr message loop can be working if yr appliaction has called message box...
I think this is VERY good question for beginners like us.
Im sure that messagebox domodal, etc. call a hoorrible nasty "PeekAndPump" type MS fudge.
Any corrections?
Dave Carkeet.
|
|
|
|
|
David Carkeet wrote:
Im sure that messagebox domodal, etc. call a hoorrible nasty "PeekAndPump" type MS fudge.
Actually, from memory it sets a flag for the app so that the window stops responding, but the message pump keeps right on pumping. I think Nish said something similar, he may know more about it than I do.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
MessageBox is just a function which displays a particular dialog box, which a few bells and whistles.
From the documentation of ::DialogBox () in the Platform SDK:
"The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box."
So, the function has its own message loop. It will also retrieve messages for the rest of your application
(e.g. WM_PAINT) and dispatch them to the appropriate handler. The MFC glue routes it eventually to your
routine (such as CView::OnDraw (...)).
Enlightened?
Iain.
|
|
|
|
|
I think it creates a mode dialog,and show it by DoModal(),so only if you
press OK or Cancel,the following codes will be executed.
Cheers
|
|
|
|
|
When a MessageBox is invoked, the parent window is disabled. Thus it cannot take mouse clicks or keyboard hits, BUT it can handle all messages sent or posted to it directly like the paint messages. When the MessageBox is dismissed the parent window is re-enabled!
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Hi.
I would like to switch the style of two buttons to/from default. For example, initial ButtonA is the default button. As the user selects an option in a dialog box, ButtonB becomes the default button and buttonA becomes a normal button.
I try changing the style of buttonB via SetStyle(BS_DEFBUTTON), however, that solution only highlights buttonB as though it is default. Nothing happens when I push Enter. When I push, Windows sends a message that buttonA is pushed. I set buttonA to default via Properties.
Do you have to set the current default button to something else before setting another button to default?
Thanks,
Kuphry
|
|
|
|
|