問合せを Static Library に

  新規プロジェクト Hanbai



1) Win32 Static Library を選択
2) プリコンパイル済みヘッダーをチェック
3) ビルド -> アクティブな構成の設定で、Win32 Release を選択

※ リソースはスタティックライブラリに保存できないので、呼び出し側で用意します

ライブラリに問い合わせ処理を全てカタログして、必要な時に各アプリケーションから利用します。
基本的な仕様は、選択結果をライブラリ内のダイアログクラスのメンバ変数の Key と Name に
コードと名称をセットするようにします。選択された場合は IDOK を返し、キャンセルした場合は
IDCANCEL を返します

MyRef.各ダイアログオブジェクト->Key
MyRef.各ダイアログオブジェクト->Name



  DlgSyain クラスを作成



DlgSyain.h

  
#include <CLClass.h>
#include <LboxDatabase.h>

class DlgSyain : public CLDlg  
{
public:
	void LVDblclick();
	void WMAll();
	void GetData();
	void ProcOperator();
	void ProcEnd();
	void WMInitdialog();

	DlgSyain();
	virtual ~DlgSyain();

	LboxDatabase CurDb;	// データベースオブジェクト(実体型)
	LboxListview *LView;	// リストビューオブジェクト(ポインタ型)

	DWORD IconId;
	DWORD LviewId;
	DWORD EditId;
	LboxString Key;
	LboxString Name;
};
  

DlgSyain.cpp

※ 基本的に HM040 プロジェクトの MyDlg2.cpp と同じです

  
#include "stdafx.h"
#include "DlgSyain.h"

//////////////////////////////////////////////////////////////////////
// 構築/消滅
//////////////////////////////////////////////////////////////////////

DlgSyain::DlgSyain()
{

}

DlgSyain::~DlgSyain()
{

}

// *********************************************************
// ダイアログ初期化イベント
// *********************************************************
void DlgSyain::WMInitdialog()
{
	this->CenterWindow();

	// ダイアログのプロパティでシステムメニューのチェックボックスを外して下さい
	this->ChangeStyle( WS_MINIMIZEBOX | WS_SYSMENU, 0 );
	this->ChangeExStyle( WS_EX_APPWINDOW, 0 );
	this->ChangeIcon( this->IconId );
	this->StatusCreate( 0 );

	LboxString Buff;

	// MySQL 接続文字列
	Buff.operator = ("MySQL,lightbox,root,");
	CurDb.SetConnectString( 3, &Buff );

	// リストビューインスタンス作成
	LView = new LboxListview( ::GetDlgItem( hDlg, this->LviewId ), 0 );
	LView->Grid();

	GetData();

	this->MoveWindow( 0, 0 );
}

// *********************************************************
// ダイアログ終了処理
// *********************************************************
void DlgSyain::ProcEnd()
{
	delete this->LView;
}

// *********************************************************
// オペレータイベント
// *********************************************************
void DlgSyain::ProcOperator()
{
	switch( ControlId ) {
		case IDOK:
			GetData();
			break;
	}
}

// *********************************************************
// 問合せ処理
// *********************************************************
void DlgSyain::GetData()
{
	if ( !CurDb.Connect() ) {
		MsgOk("接続に失敗しました \n%s", CurDb.ErrMessage.szLboxString);
		return;
	}

	LboxString Query;

	Query.operator = ("select * from 社員マスタ");

	LboxString Cond( "" );
	LboxString Buff;

	this->EditGetText( this->EditId, &Buff );
	Buff.Trim( "  " );
	if ( Buff.operator != ( ""  ) ) {
		if ( Cond.operator == ( "" ) ) {
			Cond.operator += (" where ");
		}
		else {
			Cond.operator += (" and ");
		}
		Cond.operator += (" 氏名 like ");
		Buff.Enclose( "%" );
		Buff.Enclose( "'" );
		Cond.operator += ( &Buff );
	}

	Query.operator += ( &Cond );

	int nRet;

	LView->Hide();
	this->StatusSetText( "" );
	nRet = CurDb.LoadSqlData( LView, 0, &Query );
	switch( nRet ) {
		case -1:
			this->StatusSetText( &(CurDb.ErrMessage) );
			break;
		case 0:
			this->StatusSetText( "対象データが存在しません" );
			break;
		default:
			this->StatusPrintf( "%d 件のデータが選択されました", nRet );
			break;
	}
	LView->Fit();
	LView->Show();

	CurDb.DisConnect();	
}

