#2
by Math » 5年前
このような感じでしょうか
Windows10,C++Builder(10.2.3) Community Editionを使用しています。
cx.bat
コード:
bcc64 -tW g1.cpp
g1.exe
pause
g1.cpp
コード:
#include <windows.h>
#include <stdio.h>
#define WIDTH 200
#define HEIGHT 100
LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HBITMAP hBitmap;
static HDC hMemDC;
RECT rec;
switch(uMsg) {
case WM_CREATE:
hdc=GetDC(hWnd);
hBitmap=CreateCompatibleBitmap(hdc,WIDTH,HEIGHT);
hMemDC=CreateCompatibleDC(hdc);
ReleaseDC(hWnd,hdc);
SelectObject(hMemDC,hBitmap);
DeleteObject(hBitmap);
SetTimer(hWnd,1,10,NULL);
return 0;
case WM_DESTROY:
KillTimer(hWnd,1);
DeleteDC(hMemDC);
PostQuitMessage(0);
return 0;
case WM_TIMER:
InvalidateRect(hWnd,NULL,FALSE); //背景を非消去
return 0;
case WM_PAINT:
//背景画像
SelectObject(hMemDC,GetStockObject(BLACK_BRUSH));
Rectangle(hMemDC,0,0,WIDTH,HEIGHT);
//素材画像
SelectObject(hMemDC,GetStockObject(WHITE_BRUSH));
Rectangle(hMemDC, 10,10, 40,40);
Rectangle(hMemDC,110,10,140,40);
SelectObject(hMemDC,GetStockObject(GRAY_BRUSH));
Rectangle(hMemDC, 60,60, 90,90);
Rectangle(hMemDC,160,60,190,90);
TextOut( hMemDC, 10, 30, "Hello World! 今日は世界!", 25 );
SetTextColor( hMemDC, RGB( 255, 0, 255 ) );
rec.top = 50;
rec.left = 10;
rec.right = 300;
rec.bottom = 100;
DrawText( hMemDC, "AAAAA\nBBBBB", -1, &rec,DT_WORDBREAK | DT_CENTER );
printf(" debug print --- ");
hdc=BeginPaint(hWnd,&ps);
BitBlt(hdc,0,0,WIDTH,HEIGHT,hMemDC,0,0,SRCCOPY);
EndPaint(hWnd,&ps);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wc;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = __FILE__;
if(!RegisterClass(&wc)) return 0;
HWND hWnd=CreateWindow(
__FILE__,"Win32Windows",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10,50, //Left,Top
640,400, //Width,Height
NULL,NULL,hInstance,NULL);
if(hWnd==NULL) return 0;
BOOL bRet;
/////////////////////////////////////////////////////////////
//コンソールを作成し,標準出力に割り当てる
AllocConsole();
freopen("CONOUT$", "w", stdout); //標準出力をコンソールにする
printf(" debug print = %d",nCmdShow);
while((bRet=GetMessage(&msg,NULL,0,0))!=0){
if(bRet==-1) break;
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
実行
コード:
F:\z18g_cx\0729>bcc64 -tW g1.cpp
Embarcadero C++ 7.30 for Win64 Copyright (c) 2012-2017 Embarcadero Technologies, Inc.
g1.cpp:
Turbo Incremental Link64 6.90 Copyright (c) 1997-2017 Embarcadero Technologies, Inc.
F:\z18g_cx\0729>g1.exe
なおVisualStudioの場合先頭に
#define _CRT_SECURE_NO_WARNINGS
を書くといいでしょう。
このような感じでしょうか
Windows10,C++Builder(10.2.3) Community Editionを使用しています。
cx.bat
[code]
bcc64 -tW g1.cpp
g1.exe
pause
[/code]
g1.cpp
[code]
#include <windows.h>
#include <stdio.h>
#define WIDTH 200
#define HEIGHT 100
LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HBITMAP hBitmap;
static HDC hMemDC;
RECT rec;
switch(uMsg) {
case WM_CREATE:
hdc=GetDC(hWnd);
hBitmap=CreateCompatibleBitmap(hdc,WIDTH,HEIGHT);
hMemDC=CreateCompatibleDC(hdc);
ReleaseDC(hWnd,hdc);
SelectObject(hMemDC,hBitmap);
DeleteObject(hBitmap);
SetTimer(hWnd,1,10,NULL);
return 0;
case WM_DESTROY:
KillTimer(hWnd,1);
DeleteDC(hMemDC);
PostQuitMessage(0);
return 0;
case WM_TIMER:
InvalidateRect(hWnd,NULL,FALSE); //背景を非消去
return 0;
case WM_PAINT:
//背景画像
SelectObject(hMemDC,GetStockObject(BLACK_BRUSH));
Rectangle(hMemDC,0,0,WIDTH,HEIGHT);
//素材画像
SelectObject(hMemDC,GetStockObject(WHITE_BRUSH));
Rectangle(hMemDC, 10,10, 40,40);
Rectangle(hMemDC,110,10,140,40);
SelectObject(hMemDC,GetStockObject(GRAY_BRUSH));
Rectangle(hMemDC, 60,60, 90,90);
Rectangle(hMemDC,160,60,190,90);
TextOut( hMemDC, 10, 30, "Hello World! 今日は世界!", 25 );
SetTextColor( hMemDC, RGB( 255, 0, 255 ) );
rec.top = 50;
rec.left = 10;
rec.right = 300;
rec.bottom = 100;
DrawText( hMemDC, "AAAAA\nBBBBB", -1, &rec,DT_WORDBREAK | DT_CENTER );
printf(" debug print --- ");
hdc=BeginPaint(hWnd,&ps);
BitBlt(hdc,0,0,WIDTH,HEIGHT,hMemDC,0,0,SRCCOPY);
EndPaint(hWnd,&ps);
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wc;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = __FILE__;
if(!RegisterClass(&wc)) return 0;
HWND hWnd=CreateWindow(
__FILE__,"Win32Windows",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
10,50, //Left,Top
640,400, //Width,Height
NULL,NULL,hInstance,NULL);
if(hWnd==NULL) return 0;
BOOL bRet;
/////////////////////////////////////////////////////////////
//コンソールを作成し,標準出力に割り当てる
AllocConsole();
freopen("CONOUT$", "w", stdout); //標準出力をコンソールにする
printf(" debug print = %d",nCmdShow);
while((bRet=GetMessage(&msg,NULL,0,0))!=0){
if(bRet==-1) break;
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
[/code]
実行
[code]
F:\z18g_cx\0729>bcc64 -tW g1.cpp
Embarcadero C++ 7.30 for Win64 Copyright (c) 2012-2017 Embarcadero Technologies, Inc.
g1.cpp:
Turbo Incremental Link64 6.90 Copyright (c) 1997-2017 Embarcadero Technologies, Inc.
F:\z18g_cx\0729>g1.exe
[/code]
なおVisualStudioの場合先頭に
#define _CRT_SECURE_NO_WARNINGS
を書くといいでしょう。