You are here:

C++/C graphics

Advertisement


Question
QUESTION: Is it possible to output a certain string for only a restricted no of clicks? EX: Say we have to output 's' in first four positions where the mouse  was clicked only. After that for any no of mouse clicks no action must be taken...How can we do it?

ANSWER: I don't quite follow the question.  Is this about C graphics or Windows mouse clicks outputting characters?  Output s in the first four positions of what?  Are you clicking up to 4 times or just once to get 4 characters?  What are you clicking?



---------- FOLLOW-UP ----------

QUESTION: union REGS i,o;
int initmouse()/*initialisation*/
{
  i.x.ax=0;
  int86(0x33,&i,&o);
  return(o.x.ax);
}
void getposition(int *button,double *x,double *y)
{
  i.x.ax=3;
  int86(0x33,&i,&o);
  *button=o.x.bx;/*left click or right click or no click at all*/
  *x=o.x.cx;/* x coordinate */
  *y=o.x.dx;/*y co-ordinate*/
}
void showmouse()
{
  i.x.ax=1;
  int86(0x33,&i,&o);
}
void main()
{
  initmouse();
  showmouse();
  int k=0,but,xpos,ypos;
  while(k!=4)
  {
     getposition(&but,&xpos,&ypos);
     if (but!=0)
       {
         outtextxy(xpos,ypos,"s");
         k++;
        }
   }
}
Using the above functions in C i just wanted to click on any 4 places on the screen visible(or viewport); and on the 4 positions where i have clicked on the screen i want to display s.I am finding it difficult to use it only for 4 times or any certain n no of times.It either takes first value and prints it 4 times when i have clicked (or allowes any no times without restriction instead of (while k!=4) if we use (while !kbhit) and inside add a for loop with k=0 to 3)) ...How do i make sure that the value of k increments only once for each click and s is displayed only for 4 clicks? After that any no clicks should not have any effect...  

Answer
I can't run this code as I don't have a DOS compiler and this wouldn't compile in Windows Visual C/C++.

Try the following:

       {
         outtextxy(xpos,ypos,"s");
         k++;
         while(but!=0)
         getposition(&but,&xpos,&ypos);
       }

The idea is to wait for the mouse button to come up before counting and continuing.

This site is also an excellent reference:

http://www.geocities.com/rk_page/  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering

©2016 About.com. All rights reserved.