2 * console.c -- simple windows console emulator for Winsock testing
3 * 27 June 1993 by Mark C Smith
10 static char *argv[] = { "console", "rearwindow", 0 }; /* */
14 HWND hWndMain, hWndOutputEdit;
17 int reg_classes( void );
18 void unreg_classes( void );
23 WinMain( HANDLE hInstance, HANDLE hPrevInst, LPSTR lpszCmdLine, int nCmdShow)
28 strcpy( szAppName, "console");
32 if (( rc = reg_classes()) != 0 ) {
33 MessageBox(0, "Couldn't register window classes", NULL, MB_ICONEXCLAMATION);
38 hWndMain = CreateWindow(
39 szAppName, /* Window class name */
40 "Console", /* Window's title */
41 WS_CAPTION | /* Title and Min/Max */
42 WS_SYSMENU | /* Add system menu box */
43 WS_MINIMIZEBOX | /* Add minimize box */
44 WS_MAXIMIZEBOX | /* Add maximize box */
45 WS_THICKFRAME | /* thick sizeable frame */
46 WS_CLIPCHILDREN | /* don't draw in child windows areas */
48 CW_USEDEFAULT, 0, /* Use default X, Y */
49 CW_USEDEFAULT, 0, /* Use default X, Y */
50 0, /* Parent window's handle */
51 0, /* Default to Class Menu */
52 hInst, /* Instance of window */
53 NULL ); /* Create struct for WM_CREATE */
56 MessageBox( 0, "Couldn't create main window", NULL, MB_ICONEXCLAMATION);
60 ShowWindow( hWndMain, nCmdShow );
62 hAccel = LoadAccelerators( hInst, szAppName );
64 if (( hWndOutputEdit = new_editwindow( hWndMain, "console output" )) == NULL ) {
65 MessageBox( 0, "Couldn't create output window", NULL, MB_ICONEXCLAMATION);
69 while( GetMessage( &msg, 0, 0, 0 )) {
70 if( TranslateAccelerator( hWndMain, hAccel, &msg )) {
74 TranslateMessage(&msg);
75 DispatchMessage(&msg);
83 WndProc( HWND hWnd, WORD msg, WORD wParam, LONG lParam )
100 return( DefWindowProc( hWnd, msg, wParam, lParam ));
113 memset( &ps, 0x00, sizeof( PAINTSTRUCT ));
114 hDC = BeginPaint( hWnd, &ps );
115 SetBkMode(hDC, TRANSPARENT);
122 if ( hWnd == hWndMain ) {
123 PostQuitMessage( 0 );
128 return( DefWindowProc( hWnd, msg, wParam, lParam ));
138 memset( &wndclass, 0x00, sizeof( WNDCLASS ));
141 wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
142 wndclass.lpfnWndProc = WndProc;
143 wndclass.cbClsExtra = 0;
144 wndclass.cbWndExtra = 0;
145 wndclass.hInstance = hInst;
146 wndclass.hIcon = LoadIcon(hInst, "CONSOLE");
147 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
148 wndclass.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
149 wndclass.lpszMenuName = szAppName; /* Menu Name is App Name */
150 wndclass.lpszClassName = szAppName; /* Class Name is App Name */
151 if( !RegisterClass( &wndclass )) {
159 unreg_classes( void )
161 UnregisterClass( szAppName, hInst );
166 getline( char *line, int len, FILE *s, char *prompt )
173 lpfnDlgProc = MakeProcInstance((FARPROC)GetLineDlgProc, hInst);
174 nRc = DialogBox(hInst, MAKEINTRESOURCE(200), hWndMain, lpfnDlgProc);
175 FreeProcInstance(lpfnDlgProc);
179 strncpy( line, szLineBuf, len );
180 printf( "%s\n", line );
189 printf( "%s: error %d\n", msg, WSAGetLastError());
195 printf( "exit( %d )\n", rc );
199 fprintf( FILE *f, char *fmt, void *a1, void *a2, void *a3, void *a4,
202 printf( fmt, a1, a2, a3, a4, a5 );
206 printf( char *fmt, void *a1, void *a2, void *a3, void *a4, void *a5 )
208 char *p, *send, buf[ 1024 ], *crlf = "\r\n";
210 sprintf( buf, fmt, a1, a2, a3, a4, a5 );
213 for ( p = buf; *p != '\0'; ++p ) {
216 SendMessage( hWndOutputEdit, EM_REPLACESEL, 0, (long)send );
217 SendMessage( hWndOutputEdit, EM_REPLACESEL, 0, (long)crlf );
223 SendMessage( hWndOutputEdit, EM_REPLACESEL, 0, (long)send );
228 GetLineDlgProc(HWND hWndDlg, WORD Message, WORD wParam, LONG lParam)
232 /* cwCenter(hWndDlg, 0); */
236 /* Closing the Dialog behaves the same as Cancel */
237 PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
243 SendDlgItemMessage( hWndDlg, DLG_GETLINE_TEXT, WM_GETTEXT, sizeof( szLineBuf),
245 EndDialog(hWndDlg, TRUE);
248 EndDialog(hWndDlg, FALSE);