📄 msg.c
字号:
{ WM_SETCURSOR, sent|parent }, { 0 }};/* Destruction of a modal dialog (32) */static struct message WmDestroyModalDialogSeq[] = { /* FIXME: add */ /* (inside dialog proc: EndDialog is called) */ { WM_ENABLE, sent|parent|wparam, 1 }, { WM_SETFOCUS, sent }, { WM_WINDOWPOSCHANGING, sent }, { WM_NCPAINT, sent|parent }, { WM_GETTEXT, sent|defwinproc }, { WM_ERASEBKGND, sent|parent }, { WM_WINDOWPOSCHANGED, sent }, { WM_NCACTIVATE, sent|wparam, 0 }, { WM_ACTIVATE, sent|wparam, 0 }, { WM_WINDOWPOSCHANGING, sent }, { WM_WINDOWPOSCHANGING, sent|parent }, { WM_NCACTIVATE, sent|parent|wparam, 1 }, { WM_GETTEXT, sent|defwinproc }, { WM_ACTIVATE, sent|parent|wparam, 1 }, { WM_KILLFOCUS, sent }, { WM_SETFOCUS, sent|parent }, { WM_DESTROY, sent }, { WM_NCDESTROY, sent }, { 0 }};/* Creation of a modal dialog that is resized inside WM_INITDIALOG (32) */static struct message WmCreateModalDialogResizeSeq[] = { /* FIXME: add */ /* (inside dialog proc, handling WM_INITDIALOG) */ { WM_WINDOWPOSCHANGING, sent }, { WM_NCCALCSIZE, sent }, { WM_NCACTIVATE, sent|parent|wparam, 0 }, { WM_GETTEXT, sent|defwinproc }, { WM_ACTIVATE, sent|parent|wparam, 0 }, { WM_WINDOWPOSCHANGING, sent }, { WM_WINDOWPOSCHANGING, sent|parent }, { WM_NCACTIVATE, sent|wparam, 1 }, { WM_ACTIVATE, sent|wparam, 1 }, { WM_WINDOWPOSCHANGED, sent }, { WM_SIZE, sent|defwinproc }, /* (setting focus) */ { WM_SHOWWINDOW, sent|wparam, 1 }, { WM_WINDOWPOSCHANGING, sent }, { WM_NCPAINT, sent }, { WM_GETTEXT, sent|defwinproc }, { WM_ERASEBKGND, sent }, { WM_CTLCOLORDLG, sent|defwinproc }, { WM_WINDOWPOSCHANGED, sent }, { WM_PAINT, sent }, /* (bunch of WM_CTLCOLOR* for each control) */ { WM_PAINT, sent|parent }, { WM_ENTERIDLE, sent|parent|wparam, 0 }, { WM_SETCURSOR, sent|parent }, { 0 }};static int sequence_cnt, sequence_size;static struct message* sequence;static void add_message(struct message msg){ if (!sequence) sequence = malloc ( (sequence_size = 10) * sizeof (struct message) ); if (sequence_cnt == sequence_size) sequence = realloc ( sequence, (sequence_size *= 2) * sizeof (struct message) ); assert(sequence); sequence[sequence_cnt++] = msg;}static void flush_sequence(){ free(sequence); sequence = 0; sequence_cnt = sequence_size = 0;}static void ok_sequence(struct message *expected, const char *context){ static struct message end_of_sequence = { 0, 0, 0, 0 }; struct message *actual = sequence; add_message(end_of_sequence); /* naive sequence comparison. Would be nice to use a regexp engine here */ while (expected->message || actual->message) { if (expected->message == actual->message) { if (expected->flags & wparam) ok (expected->wParam == actual->wParam, "%s: in msg 0x%04x expecting wParam 0x%x got 0x%x\n", context, expected->message, expected->wParam, actual->wParam); if (expected->flags & lparam) ok (expected->lParam == actual->lParam, "%s: in msg 0x%04x expecting lParam 0x%lx got 0x%lx\n", context, expected->message, expected->lParam, actual->lParam); /* FIXME: should we check defwinproc? */ ok ((expected->flags & (sent|posted)) == (actual->flags & (sent|posted)), "%s: the msg 0x%04x should have been %s\n", context, expected->message, (expected->flags & posted) ? "posted" : "sent"); ok ((expected->flags & parent) == (actual->flags & parent), "%s: the msg 0x%04x was expected in %s\n", context, expected->message, (expected->flags & parent) ? "parent" : "child"); expected++; actual++; } else if (expected->message && ((expected + 1)->message == actual->message) ) { todo_wine { ok (FALSE, "%s: the msg 0x%04x was not received\n", context, expected->message); expected++; } } else if (actual->message && (expected->message == (actual + 1)->message) ) { todo_wine { ok (FALSE, "%s: the msg 0x%04x was not expected\n", context, actual->message); actual++; } } else { todo_wine { ok (FALSE, "%s: the msg 0x%04x was expected, but got msg 0x%04x instead\n", context, expected->message, actual->message); expected++; actual++; } } } flush_sequence();}/* test if we receive the right sequence of messages */static void test_messages(void){ HWND hwnd, hparent, hchild; HWND hchild2, hbutton; hwnd = CreateWindowExA(0, "TestWindowClass", "Test overlapped", WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL); ok (hwnd != 0, "Failed to create overlapped window\n"); ok_sequence(WmCreateOverlappedSeq, "CreateWindow:overlapped"); ShowWindow(hwnd, TRUE); ok_sequence(WmShowOverlappedSeq, "ShowWindow:overlapped"); DestroyWindow(hwnd); ok_sequence(WmDestroyOverlappedSeq, "DestroyWindow:overlapped"); hparent = CreateWindowExA(0, "TestParentClass", "Test parent", WS_OVERLAPPEDWINDOW, 100, 100, 200, 200, 0, 0, 0, NULL); ok (hparent != 0, "Failed to create parent window\n"); flush_sequence(); hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILDWINDOW, 0, 0, 10, 10, hparent, 0, 0, NULL); ok (hchild != 0, "Failed to create child window\n"); ok_sequence(WmCreateChildSeq, "CreateWindow:child"); hchild2 = CreateWindowExA(0, "SimpleWindowClass", "Test child2", WS_CHILDWINDOW, 100, 100, 50, 50, hparent, 0, 0, NULL); ok (hchild2 != 0, "Failed to create child2 window\n"); flush_sequence(); hbutton = CreateWindowExA(0, "TestWindowClass", "Test button", WS_CHILDWINDOW, 0, 100, 50, 50, hchild, 0, 0, NULL); ok (hbutton != 0, "Failed to create button window\n"); flush_sequence(); ShowWindow(hchild, TRUE); ok_sequence(WmShowChildSeq, "ShowWindow:child"); MoveWindow(hchild, 10, 10, 20, 20, TRUE); ok_sequence(WmResizingChildWithMoveWindowSeq, "MoveWindow:child"); DestroyWindow(hchild); ok_sequence(WmDestroyChildSeq, "DestroyWindow:child");}static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ struct message msg = { message, sent|wparam|lparam, wParam, lParam }; add_message(msg); return DefWindowProcA(hwnd, message, wParam, lParam);}static BOOL RegisterWindowClasses(void){ WNDCLASSA cls; cls.style = 0; cls.lpfnWndProc = MsgCheckProcA; cls.cbClsExtra = 0; cls.cbWndExtra = 0; cls.hInstance = GetModuleHandleA(0); cls.hIcon = 0; cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW); cls.hbrBackground = GetStockObject(WHITE_BRUSH); cls.lpszMenuName = NULL; cls.lpszClassName = "TestWindowClass"; if(!RegisterClassA(&cls)) return FALSE; cls.style = 0; cls.lpfnWndProc = DefWindowProcA; cls.cbClsExtra = 0; cls.cbWndExtra = 0; cls.hInstance = GetModuleHandleA(0); cls.hIcon = 0; cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW); cls.hbrBackground = GetStockObject(WHITE_BRUSH); cls.lpszMenuName = NULL; cls.lpszClassName = "TestParentClass"; if(!RegisterClassA(&cls)) return FALSE; cls.style = 0; cls.lpfnWndProc = DefWindowProcA; cls.cbClsExtra = 0; cls.cbWndExtra = 0; cls.hInstance = GetModuleHandleA(0); cls.hIcon = 0; cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW); cls.hbrBackground = GetStockObject(WHITE_BRUSH); cls.lpszMenuName = NULL; cls.lpszClassName = "SimpleWindowClass"; if(!RegisterClassA(&cls)) return FALSE; return TRUE;}START_TEST(msg){ if (!RegisterWindowClasses()) assert(0); test_messages();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -