The static control only needs to invalidate its rect when we SetText.
[wine] / miscemu / main.c
1 /*
2  * Emulator initialisation code
3  *
4  */
5
6 #include <stdlib.h>
7 #include <assert.h>
8 #include "wine/winbase16.h"
9 #include "callback.h"
10 #include "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "thread.h"
16 #include "task.h"
17 #include "stackframe.h"
18 #include "wine/exception.h"
19 #include "debugtools.h"
20
21 static int MAIN_argc;
22 static char **MAIN_argv;
23
24 extern void DEBUG_StartDebugger(DWORD);
25
26 /***********************************************************************
27  *           Main loop of initial task
28  */
29 void MAIN_EmulatorRun( void )
30 {
31     char startProg[256], defProg[256];
32     int i, tasks = 0;
33     MSG msg;
34     BOOL err_msg = FALSE;
35
36     /* Load system DLLs into the initial process (and initialize them) */
37     if (   !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
38         || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
39         ExitProcess( 1 );
40
41     /* Get pointers to USER routines called by KERNEL */
42     THUNK_InitCallout();
43
44     /* Call FinalUserInit routine */
45     Callout.FinalUserInit16();
46
47     /* Call InitApp for initial task */
48     Callout.InitApp16( MapHModuleLS( 0 ) );
49
50     /* Add the Default Program if no program on the command line */
51     if (!MAIN_argv[1])
52     {
53         PROFILE_GetWineIniString( "programs", "Default", "",
54                                   defProg, sizeof(defProg) );
55         if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
56     }
57     
58     /* Add the Startup Program to the run list */
59     PROFILE_GetWineIniString( "programs", "Startup", "", 
60                                startProg, sizeof(startProg) );
61     if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
62
63     /* Abort if no executable on command line */
64     if (MAIN_argc <= 1) 
65     {
66         MAIN_Usage(MAIN_argv[0]);
67         ExitProcess( 1 );
68     }
69
70     /* Load and run executables given on command line */
71     for (i = 1; i < MAIN_argc; i++)
72     {
73         PROCESS_INFORMATION info;
74         STARTUPINFOA startup;
75
76         memset(&startup, 0, sizeof(startup));
77         startup.cb = sizeof(startup);
78         startup.dwFlags = STARTF_USESHOWWINDOW;
79         startup.wShowWindow = SW_SHOWNORMAL;
80         
81         if (!CreateProcessA(NULL, MAIN_argv[i], NULL, NULL, FALSE, 0,
82                             NULL, NULL, &startup, &info)) {
83             err_msg = TRUE;
84             MESSAGE("wine: can't exec '%s': ", MAIN_argv[i]);
85             switch (GetLastError()) 
86             {
87             case  2: MESSAGE("file not found\n" ); break;
88             case 11: MESSAGE("invalid exe file\n" ); break;
89             default: MESSAGE("error=%ld\n", GetLastError() ); break;
90             }
91         }
92         else 
93         {
94            tasks++;
95            /* hack until wine debugger can be moved to a separate process */
96            DEBUG_StartDebugger(info.dwProcessId);
97         }
98     }
99
100     if (!tasks)
101     {
102         if (!err_msg) MESSAGE("wine: no executable file found.\n" );
103         ExitProcess( 0 );
104     }
105
106     /* Start message loop for desktop window */
107
108     while ( GetNumTasks16() > 1  && Callout.GetMessageA( &msg, 0, 0, 0 ) )
109     {
110         Callout.TranslateMessage( &msg );
111         Callout.DispatchMessageA( &msg );
112     }
113
114     ExitProcess( 0 );
115 }
116
117
118 /**********************************************************************
119  *           main
120  */
121 int main( int argc, char *argv[] )
122 {
123     NE_MODULE *pModule;
124
125     /* Initialize everything */
126     if (!MAIN_MainInit( &argc, argv, FALSE )) return 1;
127     MAIN_argc = argc; MAIN_argv = argv;
128
129     /* Create initial task */
130     if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
131     if ( !TASK_Create( pModule, FALSE ) ) return 1;
132
133     /* Switch to initial task */
134     PostEvent16( PROCESS_Current()->task );
135     TASK_Reschedule();
136
137     /* Switch stacks and jump to MAIN_EmulatorRun */
138     CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
139
140     MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );
141     return 0;
142 }