⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windows.cpp

📁 robocup源代码2001年清华机器人源代码
💻 CPP
字号:
/*
    Copyright (C) 2001  Tsinghuaeolus

    Authors : ChenJiang, YaoJinyi, CaiYunpeng, Lishi

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

	If you make any changes or have any comments we would appreciate a 
	message to yjy01@mails.tsinghua.edu.cn.
*/

#include <windows.h>
#include "resource.h"
#include "params.h"

#define TEXT_OUT 30000

HINSTANCE hInst;
TEXTMETRIC  tm ;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int InitInstance();  // initialize application
void destruction();
void GetOptions(int argc, char** argv);
extern HWND hWND;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{	
/*      analyze commandline      */
	int MaxString = 128;
	int argc = 0, is_spaceregion = 1, scount;
	char** argv = new char*[MaxString];
	argv[argc] = new char[MaxString];
	strcpy(argv[argc],"win");
	argc++;
	char* lpstr = lpCmdLine;
	while(*lpstr != 0){
		if (is_spaceregion){
			if (*lpstr != ' '){
				argv[argc] = new char[MaxString];
				argv[argc][0] = *lpstr;
				scount = 1;
				is_spaceregion = 0;
			}
		}
		else{
			if(*lpstr == ' '){
				argv[argc][scount] = 0;
				argc++;
				is_spaceregion = 1;
			}
			else{
				argv[argc][scount] = *lpstr;
				scount ++;
			}
		}
		lpstr++;	
	}
	if (*lpCmdLine != NULL){
		argv[argc][scount] = 0;
		argc ++;
	}

	GetOptions(argc,argv); // Get Options from commandline
	for(int i=0; i<argc; i++) delete argv[i];

	delete argv;
/*************************************/

	char* szAppName = CP_appname;
	HWND        hwnd ;
	MSG         msg ;
	WNDCLASSEX  wndclass ;
	hInst=hInstance;
	wndclass.cbSize        = sizeof (wndclass) ;
	wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
	wndclass.lpfnWndProc   = WndProc ;
	wndclass.cbClsExtra    = 0 ;
	wndclass.cbWndExtra    = 0 ;
	wndclass.hInstance     = hInstance ;
	wndclass.hIcon         = LoadIcon(hInstance, (LPCTSTR)IDI_ICON);
	wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
	wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
	wndclass.lpszMenuName  = NULL ;
	wndclass.lpszClassName = szAppName;
	wndclass.hIconSm       = LoadIcon(hInstance, (LPCTSTR)IDI_ICON);
	RegisterClassEx (&wndclass) ;

	hwnd = CreateWindow (szAppName,szAppName,
						  WS_OVERLAPPED | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX,
						  CW_USEDEFAULT, CW_USEDEFAULT,
						  CW_USEDEFAULT, CW_USEDEFAULT,
						  NULL, NULL, hInstance, NULL) ;
	ShowWindow (hwnd, SW_MINIMIZE);
	UpdateWindow (hwnd) ;

	HDC hdc = GetDC (hwnd);
	GetTextMetrics (hdc, &tm);

	hWND = hwnd;

	/* Here is the interface of the Application */
	if (!InitInstance()){
		//MessageBox(hwnd,"Cannot Initialize!","Error",MB_OK);
		PostQuitMessage(0);
	}

	while (GetMessage (&msg, NULL, 0, 0)){
		TranslateMessage (&msg) ;
		DispatchMessage (&msg) ;	
	}	
	return msg.wParam ;
}

/*    scrollable output       */

int tlines;
int str_begin;
/************* for display  **************/
extern char error[CP_MaxLines][8196];
extern int current;
extern int lines;

void Refresh(HDC hdc){
	if (current == -1) return;
	tlines = lines;
	str_begin = 0;
	if (lines == CP_MaxLines) 
		str_begin = (current + 1) % CP_MaxLines;
	for(int i=0; i<tlines; i++){
		TextOut(hdc,0,i*tm.tmHeight,error[(str_begin+i)%CP_MaxLines],CP_MaxRows);
	}
}

/****************************************************************/
extern int ServerAlive;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message) 
	{
		case WM_COMMAND:
			break;
		case TEXT_OUT:
			hdc=GetDC(hWnd);
			Refresh(hdc);
			ReleaseDC(hWnd,hdc);
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			SendMessage(hWnd,TEXT_OUT,0,0);
			RECT rt;
			GetClientRect(hWnd, &rt);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			destruction();
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -