{"id":24868,"date":"2017-10-15T12:42:40","date_gmt":"2017-10-15T07:12:40","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=24868"},"modified":"2017-10-15T12:42:40","modified_gmt":"2017-10-15T07:12:40","slug":"c-program-restrict-mouse-pointer-circle","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/c-program-restrict-mouse-pointer-circle\/","title":{"rendered":"c program to restrict mouse pointer in a circle"},"content":{"rendered":"<p>This program restricts mouse pointer in a circle i.e you can&#8217;t move mouse out of a circle. When you try to bring mouse pointer outside the circle, mouse pointer is moved to it&#8217;s previous location which is inside the circle. Code to restrict mouse in circle is given below :-<\/p>\n<h2 id=\"c-programming-code\">C programming code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">#include&lt;graphics.h&gt;<br\/>#include&lt;conio.h&gt;<br\/>#include&lt;dos.h&gt;<br\/>#include&lt;stdlib.h&gt;<br\/>#include&lt;math.h&gt;<br\/> <br\/>union REGS i, o;<br\/> <br\/>int initmouse()<br\/>{<br\/>   i.x.ax = 0;<br\/>   int86(0X33, &amp;i, &amp;o);<br\/>   return ( o.x.ax );<br\/>}<br\/> <br\/>void showmouseptr()<br\/>{<br\/>   i.x.ax = 1;<br\/>   int86(0X33, &amp;i, &amp;o);<br\/>}<br\/> <br\/>void hidemopuseptr()<br\/>{<br\/>   i.x.ax = 2;<br\/>   int86(0X33,&amp;i,&amp;o);<br\/>}<br\/> <br\/>void getmousepos(int *x, int *y)<br\/>{<br\/>   i.x.ax = 3;<br\/>   int86(0X33, &amp;i, &amp;o);<br\/>   *x = o.x.cx;<br\/>   *y = o.x.dx;<br\/> <br\/>}<br\/> <br\/>void movemouseptr(int x, int y)<br\/>{<br\/>   i.x.ax = 4;<br\/>   i.x.cx = x;<br\/>   i.x.dx = y;<br\/>   int86(0X33, &amp;i, &amp;o);<br\/>}<br\/> <br\/>main()<br\/>{<br\/>   int gd = DETECT, gm, midx, midy, radius, x, y, tempx, tempy;<br\/> <br\/>   radius = 100;<br\/> <br\/>   initgraph(&amp;gd, &amp;gm, &quot;C:\\\\TC\\\\BGI&quot;);<br\/> <br\/>   if(!initmouse())<br\/>   {<br\/>      closegraph();<br\/>      exit(1);<br\/>   }<br\/> <br\/>   midx = getmaxx()\/2;<br\/>   midy = getmaxy()\/2;<br\/> <br\/>   showmouseptr();<br\/>   movemouseptr(midx, midy);<br\/>   circle(midx, midy, radius);<br\/> <br\/>   x = tempx = midx;<br\/>   y = tempy = midy;<br\/> <br\/>   while(!kbhit())<br\/>   {<br\/>      getmousepos(&amp;x, &amp;y);<br\/> <br\/>      if((pow(x-midx,2)+pow(y-midy,2)-pow(radius,2))&gt;0)<br\/>      {<br\/>         movemouseptr(tempx, tempy);<br\/>         x = tempx;<br\/>         y = tempy;<br\/>      }<br\/> <br\/>      tempx = x;<br\/>      tempy = y;<br\/>   }<br\/> <br\/>   closegraph();<br\/>   return 0;<br\/>}<\/code><\/pre> <\/div>\n[ad type=&#8221;banner&#8221;]\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>c program to restrict mouse pointer in a circle &#8211; c programming &#8211; When you bring mouse pointer outside circle, mouse pointer is moved to previous location<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82927,1],"tags":[83312,83325,83320,83317,83324,83313,83315,83314,83322,83316,83318,83323,83321,83319,83326],"class_list":["post-24868","post","type-post","status-publish","format-standard","hentry","category-c-programming-2","category-coding","tag-c-program-for-mouse-pointer","tag-c-program-to-change-mouse-cursor","tag-c-restrict-reference","tag-how-to-use-mouse-in-turbo-c","tag-mouse-click-event-in-c-language","tag-mouse-event-in-c","tag-mouse-interaction-in-c","tag-mouse-programming-in-c","tag-mouse-programming-in-c-graphics","tag-mouse-programming-in-c-pdf","tag-mouse-programming-in-computer-graphics","tag-mouse-programming-in-interactive-computer-graphics","tag-restrict-keyword-c11","tag-restrict-keyword-in-c-example","tag-restrict-mouse-pointer-in-circle"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/24868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=24868"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/24868\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=24868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=24868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=24868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}