الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

شرح برمجة الماوس المثال مرفق

مغلق
بدأه mohammed alherwi في 15 يناير 2005 · 2 رد · 840 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

المثال مأخوذ من المنتدى (vbzoom)

#include<stdiostr.h>

#include<conio.h>

#include<process.h>

#include<graphics.h>

#include<dos.h>

#define MOUSE 0x33

#define BUT1PRESSED 1

#define BUT2PRESSED 2

#define TRUE 1

#define FALSE 0

void ActivMouse()

{

/* activate mouse */

_AX=32;

geninterrupt(MOUSE);

}

int ResetMouse()

{

/* mouse reset */

_AX=0;

geninterrupt(MOUSE);

return(_AX);

}

void ShowMouse()

{

/* turn on mouse cursor */

_AX=1;

geninterrupt(MOUSE);

}

void HideMouse()

{

/* turn off mouse cursor */

_AX=2;

geninterrupt(MOUSE);

}

void ReadMouse(int *v,int *h,int *but)

{

int temp;

_AX=3;

geninterrupt(MOUSE);

// which buttons pressed: 1=left, 2=right, 3=both

temp=_BX;

*but=temp;

// horizontal coordinates

*h =_CX;

// vert coordinates

*v=_DX;

}

int main( void )

{

int gdriver = EGA, gmode=EGAHI, errorcode;

int mouseX, mouseY, mouseButton=0, currentColor=1;

int oldMouseX=0, oldMouseY=0;

char button1Down,button2Down=FALSE;

if (!ResetMouse())

{

printf("No Mouse Driver!");

return(1);

}

printf( "Instructions:\nHold down left button to draw,\n"

"Click right button to change color,\n"

"When done drawing, hit key.\n"

"Press any key to continue\n" );

getch();

initgraph(&gdriver,&gmode, "");

if (graphresult()!=grOk)

{

printf( "Graphics Init Error -- EGAVGA.BGI not in "

"current directory?" );

return(1);

}

setcolor(WHITE);

outtextxy(1,1,"COLOR");

ActivMouse();

ShowMouse();

while (!kbhit())

{

ReadMouse(&mouseY,&mouseX,&mouseButton);

if (mouseButton&BUT1PRESSED)

{

if (mouseX!=oldMouseX || mouseY!=oldMouseY)

{

// hide mouse cursor before drawing anything!

HideMouse();

if (button1Down)

line(mouseX,mouseY,oldMouseX,oldMouseY);

oldMouseX=mouseX; oldMouseY=mouseY;

ShowMouse();

}

button1Down=TRUE;

}

else

button1Down=FALSE;

if (mouseButton&BUT2PRESSED)

{

button2Down=TRUE;

}

else if (button2Down)

{

// If button 2 was down and is now up, it was

// clicked!

button2Down=FALSE;

// so change the color

++currentColor;

if (currentColor==16)

currentColor=1;

setcolor(currentColor);

HideMouse();

outtextxy(1,1,"COLOR");

ShowMouse();

}

}

closegraph();

return( 0 );

}

#2

تشكر جزيلا , وهذا المثال سيعمل في مصرفات البورلاند فقط , ولن يعمل في ال Visual Studio .

بسبب :

#include<graphics.h>
#include<dos.h>

banner_60_468.gif

NOTHING IS IMPOSSIBLE

#3

ممكن ده يفيدك

/index.ph...topic=49252&hl=

ملاحظة ..انا زيك برضه بخبط في الموضوع ده

وكان مقبلاني مشكلة هي لما اخلي الماوس يضغط في مكان بعدين اعمل clrscr()

علي اساس اني هعمل فورمة جديدة المفروض ان الماوس ميبقاش فعال في الضغط علي المكان الي انا محدده .. معايا ..يعني مثلا البرنامج بيضيف اسماء وارقام تليفونا الشاشه الرئسيه هيكون فيها اتنين bottoms واحد منهم add في النقطة x مثلا

لما اعمل clrscr() عشان ابتدي شكل جديد النقطة x هيفضل الضغط عليها بيعمل نفس المهمة وهي فتح الدالة add() ..عشان كده المفروض نعمل شرط جديد مع اماكن الضغط نخلي الشرط ده true لما نكون عايزين البوتوم يشتغل اما لو مش عايزينه يشتغل في داله جديد نخليه false

بس!

لا اله الا الله

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…