Visual C++

「Visual C++」の編集履歴(バックアップ)一覧に戻る
Visual C++」を以下のとおり復元します。
-ENTERキー、ESCキーでアプリが終了しないようにする。
 クラスビューでCXXXDlgを選択し、プロパティ-のオーバーライドボタンをクリック
 PreTranslateMessageをオーバーライドする。
 BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
 {
 	if(pMsg->message == WM_KEYDOWN){
 		if(pMsg->wParam == VK_ESCAPE) return true;
 		if(pMsg->wParam == VK_RETURN) return true;
 	}
 	return CDialog::PreTranslateMessage(pMsg);
 }

-モードレスダイアログ
 1. リソースエディタで新規ダイアログを作成
  IDを IDD_XX_DIALOG とします。
 2. クラスウィザードで新規クラスの作成
  クラス名を CXXDialog とします。
 3. OnCancel()を変更
  void CXXDialog::OnCancel()
  {
    DestroyWindow();
  }
 4. PostNcDestroy()を作成
  void CXXDialog::PostNcDestroy()
  {
    delete this;
  }
 5. 呼び出し
  CXXDialog* dlg= new CXXDialog;
  dlg->Create(IDD_XX_DIALOG,this);
  dlg->ShowWindow(SW_SHOW);
#right(){[[VC++6のMFCでモードレスダイアログを作成>http://lesailes.exblog.jp/14424/]]}

-CXXXAppのメンバーにアクセスする
  CXXXApp *app = (CXXXApp*)AfxGetApp();
  app->m_xxx = ...
 もしくは、
  extern CXXXApp theApp;
  theApp.m_xxx = ...

-CString⇔char*
  CString msg;
  char str[10];
 
  msg.Format("%s", str);
  sprintf_s(str, sizeof(str), "%s", msg);
#right(){[[ポインタと文字列とCStringと>http://www.kab-studio.biz/Programing/Codian/MxA/09.html]]}

-DoEvents()
 void DoEvents()
 {
 	MSG msg;
 
 	while(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
 		::TranslateMessage(&msg);
 		::DispatchMessage(&msg);
 	}
 }

-[[デバイスマネージャからUSBシリアルのポート番号を取得>http://www.usefullcode.net/2006/12/post_19.html]]
 2つ以上挿してもおけ。
 #pragma comment(lib, "setupapi.lib")
 #include <setupapi.h>
 
 int CtestDlg::GetUsbComPort(int port[])
 {
 	CString msg;
 	DWORD i;
 	BYTE Buffer[200];
 	HDEVINFO hDevInfo = 0;
 	SP_DEVINFO_DATA	DeviceInfoData;
 	int ret_cnt;
 
 
 	BYTE ComName[]="CP210x USB to UART Bridge Controller (COM";
 	DWORD Length=0;
 
 	ZeroMemory(&DeviceInfoData,sizeof(SP_DEVINFO_DATA));
 	DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
 	
 	//存在するデバイス情報を取得
 	hDevInfo = SetupDiGetClassDevs(NULL,0,0,DIGCF_PRESENT|DIGCF_ALLCLASSES);
 
 	ret_cnt = 0;
 	for(i=0; SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData); i++){
 
 		//デバイスのフレンドリーネームの取得
 		if(!SetupDiGetDeviceRegistryProperty(hDevInfo,&DeviceInfoData,SPDRP_FRIENDLYNAME,NULL,Buffer,sizeof(Buffer),&Length)){
 			// よく取得できない
 			continue;
 		}
 
 		//指定したシリアルポートかどうかをコンペア
 		if(strncmp((const char*)Buffer,(const char*)ComName,strlen((const char*)ComName))==0){
 			CString tmp;
 			tmp.Format("%s", Buffer+strlen((const char*)ComName));
 			tmp = tmp.Left(tmp.GetLength()-1);
 			port[ret_cnt] = atoi(tmp);
 			ret_cnt++;
 
  			msg.Format("%s%s\n", msg, Buffer);
 		}
 	}
 	SetupDiDestroyDeviceInfoList(hDevInfo);
 
 	m_static1.SetWindowText(msg);
 
 	return ret_cnt;
 }

-ウィンドウを最前面
 SetWindowPos(&wndTopMost, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);


**外部リンク
-[[1日でわかるMFC>http://hp.vector.co.jp/authors/VA011804/mfc_01.htm]]
-[[WindowsでRS232Cを使う>http://members.jcom.home.ne.jp/0434383301/vc10.htm]]
-[[RS232C シリアル通信>http://www.ys-labo.com/BCB/2007/070512%20RS232C%20zenpan.html]]

復元してよろしいですか?