で動作する、VSは 線109(のMoveTo(HDC、X、Y)上ことと、
"のMoveTo" は未定義あるVisual Studioが習慣ここで以下のコードはです "のMoveTo"(のWin32API)
は、誰かが間違っているものを私に説明できますか? これは、Win32APIのアプリケーションです。
// Win32Project.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "Win32Project4.h"
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int pNum = 0;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
const WCHAR szAppName[] = L"Third_LAB";
const WCHAR szChildClass[] = L"Child";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_CROSS);
wndclass.hbrBackground = (HBRUSH)(NULL_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SMALL));
RegisterClassEx(&wndclass);
wndclass.lpfnWndProc = ChildWndProc;
wndclass.cbWndExtra = sizeof(WORD);
wndclass.hIcon = NULL;
wndclass.lpszClassName = szChildClass;
wndclass.hIconSm = NULL;
RegisterClassEx(&wndclass);
hwnd = CreateWindowEx(
0,
szAppName, // window class name
L"Third_LAB", // window caption
WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL, // window style
200, // initial x position
150, // initial y position
800, // initial x size
500, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL
); // creation parameters
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, 0, 0, 0))
DispatchMessage(&msg);
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
{
const WCHAR szChildClass[] = L"Child";
static int cxBlock, cyBlock;
static HDC hdc;
static HPEN hPen;
static BOOL track = FALSE;
static HWND hwndCH;
static int x, y;
switch (iMsg) {
case WM_CREATE:
hdc = GetDC(hwnd);
hwndCH = CreateWindow(szChildClass, NULL,
WS_CHILDWINDOW | WS_VISIBLE,
0, 0, cxBlock/2 + 3, cyBlock + 3,
hwnd, NULL,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
MoveWindow(hwndCH, 0, 0, cxBlock/2 + 3, cyBlock + 3, NULL);
return 0;
case WM_SIZE:
cxBlock = LOWORD(lParam);
cyBlock = HIWORD(lParam);
MoveWindow(hwndCH, 0, 0, cxBlock/2 + 3, cyBlock + 3, NULL);
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case (0x51):
PostQuitMessage(0);
break;
}
return 0;
case WM_LBUTTONDOWN:
track = TRUE;
x = LOWORD(lParam);
y = HIWORD(lParam);
MoveTo(hdc, x, y);
switch (pNum)
{
case (1):
hPen = CreatePen(PS_SOLID, 5, 0);
SelectObject(hdc, hPen); break;
case (2):
hPen = CreatePen(PS_SOLID, 15, 0);
SelectObject(hdc, hPen); break;
case (3):
hPen = CreatePen(PS_SOLID, 25, 0);
SelectObject(hdc, hPen); break;
}
return 0;
case WM_LBUTTONUP:
track = FALSE;
DeleteObject(hPen);
return 0;
case WM_MOUSEMOVE:
if (track)
{
x = LOWORD(lParam);
y = HIWORD(lParam);
LineTo(hdc, x, y);
MoveTo(hdc, x, y);
}
return 0;
case WM_DESTROY:
ReleaseDC(hwnd, hdc);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
}
LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static HDC hdc;
PAINTSTRUCT ps;
static int cxBlock, cyBlock;
static int x, y;
static HPEN hPen;
switch (iMsg)
{
case WM_SIZE:
hdc = GetDC(hwnd);
cxBlock = LOWORD(lParam);
cyBlock = HIWORD(lParam);
InvalidateRect(hwnd, NULL, TRUE);
ReleaseDC(hwnd, hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetROP2(hdc, R2_BLACK);
Rectangle(hdc, 0, cyBlock/2 - 100, cxBlock, cyBlock/2 - 105);
Rectangle(hdc, 0, cyBlock/2, cxBlock, cyBlock/2 - 15);
Rectangle(hdc, 0, cyBlock/2 + 100, cxBlock, cyBlock/2 + 125);
InvalidateRect(hwnd, NULL, FALSE);
break;
case WM_RBUTTONDOWN:
x = LOWORD(lParam);
y = HIWORD(lParam);
if ((y <= (cyBlock/2 - 100)) && (y >= (cyBlock/2 - 105)))
pNum = 1;
else if ((y <= (cyBlock/2)) && (y >= (cyBlock/2 - 15)))
pNum = 2;
else if ((y >= (cyBlock/2 + 100)) && (y <= (cyBlock/2 + 125)))
pNum = 3;
return 0;
case WM_DESTROY:
DeleteObject(hPen);
ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
を、私は非常に喜んでいるだろう高速応答を待っています。
https://blogs.msdn.microsoft.com/oldnewthing/20090720-00/?p=17433 – chris
より多くのテキストを必要とするSOのことは、テキストとコードの比が非常に小さいことです。その例は巨大です。 'MoveTo'がエラーを出すことを示すために本当にコードをすべて必要としますか?もちろん違います。テキストは[mcve]を囲んでいて、完全なコンパイラエラーと、この問題をどのように解決しようとしているかについての追加情報が含まれていなければなりません。 – chris