朝思墓想
2020-08-19 23:03
采纳率: 100%
浏览 110

就是我要编写一个简易的代码编辑器,但是一点输入框就闪退?!

就是我要编写一个简易的代码编辑器,但是一点输入框就闪退,我也不知道这是什么回事
代码:

#include<windows.h>

CALLBACK LRESULT WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PTSTR szCmdLine, int iCmdShow )
{
    static TCHAR szAppName[] = "MyWindowsApp";
    HWND  hwnd;
    MSG   msg;
    WNDCLASS wdcs;

    wdcs.style = CS_HREDRAW|CS_VREDRAW;
    wdcs.lpszClassName = szAppName;
    wdcs.lpszMenuName = NULL;
    wdcs.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
    wdcs.lpfnWndProc = WinProc;
    wdcs.cbClsExtra = 0;
    wdcs.cbWndExtra = 0;
    wdcs.hInstance = hInstance;
    wdcs.hIcon = LoadIcon( NULL, IDC_ARROW );
    wdcs.hCursor = LoadCursor( NULL, IDI_APPLICATION );

    if( !RegisterClass( &wdcs ) )
    {
        MessageBox( NULL, "Window registration failed, please try again later!", szAppName, MB_ICONERROR|MB_OK );
        return 0;
    }

    hwnd = CreateWindow(
                szAppName,
                TEXT("MyWindowApp"),
                WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                NULL,
                NULL,
                hInstance,
                NULL
    );
    ShowWindow( hwnd, iCmdShow );
    UpdateWindow( hwnd );

    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
    return msg.wParam;
};

CALLBACK LRESULT WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC          hdc;
    PAINTSTRUCT ps;
    RECT        rect;
    static HWND hwndbtn1;
    static HWND hwndbtn2;
    static HWND hwndbtn3;
    static HWND hwndInput;

    switch( message )
    {
        case WM_CREATE:
            hwndbtn1 = CreateWindow(
                                TEXT("button"),
                                TEXT("退出"),
                                WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                                150, 500,
                                100, 30,
                                hwnd,
                                (HMENU)1,
                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                                NULL
            );
            hwndbtn2 = CreateWindow(
                                TEXT("button"),
                                TEXT("保存"),
                                WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                                600, 500,
                                100, 30,
                                hwnd,
                                (HMENU)2,
                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                                NULL
            );
            hwndbtn3 = CreateWindow(
                                TEXT("button"),
                                TEXT("编译"),
                                WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                                900, 500,
                                100, 30,
                                hwnd,
                                (HMENU)3,
                                (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                                NULL
            );
            hwndInput = CreateWindow(
                                TEXT("edit"),
                                NULL,
                                WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|WS_BORDER|ES_LEFT|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
                                10, 10,
                                1200, 400,
                                hwnd,
                                (HMENU)4,
                                ((LPCREATESTRUCT) lParam) -> hInstance,
                                NULL
            );
            return 0;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case 1:
                    switch(HIWORD(wParam))
                    {
                        case BN_CLICKED:
                            PostQuitMessage(0);
                            return 0;
                    }
                    return 0;
                case 2:
                    switch(HIWORD(wParam))
                    {
                        case BN_CLICKED:
                            MessageBox(hwnd, "此功能暂未开放,请联系工作人员或管理员", "Error", MB_OK|MB_ICONERROR);
                            return 0;
                    }
                    return 0;
                case 3:
                    switch(HIWORD(wParam))
                    {
                        case BN_CLICKED:
                            MessageBox(hwnd, "此功能暂未开放,请联系工作人员或管理员", "Error", MB_OK|MB_ICONERROR);
                            return 0;
                    }
            }
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
    return 0;
}

WindowsApi
(在gcc下编译)

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2020-08-20 07:41
    已采纳

    switch(LOWORD(wParam))
    这个里面的3个return 0去掉

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题