|
What about GetForegroundWindow()?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thankx a lot Mark... that worked for a bit...
The prob with ForGr..() is tht if we open any other window while this is code is running...then screenshot is changed cos it takes the picture of the window with which the user is interacting at that moment...
I'll explain my scenario a bit...
Im opening an application from my code...then that application is run and tht app will create a dialog...until the dialog is destroyed the control doesnt return to the next line of code...so im creating another thread and taking the screen shot...
GetActiveWindow() returns the handle of the window of the present thread but i want the handle to the window of another thread...
i got a start in this dir...
i used GetWindowThreadProcessId() to get the threadID and used GetGUIThreadInfo() to get the handle for the window...
but i got got stuck here...its throwing a external link error...
can u guide me in this...
Inder...
|
|
|
|
|
dudedotnet wrote: its throwing a external link error...
What specific error?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
error LNK2001: unresolved external symbol _GetGUIThreadInfo
|
|
|
|
|
Is your project configured as a win32 or MFC app?
I'm not sure why it wouldn't link - user32.lib is the import library.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
configured as win32 application
|
|
|
|
|
Hi
I have access to a CAD program that allows me to insert an ActiveX Control into its main window.
I wish to insert a TreeView, but fail to find any good ActiveX Control TreeViews. My idea is then to use the System.Windows.Forms.TreeView from the .NET framework. Is that readily usable as an ActiveX control, somehow?
I, of course, need to be able to change the content of the tree as well as receiving event from the tree. Everything is programmed in C++ using Visual Studio 2005.
I can see that I can create a wrapper for any .NET control using COM Callable Wrappers and REGASM, but if this is really necessary then surely someone must have done this before me!
Please advise. What is the easiest way to handle this problem.
Thanks
LG
---
See news at: www.dzone.com
|
|
|
|
|
Hi,
I would like to know if there is a way to switch windows focus to another application thats already running from a current application?? For example, I have two MFC applications (each application uses up one screen of the two screens connected to the system) running on a system, I spend most of the time running one of those applications, but occasionally I wanna do a quick click on another application, I dont want to waste time to drag mouse and check where the button on the other application is to click on it.
So is there a way to achieve this??
-Pavan
PKNT
|
|
|
|
|
Kiran Satish wrote: I would like to know if there is a way to switch windows focus to another application thats already running from a current application??
SetForegroundWindow()?
Kiran Satish wrote: but occasionally I wanna do a quick click on another application
That's different than just setting the focus to another application.
Do you want to click a button in another app remotely?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for answering my questions, actually the two applications(app1, app2) are on the same system, I just want to set focus to another application(app2) when I click a button/keyboard character in app1. Once I set the focus onto app2 I can read another keystroke thats now will be read in app2 and do appropriate work.
From MSDN it says- BOOL SetForegroundWindow( HWND hWnd ); How can I get handle for app2 in app1?? They both are started individually.
-Pavan.
PKNT
|
|
|
|
|
No matter what you use, you're going to need to know something
about the other process.
In this case, you need to know the other process' HWND.
FindWindow() can help if you know what you're looking for.
GetWindowThreadProcessId() may be useful as well.
It depends what info you have to identify the other process.
Once you have the window handle, you can use SetForegroundWindow()
to activate it. You should then call GetLastActivePopup(), and if it returns
a different window handle then the one you activated, call
SetForegroundWindow() on that window.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
This question is not completely related to this thread, but while working on the above, I came accross a situation where I need to get keyboard events and I am trying to use WM_KEYDOWN function to capture the events from a dilaog window thats created in a main dialog application, I tried it directly in main dialog window also, but it does nothing. I had a message box in it to pop up whenever it enter OnKeyDown() function.
I know it works, because I used the same way in another application which is in Doc/View architecture. Am I doing anything wrong here??
-Pavan.
PKNT
|
|
|
|
|
Generally, the problem is that only one window at a time can
have keyboard focus. In a dialog, it's usually one of the controls
in the dialog that has the keyboard focus, not the dialog itself.
This means you need to either
a) Handle the WM_KEYDOWNMESSAGE in the appropriate
window (control) (sub)class or
b) Override CWinApp::PreTranslateMessage() and filter every WM_KEYDOWN
that is sent on the thread.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I tried to use the override method, but I have some problems in reading the key code from it.
BOOL CMyApp::PreTranslateMessage(MSG* pMsg) <br />
{<br />
if(pMsg->message == 256)
MSGFILTER * lpMsgFilter = (MSGFILTER *)pMsg->wParam;<br />
<br />
return CDialog::PreTranslateMessage(pMsg);<br />
}
When I try to read the message into lpMsgFilter and check in debug, it is having NULL values in it and the application gives Unhandled exception..:Access Violation error. Is there any other way to read the keycode??
-Pavan.
PKNT
|
|
|
|
|
You can't call the CDialog PreTranslateMessage() from there.
I'm not sure how that even compiled.
You should be calling the base class' method.
If the message is WM_KEYDOWN, wParam is the virtual key code,
not a pointer.
Also, why would you hardcode 256 instead of using WM_KEYDOWN?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Its working and I can read the key codes directly from value passed by PreTranslateMessage.
Coming back to focuswindow, I am trying to focus another child window from other child window (both are in the same main application) and want to focus all my keystrokes on a particular button on that child window. Then, any keystrokes even like space bar should be applied to that button, at present as soon as I change focus to the child window and when I press spacebar, it applies it to the first button that I created while creating the dialogbox. How can i change this behavior, tried SetDefId(ID) and it doesnt help either.
I am using WM_KEYDOWN only, not 256 (I used it just like tht nothing particular).
Any suggestions??
thanks,
-Pavan.
PKNT
|
|
|
|
|
You should be setting focus to the button if you want the button to have focus.
If you set focus to the button's parent, yo'll get focus at whatever control
the parent passes focus to.
You can post WM_NEXTDLGCTL to the parent to set focus to a certain control
in the window.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am trying in this way and it still goes to the default button on that window that I created first.
I have three dialogs (main dialog, child dialog1, child dialog2), now I am trying to set focus onto dialog2 from dialog1 and also set the control to button4 on dialog2 and it always goes to button1 on dialog2 as soon as I set the focus on dialog2.
<br />
(parent->dialog2)->SetFocus();<br />
CButton *Button;<br />
Button=(CButton *)GetDlgItem(IDB_GRAB);<br />
(parent->dialog2)->PostMessageA(WM_NEXTDLGCTL,Button->GetDlgCtrlID(),TRUE);
Is it correct??
-Pavan.
PKNT
|
|
|
|
|
Kiran Satish wrote: Is it correct??
No.
(parent->dialog2)->SetFocus();<br />
CButton *Button;<br />
Button=(CButton *) (parent->dialog2)->
GetDlgItem(IDB_GRAB);<br />
(parent->dialog2)->PostMessageA(WM_NEXTDLGCTL,(WPARAM)(HWND)*Button,TRUE);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yep that works PERFECT... thanks alot. Feeling stupid for asking you soo many silly(stupid??) questions. More to come...
Yep here it is another one..
If I have an MFC applicaiton with executable, how can I pass command line arguments to it, I would like to pass a file name to an exe file created in MFC when executing at command prompt??
-Pavan.
PKNT
|
|
|
|
|
You're welcome
Kiran Satish wrote: how can I pass command line arguments to it
How do you pass them or how do you retrieve them?
To pass them, you can add them to a shortcut in the shell.
Programmatically, they can be included with CreateProcess().
To retrieve them, add this to your app class InitInstance() override:
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
CString FileNameStr = cmdInfo.m_strFileName;
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got it, its quite easy, I shoulda looked on MSDN before asking here (a minute difference). SOrry for wasting ur time there....
-Pavan.
PKNT
|
|
|
|
|
Does anyone know how to add and retrieve the objects of a class to/from a deque container? I am building a larger project with a similar problem but I cannot even get the basics to work.
int main () {
deque<int> Test2;
Test2.push_back(3);
Test2.push_back(4);
Test2.push_back(5);
<p></p>
Patient p;
deque< Patient> TestQue;
<p></p>
p.SetAge("20");
p.SetName("Dave");
p.SetCode("GEN");
<p></p>
TestQue.push_back(p);
<p></p>
cout << "Test: " << TestQue[0];
<p></p>
cout << "Test: " << Test2[0] << " " << Test2[1] << " " << Test2[2] << "\n";
<p></p>
system ("pause");
return EXIT_SUCCESS;
}
********************************************************
"Patient.h" procedure below:
This is part of a doctor class but I don't need it for this particular question.
********************************************************
class Patient {
private:
char* LastName;
char* Age;
char* Code;
public:
Patient();
Patient (char *, char *, char *);
void SetName(char *);
void SetAge(char *);
void SetCode(char *);
char* GetName();
char* GetAge();
char* GetCode();
~Patient();
};
********************************************************
Patient Procedure Below
********************************************************
#include "Patient.h"
Patient::Patient() {
LastName = NULL;
Age = NULL;
Code = NULL;
}
Patient::Patient(char *last, char *age, char *code) {
LastName = _strdup(last);
Age = _strdup(age);
Code = _strdup(code);
}
void Patient::SetName (char* last) { LastName = _strdup(last); }
void Patient::SetAge (char* age) { Age = _strdup(age); }
void Patient::SetCode (char* code) { Code = _strdup(code); }
<p></p>
char* Patient::GetName() { return LastName; }
char* Patient::GetAge() { return Age; }
char* Patient::GetCode() { return Code; }
|
|
|
|
|
PolarFuzz wrote: cout << "Test: " << TestQue[0]; // I cannot retrieve class objects, does not compile
What is the compiler complaining about?
"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 believe when an object gets assigned to a STL container, it gets copied into it. Your class does not have a "custom" copy constructor or a "custom" assignment operator.
-- modified at 11:59 Thursday 4th October, 2007
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|