|
To be a little clearer:
I have a dialoge that has two buttons (BT1, BT2).
I would like it to be the case that I can:
press 1 on the keybord and BT1 depresses (and calls and associated button1 clicked method). Releasing 1 un depresses BT1.
press 2 on the keybord and BT2 depresses (and calls and associated button2 clicked method). Releasing 2 un depresses BT2.
Press and hold 1 and 2 on the keyboard, and both BT1 and BT2 depress. Releasing 1 and 2 un-dpresses BT1 and BT2.
Kalvin
|
|
|
|
|
KalvinComer wrote: Press and hold 1 and 2 on the keyboard, and both BT1 and BT2 depress. Releasing 1 and 2 un-dpresses BT1 and BT2
Hope the following code may suit for you...
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if( pMsg->message == WM_KEYDOWN )
{
if( pMsg->wParam == '1' )
{
pMsg->wParam = VK_SPACE;
pMsg->hwnd = m_btn1.m_hWnd;
}
else if( pMsg->wParam == '2' )
{
pMsg->wParam = VK_SPACE;
pMsg->hwnd = m_btn2.m_hWnd;
}
}
else if( pMsg->message == WM_KEYUP )
{
if( pMsg->wParam == '1' )
{
pMsg->wParam = VK_SPACE;
pMsg->hwnd = m_btn1.m_hWnd;
}
else if( pMsg->wParam == '2' )
{
pMsg->wParam = VK_SPACE;
pMsg->hwnd = m_btn2.m_hWnd;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
- NS -
|
|
|
|
|
KalvinComer wrote: I have a dialoge that has two buttons (BT1, BT2).
I would like it to be the case that I can:
press 1 on the keybord and BT1 depresses (and calls and associated button1 clicked method). Releasing 1 un depresses BT1.
press 2 on the keybord and BT2 depresses (and calls and associated button2 clicked method). Releasing 2 un depresses BT2.
Press and hold 1 and 2 on the keyboard, and both BT1 and BT2 depress. Releasing 1 and 2 un-dpresses BT1 and BT2.
I would use "pushbutton like" checkboxes instead of normal buttons, because you can make them look depressed just by set their state to checked, and release them by seting their state to unchecked. This would also make the dialog useable for someone who doesn't want to use the keyboard. Your idea of handling two keys pressed at once would work, but I think it would be easier to just assign '1' and '2' as shortcut keys to the respective buttons. That way, a user could press, but not hold '1' to either press or release button 1, and similarly for button 2.
Nathan
|
|
|
|
|
NS17:
Thank you, your code snippet has helped me alot. The key bit I was missing was: generation of my own button down command i.e.:
pMsg->wParam = VK_SPACE;
pMsg->hwnd = m_btn1.m_hWnd;
However, can't seem to get two buttons down at the same time.
Nathan:
Thanks for your suggestion. I now have two pushlike buttons on the dialogue and it behaves just how I want it with respect to the keyboard. But with respect to the mouse can I get the control to be true whilest the mouse is over it and the LH mouse button is down, and it returns to false when the mouse LH button is released.
I'm convinced some combination of your two solutions will get me there but after several hours work, I have got no further.
Having this dicussion has clarified my thoughts: what I need is:
A control either button or push like check box, that the rest of my app can reconise as being true or not, the control must be true only whilest the key assigned to it is pressed or the mouse button is being held down over it. If two buttons are pressed via the keyboard then both control states should be true for the duration of the press.
As some back ground: I am trying to write a simulation of a piece of hardware which has several keys. The state of which are sent regularly out over the serial port, have coded all that bit. The hardware buttons are momentary push buttons i.e. there state is high only whilst they are pressed down. So in real life the user could press more than one.
I can get the behaviour I want from the keyboard thanks to Nathan's idea, that only leaves how the control should behave in response to the mouse. Here I'd like the control to be on only when the mouse is over the control and on getting a WM_LBUTTONDOWN and the control to go off when getting the next WM_LBUTTONUP.
Any further ideas?
Kalvin
|
|
|
|
|
KalvinComer wrote: Nathan:
Thanks for your suggestion. I now have two pushlike buttons on the dialogue and it behaves just how I want it with respect to the keyboard. But with respect to the mouse can I get the control to be true whilest the mouse is over it and the LH mouse button is down, and it returns to false when the mouse LH button is released.
That makes things more complicated. When a mouse button is pressed over a control, the control captures the mouse input so that other windows don't get mouse messages. If you made a subclass of CButton that informed its parent whenever it got a mouse message, and used it for control members, you could update the state of the buttons according to the mouse state as well as the keyboard state.
I've just realized that you could also intercept mouse messages in PretranslateMessage for the same effect.
Nathan
|
|
|
|
|
Nathan,
I have written an ActiveX control to provide the functionality I require, a bit of a learning curve but it's now doing just what I want.
Thanks for your help.
Kalvin
|
|
|
|
|
Hi,
I have notice that, when I open the configurations tool of the 3rd party dll that I am using, if I move the window of the configurations tool, my programm is not able to refresh while the Modal DialogBox is opened. That causes that my programm (in background) acumulates vestiges of the movement of the foreground window. I have checked it out with another programs in background but it doesn't make it.
What should I look for in order to avoid that my program acumulates the tracks of the DialogBox's movement while it is opened? Any tip?
-- modified at 8:50 Friday 5th October, 2007
I hope you can understand what I try to say
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
i have declared a variable TCHAR TBuf[ 512 ] in public section of a class. How i can initialize this variable .
if i declare the variable in a local function i initialize it as TCHAR TBuf[512] = {'\0'} , in this method entire buffer (512) bytes is initialized. How to perform this kind of initialation on a class variable.
Thanks & Regards
|
|
|
|
|
On the constructor of the class
MyClass::MyClass ()
{
}
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
void MyFunc()
{
TCHAR TBuf[ 512 ] = { '\0' } ;//this method initializes the array index 0 to 511 with null
}
//in the case of a class varibale i use the following method, is there any simple step to do the same ?
class MyClass
{
public :
TCHAR TBuf[ 512 ] ;
MyClass()
{
//
int i = 512 ;
while( i > 0 )
{
TBuf[ --i ] = '\0' ;
};
}
}
Thanks & Regards
|
|
|
|
|
better use ZeroMemory Api! or memcpy!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Au contraire!
Why should one not use a C++ function instead of something more complicated and proprietary?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
As DavidCrow mentioned, you can use memset().
Also, I would recommend NOT using hardcoded values like 512...
use the sizeof operator.
class MyClass
{
public :
TCHAR TBuf[ 512 ] ;
MyClass()
{
memset(TBuf, 0, sizeof(TBuf));
}
};
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
nitin3 wrote: How to perform this kind of initialation on a class variable.
Ever heard of memset() ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am using CreateDestop() API to create a new Desktop and SwitchDesktop() API to switch to new desktop.It works fine without any errors.
But the problem is that I am not able to open any process in new Desktop. I am not even able to open the Taskmanager in new desktop. What I get is only blank desktop there.
I am using following code to Create and Switch to new Desktop.
If you know what is the probelm please inform me.
hNewDesktop = CreateDesktop(L"NewDesktopName", NULL, NULL, 0, GENERIC_ALL, NULL);
SetThreadDesktop(hNewDesktop);
SwitchDesktop(hNewDesktop);
OpenProc(_T("userinit.exe"));
OpenProc(_T("Explorer.exe"));
Thnx in advance.
|
|
|
|
|
Take a look at STARTUPINFO argument in CreateProcess function.
Thanks & Regards
|
|
|
|
|
Thank you for Tou help.
I have made the changes in STARTUPINFO structure.
STARTUPINFO si;
si.lpDesktop = _T("NewDesktop");
I am creatring userinit.exe after changing the desktop and its wokring.
|
|
|
|
|
Hi.
is it possible to personalize the Wallpapers and ICONS for the newdesktop.
If yes can you tell me how to do this.
|
|
|
|
|
Hello
I have been trying to implement the sample at the link http://www.codeproject.com/useritems/GetNtProcessInfo.asp[^]
Its mentioned in the article to add the files "NTProcessInfo.h", "NTProcessInfo.cpp" to my project and exclude them while building the project.
I have followed the instructions to add the files and exclude them while building the project. I did a #include "NTProcessInfo.h" at the top of my file MsiInfo.cpp.
However, I get the following linking errors mentioned below:
MsiInfo.obj : error LNK2001: unresolved external symbol "void __cdecl sm_FreeNTDLLFunctions(struct HINSTANCE__ *)" (?sm_FreeNTDLLFunctions@@YAXPAUHINSTANCE__@@@Z)
MsiInfo.obj : error LNK2001: unresolved external symbol "int __cdecl sm_GetNtProcessInfo(unsigned long,struct _smPROCESSINFO *)" (?sm_GetNtProcessInfo@@YAHKPAU_smPROCESSINFO@@@Z)
MsiInfo.obj : error LNK2001: unresolved external symbol "struct HINSTANCE__ * __cdecl sm_LoadNTDLLFunctions(void)" (?sm_LoadNTDLLFunctions@@YAPAUHINSTANCE__@@XZ)
Can somebody please tell me what is the reason for this?
Thanx.
|
|
|
|
|
It seems you need to import lib file or files to your project.
|
|
|
|
|
Please remove /Zl from the command line property page.
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
Hello all,
Can someone provide me interview questions on VC++, COM, ATL.
I need those desperatly.
Thanks...... .
|
|
|
|
|
They normally provide those at the interview..
To get you started there are tens of thousands of MFC/C++ questions on this forum - mostly with answers.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Yesterday somebody on this forum told about this site http://sumedh.shende.googlepages.com/.
|
|
|
|
|
Hamid. wrote: Yesterday somebody on this forum tell about this site http://sumedh.shende.googlepages.com/
humm advertising.. but that site contain nothing, you have to ask the question to get answer there!. god knows how much time it will take to work out or create question bank!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|