百度知道(),这个讲的比较明白 windows是以消息为基础,事件为驱动而运行的 也就是说,一个事件发生后,windows会产生一个消息,传递给指定的窗口进行处理,既然这样,必须有接口给系统来调用,这个LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM)中第1个参数,是消息要传递的窗口,参数2是消息的id(也就是这是个什么样的消息,比如鼠标左键按下对应的消息是WM_LBUTTONDOWN),参数3和参数4是消息的具体内容
文章转自 : 这个比较详细
Windows程序是事件驱动的,对于一个窗口,它的大部分例行维护是由系统维护的。没个窗口都有一个消息处理函数。在消息处理函数中,对传入的消息进行处理。系统内还有它自己的缺省消息处理函数。
客户写一个消息处理函数,在窗口建立前,将消息处理函数与窗口关联。这样,每当有消息产生时,就会去调用这个消息处理函数。通常情况下,客户都不会处理全部的消息,而是只处理自己感兴趣的消息,其他的,则送回到系统的缺省消息处理函数中去。系统会将针对这个程序的消息依次放到程序的“消息队列”中,由程序自己依次取出消息,在分发到对应的窗口中去。因此,建立窗口后,将进入一个循环。在循环中,取出消息、派发消息,循环往复,直到取得的消息是退出消息。循环退出后,程序即结束。 #include "stdafx.h"#include <windows.h>//一、消息处理函数//参数:窗口句柄,消息,消息参数,消息参数LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ //处理感兴趣的消息switch (message){ case WM_DESTROY://当用户关闭窗口,窗口销毁,程序需结束,发退出消息,以退出消息循环PostQuitMessage (0) ;return 0 ;}//其他消息交给由系统提供的缺省处理函数return ::DefWindowProc (hwnd, message, wParam, lParam) ;}//二、应用程序主函数//参数:实例句柄、前一个实例的句柄、命令行参数、窗口显示方式int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ //1.注册窗口类static TCHAR szAppName[] = TEXT ("HelloWin") ;//窗口类名称//定制"窗口类"结构WNDCLASS wndclass ;wndclass.style = CS_HREDRAW | CS_VREDRAW ;wndclass.lpfnWndProc = WndProc ;//关联消息处理函数 wndclass.cbClsExtra = 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 ("RegisterClass Fail!"), szAppName, MB_ICONERROR) ;return 0 ;}//建立窗口HWND hwnd ;hwnd = CreateWindow (szAppName,//窗口类名称TEXT ("The Hello Program"),//窗口标题 WS_OVERLAPPEDWINDOW,//窗口风格CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,//实例句柄NULL);ShowWindow (hwnd, iCmdShow) ;UpdateWindow (hwnd) ;//消息循环MSG msg ;while (GetMessage (&msg, NULL, 0, 0))//从消息队列中取消息 { TranslateMessage (&msg) ;//转换消息DispatchMessage (&msg) ;//派发消息}return msg.wParam ;}【huangyangman】:the entry point to a Windows program is WinMain, which always appears like this: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) #define WINAPI __stdcallThis statement specifies a calling convention that involves how machine code is generated to place function call arguments on the stack. Most Windows function calls are declared as WINAPI. The first parameter to WinMain is something called an "instance handle." In Windows programming, a handle is simply a number that an application uses to identify something. In this case, the handle uniquely identifies the program. It is required as an argument to some other Windows function calls.The second parameter to WinMain is always NULL (defined as 0). The third parameter to WinMain is the command line used to run the program. The fourth parameter to WinMain indicates how the program should be initially displayed—either normally or maximized to fill the window, or minimized to be displayed in the task list bar.LZ要想看详细的 见《programming windows》【huangyangman】:见鬼 我的错 我都发了什么,败笔weijiangshanwww() 兄弟发的很详细了,lz慢慢学吧【wanfustudio】:回调函数路过【a_b_c_abc2】:LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM)======================================================LRESULT //表示会返回多种long型值CALLBACK //只是为了识别这是一个回调函数的空宏HWND //窗口句柄,整型值UINT //unsigned int,WM_NOTIFYWPARAM //typedef UINT WPARAM;control identifierLPARAM //typedef LONG LPARAM;notification messages【Jokar】:回调函数(CALLBACK函数) WndProc 被系统调用:message loop;while (GetMessage(....)){ TranslateMessage(&msg);DispatchMessage(&msg);}中,每当GetMessage获得窗口消息,就会通过DispatchMessage(...)将消息发送到WndProc,可以这么说,正式这个user32模块的API函数DispatchMessage(...)中调用了你的WndProc;"可能"是这样做的:BOOL WINAPI DispatchMessage(&msg){ ....WndClass wc;GetClassInfo(msg.hwnd, &wc);wc.lpfnWndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); /** 这个wc.lpfnWndProc中就记录有你的WndPoc的地址,注册窗口类时设置的~....}以后每当GetMessage获得消息,就会调用DispatchMessage,而DispatchMessage就会调用你的WndPoc了~呵呵【zerofinish】:WNDCLASS wndclass ;wndclass.style = CS_HREDRAW | CS_VREDRAW ;wndclass.lpfnWndProc = WndProc ;//关联消息处理函数 wndclass.cbClsExtra = 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;//类名称这里还是不太明白~【hailongchang】:CALLBACK function can be invoked by system or by user.WNDCLASS wndclass ;wndclass.style = CS_HREDRAW | CS_VREDRAW ;wndclass.lpfnWndProc = WndProc ;//关联消息处理函数 wndclass.cbClsExtra = 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;//类名称这段代码是初始化一个窗口类结构,填充好这个结构的各个item,去看MSDN 或者 petzold's prgramming windows【weijiangshanwww】:WNDCLASS wndclass ;wndclass.style = CS_HREDRAW | CS_VREDRAW ;wndclass.lpfnWndProc = WndProc ;//关联消息处理函数 wndclass.cbClsExtra = 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;//类名称 这是windows编程或者MFC相关书籍会讲到的东西,如果真的要说起来是很多的。如果想知道具体的用法,建议LZ找想关书籍看下就了了。【anykey_1】:看 windows 程序设计【skylittle】:楼主想要问的是a_b_c_abc2(╰ _ ╯) ==============================================LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM)======================================================LRESULT //表示会返回多种long型值CALLBACK //只是为了识别这是一个回调函数的空宏HWND //窗口句柄,整型值UINT //unsigned int,WM_NOTIFYWPARAM //typedef UINT WPARAM;control identifierLPARAM //typedef LONG LPARAM;notification messages=====================================================回答的问题吧:)