複数プロジェクト化の手順をメモしておく。
入手先
完成
staticライブラリから取得した文字列をWindowのタイトルに設定した。
ソリューション構成
手順
- Mainプロジェクトを作成する
- Libプロジェクトを作成する
- ソースコードを用意する
- プロジェクト依存関係
- プロジェクト設定
1. Mainプロジェクトを作成する
2. Libプロジェクトを作成する
3. ソースコードを用意する
ソースコードは一部抜粋。
Human.h
class Human
{
public:
Human(void);
~Human(void);
basic_string<TCHAR> Introduce();
};
Human.cpp
Human::Human(void) {}
Human::~Human(void) {}
basic_string<TCHAR> Human::Introduce()
{
basic_stringstream<TCHAR> stream;
stream << _T("Human.Introduce() 私は人間である。") << endl;
return stream.str();
}
Program.cpp
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
TCHAR szClassName[] = _T("MainProject");
HWND hWnd;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPSTR lpszCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS myProg;
if (!hPreInst) {
myProg.style = CS_HREDRAW | CS_VREDRAW;
myProg.lpfnWndProc = WndProc;
myProg.cbClsExtra = 0;
myProg.cbWndExtra = 0;
myProg.hInstance = hInstance;
myProg.hIcon = NULL;
myProg.hCursor = LoadCursor(NULL, IDC_ARROW);
myProg.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
myProg.lpszMenuName = NULL;
myProg.lpszClassName = szClassName;
if (!RegisterClass(&myProg)) { return FALSE; }
}
Human human;
hWnd = CreateWindow(szClassName, // class名
human.Introduce().c_str(), // タイトル
WS_OVERLAPPEDWINDOW, // Style
CW_USEDEFAULT, // X
CW_USEDEFAULT, // Y
CW_USEDEFAULT, // Width
CW_USEDEFAULT, // Height
NULL, // 親ウィンドウまたはオーナーウィンドウのハンドル
NULL, // メニューハンドルまたは子ウィンドウ ID
hInstance, // アプリケーションインスタンスのハンドル
NULL // ウィンドウ作成データ
);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, msg, wParam, lParam));
}
return (0L);
}
4. プロジェクト依存関係
5. プロジェクト設定
完成
ビルドして完成。