조이스틱관련소스인데요.. 메인에서 출력할려면..어떻게해하죠 ㅠ?
걸때
rsvegaprimeapp.cpp 안에 진하게 칠해논곳..
조이스틱이 움직일때마다 좌표를 나타냅니다
근데 이것을 안에다가 놓고 출력하면 안된다고 하더라구요..
그래서 메인에서 호출해서 출력하고 싶은데..
제가 c++배운지도 얼마안됐고 개념이 안잡혀서
따로 못빼내겠습니다..
어떻게해야하나요;...
좀 도와주세요..
-_-몇일째......힘듭니다..
질문 내용 :
rsvegaprimeapp.cpp
#include stdafx.h
#include rsvegaprimeapp.h
#include windows.h
#include direct.h
#include basetsd.h
#include dinput.h#define safe_delete(p) { if(p) { delete (p); (p)=null; } }
#define safe_release(p) { if(p) { (p)-release(); (p)=null; } }
lpdirectinput8 g_pdi = null;
lpdirectinputdevice8 g_pjoystick = null;
bool callback enumobjectscallback( const dideviceobjectinstance* pdidoi, void* pcontext );
bool callback enumjoystickscallback( const dideviceinstance* pdidinstance, void* pcontext );
rsvegaprimeapp::rsvegaprimeapp(void)
{
}
rsvegaprimeapp::~rsvegaprimeapp(void)
{
}
int rsvegaprimeapp::configure()
{
::setfocus(m_joystick);
initdirectinput(m_joystick);
return 1;
}
int rsvegaprimeapp::unconfigure()
{
::setfocus(m_joystick);
freedirectinput();
return 1;
}
void rsvegaprimeapp::run()
{
while(1)
{
tick();
}
}//-------------------------------------//
// 프레임별로 조이스틱 데이터 업데이트 //
//-------------------------------------//
void rsvegaprimeapp::tick(void)
{
updateinputstate(m_joystick);
}
hresult rsvegaprimeapp::initdirectinput(hwnd hdlg)
{
hresult hr;
if( failed( hr = directinput8create( getmodulehandle(null), directinput_version,
iid_idirectinput8, (void**)&g_pdi, null ) ) )
return hr;
if( failed( hr = g_pdi-enumdevices( di8devclass_gamectrl,
enumjoystickscallback,
null, diedfl_attachedonly ) ) )
return hr;
if( null == g_pjoystick )
{
return s_ok;
}
if( failed( hr = g_pjoystick-setdataformat( &c_dfdijoystick2 ) ) )
return hr;
if( failed( hr = g_pjoystick-setcooperativelevel( hdlg, discl_exclusive |
discl_foreground ) ) )
return hr;
if( failed( hr = g_pjoystick-enumobjects( enumobjectscallback,
(void*)hdlg, didft_all ) ) )
return hr;
return s_ok;
}
void rsvegaprimeapp::freedirectinput()
{
if( g_pjoystick )
g_pjoystick-unacquire();
safe_release( g_pjoystick );
safe_release( g_pdi );
}
bool callback enumjoystickscallback( const dideviceinstance* pdidinstance,
void* pcontext )
{
hresult hr;
hr = g_pdi-createdevice( pdidinstance-guidinstance, &g_pjoystick, null );
if( failed(hr) )
return dienum_continue;
return dienum_stop;
}
bool callback enumobjectscallback( const dideviceobjectinstance* pdidoi,
void* pcontext )
{
hwnd hdlg = (hwnd)pcontext;
static int nslidercount = 0;
static int npovcount = 0;
if( pdidoi-dwtype & didft_axis )
{
diproprange diprg;
diprg.diph.dwsize = sizeof(diproprange);
diprg.diph.dwheadersize = sizeof(dipropheader);
diprg.diph.dwhow = diph_byid;
diprg.diph.dwobj = pdidoi-dwtype; // specify the enumerated axis
diprg.lmin = -1000;
diprg.lmax = +1000;
// set the range for the axis
if( failed( g_pjoystick-setproperty( diprop_range, &diprg.diph ) ) )
return dienum_stop;
}
return dienum_continue;
}
//--------------------------------------//
// 조이스틱 데이터 업데이트 시킴//
//--------------------------------------//
hresult rsvegaprimeapp::updateinputstate(hwnd hdlg)
{
hresult hr;
dijoystate2 js;
if( null == g_pjoystick )
return s_ok;
hr = g_pjoystick-poll();
if( failed(hr) )
{
hr = g_pjoystick-acquire();
while( hr == dierr_inputlost )
hr = g_pjoystick-acquire();
return s_ok;
}
if( failed( hr = g_pjoystick-getdevicestate( sizeof(dijoystate2), &js ) ) )
return hr;
if ( js.rgbbuttons[0] & 0x80 ){
freedirectinput();
exit(1);
}
//if (js.ly 0xffff%2){
//printf(아래으로가는중...%d\n, js.ly);
//}else
//printf(위으로가는중...%d\n, js.ly);
//}//if (js.ly = 0 && js.ly = 30000 ){
//printf(↑가는중...%d\n, js.ly);
//}else if(js.ly 33000 && js.ly 70000 ){
//printf(↓가는중...%d\n, js.ly);
//}else if(js.lx = 0 && js.lx = 30000 ){
//printf(←가는중...%d\n, js.lx);
//}else if(js.lx = 33000 && js.lx = 70000 ){
//printf(→가는중...%d\n, js.lx);
//}else if(js.lrz = 0 && js.lrz = 30000 ){
//printf(←회전중...%d\n, js.lrz);
//}else if(js.lrz = 33000 && js.lrz = 70000 ){
//printf(→회전중...%d\n, js.lrz);
//}
printf(\n);
//printf(조이스틱:js.lx = %d js.ly = %d js.lrz = %d \n , js.lx , js.ly, js.lrz);
//printf(위아래 %d\n,js.rglslider[o]);
printf(\n);
// button
for( int i = 0; i 128; i++ )
{
if ( js.rgbbuttons[i] & 0x80 )
{
printf(button - %d\n , i);
}
}
sleep(100);
return s_ok;
}
dynamic.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
#include stdafx.h
#include rsvegaprimeapp.h
int _tmain(int argc, _tchar* argv[])
{
rsvegaprimeapp *papp = new rsvegaprimeapp;
papp-configure();
papp-run();
papp-unconfigure();
return 0;
}
stdafx.cpp : 표준 포함 파일만 들어 있는 소스 파일입니다.
// dynamic.pch는 미리 컴파일된 헤더가 됩니다.
// stdafx.obj에는 미리 컴파일된 형식 정보가 포함됩니다.
#include stdafx.h
// todo: 필요한 추가 헤더는
// 이 파일이 아닌 stdafx.h에서 참조합니다.
rsvegaprimeapp.h
#include windows.h
class rsvegaprimeapp {
public:
rsvegaprimeapp(void);
virtual ~rsvegaprimeapp(void);
int allprint();
virtual int configure( void );
virtual int unconfigure( void );
virtual void run( void );
protected:
void tick(void);
private:
hresult initdirectinput(hwnd hdlg);
void freedirectinput();
hresult updateinputstate(hwnd hdlg); hdlg);
protected:
/* joystick */
hwnd m_joystick;
};
stdafx.h : 자주 사용하지만 자주 변경되지는 않는
// 표준 시스템 포함 파일 및 프로젝트 관련 포함 파일이
// 들어 있는 포함 파일입니다.
//
#pragma once
#include iostream
#include tchar.h
// todo: 프로그램에 필요한 추가 헤더는 여기에서 참조합니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700695 | 간단한 메모장 구현을 할려고 하는데요 (9) | 늘솜 | 2025-07-07 |
2700668 | c언어 질문입니다. 도와주세요~ (3) | 가자 | 2025-07-07 |
2700639 | 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 | 두빛나래 | 2025-07-06 |
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |