码迷,mamicode.com
首页 > 其他好文 > 详细

GDI简单的按钮响应

时间:2020-09-18 02:25:33      阅读:37      评论:0      收藏:0      [点我收藏+]

标签:flag   bst   ast   sizeof   comm   visible   post   res   ror   

#include "windows.h"
#include "stdio.h"
typedef unsigned char U1;
typedef unsigned short U2;
typedef unsigned long U4;
typedef signed char S1;
typedef signed short S2;
typedef struct {
    U1 u1_flag;
    U1 u1_new;
}ST_PRACTICE6_WARNING;
ST_PRACTICE6_WARNING st_s_warning1, st_s_warning2, st_s_warning3;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC    hdc;             //句柄
    PAINTSTRUCT  ps;
    RECT    rect;            //矩形
    HINSTANCE       hInstance;       //窗口实例
    static HWND     hwndButton[2];   //button句柄
    switch (message)
    {
    case WM_CREATE: //创建button
    {
        hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
        //button1
        hwndButton[0] = CreateWindow("BUTTON", "训练",
            WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
            100, 10, 100, 100, hwnd, NULL,
            (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
        //button2
        hwndButton[1] = CreateWindow("BUTTON", "获取",
            WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
            10, 250, 100, 100, hwnd, NULL,
            (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
        return 0;
    }
    case WM_PAINT: //绘制文字
        hdc = BeginPaint(hwnd, &ps);
        GetClientRect(hwnd, &rect);
        DrawText(hdc, TEXT("By:Eastmount CSDN制作"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
        EndPaint(hwnd, &ps);
        return 0;
    case WM_COMMAND: //响应button消息
        if ((HWND)lParam == hwndButton[0])
        {
            MessageBox(NULL, TEXT("是否训练图片?"), TEXT("提示"), MB_YESNO | MB_ICONQUESTION);
        }
        if ((HWND)lParam == hwndButton[1])
        {
            MessageBox(NULL, TEXT("是否获取图片?"),TEXT("提示"),MB_YESNO|MB_ICONQUESTION);
        }
        return 0;
    case WM_CLOSE: //关闭
        if (IDYES == MessageBox(hwnd, "是否关闭程序?", "提示", MB_YESNO | MB_ICONQUESTION))
        {
            DestroyWindow(hwnd);
        }
        return 0;
    case WM_DESTROY:
        printf("\ndestroying window\n");//退出程序
        PostQuitMessage(0);
        return 0L;
    case WM_LBUTTONDOWN:
        printf("\nmouse left button down at (%d, %d)\n", LOWORD(lParam), HIWORD(lParam));
        // fall thru
    default:
        //printf(".");
        return DefWindowProc(hwnd, message, wParam, lParam);
    }
}
typedef struct MyRect {
    int x, y, width, height;
} MyRect;
int main()
{
    MSG msg;
    printf("hello world!\n");
    const char* const myclass = "myclass";
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    /* Win 3.x */
    wc.style = CS_DBLCLKS;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = GetModuleHandle(0);
    wc.hIcon = LoadIcon(0, IDI_APPLICATION);
    wc.hCursor = LoadCursor(0, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszMenuName = 0;
    wc.lpszClassName = myclass;
    /* Win 4.0 */
    wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
    if (!RegisterClassEx(&wc))
    {
        MessageBox(NULL, TEXT("注冊类失败!"), myclass, MB_ICONERROR);
        return 0;
    }
    //MessageBox(NULL, TEXT("注冊类成功!"), myclass, MB_ICONERROR);
        MyRect rect;
        rect.x = 300;
        rect.y = 300;
        rect.width = 640;
        rect.height = 480;
        HWND hwnd = CreateWindowEx(0, myclass, "title",
            WS_OVERLAPPEDWINDOW, rect.x, rect.y,
            rect.width, rect.height, 0, 0, GetModuleHandle(0), 0);
        if (hwnd)
        {
            ShowWindow(hwnd, SW_SHOWDEFAULT);
            while (GetMessage(&msg, hwnd, 0, 0))
            {
                DispatchMessage(&msg);
            }
        }
        return msg.wParam;
}

GDI简单的按钮响应

标签:flag   bst   ast   sizeof   comm   visible   post   res   ror   

原文地址:https://www.cnblogs.com/mr-surprise/p/13676548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!