vistaでvs2010 その2

#概要

vistaで、visual studio 2010やってみた。
コマンドプロンプトで、C++をコンパイルしてみた。

#コマンドプロンプトで、exeをコンパイル。リソース有り

```
rc sampleD.rc
cl sampleD.cpp sampleD.res kernel32.lib user32.lib gdi32.lib
```

#サンプルコード

sampleD.rc

```
#include <windows.h>
#include "sampleD.h"

IDD_DIALOG1 DIALOG DISCARDABLE  50, 20, 120, 88
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "簡易電卓"
FONT 10, "ＭＳ ゴシック"
BEGIN
	DEFPUSHBUTTON   "計算",	 	IDOK,	   	20, 68, 28, 14
	PUSHBUTTON	  	"ｷｬﾝｾﾙ",	IDCANCEL,   66, 68, 28, 14
	EDITTEXT					IDC_EDIT1,  16, 28, 22, 12
	EDITTEXT					IDC_EDIT2,  78, 28, 22, 12
	CONTROL		 	"＋",	   	IDC_RADIO1, "Button", BS_RADIOBUTTON, 50, 12, 16, 8
	CONTROL		 	"－",	   	IDC_RADIO2, "Button", BS_RADIOBUTTON, 50, 24, 16, 8
	CONTROL		 	"×",	   	IDC_RADIO3, "Button", BS_RADIOBUTTON, 50, 36, 16, 8
	CONTROL		 	"÷",	   	IDC_RADIO4, "Button", BS_RADIOBUTTON, 50, 48, 16, 8
END



```

sampleD.h

```
#define MENU_NAME	   	NULL
#define WIN_W		   	500
#define WIN_H		   	220
#define WIN_X		   	100
#define WIN_Y		   	50
#define IDD_DIALOG1	 	101
#define IDC_EDIT1	   	301
#define IDC_EDIT2	   	302
#define IDC_RADIO1	  	401
#define IDC_RADIO2	  	402
#define IDC_RADIO3	  	403
#define IDC_RADIO4	  	404
```

sampleD.cpp

```
#include <windows.h>
#include <stdio.h>
#include "sampleD.h"

#define CLASS_NAME  	"Sample_D1Class"
#define WIN_TITLE   	"Sample_D1"

HINSTANCE hInst;
int gNum1;
int gNum2;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK DlgProc_1(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	MSG msg;
	if (!hPrevInstance)
	{
		if (!InitApplication(hInstance))
			return FALSE;
	}
	if (!InitInstance(hInstance, nCmdShow))
	{
		return FALSE;
	}
	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}
BOOL InitApplication(HINSTANCE hInstance) {
	WNDCLASS wc;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = (WNDPROC) WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
	wc.lpszMenuName = MENU_NAME;
	wc.lpszClassName = CLASS_NAME;
	return(RegisterClass(&wc));
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {
	HWND hWnd;
	hWnd = CreateWindow(CLASS_NAME, WIN_TITLE, WS_OVERLAPPEDWINDOW, WIN_X, WIN_Y, WIN_W, WIN_H, NULL, NULL, hInstance, NULL);
	if (!hWnd)
		return FALSE;
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	HDC hDC;
	PAINTSTRUCT ps;
	int ret;
	int Num;
	char WkBuf[80];
	switch(uMsg)
	{
	case WM_PAINT:
		BeginPaint(hWnd, &ps);
		hDC = ps.hdc;
		TextOut(hDC, 10, 10, "SDK -> MFC", 10);
		EndPaint(hWnd, &ps);
	break;
	case WM_RBUTTONDOWN:
		ret = DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, (DLGPROC) DlgProc_1);
		if (ret == 0)
			break;
		switch(ret)
		{
		case 1:
			Num = gNum1 + gNum2;
		break;
		case 2:
			Num = gNum1 - gNum2;
		break;
		case 3:
			Num = gNum1 * gNum2;
		break;
		case 4:
			Num = gNum1 / gNum2;
		break;
		}
		hDC = GetDC(hWnd);
		sprintf(WkBuf, "答えは %d です", Num);
		TextOut(hDC, LOWORD(lParam), HIWORD(lParam), WkBuf, strlen(WkBuf));
		ReleaseDC(hWnd, hDC);
	break;
	case WM_DESTROY:
		PostQuitMessage(0);
	break;
	default:
		return (DefWindowProc(hWnd, uMsg, wParam, lParam));
	}
	return 0;
}
LRESULT CALLBACK DlgProc_1(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	int i,
		j;
	char WkBuf[80];
	switch(uMsg)
	{
	case WM_INITDIALOG:
		CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO4, IDC_RADIO1);
		return TRUE;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDC_RADIO1:
		case IDC_RADIO2:
		case IDC_RADIO3:
		case IDC_RADIO4:
			CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO4, LOWORD(wParam));
			return TRUE;
		case IDOK:
			GetDlgItemText(hDlg, IDC_EDIT1, WkBuf, sizeof(WkBuf));
			gNum1 = atoi(WkBuf);
			GetDlgItemText(hDlg, IDC_EDIT2, WkBuf, sizeof(WkBuf));
			gNum2 = atoi(WkBuf);
			for (i = 0; i < 4; i ++)
			{
				j = IsDlgButtonChecked(hDlg, IDC_RADIO1 + i);
				if (j == BST_CHECKED)
					break;
			}
			i ++;
			if (i == 4 && gNum2 == 0)
			{
				MessageBox(hDlg, "除数が誤りです", "エラー", MB_OK);
				SetFocus(GetDlgItem(hDlg, IDC_EDIT2));
				return TRUE;
			}
			EndDialog(hDlg, i);
			return TRUE;
		case IDCANCEL:
			EndDialog(hDlg, 0);
			return TRUE;
		}
		return FALSE;
	}
	return FALSE;
}




```


以上。