Click here to Skip to main content
15,922,574 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: help Pin
CPallini28-Jan-08 21:47
mveCPallini28-Jan-08 21:47 
QuestionRe: help Pin
David Crow29-Jan-08 2:44
David Crow29-Jan-08 2:44 
GeneralRe: help Pin
KarstenK29-Jan-08 3:06
mveKarstenK29-Jan-08 3:06 
Generalgetchar() help Pin
gentleguy28-Jan-08 15:04
gentleguy28-Jan-08 15:04 
QuestionRe: getchar() help Pin
David Crow28-Jan-08 15:56
David Crow28-Jan-08 15:56 
GeneralGetForegroundWindow() Pin
dellthinker28-Jan-08 8:12
dellthinker28-Jan-08 8:12 
GeneralRe: GetForegroundWindow() Pin
David Crow28-Jan-08 8:20
David Crow28-Jan-08 8:20 
GeneralRe: GetForegroundWindow() Pin
dellthinker28-Jan-08 13:20
dellthinker28-Jan-08 13:20 
Ok so now im using GetWindowText() and it seems to capture all window titles. But i need it to look for a specific window, Notepad in this case.

Here is my code:

<br />
#include <iostream><br />
#include <windows.h><br />
using namespace std;<br />
<br />
<br />
int main(void)<br />
{<br />
	HWND currenthwnd,hwnd;<br />
	char s[1024];<br />
	hwnd=NULL;<br />
	while (1){<br />
	Sleep(1000);<br />
		currenthwnd=GetForegroundWindow();<br />
		if (currenthwnd!=hwnd){<br />
			hwnd=currenthwnd;<br />
			GetWindowText(hwnd,s,1024);<br />
			printf("%s\n",s);<br />
		}<br />
		if(strstr(s, "Notepad") == 0){<br />
				cout << "Notepad is open! " << endl;<br />
		}<br />
		else{<br />
			cout << "Its not open " << endl;<br />
		}<br />
	}<br />
	return 0;<br />
}<br />
</windows.h></iostream>


Problem is when the program is running it prints Notepad is open when it really isnt. Can someone help me fix this? Thanx in advance!
GeneralRe: GetForegroundWindow() Pin
Mark Salsbery28-Jan-08 13:47
Mark Salsbery28-Jan-08 13:47 
GeneralRe: GetForegroundWindow() Pin
dellthinker28-Jan-08 14:48
dellthinker28-Jan-08 14:48 
AnswerRe: GetForegroundWindow() Pin
fd012900228-Jan-08 13:51
fd012900228-Jan-08 13:51 
Generaltest Pin
Member 462175228-Jan-08 7:44
Member 462175228-Jan-08 7:44 
GeneralRe: test Pin
CPallini28-Jan-08 7:56
mveCPallini28-Jan-08 7:56 
GeneralRe: test Pin
Hamid_RT28-Jan-08 19:16
Hamid_RT28-Jan-08 19:16 
GeneralGDI+ NOISE problem Pin
followait28-Jan-08 5:32
followait28-Jan-08 5:32 
GeneralRe: GDI+ NOISE problem Pin
Iain Clarke, Warrior Programmer28-Jan-08 5:34
Iain Clarke, Warrior Programmer28-Jan-08 5:34 
GeneralRe: GDI+ NOISE problem Pin
followait28-Jan-08 5:46
followait28-Jan-08 5:46 
GeneralQuestion regarding exported C++ symbols/objects Pin
Lea Hayes28-Jan-08 4:24
Lea Hayes28-Jan-08 4:24 
GeneralSmart Card Service Problem Pin
Federico Milano28-Jan-08 2:28
Federico Milano28-Jan-08 2:28 
GeneralRe: Smart Card Service Problem Pin
Maxwell Chen28-Jan-08 3:25
Maxwell Chen28-Jan-08 3:25 
GeneralRe: Smart Card Service Problem Pin
Federico Milano28-Jan-08 3:39
Federico Milano28-Jan-08 3:39 
GeneralRe: Smart Card Service Problem Pin
Maxwell Chen28-Jan-08 4:13
Maxwell Chen28-Jan-08 4:13 
GeneralLinker Error 2005 Pin
quastman28-Jan-08 1:29
quastman28-Jan-08 1:29 
QuestionRe: Linker Error 2005 Pin
CPallini28-Jan-08 1:50
mveCPallini28-Jan-08 1:50 
GeneralRe: Linker Error 2005 Pin
quastman28-Jan-08 2:19
quastman28-Jan-08 2:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.