Author Topic: C - Get Window title - small code  (Read 1900 times)

0 Members and 1 Guest are viewing this topic.

Offline imation

  • Peasant
  • *
  • Posts: 141
  • Cookies: 2
    • View Profile
C - Get Window title - small code
« on: January 10, 2012, 08:28:22 pm »
Code: [Select]
#include <stdio.h>
#include <string.h>
#include <windows.h>

char szCurTitle[1024],szLastTitle[1024];


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     char*    lpCmdLine,
                     int       nCmdShow)
{
                     
          // Get title of window
        HWND hWnd = GetForegroundWindow(); //get a handle on the current window
        GetWindowText (hWnd,szCurTitle,sizeof(szCurTitle));
          // Titles were different so update the log file and the last title
         printf("%s\n",szCurTitle);
       
       
  char* str2 = "Google";
  char* result = strstr(szCurTitle,str2);
  if( result == NULL ) printf( "Could not find '%s' in '%s'\n",str2,szCurTitle);
  else printf( "Found a substring: '%s'\n", result );
  return 0;
}