不管用什么方式win32,mfc,atl/com如何能够使一个界面的"X"关闭按钮不显示。也就是这个功能用户点击不了,无效。怎么做?

解决方案 »

  1.   

    先谢。不过我的这个界面就没有WS_SYSMENU样式。
      

  2.   

    case WM_SYSCOMMAND:
    switch(LOWORD(wParam))
    {
    case SC_CLOSE:
    return 0;
    }
    break;
      

  3.   

    对话框的X按钮不就是 WM_CLOSE 消息吗
    通常都是
    switch(xxx) {
      case WM_CLOSE:
        EndDialog();//这里注释掉也不行吗
        break;
      

  4.   

    是可以注释掉。关键是WM_CLOSE消息及其里面的函数我还在另外的地方需要,就是在x关闭按钮这里不需要了。怎么办呢?
      

  5.   

    /*------------------------------------------------------------
    HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
    (c) Charles Petzold, 1998
    ------------------------------------------------------------*/#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
    static TCHAR szAppName[] = TEXT ("HelloWin") ;
    HWND         hwnd ;
    MSG          msg ;
    WNDCLASS     wndclass ;

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

    if (!RegisterClass (&wndclass))
    {
    MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
    szAppName, MB_ICONERROR) ;
    return 0 ;
    }

    hwnd = CreateWindow (szAppName,                  // window class name
    TEXT ("The Hello Program"), // window caption
    WS_OVERLAPPEDWINDOW,        // window style
    CW_USEDEFAULT,              // initial x position
    CW_USEDEFAULT,              // initial y position
    CW_USEDEFAULT,              // initial x size
    CW_USEDEFAULT,              // initial y size
    NULL,                       // parent window handle
    NULL,                       // window menu handle
    hInstance,                  // program instance handle
    NULL) ;                     // creation parameters

    ShowWindow (hwnd, iCmdShow) ;
    UpdateWindow (hwnd) ;

    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg) ;
    DispatchMessage (&msg) ;
    }
    return msg.wParam ;
    }LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_LBUTTONUP:
    SendMessage(hwnd,WM_CLOSE,0,0);
    return 0 ;

    case WM_SYSCOMMAND:
    switch(LOWORD(wParam))
    {
    case SC_CLOSE://右上角的叉叉功能没了
    return 0;
    }
    break;

    case WM_CLOSE://你要的处理代码假设如下:
    if(MessageBox(hwnd,TEXT("退出程序吗? "),TEXT("标题"),MB_YESNO|MB_ICONQUESTION)!=IDYES)
    return 0;
    DestroyWindow(hwnd);
    return 0; case WM_DESTROY:
    PostQuitMessage (0) ;
    return 0 ;
    }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
      

  6.   

    没有WM_SYSCOMMAND样式不就没有X按钮了么
      

  7.   

    取得窗口系统菜单 GetSystemMenu啥的
    然后就和普通菜单一样的让 CLOSE 按钮不可用,CLOSE按钮句柄用ID取得即可