Monday, December 15, 2014

Your first C++ program to List All Open Windows: Part II

This article shows how to have one C++ call another and then compile.
Change the code from Your first C++ program to List All Open Windows: Part I to (change "int main" to "void listWindows":
void listWindows()
{
    cout << "START" << endl;
    const TCHAR substring[] = TEXT("Substring");
    EnumWindows(FindWindowBySubstr, (LPARAM)substring);
}

Add one line to HelloWindows.h:
void listWindows()

Create a file called HelloWorldCPP.cpp which contains the following code:
#include "HelloWindows.h"
#include <iostream>

using namespace std;
 
void sayHelloCPP () {
    cout << "Hello World! CPP" << endl;
    return;


int main() 
{
    sayHelloCPP();
    listWindows();
}

Add the file HelloWorldCPP.h

Lastly, run:

cd "C:\Users\Scott\CPrograms\"
"C:\MinGW64\bin\g++.exe" HelloWindows.cpp -o HelloWindows.exe"
HelloWindows.exe
Note: You have to make sure the main function from HelloWindows.cpp is gone since the main function is defined in HelloWorldCPP.cpp.

Note: The header file defines the functions which can be used by other .cpp files.

This post was reposted from http://scottizu.wordpress.com/2013/08/20/your-first-c-program-to-list-all-open-windows/, originally written on August 20th, 2013.

No comments:

Post a Comment