C++ 编写的 Windows 图形窗口 Hello,World 程序
龙眼图形文档 C++ 编写的 Windows 窗口 Hello,World 程序:
/* * by:beanflame * E-mail:beanflame@qq.com * 2021-4-18-9:30 */ #include <windows.h> #include <windowsx.h> #include <cstdio> #include <stdlib.h> #include <string.h> #include <tchar.h> //LG版本 #define LONGAN_PLATFORM_VERSION "0.0.1" LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; RECT rect; switch (message) { case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); GetClientRect (hWnd, &rect); DrawText(hdc, "Hello World", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } // LP创建窗口 ATOM LP_CreateWindow(int Width,int Height,const char *name) { // 设置窗口大小 RECT rect = {0, 0, Width, Height}; AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, false); WNDCLASSEXA Win_Wcx = {0}; if (!Win_Wcx.cbSize) { //////////////////////////////////////////////////////////////////////////// // 初始化 Window 类结构 /////////////////////////////////////////////////////////////////////////// Win_Wcx.cbSize = sizeof(WNDCLASSEX); Win_Wcx.style = CS_HREDRAW | CS_VREDRAW; Win_Wcx.lpfnWndProc = WndProc; Win_Wcx.cbClsExtra = 0; Win_Wcx.cbWndExtra = 0; Win_Wcx.hInstance = GetModuleHandle(NULL); Win_Wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); Win_Wcx.hCursor = LoadCursor(NULL, IDC_ARROW); Win_Wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); //CreateSolidBrush(RGB(0,0,0)); Win_Wcx.lpszMenuName = NULL; Win_Wcx.lpszClassName = "WindowCls"; Win_Wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /////////////////////////////////////////////////////////////////////////// // 类 注册 /////////////////////////////////////////////////////////////////////////// if(!RegisterClassExA(&Win_Wcx)) { return FALSE; } } //////////////////////////////////////////////////////////////////////////// // 创建窗口 //////////////////////////////////////////////////////////////////////////// HWND Win_Hwnd; #ifdef _UNICODE do { WCHAR wname[128]= {0}; MultiByteToWideChar(CP_ACP, 0,name, strlen(name), wname,128); Win_Hwnd = CreateWindowA( "WindowCls", (LPCSTR)wname, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandle(NULL), NULL ); } //while (0); # else Win_Hwnd = CreateWindowA( "WindowCls", name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, GetModuleHandle(NULL), NULL ); #endif if(!Win_Hwnd) { //MessageBoxA(0, "create window failed", "error", MB_OK); MessageBoxA(0, "Create Window Failed", "ERROR", MB_ICONERROR); return FALSE; } //////////////////////////////////////////////////////////////////////////// //渲染 窗口 //////////////////////////////////////////////////////////////////////////// ShowWindow(Win_Hwnd, SW_SHOWNORMAL); //? UpdateWindow(Win_Hwnd); //CoInitialize(NULL); DragAcceptFiles(Win_Hwnd,TRUE); ////////////////////////////////////////////////////////////////////////// return TRUE; //1 } MSG msg = {0}; int main() { printf("LONGAN_PLATFORM_VERSION: %s \n", LONGAN_PLATFORM_VERSION); //第一代窗口 LP_CreateWindow(640, 480,"Hello World"); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0;//msg.wParam; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 一文读懂知识蒸馏
· 终于写完轮子一部分:tcp代理 了,记录一下