|
If I understand Windows and dialogs and menus correctly, modal dialogs and popped-up menus have their own message loop (it's called a modal loop because the application enters a different mode when menus or modal dialogs are displayed). Again if I understand correctly, these will swallow all the messages you send to the main window and discard them or something.
So - I suspect you're hosed when modal dialogs or menus are displayed.
But I could be wrong
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Yes, most of these dialogs ARE modal. But I can stuff my whole begin-to-end keysequence
into a single SendInput sequence, and the main loop will forward subsequent keystrokes to any newly created
modal child dialog. For example, If I stuff SendInput with "{ALT}FGMyFile.xyz{ENTER}", then:
a) the sequence {ALT}FG Executes the FILE --> Generate File modal dialog. (which *IS* Modal)
b) then, within that dialog, the keys "MyFile.xyz" get stuffed into the first (default)
output filename CEditbox
c) and the final {ENTER} closes that modal dialog (because the OK button has the WantReturn property), and thus
the dirty deed is accomplished.
So, I get success when I do SENDINPUT of "{ALT}FGMyFile.xyz{ENTER}"
But I get failure when I do SENDINPUT of "{ALT}FGMyFile.xyz"
followed by another SENDINPUT of "{ENTER}"
The second SENDINPUT still tries to send to the main ABF hwTARGET, but its fubar'd
by the Modal dialog, which now has input focus, but which isnt catching any further input from my app(???).
Evidently, the Generate-File modal dialog isnt a child-window of the main app window. (but of something else instead???).
It doesnt appear after all my EnumerateChildWindows callbacks.
My questions really are. Are these dialogs *really* still children of the main window, (but maybe they're
hidden somehow, and not subject to EnumerateChildWindows?) Maybe I can find them through more painfull digging...
-or- are the modal dialogs NOT child windows of the main window, but of the main application thread instead.
And is there a way to enumerate *all* child windows of the main thread(s)? And if I find them, can I
send them direct KEY messages. (like {ESCAPE}s, just to close em)
p.s. Yes, I know a SETFOCUS followed by a targetless SENDKEYS is very sloppy, especially if the user decides
to do some multitasking, or if there are other apps around which steal input focus. Id much rather send directed
WM_KEYDN/UP messages, but I havent been able to make that work, especially since there's no security relationship
between my app and the ABF app.
All I want to do is be able to detect if there are any active modal ABF child windows, and send them {ESCAPE}
messages to close em down before my app can try its own commands.
Thanks for the response though. I learn tons from every reply.
-Dave
|
|
|
|
|
Wibble - you've done a lot of this SendInput stuff, haven't you! Let me commend you on your fortitiude
The only thing I'll ask is if a Windows macro app like this one[^] can do what you've been trying to get working? Knowing if something's possible (or not) can help...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hey Buddy
Yes you are at correct place, but i may not be of much help.
SendInput is a risky thing as you have faced already
If you get HWND of the target window, then you can treat them with your own classes
Let's say you get an edit box
CEdit* vl_pEdit = (CEdit*)CWnd::FromHandle(targethWnd);
if(vl_pEdit && IsWindow(vl_pEdit->m_hWnd))
{
//you have got CEdit
//Call GetWindowText or SetWindow Text
}
Same would be applicable to CheckBoxes
Use CButton::GetCheck() for getting state
Also
to Click on a Dialog Box, given below is an encrypt from experts exchange which requires subsription and hence pasting below
http://www.experts-exchange.com/Programming/Languages/Q_20572990.html[^]
So you can do many things without SendInput & that too in a reliable way.
However it seems you have developed functionality using SendInput and hence this information may be of little use to you, still posting here, whatever i can.
-----------------------Starts-----------------
The proper WM_COMMAND for a button click is:
PostMessage(hWndParent, WM_COMMAND, MAKEWPARAM(nID, BN_CLICKED), hWndButton);
but the lazy version is:
PostMessage(hWndParent, WM_COMMAND, nID, 0);
... assuming the parent doesn't check hWndButton. gotenks got that one.
Assuming we're dealing with a dialog box using standard button IDs, you should use IDOK for nID. Other standard values for nID include IDCANCEL, IDABORT, IDIGNORE, IDYES, IDNO, IDCLOSE. Although, if the ID is custom, it could be any value.
> ::PostMessage(hWnd,WM_LBUTTONDOWN,WM_COMMAND,MAKELONG(x,y));
> //" ::PostMessage(hWnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELONG(x,y)); "
> also tried.
> ::PostMessage(hWnd,WM_LBUTTONUP,NULL,MAKELONG(x,y));
> ::PostMessage(hWndParent,WM_LBUTTONDOWN,WM_COMMAND,MAKELPARAM(x,y));
> ::PostMessage(hWndParent,WM_LBUTTONUP,WM_COMMAND,MAKELPARAM(x,y));
This'll simulate a button click:
SetForegroundWindow(hWndParent);
PostMessage(hWndButton, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(1,0));
PostMessage(hWndButton, WM_LBUTTONUP, 0, MAKELPARAM(1,0));
SetForegroundWindow() brings up and activates the window before it handles the mouse click.
Although, if that fails, the button might be off the screen. If that happens, you should call this beforehand:
SetWindowPos(hWndParent, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
This'll move the window to the upper-left-hand corner of the screen.
If you're trying to close one certain dialog, then you should have no trouble doing so. But if you're trying to click any given button, chances are that you're gonna run into trouble sooner or later.
Until then, good luck!
Regards
-----------------------Ends-----------------
|
|
|
|
|
Thank You, Vikrant Kpr.
I know SendInput is sloppy, and dangerous when anything can pop up during my sendkeys
and steal input focus. I hadnt been able to make direct Send/PostMessage(s) work.
I presumed that it was because NT security was maybe blocking me.
I *DO* deeply appreciate you showing me how to cast target dialog bits into
my own object-type pointers. I cant wait to try this. This was a problem
I REALLY needed to solve, and it didnt appear anywhere in my many books. And
I didnt find a simple example to mimic from any CodeProject search outputs.
Thanks again.. 8-)
About sending std IDOK/IDCANCEL/IDwhateber messages... My problem (again), is that I
cant find their HWNDs. When I send to the parent window, Once the dialog has
initialized (via DoModal) perhaps, and any queued messages from the main window
get forwarded to the new child dialog, I dont know how to identify it's HWND, nor
its thread. So I cant send it anything.
All of my problem comes down to 'how do I find the main thread's topmost window?'
Can I find a way to enumerate all of ABF's threads, and then enumerate any child
windows of those threads, and then which of those is on top???
And if I can do that, can I send it directed messages (from my foreign application)
((Do I need to attach to the thread first?))
...this is highly tricksy stuff for me... And I dont grok a lot when it comes to
deep windows internals, etc.
Once I get past that last hurdle, I can try out the rest of your suggestions.
Thanks for the reply. Again, it gave me a valuable snippet I was really struggling with.
-Dave
|
|
|
|
|
|
As you know, using CWnd::GetClientRect we can get the dimensions of the client area of a window. Now suppose that we have a toolbar just below the menu bar. this toolbar has occupied a part of the client area! That's if we (e.g.) draw a line from (0, 0) to (100, 100), this line passes across the toolbar !!! My question is how can I get the client rect, but excluding the toolbar rect.
Thank you masters!
|
|
|
|
|
Well, how about getting the rectangle of the toolbar and then subtracting it from the client rectangle? Something like this:
CRect ClientRect, ToolBarRect;
GetClientRect(ClientRect);
m_MyToolBar.GetWindowRect(ToolBarRect);
ScreenToClient(ToolBarRect);
CRect AvailableRect;
AvailableRect.SubtractRect(&ClientRect, &ToolBarRect);
p.s: am not sure how SubtractRect[^] works, never used it before, so you might need to fiddle with other methods like UnionRect or IntersectRect to get a good result...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thnx 4 Ur attention.
|
|
|
|
|
I found this code fragment on t'Net:
CMainFrame *pMainFrame = (CMainFrame *) GetParentFrame();
status bar)
CRect rViewC;
pMainFrame->RepositionBars ( AFX_IDW_CONTROLBAR_FIRST,
AFX_IDW_CONTROLBAR_LAST,
AFX_IDW_PANE_FIRST, CWnd::reposQuery, &rViewC )
It looks about right to me.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I think I've told it to you once; anyway I'me gonna tell one more time: You're a genius
|
|
|
|
|
Na - I just remember lotsa crap that I can regurgitate (or find with Google) on demand
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: Na - I just remember lotsa crap that I can regurgitate (or find with Google) on demand
Isn't that what being a good programmer is all about? I doubt many of us know everything, we just have a clue where to look, or the search terms.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain Clarke wrote: Isn't that what being a good programmer is all about?
A self-reliant programmer, certainly. The trick is remembering that things actually exist, so you know to look for a solution rather than try to re-invent the wheel.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i use VS2005
today i programe a .cpp File to learn "Template"
the source code is:
<br />
#include<iostream><br />
using namespace std;<br />
<br />
template<typename Type><br />
<br />
Type min(Type a,Type b)<br />
{<br />
return a<b?a:b;<br />
}<br />
<br />
int main()<br />
{<br />
int a = 0, b = 1, c = 3;<br />
<br />
c = min<int>(a,b);<br />
<br />
cout<<c;<br />
}<br />
but when i run the result is show wrong can somebode help me
|
|
|
|
|
jeansea wrote: but when i run the result is show wrong can somebode help me
What is the result you have and what did you expect ?
|
|
|
|
|
compiler error the message is
error C2668: “min”:
|
|
|
|
|
jeansea wrote: error C2668: “min”:
Not very usefull reply...
Anyway, you don't have the error when you run but when you compile then ? That's something completely different.
The problem probably comes from the fact that min already exists (I think). Try using another name or putting the function in a specific namespace.
|
|
|
|
|
oh....yes
i think you are right when i using another name is can run and no error
thanks
|
|
|
|
|
jeansea wrote: compiler error the message is
error C2668: “min”:
Let's be more accurate - that's part of the message...this is the message I get from your code:
error C2668: 'min' : ambiguous call to overloaded function
a.cpp(6): could be 'Type min<int>(Type,Type)'
with
[
Type=int
]
C:\Program Files\Microsoft Visual Studio 9.0\VC\INCLUDE\xutility(3397): or 'const _Ty &std::min<int>(const _Ty &,const _Ty &)'
with
[
_Ty=int
]
while trying to match the argument list '(int, int)'
It helps when a) programming, or b) asking questions about programming, to get all the details correct and in place...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
i want to put all detail messages but i the message show in chinese...
i know to put all error message next thank for tips
|
|
|
|
|
jeansea wrote: i want to put all detail messages but i the message show in chinese...
OK - I'll let you off - my Chinese reading skills are sadly lacking
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
jeansea wrote: but when i run the result is show wrong can somebode help me
Cédric Moonen wrote: What is the result you have and what did you expect ?
jeansea wrote:
compiler error the message is
error C2668: “min”:
TOO FUNNY!
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
[My articles]
|
|
|
|
|
jeansea wrote: when i run the result is show wrong
When you run what?
As I expected, you get a compiler error when you try and compile that code, because the standard library already defines a template min function. You need to specify which min you want, by specifying that you want the 'no namespace' version (for that is yours) like this - oh, and you don't need to specify template parameters for functions if the function argument's types unambiguously specify the template parameters:
c = ::min(a, b);
Oh - and using namespace std; is bad form - use a using declaration instead. In your case, that would be 'using std::cout '. Those changes leave your program like this:
#include<iostream>
using std::cout;
template<typename Type>
Type min(Type a,Type b)
{
return a<b?a:b;
}
int main()
{
int a = 0, b = 1, c = 3;
c = ::min(a,b);
cout<<c;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Would you stop already? Whenever I want to answer some question here, your answer is already posted.
|
|
|
|
|