// *********************************************************
// 初期化とオペレータイベント以外の処理
// *********************************************************
void DlgSyain::WMAll()
{
	USE_LVIEW(LView)
}

// *********************************************************
// ダブルクリックイベント
// *********************************************************
void DlgSyain::LVDblclick()
{
	LboxString LWork;

	if ( LView->IsHandle( this->hTargetWindow ) ) {
		LView->GetColumnText( 0, &Key );
		LView->GetColumnText( 1, &Name );
		this->ProcEnd();
		::EndDialog( this->hDlg, IDOK );
	}
}
  



  Href クラスを作成

Href.h

  
#include <CLClass.h>
#include "DlgSyain.h"

class Href
{
public:
	Href();
	virtual ~Href();

	DlgSyain *Syain;
};
  

Href.cpp

  
#include "stdafx.h"
#include "Href.h"
#include "DlgSyain.h"

DlgSyain objSyain;
DEFINE_DLG(objSyain)

//////////////////////////////////////////////////////////////////////
// 構築/消滅
//////////////////////////////////////////////////////////////////////

Href::Href()
{
	INIT_DLG(objSyain)
	Syain = &objSyain;
}

Href::~Href()
{

}
  



  呼び出し側 ( HM040 プロジェクト )


Href.h と Hanbai.lib を参照する為に、以下の処理を行ないます

1) プロジェクト -> 設定 -> C/C++ タブ
2) カテゴリを「プリプロセッサ」とする
3) インクルードファイルのパスに Hanbai プロジェクトのディレクトリを入力
4) リンク タブに移動
5) カテゴリを「インプット」とする
6) 追加ライブラリのパスに Hanbai プロジェクトの Release ディレクトリを入力

MyDlg.h

  
#include "CLClass.h"
#include <LboxDatabase.h>

#include "Href.h"
#pragma comment( lib, "Hanbai.lib" )

class MyDlg : public CLDlg  
{
public:
	void WMAll();
	void UpdateData();
	void CancelData();
	void CheckData();
	void ProcOperator();
	void ProcEnd();
	void WMInitdialog();
	MyDlg();
	virtual ~MyDlg();

	LboxDatabase CurDb;	// データベースオブジェクト(実体型)
	LboxDTPicker CreateDate;
	LboxCombobox *Type;
	LboxCombobox *Syozoku;
	LboxTool Tool;
	LboxMenu Menu;

	Href MyRef;
};
  

MyDlg.cpp のコンストラクタ

  
MyDlg::MyDlg()
{
	MyRef.Syain->IconId = IDI_HM040;
	MyRef.Syain->LviewId = IDC_LIST1;
	MyRef.Syain->EditId = IDC_EDIT1;
}
  

MyDlg.cpp のProcOperator

  
case IDM_REF:
//	Dlg2.Open( this, IDD_DIALOG2 );
	{
		LboxString LWork;
		DWORD ret;

		ret = MyRef.Syain->Open( this, IDD_DIALOG2 );
		if ( ret != IDCANCEL ) {
			this->EditSetText( IDC_KEY, &MyRef.Syain->Key );
			this->Type->SelectedGetData( &LWork );
			if ( LWork.operator == ("1") ) {
				this->Type->Select( 1 );
			}
			this->PostCommand( IDC_CHECK );
		}
	}
	break;

  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