练习时长六年半的Programmer 2022-03-27 18:44 采纳率: 88%
浏览 24

一个关于c++的问题

用devc++上的模版,自己改了一下,运行结果是一个按钮
我想要的效果,点击按钮,跳转到网页http://www.baidu.com/
目前代码:


#include <windows.h>

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {

    HWND button1;//名称
    const int IDbutton1 = 1;//id
    
    switch(Message) {

        case WM_CREATE: {//绘画

               button1 = CreateWindow ( TEXT("button")/*文本类型*/, TEXT("按钮"),//文本内容
                   WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,//窗口类型
                   280,200,//x坐标,y坐标
                   50,50,//宽,高
                   hwnd, (HMENU)IDbutton1, ((LPCREATESTRUCT) lParam)->hInstance, NULL);//不知道
                      }
        
        /* All other messages (a lot of them) are processed using default procedures */
        default:
            return DefWindowProc(hwnd, Message, wParam, lParam);
    }
    return 0;
}


/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    WNDCLASSEX wc; /* A properties struct of our window */
    HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
    MSG msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    memset(&wc,0,sizeof(wc));
    wc.cbSize         = sizeof(WNDCLASSEX);
    wc.lpfnWndProc     = WndProc; /* This is where we will send messages to */
    wc.hInstance     = hInstance;
    wc.hCursor         = LoadCursor(NULL, IDC_ARROW);
    
    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
    wc.hIconSm         = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

    if(!RegisterClassEx(&wc)) {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, /* x */
        CW_USEDEFAULT, /* y */
        640, /* width */
        480, /* height */
        NULL,NULL,hInstance,NULL);

    if(hwnd == NULL) {
        MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }
    while(GetMessage(&msg, NULL, 0, 0) > 0) { 
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 创建了问题 3月27日

      悬赏问题

      • ¥15 这段有什么bug 为什么总报错
      • ¥15 关于#php#根据url判断选择加载模板应该如何解决?会的速来捡钱!
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云
      • ¥50 unity使用easyar录屏更换视频保存路径
      • ¥15 CECGameSession::OutputLinkSevError(iRetCode=4) LINK超时
      • ¥20 出错 textread (第 124 行) [varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
      • ¥15 tensor flow目标检测环境配置问题
      • ¥15 数据库float型转换精度问题
      • ¥15 运行您代码时出现报错,如何解决?(标签-回归|关键词-无法识别)
      • ¥50 android service弹出dialog,showdialog就出错,如何解决?