1 | initial version |
For Windows:
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumdisplaymonitors
2 | No.2 Revision |
For Windows:
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumdisplaymonitors
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
// Method 1
cout << GetSystemMetrics(SM_CMONITORS) << endl;
// Method 2
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
cout << monitor_count << endl;
return 0;
}
3 | No.3 Revision |
For Windows:
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
// Method 1
cout << GetSystemMetrics(SM_CMONITORS) << endl;
// Method 2
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use this version instead:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
// Method 1
cout << GetSystemMetrics(SM_CMONITORS) << endl;
// Method 2
size_t monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
4 | No.4 Revision |
For Windows:
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
// Method 1
cout << GetSystemMetrics(SM_CMONITORS) << endl;
// Method 2
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use this version instead:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
// Method 1
cout << GetSystemMetrics(SM_CMONITORS) << endl;
// Method 2
size_t monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
5 | No.5 Revision |
For Windows:
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, 0);
NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use this version instead:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
6 | No.6 Revision |
For Windows:
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use this the following version instead:instead. It isn't intentionally obfuscated, it's just plain old pointer use:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
7 | No.7 Revision |
For Windows:The following version for Windows uses a global variable to keep track of the number of monitors (real and virtual):
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use the following version instead. It isn't intentionally obfuscated, it's just plain old pointer use:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
8 | No.8 Revision |
The following version for Windows uses a global variable to keep track of the number of monitors (real and virtual):
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use the following version instead. It isn't intentionally obfuscated, it's just plain old pointer use:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
// Regarding pointer use:
// 1) Reinterpret the LPARAM as a size_t*
// 2) Dereference the size_t* to get the variable
// 3) Add one to the value of the variable
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
// Regarding the fourth parameter:
// 1) Get address of variable
// 2) Reinterpret the size_t* as an LPARAM
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
9 | No.9 Revision |
The following version for Windows uses a global variable to keep track of the number of monitors (real and virtual):
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use the following version instead. It isn't intentionally obfuscated, it's just plain old pointer use:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
// Regarding pointer use:
use and the fourth parameter:
// 1) Reinterpret the LPARAM as a size_t*
// 2) Dereference the size_t* to get the variable
// 3) Add one to the value of the variable
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
// Regarding the fourth parameter:
// 1) Get address of variable
// 2) Reinterpret the size_t* as an LPARAM
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
10 | No.10 Revision |
The following version for Windows uses a global variable to keep track of the number of monitors (real and virtual):
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use the following version instead. It isn't intentionally obfuscated, it's just plain old pointer use. I've included comments regarding this pointer use:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
// Regarding pointer use and the fourth parameter:
// 1) Reinterpret the LPARAM as a size_t*
// 2) Dereference the size_t* to get the variable
// 3) Add one to the value of the variable
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
// Regarding the fourth parameter:
// 1) Get address of variable
// 2) Reinterpret the size_t* as an LPARAM
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}
11 | No.11 Revision |
The following version for Windows uses a global variable to keep track of the number of monitors (real and virtual):
#include <windows.h>
#include <iostream>
using namespace std;
size_t monitor_count = 0;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
monitor_count++;
return TRUE;
}
int main(void)
{
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, NULL);
cout << monitor_count << endl;
return 0;
}
... or if you abhor global variables, then you can use the following version instead. It isn't intentionally obfuscated, it's just plain old pointer use. I've included comments regarding this pointer use:
#include <windows.h>
#include <iostream>
using namespace std;
BOOL monitor_enum_proc(HMONITOR Arg1, HDC Arg2, LPRECT Arg3, LPARAM Arg4)
{
// Regarding pointer use and the fourth parameter:
// 1) Reinterpret the LPARAM as a size_t*
// 2) Dereference the size_t* to get the variable
// 3) Add one to the value of the variable
(*reinterpret_cast<size_t *>(Arg4))++;
return TRUE;
}
int main(void)
{
size_t monitor_count = 0;
// Regarding pointer use and the fourth parameter:
// 1) Get address of variable
// 2) Reinterpret the size_t* as an LPARAM
EnumDisplayMonitors(NULL, NULL, monitor_enum_proc, reinterpret_cast<LPARAM>(&monitor_count));
cout << monitor_count << endl;
return 0;
}