ホーム » 検索結果: reg_argv

検索結果: reg_argv

2024年4月
 123456
78910111213
14151617181920
21222324252627
282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,357 アクセス



::GetDeviceCaps(dc,HORZRES)

先日のコード を利用して,Windows API の動作のテスト.


#include	<clocale>
#include	<iostream>

#include	"_tdefine.hxx"
#include	"cmd_line.hxx"
#include	"ask_cli.hxx"
//#include	"ask_path.hxx"

#include	<Windows.h>

bool	test	(c_tstring& str)
{
//	std::terr << str << std::endl ;
	HDC	dc = ::GetDC(NULL) ;
	if (dc != NULL) {
		int	hres = ::GetDeviceCaps(dc,HORZRES) ;
		int	vres = ::GetDeviceCaps(dc,VERTRES) ;
		std::terr
			<< _T("HORZRES=") << hres << _T("\t")
			<< _T("VERTRES=") << vres << _T("\t")
			<< std::endl ;
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		::reg_argv (argc,argv) ;
		}
	{
	//	::call_func(argc,argv) ;
		}
	{
		::test(_T("Test")) ;
		}
	::ask_wait() ;
	return	0 ;
	}

GetDeviceCaps HORZRES VERTRES


::GetDpiForWindow を追加して FHD と 4K 環境で実行.

bool	test	(c_tstring& str)
{
	HWND	hwnd = ::GetConsoleHwnd() ;
	{
		HDC	dc = ::GetDC(hwnd) ;
		if (dc != NULL) {
			int	hres = ::GetDeviceCaps(dc,HORZRES) ;
			int	vres = ::GetDeviceCaps(dc,VERTRES) ;
			std::terr
				<< _T("HORZRES=") << hres << _T("\t")
				<< _T("VERTRES=") << vres << _T("\t")
				<< std::endl ;
			}
		}
//	#ifdef	DPI_AWARENESS_UNAWARE
	{
		HWND	hwnd = ::GetConsoleHwnd() ;
		UINT	dpi = ::GetDpiForWindow(hwnd) ;
		std::terr << dpi << std::endl ;
		}
//	#endif
	return	true ;
	}

GetDpiForWindow

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コンソール AP のための最初のコード

API などをテストするために,個人的に使用している C++ のコード.

#include	<clocale>
#include	<iostream>

#include	"_tdefine.hxx"
#include	"cmd_line.hxx"
#include	"ask_cli.hxx"
//#include	"ask_path.hxx"

bool	test	(c_tstring& str)
{
	std::terr << str << std::endl ;
	return	true ;
	}

