雛形のソース
//------------------------------------------------------------------------------
//
//==============================================================================
// 新規作成日:
// 最終更新日:
//------------------------------------------------------------------------------
#include <tchar.h>
#include <Windows.h>
#include <Shlwapi.h> // ShLwApi.Lib
#include "resource.h"
//------------------------------------------------
// break付きのキーワード
//------------------------------------------------
#define CASE break;case
#define DEFAULT break;default
//------------------------------------------------
// アプリケーション管理の構造体を宣言
//------------------------------------------------
typedef struct tagMAINSYS {
HINSTANCE hInstance; // インスタンスのハンドル
HWND hDlg; // ダイアログのハンドル
} MAINSYS, *LPMAINSYS;
//------------------------------------------------
// ダイアログ全体の初期化
//------------------------------------------------
static BOOL funcInitDialog( HWND hDlg )
{
static MAINSYS MainSys;
LPMAINSYS sys = &MainSys;
sys->hInstance = apiGetInstance( hDlg );
sys->hDlg = hDlg;
apiSetWindowData( hDlg, LPMAINSYS, sys );
hDlg;
return SOON;
}
//------------------------------------------------
// ダイアログ全体の後始末
//------------------------------------------------
static BOOL funcTermDialog( HWND hDlg, LPMAINSYS sys )
{
sys;
DestroyWindow( hDlg );
PostQuitMessage( 0 );
return SOON;
}
//------------------------------------------------
// コマンド・グループの処理
//------------------------------------------------
static BOOL funcCommandGroup( HWND hDlg, UINT uID, UINT uCode, HWND hCtrl, LPMAINSYS sys )
{
switch ( uID ){
CASE BID_PUSH01:
CASE BID_PUSH02:
CASE BID_PUSH03:
CASE BID_PUSH04:
CASE BID_PUSH05:
CASE BID_PUSH06:
CASE BID_PUSH07:
CASE BID_PUSH08:
CASE BID_PUSH09:
CASE BID_PUSH10:
CASE MID_NULL: return TRUE;
DEFAULT: return FALSE;
}
if ( hCtrl != NULL ){
SetFocus( hCtrl );
}
UNREFERENCED_PARAMETER( uCode );
return TRUE;
}
//------------------------------------------------
// ドロップファイルの処理
//------------------------------------------------
static VOID funcDropFiles( HWND hDlg, HDROP hDrop )
{
TCHAR szPath[ MAX_PATH ];
UINT nCount;
DragAcceptFiles( hDlg, FALSE );
if ( (nCount = apiDragGetCount(hDrop)) > 0 ){
for ( UINT nIndex = 0 ; nIndex < nCount ; nIndex++ ){
DragQueryFile( hDrop, nIndex, szPath, MAX_PATH );
}
}
DragFinish( hDrop );
DragAcceptFiles( hDlg, TRUE );
}
//------------------------------------------------
// ダイアログ・プロシージャの関数
//------------------------------------------------
extern BOOL CALLBACK mainDialogProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
LPMAINSYS sys = apiGetWindowData(hDlg,LPMAINSYS);
if ( (sys == NULL) && (uMsg != WM_INITDIALOG) ){
return FALSE;
}
switch ( uMsg ){
CASE WM_INITDIALOG: funcInitDialog( hDlg );
CASE WM_CLOSE: funcTermDialog( hDlg, sys );
CASE WM_DROPFILES: funcDropFiles( hDlg, (HDROP)wParam );
CASE WM_LBUTTONDOWN: apiDragWindowMove( hDlg );
CASE WM_LBUTTONDBLCLK: apiSetWindowTopMost( hDlg, TRUE );
CASE WM_RBUTTONDBLCLK: apiSetWindowTopMost( hDlg, FALSE );
CASE WM_ENDSESSION: PostMessage( hDlg, WM_CLOSE, 0, 0 );
CASE WM_COMMAND: return funcCommandGroup( hDlg, LOWORD(wParam), HIWORD(wParam), (HWND)lParam, sys );
DEFAULT: return FALSE;
}
return TRUE;
}
//------------------------------------------------
// ウインドウ・プロシージャの関数
//------------------------------------------------
extern LRESULT CALLBACK mainWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch ( uMsg ){
CASE WM_CREATE:
CASE WM_DESTROY:
DEFAULT:return DefDlgProc( hWnd, uMsg, wParam, lParam );
}
return 0;
}
//------------------------------------------------
// ダイアログ・クラスの登録
//------------------------------------------------
static ATOM funcDialogClass( HINSTANCE hInstance, LPCTSTR lpClassName )
{
WNDCLASSEX wcex = { 0 };
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = (CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS);
wcex.lpfnWndProc = mainWindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = DLGWINDOWEXTRA;
wcex.hInstance = hInstance;
wcex.hIcon = apiLoadIcon( NULL, IDI_APPLICATION );
wcex.hIconSm = apiLoadIcon( NULL, IDI_APPLICATION );
wcex.hCursor = apiLoadCursor( NULL, IDC_ARROW );
wcex.hbrBackground = GetSysColorBrush( COLOR_3DFACE );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = lpClassName;
return RegisterClassEx( &wcex );
}
//------------------------------------------------
// このファイルで使用する定数
//------------------------------------------------
#define MSG_INIFILE TEXT("XXXX.ini")
//------------------------------------------------
// メイン関数
//------------------------------------------------
extern int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
LPCTSTR lpClassName = TEXT("XXXX_WndClass");
LPCTSTR lpIDD = MAKEINTRESOURCE(IDD_DIALOG01);
TCHAR szIniFile[ MAX_PATH ];
HWND hWnd;
MSG Msg;
// 初期化ファイル名の作成
GetModuleFileName( NULL, szIniFile, MAX_PATH );
lstrcpy( PathFindFileName(szIniFile), MSG_INIFILE );
if ( (hWnd = FindWindow(lpClassName,NULL)) != NULL ){
SetForegroundWindow( hWnd );
return 0;
}
if ( funcDialogClass(hInstance,lpClassName) == 0 ){
return -1;
}
if ( (hWnd = CreateDialog(hInstance,lpIDD,NULL,mainDialogProc)) == NULL ){
return -2;
}
while ( GetMessage(&Msg,NULL,0,0) > 0 ){
if ( !IsDialogMessage(hWnd,&Msg) ){
TranslateMessage( &Msg );
DispatchMessage( &Msg );
}
}
UNREFERENCED_PARAMETER( hPrevInstance );
UNREFERENCED_PARAMETER( lpCmdLine );
UNREFERENCED_PARAMETER( nCmdShow );
return Msg.wParam;
}
//------------------------------------------------------------------------------
// End of FileName.cpp
//------------------------------------------------------------------------------
関連記事