1.在vc6下用向导生成一个win32 Application的typical "HelloWorld"程序.代码这里不写了.
如果把UpdateWindow();语句去掉,为何开始出现的窗口上依然有"HelloWorld"?
我想,去掉UpdateWindow();后,窗口刚开始时候是不发送WM_PANIT消息的,即,这个消息处理函数不会做的.
但....
为何?谢谢!

解决方案 »

  1.   

    怎么不发送
    窗口创建时就要绘制窗口 如果不发送WM_PAINT还绘制什么窗口
    真是猪
      

  2.   

    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    你看,在UpdateWindow()之前,已经显示窗口了.
      

  3.   

    那UpdateWindow()不是多余吗?
    放在哪里干吗用?
      

  4.   

    应该是这样的,如果你对窗口显示有所跟新,那么你要用UpdateWindow()和ShowWindow(),窗口将发送一个WM_PAINT消息,调用OnDraw函数,对窗口重画。如果你不将原来的内容取消的话,那么原来的内容依然存在。而如果你没有对窗口作出更新,而且你也没有显式或隐式的调用OnDraw函数,原来的内容当然还在窗口中的啦。
      

  5.   

    刚开始的时候,框架自己会发送WM_PAINT消息,调用OnDraw函数的。不是一定要用UpdateDate函数才会引起窗口重画啊!
      

  6.   

    窗口创建时就要绘制窗口 如果不发送WM_PAINT还绘制什么窗口
    请问,那个语句发送?-----------------
    huaguocsdn(MoroseSnail(郁闷的蜗牛)) (
    我是建立一个win32工程.代码如下:
    // chp2.cpp : Defines the entry point for the application.
    //#include "stdafx.h"
    #include "resource.h"#define MAX_LOADSTRING 100// Global Variables:
    HINSTANCE hInst; // current instance
    TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text// Foward declarations of functions included in this code module:
    ATOM MyRegisterClass(HINSTANCE hInstance);
    BOOL InitInstance(HINSTANCE, int);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
      // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable; // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_CHP2, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance); // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow)) 
    {
    return FALSE;
    } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CHP2); // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    } return msg.wParam;
    }//
    //  FUNCTION: MyRegisterClass()
    //
    //  PURPOSE: Registers the window class.
    //
    //  COMMENTS:
    //
    //    This function and its usage is only necessary if you want this code
    //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
    //    function that was added to Windows 95. It is important to call this function
    //    so that the application will get 'well formed' small icons associated
    //    with it.
    //
    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_CHP2);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = (LPCSTR)IDC_CHP2;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);
    }//
    //   FUNCTION: InitInstance(HANDLE, int)
    //
    //   PURPOSE: Saves instance handle and creates main window
    //
    //   COMMENTS:
    //
    //        In this function, we save the instance handle in a global variable and
    //        create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;   hInst = hInstance; // Store instance handle in our global variable   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;
    }//
    //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_COMMAND - process the application menu
    //  WM_PAINT - Paint the main window
    //  WM_DESTROY - post a quit message and return
    //
    //
    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_HELLO, szHello, MAX_LOADSTRING); switch (message) 
    {
    case WM_COMMAND:
    wmId    = LOWORD(wParam); 
    wmEvent = HIWORD(wParam); 
    // Parse the menu selections:
    switch (wmId)
    {
    case IDM_ABOUT:
       DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
       break;
    case IDM_EXIT:
       DestroyWindow(hWnd);
       break;
    default:
       return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;
    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    RECT rt;
    GetClientRect(hWnd, &rt);
    DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
    EndPaint(hWnd, &ps);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }// Mesage handler for about box.
    LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_INITDIALOG:
    return TRUE; case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
    {
    EndDialog(hDlg, LOWORD(wParam));
    return TRUE;
    }
    break;
    }
        return FALSE;
    }
      

  7.   

    比如框架生成的时候,会自动发送WM_SIZE消息给窗口,而大家知道,WM_SIZE会引发WM_PAINT消息的发送的。所以开始如果你自己不做改动,app早帮你把窗口画好了.它的那个UpdateDate是为了让你在它之前做“你自己”的初始化的,你如果做了改动,那么UpdateDate就有用了。
      

  8.   

    真是猪
    就好比你绘制了一个图形 就调用Invalidate()更新屏幕一样
    但是窗口刚打开时并不要调用什么Invalidate()更新 
    因为它本身就执行了OnDraw()函数
    所以UpdateWindow()和WM_PAINT是没有关系的
    UpdateWindow()用于菜单 工具栏等的显示
    如果没有那些东西 完全可以去掉  UpdateWindow()
      

  9.   

    你傻啊,系统自己要发送的消息,都让你看到吗?它不发送WM_PAINT消息,那么视图之外的菜单、工具条是怎么出来 的?你要知道,窗口的一切,都是“画”出来的,可是并不是你在控制呀!!!
      

  10.   

    你CString赋值的时候都用_T("ddd")呀。_T是用来兼容ANSI和unicode的。他识别当前系统,作出判断。
    CString str(_T("hello"));
    m_edit.SetText(str);
      

  11.   

    _T()没用的 我都试过好多次了
    真不知道该怎么define 那个 _UNICODE
    楼上的知道怎么define吗
      

  12.   

    msdn:
    UpdateWindow
    The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent. If the update region is empty这句话啥意思?