{"id":16923,"date":"2009-08-31T10:00:00","date_gmt":"2009-08-31T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/08\/31\/why-do-new-controls-tend-to-use-com-instead-of-window-messages\/"},"modified":"2009-08-31T10:00:00","modified_gmt":"2009-08-31T10:00:00","slug":"why-do-new-controls-tend-to-use-com-instead-of-window-messages","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090831-00\/?p=16923","title":{"rendered":"Why do new controls tend to use COM instead of window messages?"},"content":{"rendered":"<p>\nCommenter David wonders\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#649857\">\nwhy new controls tend to use COM instead of window messages<\/a>.\n&#8220;It seems\nthat there must have been a decision to only\ndevelop COM controls after the invention of COM.&#8221;\n<\/p>\n<p>\nThere have been plenty of Win32 controls invented after the invention\nof COM.\nIn fact, the entire common controls library was developed after\nthe invention of COM.\nAll your old friends like the list view,\ntree view, and property sheets are good old Win32 controls.\nBut it&#8217;s true that the newer stuff tends to use COM.\nWhy is that?\n<\/p>\n<p>\nI am not aware of any grand pronouncement on this subject.\nEach team makes a decision that they feel is best for their customers.\nBut if you think about it,\nit&#8217;s not an unreasonable choice:\nSuppose you were writing a new C++ object.\nWould you prefer to use this:\n<\/p>\n<pre>\nclass Thing {\npublic:\n  enum MESSAGENUMBER {\n  MESSAGE_INSERTITEM,\n  MESSAGE_DELETEITEM,\n  MESSAGE_DELETEALLITEMS,\n  MESSAGE_SETLABELTEXT,\n  MESSAGE_GETNEXTITEM,\n  MESSAGE_ADDBITMAP,\n  ...\n  };\n  LRESULT Message(MESSAGENUMBER m, WPARAM wParam, lPARAM lParam);\nprivate:\n  ...\n};\n<\/pre>\n<p>\nor would you rather use this:\n<\/p>\n<pre>\nclass Thing {\npublic:\n  BOOL InsertItem(Item *item, Item *itemParent, Item *itemInsertAfter);\n  BOOL DeleteItem(Item *item);\n  BOOL DeleteAllItems();\n  BOOL SetLabelText(Item *item, PCWSTR pszText);\n  Item *GetNextItem(Item *item);\n  BOOL AddBitmap(HINSTANCE hinst, PCWSTR pszResource, COLORREF crTransparent);\n  ...\nprivate:\n  ...\n};\n<\/pre>\n<p>\nIt&#8217;s just less of a hassle using separate member functions,\nwhere you don&#8217;t have to try\nto pack all your parameters into two parameters (cryptically named\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2003\/11\/25\/55850.aspx\">\n<code>WPARAM<\/code> and <code>LPARAM<\/code><\/a>)\non the sending side,\nand then unpack the parameters on the window procedure side.\n<\/p>\n<p>\nThe overhead of sending a message can add up for high-traffic messages.\nA C++ method call is pretty direct: You set up the parameters and call\nthe method.\nWhereas when you send a window message,\nit bounces around inside the window manager\nuntil it magically pops out the other side.\n<\/p>\n<p>\nAgain, these are my personal remarks and are not the official\nposition of Microsoft on anything.\nBut if you were writing a control, which would you prefer to have\nto implement?\nAnd if you were using a control, which interface would you rather use?\n<\/p>\n<p>\n(That said,\nI can&#8217;t think of many common controls that are COM-based.\nAll the ones I know about still use boring window messages.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter David wonders why new controls tend to use COM instead of window messages. &#8220;It seems that there must have been a decision to only develop COM controls after the invention of COM.&#8221; There have been plenty of Win32 controls invented after the invention of COM. In fact, the entire common controls library was developed [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-16923","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Commenter David wonders why new controls tend to use COM instead of window messages. &#8220;It seems that there must have been a decision to only develop COM controls after the invention of COM.&#8221; There have been plenty of Win32 controls invented after the invention of COM. In fact, the entire common controls library was developed [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16923","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=16923"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16923\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=16923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=16923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=16923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}