Troudeloup
asked on
program focus
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"notepad") ;
MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
return 0;
}
this is my small test program, it pops a console window briefly. is it possible to make it NOT pop the console program, in other words, have it not taking focus at all?
also, given hwnd, how do I focus a window?
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"notepad")
MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
return 0;
}
this is my small test program, it pops a console window briefly. is it possible to make it NOT pop the console program, in other words, have it not taking focus at all?
also, given hwnd, how do I focus a window?
ASKER
no I have a handle of a window currently in the background and i make to focus it.
no i don't want it to be invisible.
no i don't want it to be invisible.
check out:
http://blogs.msdn.com/oldnewthing/archive/2004/08/02/205624.aspx
Let me know if you have any doubts.
http://blogs.msdn.com/oldnewthing/archive/2004/08/02/205624.aspx
Let me know if you have any doubts.
ASKER
i don't want a dialogue box.
not a problem.......use file i/o instead of normal i/o operations
check out:
http://www.mkssoftware.com/docs/man3/fgetln.3.asp
Hope it helps.
check out:
http://www.mkssoftware.com/docs/man3/fgetln.3.asp
Hope it helps.
sorry, ignore above comment.
to get focus :
SwitchToThisWindow
check out :
http://msdn2.microsoft.com/en-us/library/ms633553.aspx
and to switch the window to the background or even bring it to front:
SetWindowPos
check out:
http://msdn2.microsoft.com/en-us/library/ms633545.aspx
SwitchToThisWindow
check out :
http://msdn2.microsoft.com/en-us/library/ms633553.aspx
and to switch the window to the background or even bring it to front:
SetWindowPos
check out:
http://msdn2.microsoft.com/en-us/library/ms633545.aspx
Let me know if you have any doubt .......
ASKER
this one doesn't work
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"notepad") ;
// MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
::SwitchToThisWindow( hwnd, false );
return 0;
}
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"notepad")
// MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
::SwitchToThisWindow( hwnd, false );
return 0;
}
>>::SwitchToThisWindow( hwnd, false );
this is used to FOCUS on your application.
false parameter just signifies that the focus is not using the alt+tab sequence.
To keep in the background. please try SetWindowPos .......
revert back if you face any issues.
this is used to FOCUS on your application.
false parameter just signifies that the focus is not using the alt+tab sequence.
To keep in the background. please try SetWindowPos .......
revert back if you face any issues.
ASKER
you mean i should change that false to true for it to work?
ASKER
this is the error message
focus_test.cpp:17: error: `::SwitchToThisWindow' has not been declared
focus_test.cpp:17: error: `::SwitchToThisWindow' has not been declared
i mean if you want your window to run behind other applications.....then dont use SwitchToThisWindow.
Use SetWindowPos.
Use SetWindowPos.
ASKER
no i want to focus the window with this hwnd.
why do I have that error message?
why do I have that error message?
>>`::SwitchToThisWindow' has not been declared
#include "Windows.h"
is the solution.
#include "Windows.h"
is the solution.
oh then use ::SwitchToThisWindow( hwnd, true );
ASKER
I already have
#include <windows.h>
is this different?
#include "windows.h"
#include <windows.h>
is this different?
#include "windows.h"
ASKER
please also take a look of this one
https://www.experts-exchange.com/questions/22983831/how-do-I-save-a-screen-shot.html
https://www.experts-exchange.com/questions/22983831/how-do-I-save-a-screen-shot.html
>>is this different?
no its not different.
ASKER
why do I have that error message?
::SwitchToThisWindow' has not been declared
try without scope resolution operator.
SwitchToThisWindow
if your findwindow is working then SwitchToThisWindow should also work as both are defined in user32.dll and declared in windows.h
SwitchToThisWindow
if your findwindow is working then SwitchToThisWindow should also work as both are defined in user32.dll and declared in windows.h
ASKER
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"notepad") ;
// MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
cout << hwnd << endl;
switchtothisWindow( hwnd, false );
return 0;
}
this gets the same error message
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"notepad")
// MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
cout << hwnd << endl;
switchtothisWindow( hwnd, false );
return 0;
}
this gets the same error message
you are using "switchtothisWindow" and it is "SwitchToThisWindow". The cases you are using are different. :)
ASKER
#include <iostream>
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"");
// MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
cout << hwnd << endl;
SwitchToThisWindow( hwnd, false );
return 0;
}
nope, doesn't work.
#include <windows.h>
using namespace std;
int main ()
{
HWND hwnd = FindWindow(NULL,"");
// MoveWindow(hwnd, 100, 100, 400, 200, TRUE);
cout << hwnd << endl;
SwitchToThisWindow( hwnd, false );
return 0;
}
nope, doesn't work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how do I do a win32 prog with generic c++ code?
I use g++.
also, can you take a look of the code I posted?
I use g++.
also, can you take a look of the code I posted?
>>SwitchToThisWindow( hwnd, false );
try using with true.
try using with true.
ASKER
ok i ll say it again:
it still pops this:
focus_test.cpp:17: error: `SwitchToThisWindow' was not declared in this scope
how many times do I have to tell you that?!
it still pops this:
focus_test.cpp:17: error: `SwitchToThisWindow' was not declared in this scope
how many times do I have to tell you that?!
>>how many times do I have to tell you that?!
Troudeloup, would have been gud if you had told me in ur previous post. By "It doesn't work", i thought you are into the functionality rather than compile time errors.
Anyway, thanks.
Troudeloup, would have been gud if you had told me in ur previous post. By "It doesn't work", i thought you are into the functionality rather than compile time errors.
Anyway, thanks.
>>>> how do I do a win32 prog with generic c++ code?
win32 is a properietary platform. There is no generic code c++ for a platform specific thing.
>>>> I use g++.
Check the docs whether they support linker option
/subsystem:windows
If yes, it should work with g++ as well.
>>>> SwitchToThisWindow( hwnd, false );
Did you try the SetFocus instead?
win32 is a properietary platform. There is no generic code c++ for a platform specific thing.
>>>> I use g++.
Check the docs whether they support linker option
/subsystem:windows
If yes, it should work with g++ as well.
>>>> SwitchToThisWindow( hwnd, false );
Did you try the SetFocus instead?
use ShowWindow(SW_HIDE);
Let me know if you have any doubts.