|
keybd_event API is better to use
refer msdn for more help
Величие не Бога может быть недооценена.
|
|
|
|
|
audi02 wrote: But still problem - it doesn't put the letter on the notepad... why?
Functions return values for a reason. Did you bother to check the return value from SendInput() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I checked by
int res = SendInput(2, input, sizeof(INPUT));
the results is as expected
res= 2.
|
|
|
|
|
SendInput and keybd_event functions insert keyboard events into the keyboard input stream and these events are received by active/focused window. If You would like to send keystroke to non-focused window You probably should send message directly to that window.
|
|
|
|
|
audi02 wrote: But still problem - it doesn't put the letter on the notepad... why?
This is by Microsoft design. SendInput[^] and keybd_event[^] inserts keyboard input directly into the kernel input stream. The Windows subsystem Win32k.sys handles user input for usermode windows. Windows that do not have focus do not recieve the WM_KEYDOWN Notification[^], WM_CHAR Notification[^] nor the WM_KEYUP Notification[^].
If you want to send simulated keystrokes to windows that do not have focus you will need to either:
1.) Use the BringWindowToTop Function to bring the window to top before simulating keystrokes.
2.) Use the PostMessage Function[^] to do the dirty work of Win32k.sys
This should do the trick:
PostMessage(hTargetWnd,WM_CHAR,'g',0);
Note that using PostMessage to simulate keyboard input is not recommended for a variety of reasons. Some of which include... hooks will not be called... GetKeyState and GetAsyncKeyState will not return correct results... GetQueueStatus with QS_INPUT will not be correct. In a nutshell... by using PostMessage you will be bypassing alot of the Win32k subsystems which could result in undesired behavior.
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for the detailed explanation.
You are right about the PostMessage as I had tried it. It actually seems to be not practical for me because it seems that I must know what the target program is designed to receive while I only want to send the basic events of mouse and keys.
Example:
I tried for example to send WM_LBUTTONDOWN in order to simulate left mouse button click, but the target program didn't react to this even it received it. When I checked, using Spy++ the messages it accepts when the mouse is really on it, I found the messages are much more complicated than just WM_LBUTTONDOWN and includes WM_NCHITTEST, WM_SETCURSOR and more. Why it is not just WM_LBUTTONDOWN ? I don't know. it's first time for me in this subject.
If you can give some description on this behavior and a solution, that will be great.
Maybe I will use the keystrokes simulation through PostMessage and the mouse with other way?
Thanks.
|
|
|
|
|
audi02 wrote: It actually seems to be not practical
Correct. I would say that its not a good idea to use PostMessage for reliably simulating input.
audi02 wrote: If you can give some description on this behavior and a solution, that will be great.
There are so many things happening in the windows subsystem (Win32k.sys) that it will be difficult to overcome undesired side-effects. For example when the window lost focus Win32k.sys internally keeps track of the window state, the subsystem knows not to put input messages into the window message que. When injecting rogue messages into the que you cannot always predict the outcome.
I dont really have any positive advice to give you regarding injecting user input into a window. How do you know the author of notepad or ApplicationX did not check his window state when notepad recieves mouse input? You will also battle these types of issues as well.
What type of application are you developing? Why can't you just bring the window to the top?
Best Wishes,
-David Delaune
|
|
|
|
|
I'm a beginner in LCC win32.
I would like to know how to getpriority , get Thread priority.
and how to get time in nanosec.
(In Time.h can get only milisec.
Thank you in advance.
|
|
|
|
|
QueryPerformanceCounter to get the time.
int GetThreadPriority(
HANDLE hThread // handle to thread
);
check msdn for more info
Величие не Бога может быть недооценена.
modified on Tuesday, August 4, 2009 4:31 AM
|
|
|
|
|
Which VC do you like among VC6, 2005, 2008?
I still like VC6.
Just type a line about your opinion, so I know if I am correct.
Thanks
|
|
|
|
|
6!
I (am forced to) use VC05 at work and I curse it regularly.
--Mike--
Dunder-Mifflin, this is Pam.
|
|
|
|
|
I hope I work in your company.
|
|
|
|
|
i like VC 6.0 because started my career with VS 6.0
More than that, usage of IDE is very simple compared to VC 2008
but having less functionality, i agree.
Величие не Бога может быть недооценена.
|
|
|
|
|
|
I like VS2008 as the compiler does a lot more error checking statically, optimizes the code better and the error messages are more meaningful. Was checking out VS2010 and I think I'm going to like it better.
By the way, you didn't say why you like VC6.
I'm sure its because there are a lot of changes in the default UI and shortcuts.
But they all can be customized to get the VC6 feel.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I second you.
More over, the debuggers in VS2005 or VS2008 is awesome...
|
|
|
|
|
+1 for VC6. The compiler sucked at several things, but the IDE was the best (not to mention the fastest as well).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
|
No matter which version ...of VC the truth remains the same ..we still have to code on and on
|
|
|
|
|
I use VC6 for about 70% of my work. I like that it's lean and the classwizard is just plain nice. However, the intellisense sucks and the lack of tabs drives me nuts (WndTabs helps, but it's a little flaky.) The C++ compiler is middling at best and the lack of support for SDKs after 2003 keeps getting in the way.
I prefer 2008 and use that for all home projects. I would prefer it be a leaner and faster and the lack of a ClassWizard is just plain lame (the properties pane is implemented very poorly.) It integrates nicer into version control and I generally like the way solutions work more than workspaces (though the inability to truly delete a configuration is dumb.)
|
|
|
|
|
VC6
That's because of MFC, as soon as I jump the board for another UI toolkit I would use Eclipse as frontend.
|
|
|
|
|
Our users use different OS, so we use Win2k on develope PC.
CryptoAPI requires (as in MSDN)
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 95 OSR2 or later (or Windows 95 with Internet Explorer 3.02 or later).
Header: Declared in wincrypt.h.
Library: Use advapi32.lib.
So CryptoAPI can not be used by win2k.
I define _WIN32_WINNT myself then include <wincrypt.h> as following
//--------- my OS is not NT
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#include <wincrypt.h>
//--------------------------------
Now all are fine.
I just worry about if the piece of code may cause trouble in the future after distributing software to users?
Do you think if it is OK?
|
|
|
|
|
Hi,
I want to export some data, which contains unicode characters, into excel using MFC.
Also, if we want the encoding option in Save As dialog of Excel, how do we do it using MFC?
Could you please shower some help in this!
Mohan
|
|
|
|
|
Can you help me ? I need a data ,are you give me !? say thank you ealery.
|
|
|
|
|
Hi,
May i know what are default constructors generated in c++ when an object is created...
and what happens if i declare my own constructor without declaring the default constructor..
pls correct me if im wrong..
|
|
|
|