简介

编辑

函数功能:该调用DefWindowProc函数时使用窗口过程接收的相同参数。
函数原型:LRESULT DefWindowProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM IParam);

功能

编辑

DefWindowProc这个函数是默认的窗口处理函数,我们可以把不关心的消息都丢给它来处理。这个函数在处理关闭窗口消息WM_CLOSE时,是调用DestroyWindow函数关闭窗口并且发WM_DESTROY消息给应用程序;而它对WM_DESTROY这个消息是不处理的(考虑为什么?);我们在应用程序中对这个消息的处理是发出WM_QUIT消息。因此WM_CLOSE、WM_DESTROY、WM_QUIT这三个消息是先后产生的。

参数

编辑

hWnd:指向接收消息的窗口过程的句柄。
Msg:指定消息类型。
wParam:指定其余的、消息特定的信息。该参数的内容与Msg参数值有关。
IParam:指定其余的、消息特定的信息。该参数的内容与Msg参数值有关。
返回值:返回值就是消息处理结果,它与发送的消息有关。
备注:对于Windows CE;如果Msg为WM_SETTEXT那么返回0。
当DefWindowProc处理WM_DESTROY消息时,它不自动调用PostQuitMessage。
速查:Windows NT 3.1以上版本;Windows:95以上版本:Windows CE以上版本;头文件;winuser.h;库文件:user32.lib;Unicode:在Windows NT环境中以Unicode和ANSI版本实现。
=============================================================================================================================
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) //命令行参数,窗口显示方式
{
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) ;
}

DefWindowProc相关推荐

  1. [VC]WindowProc和DefWindowProc函数

    在Windows操作系统里,当窗口显示之后,它就可以接收到系统源源不断地发过来的消息,然后窗口就需要处理这些消息,因此就需要一个函数来处理这些消 息.在API里定义了一个函数为回调函数,当系统需要向窗 ...

  2. WindowProc和DefWindowProc的区别

    1. WindowProc是你给自己的窗口定义的窗口处理函数 DefWindowProc是windows平台提供的默认窗口处理函数 如果某些消息你不需要做特别的处理,调用DefWindowProc进行 ...

  3. Windows窗口的建立

    Windows窗口的建立 预备知识 DC CreateCompatibleDC() CreateDIBSection() SelectObject() BitBlt() CODE 设备上下文 (简称为 ...

  4. ATL的GUI程序设计(3)

    第三章 ATL的窗口类 CWindowImpl.CWindow.CWinTraits,ATL窗口类的奥秘尽在此三者之中.在本章里,李马将为你详细解说它们的使用方法.另外,本章的内容也可以算是本书的核心 ...

  5. DELPHI 中 Window 消息大全使用详解

    Window 消息大全使用详解 导读: Delphi是Borland公司的一种面向对象的可视化软件开发工具. Delphi集中了Visual C++和Visual Basic两者的优点:容易上手.功能 ...

  6. Windows程序设计学习笔记(1):一个简单的windows程序

    <Windows程序设计>(第五版)(美Charles Petzold著) 1 #include<windows.h> 2 3 LRESULT CALLBACK WndProc ...

  7. Windows 编程[9] - WM_CLOSE 消息

    本例效果图: program Project1;usesWindows, Messages;{供 WM_CLOSE 消息调用的自定义过程} procedure OnClose(h: HWND); be ...

  8. 【Visual C++】游戏开发笔记十三 游戏输入消息处理(二) 鼠标消息处理

    本系列文章由zhmxy555编写,转载请注明出处. http://blog.csdn.net/zhmxy555/article/details/7405479 作者:毛星云    邮箱: happyl ...

  9. 一步一步实现扫雷游戏(C语言实现)(三)

    使用WIN32API连接窗口 此项目相关博文链接 一步一步实现扫雷游戏(C语言实现)(一) 一步一步实现扫雷游戏(C语言实现)(二) 一步一步实现扫雷游戏(C语言实现)(三) 一步一步实现扫雷游戏(C ...

最新文章

  1. 考研国家线罕见大幅上涨,12个学科涨幅10分以上,超300万人将落榜
  2. 自定义标签 (转载)
  3. 两个软件相互交换数据_六轴算法机软件使用说明
  4. Page cache和Buffer cache[转1]
  5. Python学习:函数
  6. 大数据统计分析毕业设计_大数据分析与传统统计分析的区别
  7. 【转】最为详尽的WPF类继承关系*!
  8. c语言define定义全局变量,webpack中使用DefinePlugin定义全局变量
  9. 什么是微型计算机的组成原理,1微型计算机基本组成原理.ppt
  10. 追踪研读法破解EZ-USB的“远程唤醒”
  11. 内外网切换,内网固定ip
  12. 关于嵌入式的学习和职业发展
  13. 如何将工作流程“简单化”,从而提高工作效率?
  14. 解决阿里云oss 图片跨域问题
  15. 一个项目经理的经验总结_小七_新浪博客
  16. 魅族20值得入手吗 魅族20参数配置
  17. SAP案例教程FI财务后台配置
  18. 考研英语复试口语常见问题(上岸必备)
  19. JavaScript进阶 - 第9章 DOM对象,控制HTML元素
  20. css中多行文本溢出显示省略号的方法

热门文章

  1. 实训23 2018.4.27
  2. js 根据所输内容生成助记码
  3. C#开发微信门户及应用(25)-微信企业号的客户端管理功能
  4. Redis总结(二)C#中如何使用redis
  5. Linux硬件信息查看
  6. mac找不到mysql数据库_mac下mysql升级后找回丢失数据库
  7. mysql query plan_MySQL Execution Plan--IN查询计划(2)
  8. 【控制】《自动控制原理》胡寿松老师-第9章-线性系统的状态空间分析与综合
  9. 5.8 程序示例--线性分类-机器学习笔记-斯坦福吴恩达教授
  10. LINUX 使用tcgetattr函数与tcsetattr函数控制终端四