|
Ok, but what is the problem ?? You still didn't explain precisely where you are stuck. Please, try to be as clear as possible.
|
|
|
|
|
The problem I'm having is how do I code somthing thats going to be generated dynamiclly.
Static menus are simple:
<pre>cout << "1.Create new object"
<< "\n2.Quit to main menu"
<< "\n Please choose one: ";
cin >> choice;
if (choice == 1)
{
createObject();
runMenu(); //would be done recursivly if you get my drift
}
else if (choice == 2)
{
runMenu();
}
else
{
error();
}
</pre>
That I can hard code the different numbers to do different things, but since I don't know how many object the user will create I can't really hard code it. I hope that helps somewhat.
|
|
|
|
|
Ooookay, that makes finally a bit more sense . So, as you said, your objects are stored in a vector and you would like to add a line in your 'menu' for each element, right ?
So, simply do something like this:
int menuIndex = 1;<br />
vector<MyObject>::iterator iter = m_vector.begin();<br />
for (iter; iter!=m_vector.end();iter++)<br />
{<br />
cout << menuIndex << ". Show details of element " << (*iter).name << endl;<br />
}<br />
And then, for the choices, you check if what the user entered is between 1 and m_vector.size(). If that's the case, then you can retrieve this element from the vector and display its content (m_vector[choice]).
Does it make more sense ?
|
|
|
|
|
You are wanting to do a simple "text interface".
Well, you need a lot of std::cout, std::cin, and a "state machne"
for example :
you have this menu ( I assume typing the number will "do" the action)
1.create new object
2.quit to main menu
user press "1" this will do the "create new object" action and print the same menu again (stays in the same state); user press "2" then the program goes to a new state) and print the "main menu" (for example )
1.score
2.create new object
3.quite to main menu
user press "1" to do the score state (or action).
'anyway, I hope you get the picture.
One suggestion, is to take a piece of paper, a pen and draw the different link (arrows) between each action and each "state" and after the "scenario" is drawn, try to put in in code. (lot of if , case , loops , ...
|
|
|
|
|
Don't worry guys / gals I managed to work it out.
Thanks for your help anyway.
|
|
|
|
|
Hi,
I do not know how to test CallStack and debug can anyone tell me how to do it or can anyone provide any documents about it.
Thanks & Regards,
Ramarao.
|
|
|
|
|
Start your debugger (press F5), to see the callstack window go into (Debug/Windows/Call Stack) for VC2005. When your program crashed, you can check the callstack to see which of your function caused the problem. There you can put some breakpoints (F9) and go step by step to see what's happening. Hover your mouse over the different variables to see their values.
|
|
|
|
|
Thanks
I did it and i found that the problem comes when we call MessageBoxIndirect(). Everything is loading very well into MSGPARAMS, so what might causing the crash?
Regards,
Ramarao.
|
|
|
|
|
Do you have an assertion message ? If yes, please provide the text because it is almost impossible to guess what might be wrong.
|
|
|
|
|
Hi there .
How can I get the printer DC ?
DMASTER
|
|
|
|
|
See if you can use CPrintDialog::GetPrinterDC
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thanks to your reply.
I don't want to use MFC, I need a solution with windows API.
DMASTER
|
|
|
|
|
|
|
HDC hDC;
CDC PrinterDC;
hDC = CreateDC( NULL, "YOUR PRINTERNAME", NULL, NULL );
PrinterDC.Attach( hDC );
DOCINFO stDocInfo;
memset( &stDocInfo, 0, sizeof( DOCINFO ));
stDocInfo.cbSize = sizeof( DOCINFO );
stDocInfo.lpszDocName = _T( "TEST" ); // Document name
StartDoc( hDC, &stDocInfo );
CPen DrawPen( PS_DASH, 5, RGB( 0, 0, 0 ));
CBrush DrawBrush( HS_BDIAGONAL, RGB( 0, 0, 255 ));
PrinterDC.SelectObject( &DrawPen );
//PrinterDC.SelectObject( &DrawBrush ) ;
PrinterDC.SetBkMode( TRANSPARENT );
StartPage( hDC );
CRect Rect( 0, 0, 100, 100 );
PrinterDC.Rectangle( &Rect );
PrinterDC.MoveTo( 0, 0 );
PrinterDC.LineTo( 100, 100 );
CString csText( _T( "Orientation" ));
TextOut( hDC, 50, 50, csText.operator LPCTSTR(), csText.GetLength());
EndPage( hDC );
EndDoc( hDC );
PrinterDC.Detach();
|
|
|
|
|
|
I have Help button in property sheet,when i click on it the associated help gets invoke.Similarly when i click F1 it does the same.
When i do it both one after the other,the focus is no more when i try to press F1.
Can anyone help me out from this situation
|
|
|
|
|
Hi,
InitThunk((TMFP) &CExtBox::HookProc, this);
m_hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC) GetThunk(), NULL,GetCurrentThreadId());
ASSERT(m_hHook);
nRes = MessageBoxIndirect(&mp);
if(m_hHook)
UnhookWindowsHookEx(m_hHook);
This is the code part i am using and it was crashing when it calls MessageBoxIndirect().
This code was running from a long time now in fresh version of release this is giving problem. If i use MessageBox( ) then it is working but the function that i am calling is used in somany places so i cannot avoid it.
It is giving the following Application error
Event Type: Error
Event Source: Application Error
Event Category: (100)
Event ID: 1000
Date: 3/13/2008
Time: 7:14:39 AM
User: N/A
Computer: SILT06-FERG
Description:
Faulting application Acp.exe, version 5.2.1002.21, faulting module unknown, version 0.0.0.0, fault address 0x01f5f968.
Data:
0000: 41 70 70 6c 69 63 61 74 Applicat
0008: 69 6f 6e 20 46 61 69 6c ion Fail
0010: 75 72 65 20 20 41 63 70 ure Acp
0018: 2e 65 78 65 20 35 2e 32 .exe 5.2
0020: 2e 31 30 30 32 2e 32 31 .1002.21
0028: 20 69 6e 20 75 6e 6b 6e in unkn
0030: 6f 77 6e 20 30 2e 30 2e own 0.0.
0038: 30 2e 30 20 61 74 20 6f 0.0 at o
0040: 66 66 73 65 74 20 30 31 ffset 01
0048: 66 35 66 39 36 38 f5f968
I do not know how to check the callstack so please suggest me, now what can i do? This is a customer issue i need a solution badly please help me.
Yes everything is fine it was working from a long time and recently it is causing this problem and only with some systems.
So i dont think it is the problem with coding, it might be the problem with PC because it varies from PC to PC.
Thanks & Regards,
Ramarao.
|
|
|
|
|
Have you initialized properly the MSGBOXPARAMS struct?
For instance, missing mp.cbSize = sizeof(mp); is a common pitfall.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes everything is fine it was working from a long time and recently it is causing this problem and only with some systems.
So i dont think it is the problem with coding, it might be the problem with PC because it varies from PC to PC.
Thanks & Regards,
Ramarao.
|
|
|
|
|
RamaraoPV wrote: So i dont think it is the problem with coding, it might be the problem with PC
You are kidding, right ?
|
|
|
|
|
RamaraoPV wrote: So i dont think it is the problem with coding, it might be the problem with PC because it varies from PC to PC.
the problem is between the chair and the keyboard.
|
|
|
|
|
RamaraoPV wrote: nRes = MessageBoxIndirect(&mp);
How is mp initialized?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello
I need to write an application to recognize which USB HID Mouse is using at the moment. At least two mice are connected to the PC at one time. It should work in background and show in the background window or write to file movement positions of currently moving mouse in the system.
My way of thinking is to:
1) create main application (exe or DLL) with window which will:
- detects all Raw Input HID mouses but not regist them yet
- recieve messages from its window and from hooking DLL
- detects in seperate thread which window is currently on top (Foreground)
- if new window is on top call first RegisterRawInputDevices with Handle to new window then call "CreateHook" from DLL to reset Hooks to new thread
Below the code for the thread detecting top most window:
<br />
while (Running) {<br />
Sleep(1000); <br />
hWnd_curr = GetForegroundWindow();<br />
if(hWnd_curr != hWnd_old) {<br />
hWnd_old = hWnd_curr;<br />
GetWindowText(hWnd_curr,window_name,sizeof(window_name));<br />
<br />
Rid[0].hwndTarget = hWnd_curr;
<br />
if(!RegisterRawInputDevices(Rid, 1, sizeof (Rid[0]))) {<br />
_snprintf(logevent,sizeof(logevent),"Register Raw Input Devices FAILED");<br />
Write2File(logevent);<br />
continue;<br />
}<br />
<br />
if(pCreateHook != NULL && (dwThreadId = GetWindowThreadProcessId(hWnd_curr,&dwProcessId))!=0) <br />
msgHook = pCreateHook(WH_CALLWNDPROC,hwndMain,dwThreadId);<br />
<br />
}<br />
}
Unfortunately I cannot register raw input devices to the other window than the one I created in main program.
2) create a DLL that that be using Global Hooks for all messages from the window that is on top. DLL will contains one external function:
- CreateHook - clears old hook if not NULL and sets new hook for given threadID
in the DLL there is a callback function for collecting hooked messages which are directly sent to main application
static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam) {<br />
<br />
if(nCode < 0) {<br />
CallNextHookEx(hook, nCode, wParam, lParam);<br />
return 0;<br />
}<br />
<br />
INFO f; <br />
f.code=nCode; <br />
f.hhook=hook; <br />
f.lParam=lParam;<br />
<br />
cwpMessageParams = (PMSG)lParam;<br />
<br />
if(cwpMessageParams->message == WM_INPUT) <br />
SendMessage(mForm, messageCode, (WPARAM)(cwpMessageParams->message), (LPARAM)&f);<br />
<br />
return CallNextHookEx(hook, nCode, wParam, lParam);<br />
}
The second problem with is that this callback never gets WM_INPUT even if raw inputs are register to the window created in main application.
I'm using Win32 in VC++.
Any suggestions? Or maybe my way of thinking is wrong??
How is it possible to get at least the name of currently working mouse??
Thanks for any help
Maciek
modified on Wednesday, April 2, 2008 6:10 AM
|
|
|
|
|
I do not believe you can reliably detect which mouse has produced the input from usermode... ring-3. RegisterRawInputDevices does not work like you are suggesting. You will need to write a filter driver. You need to create a mouse filter driver which is connected to \\Device\\PointerClass0 and \\Device\\PointerClass1 all other pointerclass input devices on the device chain.
You would need to implement some shared memory protected by KeAcquireSpinLock/KeReleaseSemaphore and each time the mouse moves, the filter driver would set this information in the shared memory each time it recieves input. You would need to also write a windows service which polls the driver IOCTL interface at regular intervals and retrieves the mouse currently/last in use. When multiple pointing devices are moving at the same time the resolution will be equal to your polling rate.
Its not a simple task.
Good luck,
-David Delaune
|
|
|
|
|