LoginSignup
0
0

More than 3 years have passed since last update.

vistaでvs2010

Last updated at Posted at 2020-11-08

概要

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

コマンドプロンプトで、exeをコンパイル。

cl sampleA.cpp kernel32.lib user32.lib gdi32.lib

サンプルコード

sampleA.h

#define MENU_NAME       NULL
#define WIN_W           500
#define WIN_H           180
#define WIN_X           100
#define WIN_Y           50

sampleA.cpp


#include <windows.h>
#include "sampleA.h"

#define CLASS_NAME      "Sample_A1Class"
#define WIN_TITLE       "Sample_A1"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
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;
    switch(uMsg)
    {
    case WM_PAINT:
        BeginPaint(hWnd, &ps);
        hDC = ps.hdc;
        TextOut(hDC, 10, 10, "SDK -> MFC", 10);
        EndPaint(hWnd, &ps);
    break;
    case WM_LBUTTONDOWN:
        hDC = GetDC(hWnd);
        TextOut(hDC, LOWORD(lParam), HIWORD(lParam), "Hello World", 11);
        ReleaseDC(hWnd, hDC);
    break;
    case WM_CLOSE:
        ret = MessageBox(hWnd, "プログラムを終了しますか", "確認", MB_YESNO | MB_ICONQUESTION);
        if (ret == IDYES)
            DestroyWindow(hWnd);
    break;
    case WM_DESTROY:
        PostQuitMessage(0);
    break;
    default:
        return(DefWindowProc(hWnd, uMsg, wParam, lParam));
    }
    return 0;
}



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0