CSDN=>FAQ=>FAQ 展示
  • 问题内容:父窗口里有CS_NOCLOSE风格,子窗口如何去掉这个风格不影响父窗口
  • 原讨论链接:http://community.csdn.net/expert/topicview1.asp?id=5663759
  • 所属论坛:界面     审核组:VC/MFC
  • 提问者:rand0941     解决者:WindAndSnow
  • 感谢:mfc168 ReverseEngineering WindAndSnow emptyness
  • 关键字:VC/MFC 界面
  • 答案:

    父窗口里有CS_NOCLOSE风格,子窗口如何去掉这个风格不影响父窗口

    相关代码
    #include "stdafx.h"
    #include "resource.h"

    #define MAX_LOADSTRING 100

    HINSTANCE hInst;
    TCHAR szTitle[MAX_LOADSTRING];
    TCHAR szWindowClass[MAX_LOADSTRING];


    ATOM MyRegisterClass( HINSTANCE hInstance );
    ATOM Modify( HINSTANCE hInstance );
    BOOL InitInstance( HINSTANCE, int );
    LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
    BOOL dump(void);

    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow )
    {

    MSG msg;
    HACCEL hAccelTable;


    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_DUMP, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass( hInstance );

    if( !InitInstance( hInstance, nCmdShow ) ) 
    {
    return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DUMP);

    while( GetMessage(&msg, NULL, 0, 0) ) 
    {
    if( !TranslateAccelerator (msg.hwnd, hAccelTable, &msg) ) 
    {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
    }
    }

    return msg.wParam;
    }

    ATOM MyRegisterClass( HINSTANCE hInstance )
    {
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX); 

    wcex.style = CS_HREDRAW | CS_VREDRAW ;
    wcex.lpfnWndProc = (WNDPROC)WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DUMP);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = (LPCSTR)IDC_DUMP;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
    wcex.style = wcex.style | CS_NOCLOSE;
    // wcex.style = wcex.style & ~CS_NOCLOSE;
    return RegisterClassEx( &wcex );
    }
    ATOM Modify( HINSTANCE hInstance )
    {
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX); 

    wcex.style = CS_HREDRAW | CS_VREDRAW ;
    wcex.lpfnWndProc = (WNDPROC)dump;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DUMP);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = (LPCSTR)IDC_DUMP;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
    return RegisterClassEx( &wcex );
    }

    BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
    {
       HWND hWnd;

       hInst = hInstance; 

       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

       if( !hWnd ) 
       {
          return FALSE;
       }

       ShowWindow( hWnd, nCmdShow );
       UpdateWindow( hWnd );

       return TRUE;
    }


    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR szHello[MAX_LOADSTRING];
    LoadString(hInst, IDS_GOOD, szHello, MAX_LOADSTRING);

    switch( message ) 
    {
    case WM_COMMAND:
    wmId    = LOWORD(wParam); 
    wmEvent = HIWORD(wParam); 
    switch( wmId ) 
    {
    case IDM_EXIT:
       DestroyWindow( hWnd );
       break;
    default:
       return DefWindowProc( hWnd, message, wParam, lParam );
    }
    break;
    case WM_KEYDOWN:
    return dump();
    break;
    case WM_PAINT:
    hdc = BeginPaint (hWnd, &ps);
    RECT rt;
    GetClientRect( hWnd, &rt );
    DrawText( hdc, szHello, strlen(szHello), &rt, DT_CENTER );
    TextOut(hdc,40,40,"40",1);
    EndPaint( hWnd, &ps );
    break;
    case WM_DESTROY:
    PostQuitMessage( 0 );
    break;
    default:
    return DefWindowProc( hWnd, message, wParam, lParam );
       }
       return 0;
    }

    BOOL dump( )
    {
    HINSTANCE hInstance =GetModuleHandleA(NULL);
    HWND hWnd;
    Modify(hInstance);
        hInst = hInstance; 
       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW&~WS_MINIMIZEBOX|WS_SYSMENU,
          CW_USEDE

  • 评价: 有价值 给朵鲜花(2) 无价值 扔个鸡蛋(0)
相关FAQ
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo