{"id":15643,"date":"2009-12-17T07:00:00","date_gmt":"2009-12-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/12\/17\/what-was-the-showcursor-function-intended-to-be-used-for\/"},"modified":"2009-12-17T07:00:00","modified_gmt":"2009-12-17T07:00:00","slug":"what-was-the-showcursor-function-intended-to-be-used-for","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20091217-00\/?p=15643","title":{"rendered":"What was the ShowCursor function intended to be used for?"},"content":{"rendered":"<p>\nBack in the days when Windows was introduced,\na mouse was a fancy newfangled gadget\nwhich not everybody had on their machine.\nWindows acknowledged this and supported systems without\na mouse by having keyboard accelerators for everything\n(or at least that was the intent).\nBut if the design stopped there, you&#8217;d have a dead cursor\nin the middle of your screen all the time,\nwhich you could move around if you had a mouse,\nwhich you didn&#8217;t.\n<\/p>\n<p>\nEnter the <code>ShowCursor<\/code> function.\n<\/p>\n<p>\nThe <code>ShowCursor<\/code> function takes a parameter\nthat indicates whether you want to show or hide the cursor.\n(It would perhaps be more verbosely named\n<code>ChangeCursorShowState<\/code>.)\nIf you call <code>ShowCursor(TRUE)<\/code> then the cursor\nshow count is incremented by one;\nif you call <code>ShowCursor(FALSE)<\/code> then the cursor\nshow count is decremented by one.\nA cursor is show on the screen if the cursor show count is greater\nthan or equal to zero.\n<\/p>\n<p>\nWhen Windows starts up, it checks if you have a mouse.\nIf so, then the cursor show count is initialized to zero;\notherwise, it is initialized to negative one.\nThat way, you don&#8217;t get an annoying immovable cursor on the screen\nif you don&#8217;t have a mouse.\n<\/p>\n<p>\nIf a program entered a state where it wanted to show the cursor\neven on systems without a mouse, it would call\n<code>ShowCursor(TRUE)<\/code> when it entered the state,\nand\n<code>ShowCursor(FALSE)<\/code> when it left it.\nOne such state might be when activating the keyboard interface\nfor selecting a rectangular region in a document.\nUnder these conditions, a program naturally is expected to\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2007\/07\/06\/3716170.aspx#3838293\">\nmove the cursor around in response to user actions<\/a>,\neven if the user didn&#8217;t move the physical mouse hardware.\n<\/p>\n<p>\nBut the most common reason for forcing the cursor to be shown\nis in order to show an hourglass cursor because it&#8217;s busy.\nThat&#8217;s right, back in the mouseless days, code to display\nan hourglass cursor went like this:<\/p>\n<pre>\nHCURSOR hcurPrev = SetCursor(LoadCursor(NULL, IDC_WAIT));\n<font COLOR=\"blue\">ShowCursor(TRUE); \/\/ force cursor shown on mouseless systems<\/font>\n... perform long operation ...\n<font COLOR=\"blue\">ShowCursor(FALSE); \/\/ re-hide cursor on mouseless systems<\/font>\nSetCursor(hcurPrev);\n<\/pre>\n<p>\nConversely, if a program entered a state where it wanted to hide\nthe cursor even on systems with a mouse, it would call\n<code>ShowCursor(FALSE)<\/code> when it entered the state,\nand\n<code>ShowCursor(TRUE)<\/code> when it left it.\nFor example, you might do this when showing a slide show.\n<\/p>\n<p>\nLet&#8217;s look at how this all worked out in practice.\nI use a table because people seem to like tables.\n<\/p>\n<table STYLE=\"border-collapse: collapse\">\n<tr>\n<td STYLE=\"border: solid .75pt black\"><\/td>\n<th STYLE=\"border: solid .75pt black\">Machine with mouse<\/th>\n<th STYLE=\"border: solid .75pt black\">Machine without mouse<\/th>\n<\/tr>\n<tr>\n<td STYLE=\"border: solid .75pt black\">Normal<\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">0 (cursor shown)<\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">-1 (cursor hidden)<\/td>\n<\/tr>\n<tr>\n<th COLSPAN=\"3\" STYLE=\"border: solid .75pt black\">Enter mode where cursor should be forced shown<\/th>\n<\/tr>\n<tr>\n<td STYLE=\"border: solid .75pt black\"><code>ShowCursor(TRUE)<\/code><\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">1 (cursor shown)<\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">0 (cursor shown)<\/td>\n<\/tr>\n<tr>\n<th COLSPAN=\"3\" STYLE=\"border: solid .75pt black\">Exit mode where cursor should be forced shown<\/th>\n<\/tr>\n<tr>\n<td STYLE=\"border: solid .75pt black\"><code>ShowCursor(FALSE)<\/code><\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">0 (cursor shown)<\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">-1 (cursor hidden)<\/td>\n<\/tr>\n<tr>\n<th COLSPAN=\"3\" STYLE=\"border: solid .75pt black\">Enter mode where cursor should be forced hidden<\/th>\n<\/tr>\n<tr>\n<td STYLE=\"border: solid .75pt black\"><code>ShowCursor(FALSE)<\/code><\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">-1 (cursor hidden)<\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">-2 (cursor hidden)<\/td>\n<\/tr>\n<tr>\n<th COLSPAN=\"3\" STYLE=\"border: solid .75pt black\">Exit mode where cursor should be forced hidden<\/th>\n<\/tr>\n<tr>\n<td STYLE=\"border: solid .75pt black\"><code>ShowCursor(TRUE)<\/code><\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">0 (cursor shown)<\/td>\n<td ALIGN=\"right\" STYLE=\"border: solid .75pt black\">-1 (cursor hidden)<\/td>\n<\/tr>\n<\/table>\n<p>\nNow that all systems come with a mouse as standard equipment,\nthis historical information is not of much use,\nbut there it is in case you were wondering.\n(And in a case of <i>everything old is new again<\/i>,\nthe growing popularity of touch computing means that\nyou once again have a class of computers with no mouse.\nSo maybe this information is useful after all.\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2009\/10\/28\/9913810.aspx\">\nJust a fluke, I assure you<\/a>.)\n<\/p>\n<p>\nBack in the old 16-bit days,\nthis counter was a global state,\nalong with other window manager states like the focus window\nand the input queue.\nDuring the conversion to Win32,\nthe cursor show counter became a thread-local state.\n(Naturally,\nmultiple threads could merge their cursor show counters\nby attachment.)\nConsequently, when a thread calls <code>ShowCursor<\/code>\nit affects the cursor show state only for windows that\nbelong to that thread.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in the days when Windows was introduced, a mouse was a fancy newfangled gadget which not everybody had on their machine. Windows acknowledged this and supported systems without a mouse by having keyboard accelerators for everything (or at least that was the intent). But if the design stopped there, you&#8217;d have a dead cursor [&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":[2],"class_list":["post-15643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-history"],"acf":[],"blog_post_summary":"<p>Back in the days when Windows was introduced, a mouse was a fancy newfangled gadget which not everybody had on their machine. Windows acknowledged this and supported systems without a mouse by having keyboard accelerators for everything (or at least that was the intent). But if the design stopped there, you&#8217;d have a dead cursor [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15643","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=15643"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/15643\/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=15643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=15643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=15643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}