Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / 2 / lab.03.by mice / claw / root

.h
Скачиваний:
13
Добавлен:
17.04.2013
Размер:
3.64 Кб
Скачать
/*******************************************************************************
* file:         root.h                                                         *
* version:      0.0.2                                                          *
* author:       d-evil [tmd] (mailto:d-evil.tmd@mail.ru)                       *
* description:  not available                                                  *
*******************************************************************************/

#ifndef ROOT_INCLUDED
#define ROOT_INCLUDED

#include <afx.h>
#include <afxwin.h>
#include <afxtempl.h>

#include "server.h"


////////////////////////////////////////////////////////////////////////////////
// ccw_root declaration
class ccw_root: public CDialog {
public:
	ccw_root();
	~ccw_root();

	int ch_name(const char *const new_name);

	virtual BOOL OnInitDialog();
	virtual void OnOK();
	virtual void OnCancel() {}
	virtual void OnClose();
	virtual void OnSysCommand(UINT nID, LPARAM lParam);
	virtual void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);

	int run() { DoModal(); return 0; }

	// icons
	void set_icon(const HICON hicon) { _hicon = hicon; }
	HICON get_icon() const { return _hicon; }

protected:
	////////////////////////////////////////////////////////////////////////////
	// protected event handlers
	DECLARE_MESSAGE_MAP();

	// shell icon
	void _to_tray();
	void _from_tray();
	virtual LRESULT _on_tb_msg(WPARAM hz, LPARAM msg);

	// char pipe
	int _char_to_pipe(const int ch);
	int _char_to_pipe_raw(const int ch);
	int _char_from_pipe(int *const ch);

	// console
	int _write_console(const char *const str);

	// graph
	int _run_graph();
	int _init_graph();
	int _close_graph();
	int _stop_graph();
	int _pause_graph();
	int _upause_graph();
	int _graph_proc();
	static int __stdcall _graph_proc_helper(ccw_root *const dlg) {
		return dlg->_graph_proc();
	}

	char *_str_clone_new(const char *const str);
	void _str_clone_del(char *const str);
	virtual LRESULT _on_cl_str(WPARAM pch, LPARAM hz);

	int _show_all(const int mode = SW_SHOW);

	// net
	int _add_server();
	int _del_server(int claw_id);

	int _add_client(ccw_client *const clnt2add = NULL, const bool give_life = true);
	int _del_client(int claw_id);

	virtual LRESULT _on_add_recver_msg(WPARAM cl, LPARAM hz);
	virtual LRESULT _on_del_client_msg(WPARAM cwid, LPARAM hz);
	virtual LRESULT _on_del_server_msg(WPARAM cwid, LPARAM hz);

private:
	// graph
	DWORD _gthread_id;
	HANDLE _gthread_h;
	HANDLE _graph_mtx;
	HANDLE _pause_mtx;
	bool _graph_paused;
	bool _graph_stoped;
	int _gx, _gy;		// x and y position of graph
	int _gw, _gh;		// graph width and height
	HBITMAP _buf_bmp;
	HBITMAP _txt_bmp;
	RGBQUAD *_pxls;
	RGBQUAD *_txls;
	CDC *_dlg_pcdc;
	HDC	_dlg_dc;
	HDC _buf_dc;
	HDC _txt_dc;
	HPEN _hpen;
	HBRUSH _hbrush;
	HFONT _hfont;
	char *_inv_str;
	char *_cur_str;
	static const int _MARGINS = 0;
	static const int _NORM_FPS = 13;
	static const int _FONT_HEIGTH = 18;
	static const int _LINES_NUM = 256;
	static const int _LINES_MX_LEN = 1024;
	bool _was_about;

	// input pipe
	static const int _CH_PIPE_LEN = 256;
	char _ch_pipe[_CH_PIPE_LEN];
	int _ch_pipe_h;
	int _ch_pipe_t;
	HANDLE _ch_pipe_mtx;
	char _kbd_state[256];
	short _kbd_tr[2];
	static const int _SYNH_TIMEOUT = 5000;

	static const int CL_STR = WM_USER + 0xD;
	static const int TB_MSG = WM_USER + 0xE;

	HICON _hicon;

	// net
	CMap<int, int, ccw_server *, ccw_server *> _servers;
	CMap<int, int, ccw_client *, ccw_client *> _clients;
};



#endif
Соседние файлы в папке claw