|
Hello All,
I want to read through a 8 button (USB port) joystick in my MFC application. Please tell me how to go about doing this. Tell me all the steps that I have to go through. If possible send me code for this also.
Thanks
Nasirul Haque
|
|
|
|
|
Your best bet will be to use DirectInput which is part of the DirectX SDK. The SDK contains examples (including a comprehensive framework) for reading from Joysticks.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
ok i have a header file and this is the error i get:
error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
and here is my code, im stumped:
#define BAUDRATES_C
#include "stdafx.h"
#include "BaudRates.h"
typedef struct{
char BaudRate[15];
unsigned char Length;
}BaudRateType;
const BaudRateType BaudRateList[16] =
{
{"110", 3},
{"200", 3},
{"300", 3},
{"1200", 4},
{"2400", 4},
{"4800", 4},
{"9600", 4},
{"14400", 5},
{"19200", 5},
{"28800", 5},
{"38400", 5},
{"56000", 5},
{"57600", 5},
{"115200", 6},
{"128000", 6},
{"256000", 6},
};
void PopulateBaudDropdown(CComboBox *box)
{
int i;
for(i=0;i<16;i++)
{
box->AddString((char*)&BaudRateList[i].BaudRate);
}
}
char ReadBaudDropdown(CComboBox *box)
{
int baudindex;
char rate;
baudindex = box->GetCurSel();
sprintf(rate,"%d",BaudRateList[baudindex].BaudRate);
return rate;
}
please help, thank you
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
Hi,
I've found two mistakes in your code:
in the line:
box->AddString((char*)&BaudRateList[i].BaudRate);
make this change:
box->AddString(BaudRateList[i].BaudRate);
and
in the line:
sprintf(rate,"%d", BaudRateList[baudindex].BaudRate);
make this change:
sprintf(rate,"%s", BaudRateList[baudindex].BaudRate);
Lada
|
|
|
|
|
umm i changed it and still got the same error
ty
---------------------
And Like The Wind Our Hero Vanishes Off Into The Distance...
|
|
|
|
|
I overlooked another mistake.
change
char ReadBaudDropdown(CComboBox *box)
{
int baudindex;
char rate;
baudindex = box->GetCurSel();
sprintf(rate,"%d",BaudRateList[baudindex].BaudRate);
return rate;
}
to
CString ReadBaudDropdown(CComboBox *box)
{
int nBaudindex;
CString strRate;
strRate = "";
nBaudindex = box->GetCurSel();
if(nBaudindex > -1)
strRate.Format("%s", BaudRateList[baudindex].BaudRate);
return strRate;
}
|
|
|
|
|
Why not just use char rate[256] // or whatever size you need
BD
"You know "that look" women get when they want sex? Me neither."
--Steve Martin
|
|
|
|
|
error C2664: 'sprintf' : cannot convert parameter 1 from 'char' to 'char *' is right answer
Why you would define char rate for only one character instead char rate[15]. You have defined char BaudRate[15] in BaudRateType structure:
char& ReadBaudDropdown(CComboBox *box)
{
int baudindex;
char rate[15];
rate[0] = 0;
baudindex = box->GetCurSel();
if(baudindex != CB_ERR)
sprintf(rate,"%s",BaudRateList[baudindex].BaudRate);
return rate;
}
and calling:
char *baud;
baud = &ReadBaudDropdown(Cbox);
if(baud[0] == 0)
error?? // what you want to do
...
|
|
|
|
|
Hello
for why should you try to get the value from the struct itself?
You can Attach that value to the ComboBox by SetItemData()
in that index you add the string and attach an itemdata
then you can easily retrieve data corresponding to the selected item by using GetItemData()
I want to change Myself..Can u help me?
|
|
|
|
|
Hi,
The variable rate is only one byte long, where as the first parameter type of sprint is char*, hence its giving u error.
Try with rate as a char array.
Rahul
|
|
|
|
|
I'm creating a SDI application with the view derived from CFormview, and I want to change the window style so that it'll have a full screen view on it.
I'd changed the window style into WS_POPUP|WS_VISIBLE|WS_MAXIMIZE on the PreCreateWindow method of the CMainFrame but the result is my app always hiding.
It works for a SDI app with a base CView..
Does anyone know how to make/change my window style in a SDI app (especially using formview since in simple SDI it works)??
|
|
|
|
|
1) in ShowWindow change SW_SHOW with SW_MAXIMIZE.
2) in PreCreateWindow(CREATESTRUCT& cs)add lines:
cs.cx = GetSystemMetrics(SM_CXMAXIMIZED);
cs.cy = GetSystemMetrics(SM_CYMAXIMIZED);
cs.x = 0;
cs.y = 0;
one or both if you shall
|
|
|
|
|
in Your InitInstance()
m_pMainWnd->ShowWindow(SW_MAXIMIZE);
I want to change Myself..Can u help me?
|
|
|
|
|
Is it better to use nested functions:
<br />
ShowWindow(FindWindowEx(FindWindow("Shell_TrayWnd",0),0,"Button",0),SW_HIDE);<br />
or variables inside the functions:
<br />
HWND hWndOne = FindWindow("Shell_TrayWnd",0);<br />
HWND hWndTwo = FindWindowEx(hWndOne,0,"Button",0);<br />
ShowWindow(hWndTwo,SW_HIDE);<br />
and do they take up the same memory?
wWw.KruncherInc.cOm - My cool programs
|
|
|
|
|
Variables. It makes the code much easier to follow. The optimizer will optimize the variables away in the release version.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
|
Imho, it's not a good practice to use nested functions because it usually makes it harder to debug the code and handle errors. Consider doing:
HWND hWndOne = FindWindow("Shell_TrayWnd",0);
if (hWndOne != NULL) {
HWND hWndTwo = FindWindowEx(hWndOne,0,"Button",0);
if (hWndTwo != NULL)
ShowWindow(hWndTwo,SW_HIDE);
}
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
How are you going to do error-handling with this?
ShowWindow(FindWindowEx(FindWindow("Shell_TrayWnd",0),0,"Button",0),SW_HIDE);
That's right, you can't. There's your answer.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
I never said I was going to do error checking. I was using this as a simple example. I just wanted to know which one uses more memory or if they use the same.
Like if a function returns a value and you don't put it into a variable, does it take up memory?
wWw.KruncherInc.cOm - My cool programs
|
|
|
|
|
if you dont give a damn about ur software chrashes in front of your client then its perfectly legal
|
|
|
|
|
Actually, there is nothing there that will crash. It just won't do anything. Sometimes this is perfectly normal. In fact I have seen many program that did too much error checking that resulted in the program spamming the desktop with error message boxes.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
In fact I have seen many program that did too much error checking that resulted in the program spamming the desktop with error message boxes.
there is fine line which error should be notified to the user and errors that should be handled gracefully...
I have a simple moto, 75% of the code should be handling the errors. and 25% logic... The application should not crash or hang under any circumstances... if it does then the software looses the interest of the user.
|
|
|
|
|
no Doubt!
variables - by using variables you can check the validity of the data, which the fucntion returns, before calling another function.
My vote is for variables
I want to change Myself..Can u help me?
|
|
|
|
|
Personally, I would use the latter. A compiler will write the same code for both, (i.e. it will create temporary variables to hold the return values from the two FindWindow calls) so there's no performance disadvantage, but with the second, you can see (and therefore debug) the results a lot easier. For example, if the first call to FindWindow fails, it will be a lot easier to spot when stepping through the code.
|
|
|
|
|
Normaly it is better to do the second one: Because it is esier to read and esier to debug. The only time you might use nested function is if the value returned by a nested function, if invalid, will be rejected by the function that is using it as an argument. The problem with nested functions is that if one of them fails you do not kwon which one it was. If each function will reject invalid arguments, you can get away with just checking the result of the last function to see if something went wrong, but that will not tell precisely what went wrong. Generaly the only time you might use nested function is when you are sure that none of them will (or can) fail.
INTP
|
|
|
|