龙眼图形文档 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;
}

 

posted @ 2021-04-23 17:06  豆焰  阅读(105)  评论(0编辑  收藏  举报