DefWindowProc
生活随笔
收集整理的這篇文章主要介紹了
DefWindowProc
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
簡(jiǎn)介
編輯 函數(shù)功能:該調(diào)用DefWindowProc函數(shù)時(shí)使用窗口過(guò)程接收的相同參數(shù)。 函數(shù)原型:LRESULT DefWindowProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam);功能
編輯 DefWindowProc這個(gè)函數(shù)是默認(rèn)的窗口處理函數(shù),我們可以把不關(guān)心的消息都丟給它來(lái)處理。這個(gè)函數(shù)在處理關(guān)閉窗口消息WM_CLOSE時(shí),是調(diào)用DestroyWindow函數(shù)關(guān)閉窗口并且發(fā)WM_DESTROY消息給應(yīng)用程序;而它對(duì)WM_DESTROY這個(gè)消息是不處理的(考慮為什么?);我們?cè)趹?yīng)用程序中對(duì)這個(gè)消息的處理是發(fā)出WM_QUIT消息。因此WM_CLOSE、WM_DESTROY、WM_QUIT這三個(gè)消息是先后產(chǎn)生的。參數(shù)
編輯 hWnd:指向接收消息的窗口過(guò)程的句柄。 Msg:指定消息類型。 wParam:指定其余的、消息特定的信息。該參數(shù)的內(nèi)容與Msg參數(shù)值有關(guān)。 IParam:指定其余的、消息特定的信息。該參數(shù)的內(nèi)容與Msg參數(shù)值有關(guān)。 返回值:返回值就是消息處理結(jié)果,它與發(fā)送的消息有關(guān)。 備注:對(duì)于Windows CE;如果Msg為WM_SETTEXT那么返回0。 當(dāng)DefWindowProc處理WM_DESTROY消息時(shí),它不自動(dòng)調(diào)用PostQuitMessage。 速查:Windows NT 3.1以上版本;Windows:95以上版本:Windows CE以上版本;頭文件;winuser.h;庫(kù)文件:user32.lib;Unicode:在Windows NT環(huán)境中以Unicode和ANSI版本實(shí)現(xiàn)。 ============================================================================================================================= DefWindowProc Function -------------------------------------------------------------------------------- The DefWindowProc function calls the default window procedure to provide default processing for any window messages that an application does not process. This function ensures that every message is processed. DefWindowProc is called with the same parameters received by the window procedure. Syntax LRESULT DefWindowProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ); Parameters hWnd [in] Handle to the window procedure that received the message. Msg [in] Specifies the message. wParam [in] Specifies additional message information. The content of this parameter depends on the value of the Msg parameter. lParam [in] Specifies additional message information. The content of this parameter depends on the value of the Msg parameter. Return Value The return value is the result of the message processing and depends on the message. Remarks Windows 95/98/Me: DefWindowProcW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems . Example For an example, see Designing a Window Procedure. Function Information Minimum DLL Version user32.dll Header Declared in Winuser.h, include Windows.h Import library User32.lib Minimum operating systems Windows 95, Windows NT 3.1 Unicode Implemented as ANSI and Unicode versions范例
編輯 /*------------------------------------------------------------ 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) //命令行參數(shù),窗口顯示方式 { static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsEx tra = 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) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case?WM_CREATE: PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case?WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }總結(jié)
以上是生活随笔為你收集整理的DefWindowProc的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: AfxBeginThread
- 下一篇: PostMessage