文章編號: 121541 - 上次校閱: 2005年7月11日 - 版次: 1.3

如何覆寫滿拖曳

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

結論

Windows NT 版本 3.5 介紹可讓您查看整個視窗移動或調整大小而非查看剛才的視窗移動外框或調整大小的完整拖曳。下面的範例應用程式會示範如何執行桌面控制台小程式,並選取 [完整拖曳] 核取方塊,啟用完整的拖曳。

其他相關資訊

當您啟用完整拖曳以調整視窗時,應用程式會收到許多訊息指出視窗調整大小。(您可以確認這與間諜)。如果這有您的應用程式上的非預期效果,您必須覆寫您的應用程式中的完整的拖曳功能。

移動或調整大小啟動時應用程式會收到這個訊息:
   WM_ENTERSIZEMOVE (0231)
				
時移動或調整大小完成應用程式會接收此訊息:
   WM_EXITSIZEMOVE (0232)
				
上述的郵件做為通知視窗是進入及離開調整大小或移動的作業。如果您想您可用來設定旗標,以防止程式移動期間處理 WM_PAINT 訊息這些通知,或拖曳大小作業,以覆寫滿。

範例程式碼

   /***********************************************************************
    *
    · Fulldrag.c
     *
    · Copyright (c) 1997 Microsoft Corporation.
     *
    · Abstract:
     *
    · Sample program that demonstrates how a program can override
    · Full Drag.
     *

   ***********************************************************************/ 

    #define STRICT
    #include <windows.h>


   /***********************************************************************
     *
    · Globals
     *
    · g_fMoveSize
     *
    · Set while you are in a move/size loop. The WM_ENTERSIZEMOVE
    · and WM_EXITSIZEMOVE messages tell you when these things happen.
     *
    · g_fPaintDeferred
     *
    · Set if you deferred a paint that occurred while you were
    · busy doing a Move/Size. When the Move/Size completes
    · and you discover that a paint was deferred, you force
    · a full repaint to complete the deferred paint.
     *
     *
    · Note:
     *
    · In a real (that is, non-sample) program, these would not be global
    · variables. They would be per-window variables.
     *

   ***********************************************************************/ 

    BOOL g_fDragging;
    BOOL g_fPaintDeferred;


   /***********************************************************************
     *
    · Hilbert
     *
    · Draws a segment of the hilbert curve.
     *
    · The math is not important. What is important is that drawing
    · a hilbert curve takes a long time.
     *

   ***********************************************************************/ 

    #define MAXDEPTH 8      /* Bigger depth takes longer to draw. */ 
    void
    Hilbert(HDC hdc, int x, int y, int vx, int vy, int wx, int wy, int n)
    {
    if (n >= MAXDEPTH) {
    LineTo(hdc, x + (vx+wx)/2, y + (vy+wy)/2);
    } else {
    n++;
    Hilbert(hdc, x, y, wx/2, wy/2, vx/2, vy/2, n);
    Hilbert(hdc, x+vx/2, y+vy/2, vx/2, vy/2, wx/2, wy/2, n);
    Hilbert(hdc, x+vx/2+wx/2, y+vy/2+wy/2, vx/2, vy/2, wx/2, wy/2, n);
    Hilbert(hdc, x+vx/2+wx, y+vy/2+wy, -wx/2, -wy/2, -vx/2, -vy/2, n);
        }
    }


   /***********************************************************************
     *
    · Hilbert_OnPaint
     *
    · Handle the WM_PAINT message.
     *
    · If the user is dragging the window, then don't do painting,
    · because that would make the dragging very jerky. Instead, just
    · remember that there was a paint message that you ignored. After
    · the size/move is complete, you will perform one big paint to do
    · the things that you ignored.
     *

   ***********************************************************************/ 

    void
    Hilbert_OnPaint(HWND hwnd)
    {
    PAINTSTRUCT ps;
    RECT rc;
    HDC hdc;

    hdc = BeginPaint(hwnd, &ps);
    if (hdc) {
    if (g_fDragging) {
    g_fPaintDeferred = TRUE;
    } else {
    HBRUSH hbrOld;
    HPEN hpenOld;
    HCURSOR hcurOld;

    hcurOld = SetCursor(LoadCursor(0, IDC_WAIT));
    hbrOld = SelectObject(hdc, GetStockObject(BLACK_BRUSH)); hpenOld =
    SelectObject(hdc, GetStockObject(BLACK_PEN));
    MoveToEx(hdc, 0, 0, 0);
    Hilbert(hdc, 0, 0, GetSystemMetrics(SM_CXFULLSCREEN), 0,
    0, GetSystemMetrics(SM_CYFULLSCREEN), 0);
    SelectObject(hdc, hpenOld);
    SelectObject(hdc, hbrOld);
    SetCursor(hcurOld);
            }
    EndPaint(hwnd, &ps);
        }
    }


   /***********************************************************************
     *
    · Hilbert_WndProc
     *
    · Window procedure.
     *

   ***********************************************************************/ 

    LRESULT CALLBACK
    Hilbert_WndProc(HWND hwnd, UINT wm, WPARAM wp, LPARAM lp)
    {
    switch (wm) {
    case WM_PAINT:
    Hilbert_OnPaint(hwnd);
    break;

    case WM_DESTROY:
    PostQuitMessage(0); break;

        /*
    · When you begin a Size/Move operation, remember that you are
    · performing a Size/Move operation so you don't paint during the
    . Size/Move.
         */ 
    case WM_ENTERSIZEMOVE:
    g_fDragging = TRUE; break;

        /*
    · When you finish a Size/Move operation, remember that you are
    · performing a Size/Move operation so you will resume painting,
    . and if there were any deferred paint messages, re-invalidate
    . yourself they will be regenerated.
         */ 
    case WM_EXITSIZEMOVE:
    g_fDragging = FALSE;
    if (g_fPaintDeferred) {
    g_fPaintDeferred = FALSE;
    InvalidateRect(hwnd, 0, TRUE);
            }
    break;

        }

    return DefWindowProc(hwnd, wm, wp, lp);
    }


   /***********************************************************************
     *
    · WinMain
     *
    · Program entry point.
     *
    · Register the class, create the window, and go into a message loop.
     *

   ***********************************************************************/ 

    int WINAPI
    WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR pszCmdLine, int
    nCmdShow)
    {
    HWND hwnd;
    MSG msg;
    WNDCLASS wc = {
    0,
    Hilbert_WndProc,
    0,
    0,
    hinst,
    LoadIcon(0, IDI_APPLICATION),
    LoadCursor(0, IDC_ARROW),
    (HBRUSH)(COLOR_WINDOW+1),
    0,
    "Hilbert"
        };

    RegisterClass(&wc);
    hwnd = CreateWindow("Hilbert", "Hilbert", WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT,
    CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hinst, 0);
    ShowWindow(hwnd, nCmdShow);
    while (GetMessage(&msg, 0, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
        }

    return 0;
    }
				

這篇文章中的資訊適用於:
  • Microsoft Platform Software Development Kit-January 2000 Edition
關鍵字:?
kbmt kbhowto kbwndw KB121541 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:121541? (http://support.microsoft.com/kb/121541/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。