重温WIN32 API ------ Window消息跟踪

1 探索消息处理过程的必要性与可能性

Windows操作系统的名称本身就是其核心概念--窗口。与窗口密不可分的就是消息了,本文建立一个最简单的Windows窗口程序,然后增加跟踪代码,把所有的Windows消息打印到文件中。我们知道,Windows处理消息的时候是序列化处理的,只有一个线程来完成,所以消息的处理具有严格的顺序,这也便于我们分析消息处理过程。

运行环境: Windows8.1

编译环境:VS2013

项目源码:见附录

2 消息跟踪结果与分析

2.1 结果文件

由于结果文件太大了,请读者自己编译此项目运行查看,项目源码已放到了文后的附录里。

2.2 分析结论

USER32.dll中的代码和我们编写的代码彼此调用,下面是几个具体的小结论。

(1)当我们调用CreateWindow()创建窗口的时候,这个函数的内部却在以不同参数多次调用我们编写的窗口过程WndProc了;

(2)当我们调用ShowWindow()显示窗口的时候,这个函数内部疯狂地多次以不同参数调用WndProc();

(3)当我们调用UpdateWindow()更新窗口时,这个函数内部以WM_PAINT参数调用WndProc();

(4)当我们调用GetMessage()从消息队列取消息时,这个函数内部可能会多次调用WndProc()来处理Send到消息队列中的消息,处理完sent的消息后,才返回一个posted的消息;

(5)我们在WndProc()里调用了DefWindowProc(),而这个函数内部也会根据处理消息的类型,反过来调用WndProc(),有点像递归调用了,不过每次使用的参数值不同,不会出现死循环;

(6)窗口被销毁后,User32模块内部以WM_DESTROY参数调用WndProc()。

(7)应用程序必须自己主动调用PostQuitMessage()来把WM_QUIT放入消息队列中结束消息循环。

附录 项目源代码

main.cpp

 

#include <Windows.h>
#include "LogWriter.h"
#include "WindowsMessages.h"

LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t* szCmdLine, int iCmdShow)
{
	LOG(L"程序开始");
	wchar_t szClassName[] = L"MyWindowClass";
	// 注册窗口类
	WNDCLASSEX wcex;
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = NULL;
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = szClassName;
	wcex.hIconSm = NULL;
	LOG(L"RegisterClassEx()开始");
	::RegisterClassEx(&wcex);
	LOG(L"RegisterClassEx()返回");

	// 创建窗口
	LOG(L"CreateWindow()开始");
	HWND hWnd = CreateWindow(szClassName, L"Windows 消息测试", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	LOG(L"CreateWindow()返回");

	LOG(L"ShowWindow()开始");
	::ShowWindow(hWnd, SW_SHOW);
	LOG(L"ShowWindow()返回");

	LOG(L"UpdateWindow()开始");
	::UpdateWindow(hWnd);
	LOG(L"UpdateWindow()返回");

	// 开启消息循环, 直到取回WM_QUIT消息,GetMessage()返回0,退出循环
	MSG msg;
	BOOL bRet = 0;
	wchar_t str[256];
	while (1)
	{
		LOG(L"GetMessage()开始");
		bRet = GetMessage(&msg, NULL, 0, 0);
		::wsprintf(str, L"GetMessage()返回,取回消息:%s,对应窗口:%X", get_msg_name(msg.message), msg.hwnd);
		LOG(str);

		if (bRet == 0)
		{
			// 收到了WM_QUIT,退出循环
			break;
		}
		else if (bRet == -1)
		{
			// 处理错误
		}
		else
		{
			TranslateMessage(&msg);
			LOG(L"DispatchMessage()开始");
			DispatchMessage(&msg);   // 根据msg.hwnd调用指定窗口过程
			LOG(L"DispatchMessage()返回");
		}
	}

	// 程序结束
	LOG(L"程序结束");
	ENDLOG
	return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	wchar_t str[128];
	::wsprintf(str, L"WndProc被调用开始,消息参数: %s", get_msg_name(message));
	LOG(str);
	int r = 0;
	switch (message)
	{
	case WM_CREATE:
		break;
	case WM_DESTROY:
		::PostQuitMessage(0);   // 窗口销毁后,指示退出消息循环
		break;
	default:
		LOG(L"DefWindowProc()开始");
		r = ::DefWindowProc(hWnd, message, wParam, lParam);
		LOG(L"DefWindowProc()返回");

		LOG(L"WndProc返回");
		return r;
	}
	LOG(L"WndProc返回");
	return 0;
}

 


其他辅助文件的功能包括:打印到文件和根据消息号获得消息名称。这些辅助文件一并列到下面:

LogWriter.h

#pragma once
/*
日志记录类
功能描述:
根据当前时间自动生成日志文件名,自动记录日志到日志文件。

日志文件名格式(样例):
20141219211252255.log

日志内容格式(样例):
2014年12月19日11时52分55秒,源文件:e:\work\udptest\udptestdlg.cpp,第109行, 这里是要写的日志内容

使用方式:
此类采用单例模式设计,为使用方便,定义了两个宏供用户调用。样例代码:
LOG(L"这里是要写的日志内容");  // 记录日志到文件
ENDLOG  // 程序退出之前调用,关闭日志文件
*/
#include <stdio.h>
class LogWriter
{
protected:
	LogWriter();
	~LogWriter();
private:
	wchar_t fileName[1024];
	FILE* fp;
public:
	void Log(wchar_t* log);
public:
	static LogWriter* GetLogWriter();
	static void DeleteLogWriter();
private:
	static LogWriter* theOnlyLogWriter;
};

#define LOG(x) { 	wchar_t buffer[2048]; 	SYSTEMTIME st; 	::GetLocalTime(&st); 	swprintf_s(buffer, L"%04d年%02d月%02d日%02d时%02d分%02d秒,源文件:%s,第%d行, %s\n", 	st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, 	TEXT(__FILE__), __LINE__, x); 	LogWriter::GetLogWriter()->Log(buffer); }

#define ENDLOG 	LogWriter::DeleteLogWriter();


LogWriter.cpp

#include <stdio.h>
#include "LogWriter.h"
#include "share.h"
#include <Windows.h>
LogWriter* LogWriter::theOnlyLogWriter = NULL;

LogWriter::LogWriter()
{
	// determine the log file‘s name, yyyyMMddhhmmss.log
	SYSTEMTIME st;
	::GetLocalTime(&st);
	::swprintf_s(this->fileName, L"%04d%02d%02d%02d%02d%02d.log", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	fp = ::_wfsopen(this->fileName, L"w,ccs=UTF-8", _SH_DENYNO); // 以共享读写模式打开日志文件
}

// 线程安全的写入文件
void LogWriter::Log(wchar_t* log)
{
	if (fp != NULL)
	{
		::fwprintf(this->fp, L"%s", log);
	}
}
LogWriter::~LogWriter()
{
	if (this->fp != NULL)
		::fclose(fp);
}

LogWriter* LogWriter::GetLogWriter()
{
	if (theOnlyLogWriter == NULL)
	{
		theOnlyLogWriter = new LogWriter();
	}
	return theOnlyLogWriter;
}

void LogWriter::DeleteLogWriter()
{
	if (theOnlyLogWriter != NULL)
	{
		delete theOnlyLogWriter;
		theOnlyLogWriter = NULL;
	}
}


WindowsMessage.h

#pragma once
#include <Windows.h>
wchar_t* get_msg_name(int message);

static wchar_t* Messages[] =
{
	L"WM_NULL",//0x0000
	L"WM_CREATE",//0x0001
	L"WM_DESTROY",//0x0002
	L"WM_MOVE",//0x0003
	L"WM_SIZEWAIT",//0x0004
	L"WM_SIZE",//0x0005
	L"WM_ACTIVATE",//0x0006
	L"WM_SETFOCUS",//0x0007
	L"WM_KILLFOCUS",//0x0008
	L"WM_SETVISIBLE",//0x0009
	L"WM_ENABLE",//0x000a
	L"WM_SETREDRAW",//0x000b
	L"WM_SETTEXT",//0x000c
	L"WM_GETTEXT",//0x000d
	L"WM_GETTEXTLENGTH",//0x000e
	L"WM_PAINT",//0x000f
	L"WM_CLOSE",   /* 0x10 */
	L"WM_QUERYENDSESSION",//0x0011
	L"WM_QUIT",//0x0012
	L"WM_QUERYOPEN",//0x0013
	L"WM_ERASEBKGND",//0x0014
	L"WM_SYSCOLORCHANGE",//0x0015
	L"WM_ENDSESSION",//0x0016
	L"WM_SYSTEMERROR",//0x0017
	L"WM_SHOWWINDOW",//0x0018
	L"WM_CTLCOLOR",//0x0019
	L"WM_WININICHANGE",//0x001a
	L"WM_DEVMODECHANGE",//0x001b
	L"WM_ACTIVATEAPP",//0x001c
	L"WM_FONTCHANGE",//0x001d
	L"WM_TIMECHANGE",//0x001e
	L"WM_CANCELMODE",//0x001f
	L"WM_SETCURSOR",  /* 0x20 */
	L"WM_MOUSEACTIVATE",//0x0021
	L"WM_CHILDACTIVATE",//0x0022
	L"WM_QUEUESYNC",//0x0023
	L"WM_GETMINMAXINFO",//0x0024
	L"WM_LOGOFF",//0x0025
	L"WM_PAINTICON",//0x0026
	L"WM_ICONERASEBKGND",//0x0027
	L"WM_NEXTDLGCTL",//0x0028
	L"WM_ALTTABACTIVE",//0x0029
	L"WM_SPOOLERSTATUS",//0x002a
	L"WM_DRAWITEM",//0x002b
	L"WM_MEASUREITEM",//0x002c
	L"WM_DELETEITEM",//0x002d
	L"WM_VKEYTOITEM",//0x002e
	L"WM_CHARTOITEM",//0x002f
	L"WM_SETFONT",  /* 0x30 */
	L"WM_GETFONT",//0x0031
	L"WM_SETHOTKEY",//0x0032
	L"WM_GETHOTKEY",//0x0033
	L"WM_FILESYSCHANGE",//0x0034
	L"WM_ISACTIVEICON",//0x0035
	L"WM_QUERYPARKICON",//0x0036
	L"WM_QUERYDRAGICON",//0x0037
	L"WM_WINHELP",//0x0038
	L"WM_COMPAREITEM",//0x0039
	L"WM_FULLSCREEN",//0x003a
	L"WM_CLIENTSHUTDOWN",//0x003b
	L"WM_DDEMLEVENT",//0x003c
	L"WM_GETOBJECT",//0x003d
	NULL,//0x003e
	L"WM_CALCSCROLL",//0x003f
	L"WM_TESTING",           /* 0x40 */
	L"WM_COMPACTING",//0x0041
	L"WM_OTHERWINDOWCREATED",//0x0042
	L"WM_OTHERWINDOWDESTROYED",//0x0043
	L"WM_COMMNOTIFY",//0x0044
	L"WM_MEDIASTATUSCHANGE",//0x0045
	L"WM_WINDOWPOSCHANGING", /* 0x0046 */
	L"WM_WINDOWPOSCHANGED", /* 0x0047 */
	L"WM_POWER",//0x0048
	L"WM_COPYGLOBALDATA",//0x0049
	L"WM_COPYDATA",//0x004a
	L"WM_CANCELJOURNAL",//0x004b
	L"WM_LOGONNOTIFY",//0x004c
	L"WM_KEYF1",//0x004d
	L"WM_NOTIFY",//0x004e
	L"WM_ACCESS_WINDOW",//0x004f
	L"WM_INPUTLANGCHANGEREQUEST",/* 0x0050 */
	L"WM_INPUTLANGCHANGE",//0x0051
	L"WM_TCARD",//0x0052
	L"WM_HELP",//0x0053
	L"WM_USERCHANGED",//0x0054
	L"WM_NOTIFYFORMAT",//0x0055
	NULL,//0x0056
	NULL,//0x0057
	NULL,//0x0058
	NULL,//0x0059
	NULL,//0x005a
	NULL,//0x005b
	NULL,//0x005c
	NULL,//0x005d
	NULL,//0x005e
	NULL,//0x005f
	NULL,/* 0x0060 */
	NULL,//0x0061
	NULL,//0x0062
	NULL,//0x0063
	NULL,//0x0064
	NULL,//0x0065
	NULL,//0x0066
	NULL,//0x0067
	NULL,//0x0068
	NULL,//0x0069
	NULL,//0x006a
	NULL,//0x006b
	NULL,//0x006c
	NULL,//0x006d
	NULL,//0x006e
	NULL,//0x006f
	L"WM_FINALDESTROY",/* 0x0070 */
	L"WM_MEASUREITEM_CLIENTDATA",//0x0071
	L"WM_TASKACTIVATED",//0x0072
	L"WM_TASKDEACTIVATED",//0x0073
	L"WM_TASKCREATED",//0x0074
	L"WM_TASKDESTROYED",//0x0075
	L"WM_TASKUICHANGED",//0x0076
	L"WM_TASKVISIBLE",//0x0077
	L"WM_TASKNOTVISIBLE",//0x0078
	L"WM_SETCURSORINFO",//0x0079
	NULL,//0x007a
	L"WM_CONTEXTMENU",//0x007b
	L"WM_STYLECHANGING",//0x007c
	L"WM_STYLECHANGED",//0x007d
	L"WM_DISPLAYCHANGE",//0x007e
	L"WM_GETICON",//0x007f
	L"WM_SETICON",  /* 0x0080 */
	L"WM_NCCREATE",  /* 0x0081 */
	L"WM_NCDESTROY",  /* 0x0082 */
	L"WM_NCCALCSIZE",  /* 0x0083 */
	L"WM_NCHITTEST",         /* 0x0084 */
	L"WM_NCPAINT",           /* 0x0085 */
	L"WM_NCACTIVATE",        /* 0x0086 */
	L"WM_GETDLGCODE",  /* 0x0087 */
	L"WM_SYNCPAINT",//0x0088
	L"WM_SYNCTASK",//0x0089
	NULL,//0x008a
	L"WM_KLUDGEMINRECT",//0x008b
	L"WM_LPKDRAWSWITCHWND",//0x008c
	NULL,//0x008d
	NULL,//0x008e
	NULL,//0x008f
	NULL,/* 0x0090 */
	NULL,//0x0091
	NULL,//0x0092
	NULL,//0x0093
	NULL,//0x0094
	NULL,//0x0095
	NULL,//0x0096
	NULL,//0x0097
	NULL,//0x0098
	NULL,//0x0099
	NULL,//0x009a
	NULL,//0x009b
	NULL,//0x009c
	NULL,//0x009d
	NULL,//0x009e
	NULL,//0x009f
	L"WM_NCMOUSEMOVE",  /* 0x00A0 *//* 0x00A0 */
	L"WM_NCLBUTTONDOWN",  /* 0x00A1 */
	L"WM_NCLBUTTONUP",  /* 0x00A2 */
	L"WM_NCLBUTTONDBLCLK", /* 0x00A3 */
	L"WM_NCRBUTTONDOWN",  /* 0x00A4 */
	L"WM_NCRBUTTONUP",  /* 0x00A5 */
	L"WM_NCRBUTTONDBLCLK", /* 0x00A6 */
	L"WM_NCMBUTTONDOWN",  /* 0x00A7 */
	L"WM_NCMBUTTONUP",  /* 0x00A8 */
	L"WM_NCMBUTTONDBLCLK", /* 0x00A9 */
	NULL,//0x00AA
	L"WM_NCXBUTTONDOWN",//0x00AB
	L"WM_NCXBUTTONUP",//0x00AC
	L"WM_NCXBUTTONDBLCLK",//0x00AD
	L"WM_NCUAHDRAWCAPTION", /* 0x00AE */
	L"WM_NCUAHDRAWFRAME", /* 0x00AF */
	L"EM_GETSEL32",              /* 0x00b0 */ /* 0x00B0 - Win32

	Edit controls */
	L"EM_SETSEL32",              /* 0x00b1 */
	L"EM_GETRECT32",             /* 0x00b2 */
	L"EM_SETRECT32",             /* 0x00b3 */
	L"EM_SETRECTNP32",           /* 0x00b4 */
	L"EM_SCROLL32",              /* 0x00b5 */
	L"EM_LINESCROLL32",          /* 0x00b6 */
	L"EM_SCROLLCARET32",         /* 0x00b7 */
	L"EM_GETMODIFY32",           /* 0x00b8 */
	L"EM_SETMODIFY32",           /* 0x00b9 */
	L"EM_GETLINECOUNT32",        /* 0x00ba */
	L"EM_LINEINDEX32",           /* 0x00bb */
	L"EM_SETHANDLE32",           /* 0x00bc */
	L"EM_GETHANDLE32",           /* 0x00bd */
	L"EM_GETTHUMB32",            /* 0x00be */
	NULL,                       /* 0x00bf */
	NULL,                       /* 0x00c0 */
	L"EM_LINELENGTH32",          /* 0x00c1 */
	L"EM_REPLACESEL32",          /* 0x00c2 */
	L"EM_SETFONT",                /* 0x00c3 */
	L"EM_GETLINE32",             /* 0x00c4 */
	L"EM_LIMITTEXT32",           /* 0x00c5 */
	L"EM_CANUNDO32",             /* 0x00c6 */
	L"EM_UNDO32",                /* 0x00c7 */
	L"EM_FMTLINES32",            /* 0x00c8 */
	L"EM_LINEFROMCHAR32",        /* 0x00c9 */
	L"EM_SETWORDBREAK",          /* 0x00ca */
	L"EM_SETTABSTOPS32",         /* 0x00cb */
	L"EM_SETPASSWORDCHAR32",     /* 0x00cc */
	L"EM_EMPTYUNDOBUFFER32",     /* 0x00cd */
	L"EM_GETFIRSTVISIBLELINE32", /* 0x00ce */
	L"EM_SETREADONLY32",         /* 0x00cf */
	L"EM_SETWORDBREAKPROC32",    /* 0x00d0 */
	L"EM_GETWORDBREAKPROC32",    /* 0x00d1 */
	L"EM_GETPASSWORDCHAR32",     /* 0x00d2 */
	L"EM_SETMARGINS32",          /* 0x00d3 */
	L"EM_GETMARGINS32",          /* 0x00d4 */
	L"EM_GETLIMITTEXT32",        /* 0x00d5 */
	L"EM_POSFROMCHAR32",         /* 0x00d6 */
	L"EM_CHARFROMPOS32",         /* 0x00d7 */
	L"EM_SETIMESTATUS",//0x00D8
	L"EM_GETIMESTATUS",//0x00D9
	L"EM_MSGMAX",//0x00DA
	NULL,//0x00DB
	NULL,//0x00DC
	NULL,//0x00DD
	NULL,//0x00DE
	NULL,//0x00DF
	L"SBM_SETPOS32",             /* 0x00e0 *//* 0x00E0 - Win32

	Scrollbars */
	L"SBM_GETPOS32",             /* 0x00e1 */
	L"SBM_SETRANGE32",           /* 0x00e2 */
	L"SBM_GETRANGE32",           /* 0x00e3 */
	L"SBM_ENABLE_ARROWS32",      /* 0x00e4 */
	NULL,//0x00e5
	L"SBM_SETRANGEREDRAW32",     /* 0x00e6 */
	NULL,//0x00e7
	NULL,//0x00e8
	L"SBM_SETSCROLLINFO32",      /* 0x00e9 */
	L"SBM_GETSCROLLINFO32",      /* 0x00ea */
	NULL,//0x00eb
	NULL,//0x00ec
	NULL,//0x00ed
	NULL,//0x00ee
	NULL,//0x00ef
	L"BM_GETCHECK32",            /* 0x00f0 *//* 0x00F0 - Win32

	Buttons */
	L"BM_SETCHECK32",            /* 0x00f1 */
	L"BM_GETSTATE32",            /* 0x00f2 */
	L"BM_SETSTATE32",            /* 0x00f3 */
	L"BM_SETSTYLE32",            /* 0x00f4 */
	L"BM_CLICK32",               /* 0x00f5 */
	L"BM_GETIMAGE32",            /* 0x00f6 */
	L"BM_SETIMAGE32",            /* 0x00f7 */
	NULL,//0x00f8
	NULL,//0x00f9
	NULL,//0x00fa
	NULL,//0x00fb            
	NULL,//0x00fc
	NULL,//0x00fd
	NULL,//0x00fe
	L"WM_INPUT",//0x00ff
	L"WM_KEYDOWN",  /* 0x0100 */
	L"WM_KEYUP",   /* 0x0101 */
	L"WM_CHAR",   /* 0x0102 */
	L"WM_DEADCHAR",  /* 0x0103 */
	L"WM_SYSKEYDOWN",  /* 0x0104 */
	L"WM_SYSKEYUP",  /* 0x0105 */
	L"WM_SYSCHAR",  /* 0x0106 */
	L"WM_SYSDEADCHAR",  /* 0x0107 */
	L"WM_YOMICHAR",  /* 0x0108 */
	L"WM_UNICHAR",//0x0109
	L"WM_CONVERTREQUEST",//0x010a
	L"WM_CONVERTRESULT",//0x010b
	L"WM_INTERIM",//0x010c
	L"WM_IME_STARTCOMPOSITION",//0x010d
	L"WM_IME_ENDCOMPOSITION",//0x010e
	L"WM_IME_COMPOSITION",//0x010f
	L"WM_INITDIALOG",  /* 0x0110 */
	L"WM_COMMAND",  /* 0x0111 */
	L"WM_SYSCOMMAND",        /* 0x0112 */
	L"WM_TIMER",   /* 0x0113 */
	L"WM_HSCROLL",  /* 0x0114 */
	L"WM_VSCROLL",  /* 0x0115 */
	L"WM_INITMENU",              /* 0x0116 */
	L"WM_INITMENUPOPUP",         /* 0x0117 */
	L"WM_SYSTIMER",  /* 0x0118 */
	NULL,//0x0119
	NULL,//0x011a
	NULL,//0x011b
	NULL,//0x011c
	NULL,//0x011d
	NULL,//0x011e
	L"WM_MENUSELECT",            /* 0x011f */
	L"WM_MENUCHAR",              /* 0x0120 */
	L"WM_ENTERIDLE",             /* 0x0121 */
	L"WM_MENURBUTTONUP",//0x0122
	L"WM_MENUDRAG",//0x0123
	L"WM_MENUGETOBJECT",//0x0124
	L"WM_UNINITMENUPOPUP",//0x0125
	L"WM_MENUCOMMAND",//0x0126
	L"WM_CHANGEUISTATE",//0x0127
	L"WM_UPDATEUISTATE",//0x0128
	L"WM_QUERYUISTATE",//0x0129
	NULL,//0x012a
	NULL,//0x012b
	NULL,//0x012c
	NULL,//0x012d
	NULL,//0x012e
	NULL,//0x012f
	NULL,/* 0x0130 */
	L"WM_LBTRACKPOINT",          /* 0x0131 */
	L"WM_CTLCOLORMSGBOX",        /* 0x0132 */
	L"WM_CTLCOLOREDIT",          /* 0x0133 */
	L"WM_CTLCOLORLISTBOX",       /* 0x0134 */
	L"WM_CTLCOLORBTN",           /* 0x0135 */
	L"WM_CTLCOLORDLG",           /* 0x0136 */
	L"WM_CTLCOLORSCROLLBAR",     /* 0x0137 */
	L"WM_CTLCOLORSTATIC",        /* 0x0138 */
	NULL,//0x0139
	NULL,//0x013a
	NULL,//0x013b
	NULL,//0x013c
	NULL,//0x013d
	NULL,//0x013e
	NULL,//0x013f
	L"CB_GETEDITSEL32",          /* 0x0140 *//* 0x0140 - Win32

	Comboboxes */
	L"CB_LIMITTEXT32",           /* 0x0141 */
	L"CB_SETEDITSEL32",          /* 0x0142 */
	L"CB_ADDSTRING32",           /* 0x0143 */
	L"CB_DELETESTRING32",        /* 0x0144 */
	L"CB_DIR32",                 /* 0x0145 */
	L"CB_GETCOUNT32",            /* 0x0146 */
	L"CB_GETCURSEL32",           /* 0x0147 */
	L"CB_GETLBTEXT32",           /* 0x0148 */
	L"CB_GETLBTEXTLEN32",        /* 0x0149 */
	L"CB_INSERTSTRING32",        /* 0x014a */
	L"CB_RESETCONTENT32",        /* 0x014b */
	L"CB_FINDSTRING32",          /* 0x014c */
	L"CB_SELECTSTRING32",        /* 0x014d */
	L"CB_SETCURSEL32",           /* 0x014e */
	L"CB_SHOWDROPDOWN32",        /* 0x014f */
	L"CB_GETITEMDATA32",         /* 0x0150 */
	L"CB_SETITEMDATA32",         /* 0x0151 */
	L"CB_GETDROPPEDCONTROLRECT32",/* 0x0152 */
	L"CB_SETITEMHEIGHT32",       /* 0x0153 */
	L"CB_GETITEMHEIGHT32",       /* 0x0154 */
	L"CB_SETEXTENDEDUI32",       /* 0x0155 */
	L"CB_GETEXTENDEDUI32",       /* 0x0156 */
	L"CB_GETDROPPEDSTATE32",     /* 0x0157 */
	L"CB_FINDSTRINGEXACT32",     /* 0x0158 */
	L"CB_SETLOCALE32",           /* 0x0159 */
	L"CB_GETLOCALE32",           /* 0x015a */
	L"CB_GETTOPINDEX32",         /* 0x015b */
	L"CB_SETTOPINDEX32",         /* 0x015c */
	L"CB_GETHORIZONTALEXTENT32", /* 0x015d */
	L"CB_SETHORIZONTALEXTENT32", /* 0x015e */
	L"CB_GETDROPPEDWIDTH32",     /* 0x015f */
	L"CB_SETDROPPEDWIDTH32",     /* 0x0160 */
	L"CB_INITSTORAGE32",         /* 0x0161 */
	NULL,//0x0162
	L"CB_MULTIPLEADDSTRING",//0x0163
	L"CB_GETCOMBOBOXINFO",//0x0164
	NULL,//0x0165
	NULL,//0x0166
	NULL,//0x0167
	NULL,//0x0168
	NULL,//0x0169
	NULL,//0x016a
	NULL,//0x016b
	NULL,//0x016c
	NULL,//0x016d
	NULL,//0x016e
	NULL,//0x016f
	L"STM_SETICON32",  /* 0x0170 */ /* 0x0170 - Win32 Static

	controls */
	L"STM_GETICON32",  /* 0x0171 */
	L"STM_SETIMAGE32",  /* 0x0172 */
	L"STM_GETIMAGE32",  /* 0x0173 */
	L"STM_MSGMAX",//0x0174
	NULL,//0x0175
	NULL,//0x0176
	NULL,//0x0177
	NULL,//0x0178
	NULL,//0x0179
	NULL,//0x017a
	NULL,//0x017b
	NULL,//0x017c
	NULL,//0x017d
	NULL,//0x017e
	NULL,//0x017f
	L"LB_ADDSTRING32",           /* 0x0180 *//* 0x0180 - Win32

	Listboxes */
	L"LB_INSERTSTRING32",        /* 0x0181 */
	L"LB_DELETESTRING32",        /* 0x0182 */
	L"LB_SELITEMRANGEEX32",      /* 0x0183 */
	L"LB_RESETCONTENT32",        /* 0x0184 */
	L"LB_SETSEL32",              /* 0x0185 */
	L"LB_SETCURSEL32",           /* 0x0186 */
	L"LB_GETSEL32",              /* 0x0187 */
	L"LB_GETCURSEL32",           /* 0x0188 */
	L"LB_GETTEXT32",             /* 0x0189 */
	L"LB_GETTEXTLEN32",          /* 0x018a */
	L"LB_GETCOUNT32",            /* 0x018b */
	L"LB_SELECTSTRING32",        /* 0x018c */
	L"LB_DIR32",                 /* 0x018d */
	L"LB_GETTOPINDEX32",         /* 0x018e */
	L"LB_FINDSTRING32",          /* 0x018f */
	L"LB_GETSELCOUNT32",         /* 0x0190 */
	L"LB_GETSELITEMS32",         /* 0x0191 */
	L"LB_SETTABSTOPS32",         /* 0x0192 */
	L"LB_GETHORIZONTALEXTENT32", /* 0x0193 */
	L"LB_SETHORIZONTALEXTENT32", /* 0x0194 */
	L"LB_SETCOLUMNWIDTH32",      /* 0x0195 */
	L"LB_ADDFILE32",             /* 0x0196 */
	L"LB_SETTOPINDEX32",         /* 0x0197 */
	L"LB_GETITEMRECT32",         /* 0x0198 */
	L"LB_GETITEMDATA32",         /* 0x0199 */
	L"LB_SETITEMDATA32",         /* 0x019a */
	L"LB_SELITEMRANGE32",        /* 0x019b */
	L"LB_SETANCHORINDEX32",      /* 0x019c */
	L"LB_GETANCHORINDEX32",      /* 0x019d */
	L"LB_SETCARETINDEX32",       /* 0x019e */
	L"LB_GETCARETINDEX32",       /* 0x019f */
	L"LB_SETITEMHEIGHT32",       /* 0x01a0 */
	L"LB_GETITEMHEIGHT32",       /* 0x01a1 */
	L"LB_FINDSTRINGEXACT32",     /* 0x01a2 */
	L"LB_CARETON32",             /* 0x01a3 */
	L"LB_CARETOFF32",            /* 0x01a4 */
	L"LB_SETLOCALE32",           /* 0x01a5 */
	L"LB_GETLOCALE32",           /* 0x01a6 */
	L"LB_SETCOUNT32",            /* 0x01a7 */
	L"LB_INITSTORAGE32",         /* 0x01a8 */
	L"LB_ITEMFROMPOINT32",       /* 0x01a9 */
	L"LB_INSERTSTRINGUPPER",//0x01aa
	L"LB_INSERTSTRINGLOWER",//0x01ab
	L"LB_ADDSTRINGUPPER",//0x01ac
	L"LB_ADDSTRINGLOWER",//0x01ad
	L"LBCB_STARTTRACK",//0x01ae
	L"LBCB_ENDTRACK",//0x01af
	NULL,/* 0x01B0 */
	L"LB_MULTIPLEADDSTRING",//0x01b1
	L"LB_GETLISTBOXINFO",//0x01b2
	NULL,//0x01b3
	NULL,//0x01b4
	NULL,//0x01b5
	NULL,//0x01b6
	NULL,//0x01b7
	NULL,//0x01b8
	NULL,//0x01b9
	NULL,//0x01ba
	NULL,//0x01bb
	NULL,//0x01bc
	NULL,//0x01bd
	NULL,//0x01be
	NULL,//0x01bf
	NULL,/* 0x01C0 */
	NULL,//0x01c1
	NULL,//0x01c2
	NULL,//0x01c3
	NULL,//0x01c4
	NULL,//0x01c5
	NULL,//0x01c6
	NULL,//0x01c7
	NULL,//0x01c8
	NULL,//0x01c9
	NULL,//0x01ca
	NULL,//0x01cb
	NULL,//0x01cc
	NULL,//0x01cd
	NULL,//0x01ce
	NULL,//0x01cf
	NULL,/* 0x01D0 */
	NULL,//0x01d1
	NULL,//0x01d2
	NULL,//0x01d3
	NULL,//0x01d4
	NULL,//0x01d5
	NULL,//0x01d6
	NULL,//0x01d7
	NULL,//0x01d8
	NULL,//0x01d9
	NULL,//0x01da
	NULL,//0x01db
	NULL,//0x01dc
	NULL,//0x01dd
	NULL,//0x01de
	NULL,//0x01df
	NULL,/* 0x01E0 */
	NULL,//0x01e1
	NULL,//0x01e2
	L"MN_SETHMENU",//0x01e3
	L"MN_GETHMENU",//0x01e4
	L"MN_SIZEWINDOW",//0x01e5
	L"MN_OPENHIERARCHY",//0x01e6
	L"MN_CLOSEHIERARCHY",//0x01e7
	L"MN_SELECTITEM",//0x01e8
	L"MN_CANCELMENUS",//0x01e9
	L"MN_SELECTFIRSTVALIDITEM",//0x01ea
	NULL,//0x01eb
	NULL,//0x01ec
	NULL,//0x01ed
	L"MN_FINDMENUWINDOWFROMPOINT",//0x01ee
	L"MN_SHOWPOPUPWINDOW",//0x01ef
	L"MN_BUTTONUP",//0x01f0
	L"MN_SETTIMERTOOPENHIERARCHY",//0x01f1
	L"MN_DBLCLK",//0x01f2
	L"MN_ACTIVEPOPUP",//0x01f3
	L"MN_ENDMENU",//0x01f4
	L"MN_DODRAGDROP",//0x01f5
	NULL,//0x01f6
	NULL,//0x01f7
	NULL,//0x01f8
	NULL,//0x01f9
	NULL,//0x01fa
	NULL,//0x01fb
	NULL,//0x01fc
	NULL,//0x01fd
	NULL,//0x01fe
	NULL,//0x01ff
};

WindowsMessages.cpp

#include "WindowsMessages.h"

wchar_t* get_msg_name(int message)
{
	static wchar_t str[64];
	if ( message<0 || message>(sizeof(Messages) / sizeof(wchar_t) ))
	{
		wsprintf(str, L"未收录消息:%X", message);
		return str;
	}
	wchar_t* msg = Messages[message];
	if (msg == NULL)
	{
		wsprintf(str, L"不明消息:%X", message);
		return str;
	}
	return msg;
}


 

重温WIN32 API ------ Window消息跟踪

上一篇:window中更改系统管理员Adminstrator名称


下一篇:二叉树的层序遍历题目汇总