// 謎の螺旋???.cpp : アプリケーションのエントリ ポイントを定義します。
//
//#include "stdafx.h"
//#include "謎の螺旋???.h"
#include <vector>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#define MAX_LOADSTRING 100
//////////////////////
#define IDS_APP_TITLE 103
#define IDR_MAINFRAME 128
#define IDD_MY_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_MY 107
#define IDI_SMALL 108
#define IDC_MY 109
#define IDC_MYICON 2
#ifndef IDC_STATIC
#define IDC_STATIC -1
#endif
//////////////////////
// グローバル変数:
HINSTANCE hInst; // 現在のインターフェイス
TCHAR szTitle[MAX_LOADSTRING]; // タイトル バーのテキスト
TCHAR szWindowClass[MAX_LOADSTRING]; // メイン ウィンドウ クラス名
// このコード モジュールに含まれる関数の宣言を転送します:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
bool MoveTo(HDC hdc, POINT To, LPPOINT LastPoint){
::MoveToEx(hdc, To.x, To.y, LastPoint);
return true;
}
bool LineTo(HDC hdc, POINT To, HPEN Pen){
HPEN Old = (HPEN)SelectObject(hdc, Pen);
::LineTo(hdc, To.x, To.y);
SelectObject(hdc, Old);
return 0;
}
bool DrawText(HDC hdc, LPTSTR Text, int TextCount, LPRECT Rect, UINT Format, COLORREF COLOR, HFONT Font){
HFONT OldFont = (HFONT)SelectObject(hdc, Font);
COLORREF Color = SetTextColor(hdc, COLOR);
::DrawText(hdc, Text, TextCount, Rect, Format);
SelectObject(hdc, OldFont);
SetTextColor(hdc, Color);
return true;
}
std::vector<bool> Prime;
bool MakePrime(std::size_t N){//追記型エラトステネスの篩
std::size_t Start = Prime.size();
std::size_t End = N;
bool F = false;
if (Prime.size() == 0){
Prime.push_back(false);
Prime.push_back(false);
Prime.push_back(true);
}
Start = Prime.size();
for (std::size_t i = Start; i < End; i++){
F = true;
for (std::size_t j = 1; j < i; j++){
if (Prime[j] == false)continue;
if (i%j == 0){
F = false;
break;
}
}
Prime.push_back(F);
}
return true;
}
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: ここにコードを挿入してください。
MSG msg;
HACCEL hAccelTable;
// グローバル文字列を初期化しています。
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// アプリケーションの初期化を実行します:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY));
// メイン メッセージ ループ:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// 関数: MyRegisterClass()
//
// 目的: ウィンドウ クラスを登録します。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MY));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MY);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// 関数: InitInstance(HINSTANCE, int)
//
// 目的: インスタンス ハンドルを保存して、メイン ウィンドウを作成します。
//
// コメント:
//
// この関数で、グローバル変数でインスタンス ハンドルを保存し、
// メイン プログラム ウィンドウを作成および表示します。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // グローバル変数にインスタンス処理を格納します。
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// 関数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 目的: メイン ウィンドウのメッセージを処理します。
//
// WM_COMMAND - アプリケーション メニューの処理
// WM_PAINT - メイン ウィンドウの描画
// WM_DESTROY - 中止メッセージを表示して戻る
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static const int TW = 16;
static const int TH = 16;
RECT rt;
RECT Prog = { 0, };
int Dir = 0;
int Count = 0;
GetClientRect(hWnd, &rt);
int CW = rt.right - rt.left;
int CH = rt.bottom - rt.top;
int CX = CW / 2;
int CY = CH / 2;
POINT Pos = { CX, CY };
int L = 0;
int M = 1;
TCHAR Str[1024] = _T("");
POINT D[4] = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } };
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 選択されたメニューの解析:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
MoveTo(hdc, { CX, CY }, NULL);
// TODO: 描画コードをここに追加してください...
Prog.right = 1;
L = 1;
while (true){
Dir++;
Dir %= 4;
if(Count == 0)goto Label;
if (Dir == 0){
Prog.bottom = Prog.top + 2;
L = Prog.bottom;
}
if (Dir == 1){
Prog.right = Prog.left + 2;
L = Prog.right;
}
if (Dir == 2){
Prog.top = Prog.bottom + 2;
L = Prog.top;
}
if (Dir == 3){
Prog.left = Prog.right + 2;
L = Prog.left;
}
Label:
for (int i = 0; i < L; i++){
Pos.x = Pos.x + (D[Dir].x*TW);
Pos.y = Pos.y + (D[Dir].y*TH);
LineTo(hdc, { Pos.x, Pos.y }, (HPEN)GetStockObject(BLACK_PEN));
Count++;
MakePrime(Count+1);
if (Prime[Count] == true){
wsprintf(Str, _T("%d"),Count);
int Len = lstrlen(Str);
RECT SR{Pos.x-64,Pos.y,Pos.x+64,Pos.y+16};
DrawText(hdc, Str, Len, &SR, DT_CENTER);
}
//if (Count == 1024) goto End;
if (Pos.x > CW) goto End;
if (Pos.x < 0) goto End;
if (Pos.y > CH) goto End;
if (Pos.y < 0)goto End;
}
}
End:
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_MOUSEMOVE:
InvalidateRect(hWnd, NULL, FALSE);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// バージョン情報ボックスのメッセージ ハンドラーです。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
Ly8g6KyO44Gu6J665peL77yf77yf77yfLmNwcCA6IOOCouODl+ODquOCseODvOOCt+ODp+ODs+OBruOCqOOD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