|
I want to write a game program can support two joystick(USB head)
Now I success to control player one's joystick.
But how to I control player two's joystick.
What I should set DirectInput to support two joystick?
Do any webs have any sample or book mentioned it?
My Source Code as below:
case JOYSTICK:
if(FAILED(m_Input->GetDirectInputCOM()->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticks, this, DIEDFL_ATTACHEDONLY)))
return FALSE;
if(m_pDIDevice == NULL)
return FALSE;
DataFormat = (DIDATAFORMAT*)&c_dfDIJoystick;
break;
// Set the windowed usage
m_Windowed = Windowed;
// Set the data format of keyboard
if(FAILED(m_pDIDevice->SetDataFormat(DataFormat)))
return FALSE;
// Set the cooperative level - Foreground & Nonexclusive
if(FAILED(m_pDIDevice->SetCooperativeLevel(m_Input->GethWnd(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
return FALSE;
// Set the special properties if it's a joystick
if(Type == JOYSTICK) {
// Set the special properties of the joystick - range
DIprg.diph.dwSize = sizeof(DIPROPRANGE);
DIprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
DIprg.diph.dwHow = DIPH_BYOFFSET;
//DIprg.diph.dwHow = DIPH_BYID;
DIprg.lMin = -1024;
DIprg.lMax = +1024;
// Set X range
DIprg.diph.dwObj = DIJOFS_X;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_RANGE, &DIprg.diph)))
return FALSE;
// Set Y rangine
DIprg.diph.dwObj = DIJOFS_Y;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_RANGE, &DIprg.diph)))
return FALSE;
// Set the special properties of the joystick - deadzone 12%
DIpdw.diph.dwSize = sizeof(DIPROPDWORD);
DIpdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
DIpdw.diph.dwHow = DIPH_BYOFFSET;
DIpdw.dwData = 128;
// Set X deadzone
DIpdw.diph.dwObj = DIJOFS_X;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_DEADZONE, &DIpdw.diph)))
return FALSE;
// Set Y deadzone
DIpdw.diph.dwObj = DIJOFS_Y;
if(FAILED(m_pDIDevice->SetProperty(DIPROP_DEADZONE, &DIpdw.diph)))
return FALSE;
|
|
|
|
|
For OLEDB coonection with databse i am folowiwng steps....can anybody answer me one thig...is this the only way to do OLEDB coonection....or is there some other way.....
1. insert
2. new atl object
3. dataaccess
4. consumer.
1) Open the Add Class wizard and select "Add ATL Support to MFC". Press 'Open' and to close the wizard and then choose Ok
on any subsequent dialogs.
2) Open the Add Class wizard again and select 'ATL OLEDB Consumer' and hit 'Open'.
3) The ATL OLEDB Consumer Wizard will open. Uncheck the 'Attributed' checkbox and select 'DataSource' to open
the Datalink Properties dialog.
4) In the Provider tab, choose 'Microsoft Jet 4.0 OLE DB Provider'. Press Next.
5) Under the Connection tab, enter the access database name (such as Northwind.mdb). Set the appropriate logon
info (or use the defaults). Press the Test connection button to verify if the connection has succeeded.
6) Hit the Okay button to close the DataLink Properties dialog.
Next you must choose the View, table or stored procedure to connect to.
7) In the Select Database Object dialog, expand the 'Tables' node and choose 'Employees'. Press okay.
8) Press 'Finish' to close the ATL OLE DB Consumer Wizard.
9) As before in the ODBC generated code, remove the #error line.
|
|
|
|
|
|
Hi guys,
I have a doubt.
Check the code below you'll see.
[code]
//test.h
#ifndef TEST_H
#define TEST_H
class Base
{
public:
virtual void annunce(void);
virtual ~Base();
};
class Derived : public Base
{
private:
//Base::annunce;
virtual void annunce(void);
virtual ~Derived();
};
#endif
//test.cpp
#include <iostream>
#include "test.h"
using namespace std;
void Base::annunce(void)
{
cout<<"Base"<<endl;
}
="" void="" derived::annunce(void)
="" {
="" cout<<"derived"<<endl;
="" }
="" int="" main(void)
="" {
="" base="" *base="new" derived();
="" this="" line="" can="" be="" compiled="" ok="" and="" run="" too.why?
="" base-="">annunce(); //*
delete base;
return 0;
}
[/code]
See, the line with '*' disables the "private". How can this happen?
My compiler is VC60.
Is this the compiler's fault?
If not, maybe it is because access level is used in compilation which is "static" and the virtual function invokation is dynamically resolved during execution. When compiler checks, it only thinks "Base's annunce,ok, it's public". But actually the Derived's annunce is invoked which is private.
Compiler has no idea about this.
So am i right?
I need an explanation.
Thanks a lot.
Never understand radical version
|
|
|
|
|
From the compiler's point of view it's public relative to a Base pointer.
I guess you know that because you tried it
Does it make sense to hide a virtual function in derived classes?
I can't think of a good reason but apparently since one can still get at it anyway through
the base class I guess it doesn't matter...
Mark
|
|
|
|
|
I have noticed in application I'm working on that if the screensaver comes up at any time, it seems to destroy the direct3D rendering. By destroy, I mean all the windows containing a rendered image are filled with multicoloured gibberish. The only way to restore the rendering seems to be to shut the application down and restart it. I'm guessing it may be something to do with the render device losing it's handle or something. Has anybody encountered anything like this before?
When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
|
|
|
|
|
Hi everybody:
I am a beginner programmer.I have one question:
I want to add a button on my dialog,when I click the button,I can print my controls by the printer. the control is on my dialog.such as ClistCtrl and so on ,I really have on idea,who can give me some good advices? Thanks very much!
beginner
|
|
|
|
|
What do you need?print or add a button on dialog?
|
|
|
|
|
Hello Everyone,
I'm a newbie, Please help me!
I'm adopting the code that could redirect a console output into the MFC Edit box.
My problem is, i want to have a live redirection from the console output to the edit box because i have a console application that will run about 5-10 mins and produces lots of information (output) in between those time in the command line.
My recent code will just wait the application to finish up before it could redirect the output from the command line to the Edit box.
Please help!.... thank you very much..
-rupert-
i need to learn more... i want to be like you guys... i'm just a begginer
|
|
|
|
|
|
I have this simple code in c++ and I was wondaring if anyone can tell me what does it do.And I mean line by line. Tnx I know what it does i just can figure out what it does in the lines. tnx again
#include
using namespace std;
main(){
int a,b,i,j;
cout<<"Vpisi a ";
cin>>a;
cout<<"Vpisi b ";
cin>>b;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if((i==1)||(i==a))
{
cout<<"*";}
else{
if((j==1)||(j==b))
{
cout<<"*";}
else{
cout<<" ";}
}
}
cout<<endl;
}
system("pause");
return 0;
}
=""
=""
<div="" class="ForumSig">I'm The Stig
|
|
|
|
|
First of all, use the pre and code tags when posting code so that it is formatted properly:
#include <iostream>
using namespace std;
main()
{
int a,b,i,j;
cout<<"Vpisi a ";
cin>>a;
cout<<"Vpisi b ";
cin>>b;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if((i==1)||(i==a))
{
cout<<"*";
}
else
{
if((j==1)||(j==b))
{
cout<<"*";
}
else
{
cout<<" ";
}
}
}
cout<<endl;
}
system("PAUSE");
return 0;
}
Basically, it is printing a rectangular box of *'s filled with empty spaces.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Ray_mond wrote: using namespace std;
This tells me this is C++ and not C
Ray_mond wrote: int a,b,i,j;
This tells me the person who wrote it was a C programmer, or learned from one. Don't create variables until you need them, and ALWAYS give them an initial value.
And one per line doesn't hurt, either.
Ray_mond wrote: cout<<"Vpisi a ";
Outputs text. Goodness knows why - what's Vpisi ?
Ray_mond wrote: cin>>a;
Accepts an integer value into a.
Ray_mond wrote: for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if((i==1)||(i==a))
{
cout<<"*";}
else{
if((j==1)||(j==b))
{
cout<<"*";}
else{
cout<<" ";}
}
}
cout<<endl;
}< blockquote="">
Loops a and b times to draw a box.
Generally, one would loop from 0 to a, not 1 to a-1.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Two questions
1. Why does the following code gives syntax error in VC++ (6.0) ??
It should initilize the struct elements.
The struct is declared / used in class.
( Does that makes a difference as opposed to "plain" C ?)
struct Structure_Tag
{
int test1;
int test2;
}m_Test = {0,0};
2. In the following code the pTest is not initialized and I am getting "Access violation". How do I do that if I cannot initialize as shown above?
...
pTest->test1 = 0;
...
struct Structure_Tag
{
int test1;
int test2;
}*pTest;
Thanks for your help.
|
|
|
|
|
Vaclav_Sal wrote: struct Structure_Tag
{
int test1;
int test2;
}m_Test = {0,0};
Use:
struct Structure_Tag
{
Structure_Tag()
{
test1 = 0;
test2 = 0;
}
int test1;
int test2;
} m_Test;
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Very nice trick! Thanks a million!
How did you figure out that?
Now all I need to work on the pointer.
Any suggestions?
Thanks again
|
|
|
|
|
In C++, the only difference between structs and classes is that structs default to public access while classes default to private. Everything you can do in a class, you can do in a struct.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Vaclav_Sal wrote: pTest->test1 = 0;
Any pointer in your code should be initialised to NULL. If you delete a pointer, set it back to NULL. Otherwise, you get these errors. You can still get errors, you need to remember to check if the value is NULL.
if(pTest)
{
pTest->test1 = 0;
}
is the easiest way to do that. Note this won't work unless any uninitialised value for pTest is guarenteed to be NULL ( by you )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
OK,
the elements initialization works fine and I have set the pointer to NULL
in the default constructor and it still gives me "Access violation".
struct DH_Tag
{
DH_Tag()
{
m_Alpha = 0; // joint angle
m_LinkLenght = 0; // link lenght
m_Distance = 0; // jpont disatance
m_Theta = 0; // twist angle
}
float m_Alpha; // joint angle
float m_LinkLenght; // link lenght
float m_Distance; // jpont disatance
float m_Theta; // twist angle
}m_DH_Data,*pm_DH_Data; // link Denavit-Hartenberg data
Are there any notes on the web about using struct like this?
Thanks guys, you are a big help.
|
|
|
|
|
Hey, I think I got it.
pm_DH_Data = new struct DH_Tag;
Can I put thes in constructor?
|
|
|
|
|
Vaclav_Sal wrote: the elements initialization works fine and I have set the pointer to NULL
in the default constructor and it still gives me "Access violation".
If a pointer is null, you can't use it, you need to use the code I gave you to deal with this. So, use new if you want to use it. You can also lazy initialize ( call new when you need it and not before ).
Don't forget to call delete in your destructor
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Is there any simple way to take graphics.... drawn in either GDI+, DirectX, OpenGL, etc...and hook that executable process to a running or existing application or process....and if so can I use the SetWindowsHookEx to do so....?
Or more clearly, what are all the functions that I definitely need to use to accomplish this...?
Any help will be greatly appreciated!!
Thanks...
|
|
|
|
|
I'm sorry but I dont understand what you said
|
|
|
|
|
I'm trying to use hooks to hook a program written in C#, using GDI+ specifically to draw, to another existing/already running application/process. Do I need to use SetWindowsHookEx() or is there another way to hook?
Also, how do I go about the whole process of "hooking a process to another process"?
I hope this explains it a little better.
Thanks...
|
|
|
|
|
hi
i wanna open a MSWORD DOC such as double click on it but by my application call and pdf too.
WinExec(file path) is only for .EXE files and can not be used for .DOC or .PDF !
can u help me ?
|
|
|
|