none
vc++运行没问题但是显示不出窗口~ RRS feed

  • 问题

  • #include <windows.h>
    #include <stdlib.h>
    #include <string.h>

    LRESULT CALLBACK wndproc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam );

    int WINAPI WinMain(
      HINSTANCE hInstance,      // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,          // command line
      int nCmdShow              // show state
      )
    {
    WNDCLASS wndclass;
    wndclass.cbClsExtra=0;
    wndclass.cbWndExtra=0;
    wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.hCursor=LoadCursor(hInstance,IDC_CROSS);
    wndclass.hIcon=LoadIcon(hInstance,IDI_WARNING);
    wndclass.hInstance=hInstance;
    wndclass.lpfnWndProc=wndproc;
    wndclass.lpszClassName="示例";
    wndclass.lpszMenuName=NULL;
    wndclass.style=CS_HREDRAW|CS_VREDRAW;

    if (!RegisterClass(&wndclass))
    {
    MessageBeep(0);
    return false;
    }

    HWND hwnd;
    hwnd=CreateWindow("示例","my_show",WS_OVERLAPPEDWINDOW,100,100,500,500,NULL,NULL,hInstance,NULL);

    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd);

    MSG msg;
    while (GetMessage(&msg,hwnd,0,0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);

    }
    return 0;
    }
    LRESULT CALLBACK wndproc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam )
    {
    HFONT hf_black;
    PAINTSTRUCT ps;
    TEXTMETRIC tm;
    char lpz_1[]="这是一行字";
    char lpz_2[]="这还是一行字";

    switch(uMsg)
    {
    case WM_PAINT:
    HDC hdc;
    hdc=BeginPaint(hwnd,&ps);
    SetTextColor(hdc,RGB(255,0,0));
    GetTextMetrics(hdc,&tm);
    TextOut(hdc,0,0,lpz_1,strlen(lpz_1));

    hf_black=CreateFont(0,0,0,0,400,0,0,0,GB2312_CHARSET,OUT_CHARACTER_PRECIS,OUT_CHARACTER_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"不认识");
    SetTextColor(hdc,RGB(0,255,0));
    SelectObject(hdc,hf_black);
    TextOut(hdc,0,100,lpz_2,strlen(lpz_2));
    EndPaint(hwnd,&ps);
    break;
    case WM_CLOSE:
    if (IDYES==MessageBox(hwnd,"是否真的结束","myself",MB_YESNO))
    {
    DestroyWindow(hwnd);
    }
    break;

    case WM_DESTROY:
    PostQuitMessage(0);

    default:
    return DefWindowProc(hwnd,uMsg,wParam,lParam);


    }
    return 0;
    }
    2009年7月22日 7:00

答案