ホーム WTL Mobile
スケルトン
ドキュメント種別 ATL/WTL に関する文書
最終更新日 2009/08/19
PR
 これまで WTL Mobile Application Wizard を使用せずに「Win32 スマート デバイス プロジェクト」として プログラムを作成してきましたが、ここでは WTL Mobile Application Wizard を使用してプロジェクトを作成します。

次に示すのは WTL Mobile Application Wizard で作成したダイアログアプリケーションのスケルトン(雛形)です。 作成するには、WTL Mobile Application Wizard を実行して、[Application Type] 設定画面で [Dialog based] を選択し、[Finish] ボタンを押します。 なお、改行は元のソースから変更している部分があります。

// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//      are changed infrequently
//

#pragma once

// Change this value to use different versions
#define WINVER 0x0420
#include <atlbase.h>
#if _ATL_VER == 0x900
#define _SECURE_ATL 1
#endif
#include <atlstr.h>

#define _WTL_NO_CSTRING
#include <atlapp.h>

extern CAppModule _Module;

#include <atlwin.h>

#include <tpcshell.h>
#include <aygshell.h>
#pragma comment(lib, "aygshell.lib")
			

// stdafx.cpp : source file that includes just the standard includes
//  SampleProject.pch will be the pre-compiled header
//  stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"
			

// aboutdlg.h : interface of the CAboutDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

class CAboutDlg : public CStdDialogImpl
{
public:
    enum { IDD = IDD_ABOUTBOX };

    BEGIN_MSG_MAP(CAboutDlg)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        CHAIN_MSG_MAP(CStdDialogImpl<CAboutDlg>)
    END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//  LRESULT MessageHandler(
//      UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//  LRESULT CommandHandler(
//      WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//  LRESULT NotifyHandler(
//      int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

    LRESULT OnInitDialog(
        UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
    {
        AtlCreateEmptyMenuBar(m_hWnd);

        return bHandled = FALSE;
    }
};
			

// SampleProjectDialog.h : interface of the CSampleProjectDialog class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

class CSampleProjectDialog : 
    public CAppStdDialogImpl<CSampleProjectDialog>,
    public CUpdateUI<CSampleProjectDialog>,
    public CMessageFilter, public CIdleHandler
{
public:
    DECLARE_APP_DLG_CLASS(NULL, IDR_MAINFRAME, L"Software\\WTL\\SampleProject")

    enum { IDD = IDD_MAINDLG };

    virtual BOOL PreTranslateMessage(MSG* pMsg)
    {
        return CWindow::IsDialogMessage(pMsg);
    }

// CAppWindow operations
    bool AppHibernate( bool bHibernate)
    {
        // Insert your code here or delete member if not relevant
        return bHibernate;
    }

    bool AppNewInstance( LPCTSTR lpstrCmdLine)
    {
        // Insert your code here or delete member if not relevant
        return false;
    }

    void AppSave()
    {
        CAppInfo info;
        // Insert your code here or delete member if not relevant
    }

    virtual BOOL OnIdle()
    {
        return FALSE;
    }

    BEGIN_UPDATE_UI_MAP(CSampleProjectDialog)
    END_UPDATE_UI_MAP()

    BEGIN_MSG_MAP(CSampleProjectDialog)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
        CHAIN_MSG_MAP(CAppStdDialogImpl<CSampleProjectDialog>)
    END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//  LRESULT MessageHandler(
//      UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//  LRESULT CommandHandler(
//      WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//  LRESULT NotifyHandler(
//      int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

    LRESULT OnInitDialog(
        UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
    {
        HWND hMenuBar = CreateMenuBar(ATL_IDM_MENU_DONECANCEL);
        UIAddToolBar(hMenuBar);
        UIAddChildWindowContainer(m_hWnd);

        // register object for message filtering and idle updates
        CMessageLoop* pLoop = _Module.GetMessageLoop();
        ATLASSERT(pLoop != NULL);
        pLoop->AddMessageFilter(this);
        pLoop->AddIdleHandler(this);

        return bHandled = FALSE;
    }

    LRESULT OnAppAbout(
        WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    {
        CAboutDlg dlg;
        dlg.DoModal();
        return 0;
    }
};
			

// SampleProject.cpp : main source file for SampleProject.exe
//

#include "stdafx.h"

#include <atlframe.h>
#include <atlctrls.h>
#define _WTL_CE_NO_ZOOMSCROLL
#define _WTL_CE_NO_FULLSCREEN
#include <atlwince.h>

#include "resourceppc.h"

#include "AboutDlg.h"
#include "SampleProjectDialog.h"

CAppModule _Module;

int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
    HRESULT hRes = 
        CSampleProjectDialog::ActivatePreviousInstance(hInstance, lpstrCmdLine);

    if(FAILED(hRes) || S_FALSE == hRes)
    {
        return hRes;
    }

    hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    AtlInitCommonControls(ICC_DATE_CLASSES);
    SHInitExtraControls();

    hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    int nRet = CSampleProjectDialog::AppRun(lpstrCmdLine, nCmdShow);

    _Module.Term();
    ::CoUninitialize();

    return nRet;
}
			

 stdafx.hファイルでは、マクロの定義やヘッダファイルのインクルード、 ライブラリファイルをリンクするコードが生成されます。

 AboutDlg.hファイルでは、バージョン情報ダイアログとなるCAboutDlgクラスが定義され、 そのクラス内でWM_INITDIALOGメッセージハンドラが定義されます。

 SampleProjectDialog.hファイルでは、メインウィンドウとなるCSampleProjectDialogクラスが定義され、 そのクラス内でWM_INITDIALOGメッセージハンドラと[About]ボタンコマンドメッセージハンドラが定義されます。

 SampleProject.cppファイルの_tWinMain()では、 ダイアログを作成するコードのほかに、COM初期化関数の呼び出しやコントロール初期化のためのコードが生成されます。