#4
by あたっしゅ » 4年前
俺の環境(Windows 10 Pro 64bit)で失敗する。
コード:
//
// https://dixq.net/forum/viewtopic.php?f=3&t=16763&p=131339&hilit=%E3%82%B3%E3%83%B3%E3%82%BD%E3%83%BC%E3%83%AB#p131339
//
//
// Embarcadero Dev-c++ 5.5
// TDM-GCC 4.9.2 64bit Release
//
// Tools
// Compiler Option
// General
// Add compiler
// -Wall -Wextra -s -O2 -o -lrpcrt4 -lgdi32
// Add linker
// -static-libgcc
//
#include <cstdio>
#include <conio.h>
#include <windows.h>
//#define RPC
#ifdef RPC
#include <rpc.h>
#endif
//
//
//
HWND
getConsoleWindowHandle(void)
{
static wchar_t title[1000000];
static wchar_t title_text[1000000];
#ifdef RPC
//char uuid[100];
//unsigned char *p;
//UUID uuidData;
#endif
HWND hWnd;
/* 今のタイトルを取得 */
if( !GetConsoleTitleW(title, sizeof(title)/sizeof(title[0]))==0 ) {
printf( "Error:%s:%d", __FILE__, __LINE__ );
return NULL;
}
#ifdef RPC
/* 一意なタイトルを生成 */
//UuidCreate(&uuidData);
//UuidToString(&uuidData, &p);
//lstrcpyA(uuid, (char*)p);
//RpcStringFree(&p);
/* 一意なタイトルを設定 */
//if(SetConsoleTitleA(uuid)==0) return NULL;
//Sleep(40);
/* ウィンドウハンドルを取得 */
//hWnd = FindWindowA(NULL, uuid);
#else
hWnd = FindWindowW(NULL, title);
#endif
/* タイトルを戻す */
//SetConsoleTitleW(title);
/* 正しいウィンドウハンドルかチェックする */
if (hWnd != NULL) {
Sleep(40);
GetWindowTextW(hWnd, title_text, sizeof(title_text)/sizeof(title_text[0]));
if(lstrcmpW(title, title_text)!=0)return NULL;
}
return hWnd;
}
int
main(void)
{
HWND hWnd;
HDC hDC;
POINT oldPosition;
//HPEN oldPen;
HGDIOBJ oldPen;
/* 準備 */
hWnd = getConsoleWindowHandle();
if( hWnd == NULL ) {
return EXIT_FAILURE;
}
hDC = GetDC(hWnd);
oldPen = SelectObject(hDC, GetStockObject(WHITE_PEN));
/* 三角形を描画 */
MoveToEx(hDC, 200, 100, &oldPosition);
LineTo(hDC, 250, 187);
LineTo(hDC, 150, 187);
LineTo(hDC, 200, 100);
/* 円を描画 */
Arc(hDC, 200, 143, 400, 343, 300, 143, 300, 143);
getch();
/* 後片付け */
MoveToEx(hDC, oldPosition.x, oldPosition.y, NULL);
SelectObject(hDC, oldPen);
ReleaseDC(hWnd, hDC);
return EXIT_SUCCESS;
}
// end.
Embarcadero Dev-C++(C++ Builder とは別)
https://www.embarcadero.com/jp/free-tools/dev-cpp
俺の環境(Windows 10 Pro 64bit)で失敗する。
[code]
//
// https://dixq.net/forum/viewtopic.php?f=3&t=16763&p=131339&hilit=%E3%82%B3%E3%83%B3%E3%82%BD%E3%83%BC%E3%83%AB#p131339
//
//
// Embarcadero Dev-c++ 5.5
// TDM-GCC 4.9.2 64bit Release
//
// Tools
// Compiler Option
// General
// Add compiler
// -Wall -Wextra -s -O2 -o -lrpcrt4 -lgdi32
// Add linker
// -static-libgcc
//
#include <cstdio>
#include <conio.h>
#include <windows.h>
//#define RPC
#ifdef RPC
#include <rpc.h>
#endif
//
//
//
HWND
getConsoleWindowHandle(void)
{
static wchar_t title[1000000];
static wchar_t title_text[1000000];
#ifdef RPC
//char uuid[100];
//unsigned char *p;
//UUID uuidData;
#endif
HWND hWnd;
/* 今のタイトルを取得 */
if( !GetConsoleTitleW(title, sizeof(title)/sizeof(title[0]))==0 ) {
printf( "Error:%s:%d", __FILE__, __LINE__ );
return NULL;
}
#ifdef RPC
/* 一意なタイトルを生成 */
//UuidCreate(&uuidData);
//UuidToString(&uuidData, &p);
//lstrcpyA(uuid, (char*)p);
//RpcStringFree(&p);
/* 一意なタイトルを設定 */
//if(SetConsoleTitleA(uuid)==0) return NULL;
//Sleep(40);
/* ウィンドウハンドルを取得 */
//hWnd = FindWindowA(NULL, uuid);
#else
hWnd = FindWindowW(NULL, title);
#endif
/* タイトルを戻す */
//SetConsoleTitleW(title);
/* 正しいウィンドウハンドルかチェックする */
if (hWnd != NULL) {
Sleep(40);
GetWindowTextW(hWnd, title_text, sizeof(title_text)/sizeof(title_text[0]));
if(lstrcmpW(title, title_text)!=0)return NULL;
}
return hWnd;
}
int
main(void)
{
HWND hWnd;
HDC hDC;
POINT oldPosition;
//HPEN oldPen;
HGDIOBJ oldPen;
/* 準備 */
hWnd = getConsoleWindowHandle();
if( hWnd == NULL ) {
return EXIT_FAILURE;
}
hDC = GetDC(hWnd);
oldPen = SelectObject(hDC, GetStockObject(WHITE_PEN));
/* 三角形を描画 */
MoveToEx(hDC, 200, 100, &oldPosition);
LineTo(hDC, 250, 187);
LineTo(hDC, 150, 187);
LineTo(hDC, 200, 100);
/* 円を描画 */
Arc(hDC, 200, 143, 400, 343, 300, 143, 300, 143);
getch();
/* 後片付け */
MoveToEx(hDC, oldPosition.x, oldPosition.y, NULL);
SelectObject(hDC, oldPen);
ReleaseDC(hWnd, hDC);
return EXIT_SUCCESS;
}
// end.
[/code]
Embarcadero Dev-C++(C++ Builder とは別)
https://www.embarcadero.com/jp/free-tools/dev-cpp