/******************************************/
#if 0
#include <Windows.h>
#include <atlbase.h>
#include <atlwin.h>
class CMyWindow : public CWindowImpl<CMyWindow>
{
public:
DECLARE_WND_CLASS(_T("CMyWindowClass"))
BEGIN_MSG_MAP(CMyWindow)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
END_MSG_MAP()
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(&ps);
// 绘制窗口内容
RECT rect;
GetClientRect(&rect);
DrawText(hdc, _T("Hello, World!"), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint(&ps);
return 0;
}
};
/*
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 创建窗口
CMyWindow wnd;
wnd.Create(nullptr, CRect(100, 100, 400, 300), _T("My Window"), WS_OVERLAPPEDWINDOW);
// 获取窗口矩形区域
CRect rect;
wnd.GetWindowRect(rect);
// 无效化窗口矩形区域并触发重绘
wnd.InvalidateRect(rect, TRUE);
// 消息循环
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast<int>(msg.wParam);
}*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 创建窗口
HWND hWnd = CreateWindow(
_T("STATIC"), _T("My Window"), WS_OVERLAPPEDWINDOW,
100, 100, 400, 300,
nullptr, nullptr, hInstance, nullptr
);
// 获取窗口矩形区域
RECT rect;
GetWindowRect(hWnd, &rect);
// 将矩形坐标转换为客户区坐标
POINT pt = { 0, 0 };
ScreenToClient(hWnd, &pt);
OffsetRect(&rect, -pt.x, -pt.y);
// 无效化窗口矩形区域并触发重绘
// InvalidateRect(hWnd, &rect, TRUE);
// 显示窗口
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast<int>(msg.wParam);
}
#include <Windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// 绘制背景
RECT rect;
GetClientRect(hWnd, &rect);
HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // 白色背景
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
// 绘制文本
SetTextColor(hdc, RGB(0, 0, 0)); // 黑色文本
SetBkMode(hdc, TRANSPARENT); // 文本背景透明
DrawText(hdc, L"Hello, World!", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint(hWnd, &ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 注册窗口类
const wchar_t* CLASS_NAME = L"MyWindowClass";
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hWnd = CreateWindowEx(
0, CLASS_NAME, L"My Window", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
NULL, NULL, hInstance, NULL
);
if (hWnd == NULL)
return 0;
// 显示窗口
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
#include <Windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// 绘制背景
RECT rect;
GetClientRect(hWnd, &rect);
HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // 白色背景
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
// 绘制文本
SetTextColor(hdc, RGB(0, 0, 0)); // 黑色文本
SetBkMode(hdc, TRANSPARENT); // 文本背景透明
DrawText(hdc, L"Hello, World!", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint(hWnd, &ps);
return 0;
case WM_RBUTTONDOWN:
hdc = GetDC(hwnd);
GetClientRect(hwnd, &rect);
DrawText(hdc, TEXT("右键键被单机咯!"), 13, &rect, DT_VCENTER | DT_SINGLELINE);
ReleaseDC(hWnd, hdc);
InvalidateRect(hWnd, NULL, true);
//UpdateWindow(hwnd);
Sleep(1000);
return 0;
case WM_LBUTTONDOWN:
hdc = GetDC(hWnd);
GetClientRect(hWnd, &rect);
DrawText(hdc, TEXT("左键被单机咯!"), 13, &rect, DT_CENTER | DT_SINGLELINE);
ReleaseDC(hWnd, hdc);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
void InvalidateWindow(HWND hWnd)
{
RECT rect;
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, TRUE);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 注册窗口类
const wchar_t* CLASS_NAME = L"MyWindowClass";
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hWnd = CreateWindowEx(
0, CLASS_NAME, L"My Window", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
NULL, NULL, hInstance, NULL
);
if (hWnd == NULL)
return 0;
// 显示窗口
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// 模拟触发重绘
InvalidateWindow(hWnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
#endif
#include <Windows.h>
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// 绘制背景
RECT rect;
GetClientRect(hWnd, &rect);
HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255)); // 白色背景
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
// 绘制文本
SetTextColor(hdc, RGB(0, 0, 0)); // 黑色文本
SetBkMode(hdc, TRANSPARENT); // 文本背景透明
DrawText(hdc, L"Hello, World!", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
EndPaint(hWnd, &ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_RBUTTONDOWN:
{
HDC hdc = GetDC(hWnd);
RECT rect;
GetClientRect(hWnd, &rect);
DrawText(hdc, L"右键被点击了!", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
ReleaseDC(hWnd, hdc);
InvalidateRect(hWnd, NULL, TRUE);
Sleep(10000);
return 0;
}
case WM_LBUTTONDOWN:
{
HDC hdc = GetDC(hWnd);
RECT rect;
GetClientRect(hWnd, &rect);
DrawText(hdc, L"左键被点击了!", -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
ReleaseDC(hWnd, hdc);
return 0;
}
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 注册窗口类
const wchar_t* CLASS_NAME = L"MyWindowClass";
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// 创建窗口
HWND hWnd = CreateWindowEx(
0, CLASS_NAME, L"My Window", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
NULL, NULL, hInstance, NULL
);
if (hWnd == NULL)
return 0;
// 显示窗口
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
class NcPose
{
public:
NcPose(long index, NC_CODE_TYPE type)
{
lineIndex = index;
codeType = type;
updateX = updateY = updateZ = false;
updateA = updateB = updateC = false;
}
long lineIndex;
NC_CODE_TYPE codeType;
bool updateX, updateY, updateZ, updateA, updateB, updateC;
float x, y, z;
float a, b, c;
};
int main()
{
vector<NcPose> pose;
NcPose po(1, G1_CODE);
pose.emplace_back(1, G1_CODE);
}
#include <stdio.h>
enum NC_CODE_TYPE
{
UNKNOWN_CODE = 0,
G0_CODE, // Position
G1_CODE, // Line
G2_CODE, // CW arc
G3_CODE, // CCW arc
};
void fun(enum NC_CODE_TYPE e)
{
// int i = e;
printf("%d", e);
}
int main()
{
for(int i=G1_CODE;i<G3_CODE;i++)
{
}
// fun(1);
return 0;
}
> #include <iostream>
> #include <afx.h> // 包含 MFC 的头文件
> int main() {
> CString a, b;
> a = "X23456789";
> b = a.Left(4);
> std::wcout << "\n" << b.GetString();
> std::wcout << "\n" << a.Left(4).GetString();
> b = a.Mid(1);
> std::wcout << "\n" << b.GetString();
> b = a.Mid(2, 4);
> std::wcout << "\n" << b.GetString();
> b = a.Right(4);
> std::wcout << "\n" << b.GetString();
> return 0;
> }
#include <windows.h>
#include <tchar.h>
#define IDM_FILE_NEW 101
#define IDM_FILE_OPE 103
#define IDM_FILE_SAVE 104
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
// 处理菜单项的命令
switch (LOWORD(wParam))
{
case IDM_FILE_NEW:
// 处理 New 菜单项的命令
MessageBox(hWnd, L"New selected!", L"Menu", MB_OK);
break;
case IDM_FILE_OPE:
// 处理 Open 菜单项的命令
MessageBox(hWnd, L"Open selected!", L"Menu", MB_OK);
break;
case IDM_FILE_SAVE:
// 处理 Save 菜单项的命令
MessageBox(hWnd, L"Save selected!", L"Menu", MB_OK);
break;
}
break;
case WM_DESTROY:
// 窗口关闭时的处理
PostQuitMessage(0);
OutputDebugString(L"close");
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
HMENU CreateMyMenu()
{
HMENU hMenu = CreateMenu();
HMENU hSubMenu = CreatePopupMenu();
// 添加菜单项
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_NEW, L"New");
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_OPE, L"OpenFile");
AppendMenu(hSubMenu, MF_STRING, IDM_FILE_SAVE, L"Save");
AppendMenu(hMenu, MF_STRING, IDM_FILE_NEW, L"jack");
// 将子菜单添加到主菜单
AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hSubMenu, L"File");
return hMenu;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// 注册窗口类
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName =L"MyWindowClass";
RegisterClass(&wc);
// 创建窗口
HWND hWnd = CreateWindow(L"MyWindowClass", L"My Window", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 1960, 960,
NULL, NULL, hInstance, NULL);
if (hWnd == NULL)
{
// 窗口创建失败
return 0;
}
// 创建菜单
HMENU hMenu = CreateMyMenu();
SetMenu(hWnd, hMenu);
// 显示窗口
ShowWindow(hWnd, nCmdShow);
// 消息循环
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// 销毁菜单
DestroyMenu(hMenu);
return msg.wParam;
}