Programming Language/Windows API
출력
#include "stdafx.h"
#include "2A_demo1.h"
#define MAX_LOADSTRING 100
// 전역 변수:
HINSTANCE hInst; // 현재 인스턴스입니다.
WCHAR szTitle[MAX_LOADSTRING]; // 제목 표시줄 텍스트입니다.
WCHAR 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);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: 여기에 코드를 입력합니다.
// 전역 문자열을 초기화합니다.
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_MY2ADEMO1, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// 응용 프로그램 초기화를 수행합니다.
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY2ADEMO1));
MSG msg;
// 기본 메시지 루프입니다.
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// 함수: MyRegisterClass()
//
// 목적: 창 클래스를 등록합니다.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW 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_MY2ADEMO1));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_MY2ADEMO1);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassExW(&wcex);
}
//
// 함수: InitInstance(HINSTANCE, int)
//
// 목적: 인스턴스 핸들을 저장하고 주 창을 만듭니다.
//
// 설명:
//
// 이 함수를 통해 인스턴스 핸들을 전역 변수에 저장하고
// 주 프로그램 창을 만든 다음 표시합니다.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // 인스턴스 핸들을 전역 변수에 저장합니다.
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// 함수: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 목적: 주 창의 메시지를 처리합니다.
//
// WM_COMMAND - 응용 프로그램 메뉴를 처리합니다.
// WM_PAINT - 주 창을 그립니다.
// WM_DESTROY - 종료 메시지를 게시하고 반환합니다.
//
#include<time.h>
int g_data[10];
void myini() {
srand(time(NULL));
for (int i = 0; i < sizeof(g_data) / 4; i++) {
int a = rand() % 10 + 1;
g_data[i] = a;
for (int j = 0; j < i; j++) {
if (a == g_data[j]) {
i--;
break;
}
}
}
}
void mydraw(HDC hdc) {
TCHAR tmp[80];
for (int i = 0; i < sizeof(g_data) / 4; i++) {
_stprintf_s(tmp, _T("%d"), g_data[i]);
TextOut(hdc, i * 30, i * 30, tmp, _tcslen(tmp));
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(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:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: 여기에 hdc를 사용하는 그리기 코드를 추가합니다.
myini();
mydraw(hdc);
/*
int data[5] = { 10, 20, 30, 40, 50 };
float time = 10.30;
int age = 100;
int no = 2;
int array[7] = { 20, 30, 40, 50, 60, 80, 90 };
TCHAR tmp[80];
for (int i = 0; i < sizeof(array) / 4; i++) {
_stprintf_s(tmp, _T("%d"), array[i]);
TextOut(hdc, i * 30, 10, tmp, _tcslen(tmp));
}*/
/*for (int i = 0; i < sizeof(data) / 4; i++) {
_stprintf_s(tmp, _T("%d, "), data[i]);
TextOut(hdc, i * 30, 10, tmp, _tcslen(tmp));
}*/
//_stprintf_s(tmp, _T("haha"));
////string printf secure 는 문자열을 저장, bof방지
//TextOut(hdc, 70, 70, tmp, _tcslen(tmp));
////tcharacter string length = 문자열길이.
//_stprintf_s(tmp, _T("가나다라"));
//
//TextOut(hdc, 130, 130, tmp, _tcslen(tmp));
//_stprintf_s(tmp, _T("도레미파"));
//TextOut(hdc, 200, 200, tmp, _tcslen(tmp));
//_stprintf_s(tmp, _T("kmw"));
//TextOut(hdc, 300, 300, tmp, _tcslen(tmp));
//TextOut(hdc, 20, 40, _T("sad"), 3);
//TextOut(hdc, 30, 60, _T("soso"), 4);
//TextOut(hdc, 50, 90, _T("string"), 6);
//TextOut(hdc, 100, 200, _T("haha"), 4);
////_T()는 방식
//_stprintf_s(tmp, _T("age : %d"), age);
//TextOut(hdc, 100, 10, tmp, _tcslen(tmp));
//_stprintf_s(tmp, _T("number : %d"), no);
//TextOut(hdc, 200, 10, tmp, _tcslen(tmp));
//_stprintf_s(tmp, _T("time : %.2f"), time);
//TextOut(hdc, 300, 10, tmp, _tcslen(tmp));
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
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;
}
'Programming Language > Windows API' 카테고리의 다른 글
| keyboard[1] (0) | 2018.08.27 |
|---|---|
| 키보드 메세지 처리 (0) | 2018.08.26 |
| TextOut(), DrawText() (0) | 2018.08.26 |
| 기본구조 상세설명 (0) | 2018.08.25 |
| 용어 (0) | 2018.07.14 |
댓글