Winapi Visual studio无法使用“移动到”(win32api)
这是下面的代码,VS在 第109行移动到hdc,x,y; MoveTo未定义 有人能解释一下怎么了吗? 这是一个win32api应用程序Winapi Visual studio无法使用“移动到”(win32api),winapi,visual-c++,Winapi,Visual C++,这是下面的代码,VS在 第109行移动到hdc,x,y; MoveTo未定义 有人能解释一下怎么了吗? 这是一个win32api应用程序 // Win32Project.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "Win32Project4.h" #include <windows.h> #include <stdio.h> #include &l
// 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);
等待快速响应,我将非常高兴 MoveTo是一个不再受支持的Windows 3.x功能。改为使用,将最后一个参数设置为NULL。您可以定义自己的MoveTo来执行此操作,例如:
#define MoveTo(hdc, x, y) ((void)MoveToEx(hdc, x, y, NULL))
或:
之所以需要更多的文本,是因为您的文本与代码的比率非常小。这个例子是巨大的。您真的需要所有这些代码来展示MoveTo给您带来的错误吗?当然不是。文本应该在a左右,包括完整的编译器错误以及关于您如何尝试解决此问题的任何其他信息。在此处确认-
inline void MoveTo(HDC hdc, int X, int Y) { MoveToEx(hdc, X, Y, NULL); }