inline	bool	call_func	(int argc,TCHAR* argv[])
{
	if (argc > 1) {
		for (int index=1 ; index<argc ; index++) {
			tstring	av = argv[index] ;
			::test(av) ;
			}
		}
	else {
		while(true)	{
			tstring	path ;
			{
				#ifdef	OFN_filter_All
					path = ::ask_path(false) ;
				#else
					path = ::ask_cli(_T("file ... ? =")) ;
				#endif
				}
			if (path.empty())	{	break ;		}
			::test(path) ;
			}
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	{
		::reg_argv (argc,argv) ;
		}
	{
		::call_func(argc,argv) ;
		}
	{
		::test(_T("Test")) ;
		}
	::ask_wait() ;
	return	0 ;
	}

//#include	"messbar.cxx"

インクルードしているファイルは cpp6_hxx.zip にある.
コンソール AP のための最初のコード
上のコードを test.cpp などとして保存し,同じ所に zip を展開.
g++ test.cpp などでコンパイル可能.


これらを使用したコード.
https://dev.mish.work/wordpress/?s=reg_argv

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

::CreateMutex の名称

以前作成した W_mutex を利用.
同じドキュメントを開かない様なガードに使えると思い,単体テスト用のコードを書いた.

#include	"messbar.hxx"
#include	"itls_tmp.hxx"
#include	"cmd_line.hxx"
#include	"S_Exec.hxx"
#include	"W_mutex.hxx"

tstring	make_mutex_name	(const tstring& doc_name)
{
	tstring		mutex_name ;
	v_tstring	argv = ::get_arg() ;
	if (argv.size() > 0) {
		mutex_name += argv[0] ;
		mutex_name += _T(" ") ;
		}
	mutex_name += doc_name ;
///////////////////////////////////////////////////////////////
//	mutex_name = ::Path_Normalize(mutex_name,_T('/')) ;
///////////////////////////////////////////////////////////////
	std::terr << mutex_name << std::endl ;
	return	mutex_name ;
	}

bool	t_wait	(const tstring& doc_name)
{
	tstring		mutex_n = ::make_mutex_name(doc_name) ;
	size_t		bar_max = 1000 ;
	MessageBar	bar(_T("wait"),bar_max) ;
	for (size_t index=0 ; index<bar_max ; index++) {
		::Sleep(100) ;
		W_mutex	mutex(mutex_n.c_str()) ;
		bar.SetBarInc() ;
		if (mutex.Is_exist()) {
			}
		else {
			break ;
			}
		}
	return	true ;
	}

bool	t_loop	(const tstring& doc_name)
{
	tstring		mutex_n = ::make_mutex_name(doc_name) ;
	W_mutex		mutex(mutex_n.c_str()) ;
	size_t		bar_max = 100 ;
	MessageBar	bar(_T("loop"),bar_max) ;
	for (size_t index=0 ; index<bar_max ; index++) {
		bar.SetBarInc() ;
		::Sleep(30) ;
		}
	::Sleep(2000) ;
	return	true ;
	}

bool	test	(const tstring& doc_name)
{
	::t_wait(doc_name) ;
	::t_loop(doc_name) ;
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	::reg_argv(argc,argv) ;
	if (argc > 1) {
		test(argv[1]) ;
		}
	else {
		time_t	now = ::time(NULL) ;
		size_t	count = 5 ;
		tstring	test_cmd ;
		S_Exec	se ;
		{
			tstring	exe_name ;
			tstring	tmp_name ;
			{
				exe_name = argv[0] ;
				}
			{
				tstring	temp_dir = ::Get_i_Tools_tmp() ;
				tstring	time_str = ::Now_Format(_T("%H%M%S")) ;
					tmp_name = ::Path_AddLastSP(temp_dir) + time_str + _T(".tmp") ;
				}
			{
				test_cmd = exe_name + _T(" ") + tmp_name ;
				}
			{
				se.SetFile      (exe_name.c_str()) ;
				se.SetParamaters(tmp_name.c_str()) ;
				}
			{
				for (size_t index=0 ; index<count ; index++) {
					std::terr << test_cmd << std::endl ;
					se.Execute() ;
					::Sleep(2000) ;
					}
				}
			{
				::Sleep(1000) ;
				tstring		mutex_n = ::make_mutex_name(tmp_name.c_str()) ;
				size_t		bar_max = 1000 ;
				MessageBar	bar(_T("test wait "),bar_max) ;
				for (size_t index=0 ; index<bar_max ; index++) {
					W_mutex	mutex(mutex_n.c_str()) ;
					if (mutex.Is_exist()) {
						bar.SetBarInc() ;
						::Sleep(100) ;
						}
					else {
						break ;
						}
					}
				}
			}
		}
	return	0 ;
	}

#include	"messbar.cxx"

Mutex の名称としては,exe 名とドキュメント名を連結したものとした.


最初,実行させるとうまく動作しない(Mutex オブジェクトが存在するはずなのに抜ける).
::CreateMutex に与えている名称がうまくなかった.’\’ が使えない.
パスの区切りを ‘/’ に変更してうまくいった.
CreateMutex の名称で '\' は使えない


次の様なコードをアプリケーションクラスの InitInstance に追加.

	{
		if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen) {
			tstring	doc_name = cmdInfo.m_strFileName ;
			tstring	exe_name = ::Get_module_name() ;
			tstring	mtx_name = exe_name + _T(" ") + doc_name ;
				mtx_name = ::Path_Normalize(mtx_name,_T('/')) ;
			static	W_mutex	mutex(mtx_name.c_str()) ;
			if (mutex.Is_exist()) {
				return	FALSE ;
				}
			}
		}
Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コンソール AP で SetRegistryKey …

以前一度やっているが…
https://dev.mish.work/wordpress/2015/01/28/console-ap-reg-read/

class	CMy_App	:	public	CWinApp	{
public:
	void	SetRegistryKey_	(LPCTSTR key)	{	SetRegistryKey(key) ;	}
	} ;

//CWinApp	theApp ;
CMy_App		theApp ;

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	::reg_argv(argc,argv) ;
	{
		if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) {
			std::terr << _T("Fatal Error: MFC initialization failed") << std::endl ;
			}
		theApp.SetRegistryKey_(Profile::GetRegKey_Base()) ;	//	レジストリを使用する
		}
	if (argc > 1) {
		for (int index=1 ; index<argc ; index++) {
			tstring	fold = argv[index] ;
			::test(fold) ;
			}
		}
	else {
		tstring	def_path = LPCTSTR(::PC_get_current_page()) ;
		tstring	fold = def_path ;
		while(true)	{
			fold = ::ask_folder(fold.c_str()) ;
			if (fold.empty())	{	break ;		}
			::test(fold) ;
			}
		}
	return	0 ;
	}

CMy_App SetRegistryKey

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.