コード:
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include "DxLib.h"
#include <string>
#include <vector>
#include <fstream>
using namespace std;
class newwin{
WNDCLASSEX wc;
HWND mainWH;
int childCou;
char textCont[101];
static LRESULT CALLBACK WindowProc(HWND hwnd,UINT uiMsg,WPARAM wParam,LPARAM lParam){
int childID = (int)GetWindowLongPtr((HWND)lParam, GWLP_ID);
COLORREF wORb[2] = {RGB(255,255,255), RGB(200,255,255)};
switch(uiMsg){
case WM_CTLCOLORSTATIC:
// 背景色を水色に設定
if(childID>=100 && childID<124){
if(childID%2){
SetBkColor( (HDC)wParam, RGB(255,255,255) );
DeleteObject(GetSysColorBrush(COLOR_WINDOW) );
HBRUSH hBrush = CreateSolidBrush(RGB(255,255,255) );
return (BOOL)hBrush;
}
else{
SetBkColor( (HDC)wParam, RGB(200,255,255) );
DeleteObject(GetSysColorBrush(COLOR_WINDOW) );
HBRUSH hBrush = CreateSolidBrush(RGB(200,255,255) );
return (BOOL)hBrush;
}
}
default:
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}
}
public:
newwin(){}
void init(const string &title, int width, int height){
childCou = 100;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wc.hCursor = LoadCursor(GetModuleHandle(NULL),IDC_ARROW);
wc.hIcon = NULL;
wc.hIconSm = NULL;
wc.hInstance = GetModuleHandle(NULL);
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = "myClass";
wc.lpszMenuName = NULL;
wc.style = CS_DBLCLKS;
RegisterClassEx(&wc);
mainWH = CreateWindowEx(
WS_EX_TOOLWINDOW,
"myClass",
title.c_str(),
WS_BORDER|WS_SYSMENU,
CW_USEDEFAULT,CW_USEDEFAULT,
width,height,
NULL,NULL,GetModuleHandle(NULL),NULL
);
ShowWindow(mainWH,SW_SHOWDEFAULT);
UpdateWindow(mainWH);
}
newwin(const string &title, int width, int height){ init(title, width, height); }
HWND child(const string &mode, const string &oput, int x, int y, int width, int height){
return CreateWindow(
mode.c_str(),
oput.c_str(),
WS_CHILD|WS_VISIBLE,
x,y,
width,height,
mainWH,
(HMENU)childCou++,
GetModuleHandle(NULL),
NULL
);
}
const char* gets(HWND hwnd){
GetWindowText(hwnd, textCont, 100);
return textCont;
}
void sets(HWND hwnd, const string &oput){
SetWindowText(hwnd, oput.c_str() );
}
~newwin(){
for(int i=100;i<(int)childCou;i++) DestroyWindow( (HWND)i);
DestroyWindow(mainWH);
DeleteObject(GetSysColorBrush(COLOR_WINDOW) );
}
};
class view{
newwin w;
WNDCLASSEX wc;
HWND mainWH;
HWND children[24];
int next;
public:
view(){
w.init("Information", 320, 480);
for(int i=0;i<24;i++) children[i] = w.child("STATIC", "", 0,19*i, 320,19);
next = 0;
}
void clear(){
for(int i=0;i<24;i++) w.sets(children[i], "");
next = 0;
}
void add(const string &str){ if(next < 24) w.sets(children[next++], str); }
void set(const string &str, int num){ if(next < 24) w.sets(children[num], str); }
};
int WINAPI WinMain(HINSTANCE hI,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nC){
ChangeWindowMode(TRUE);
SetOutApplicationLogValidFlag(FALSE);
SetWindowText("DxLib");
if(DxLib_Init() == -1) return(-1);
SetAlwaysRunFlag(TRUE);
SetDrawScreen(DX_SCREEN_BACK);
view v;
v.add("test");
while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
ClsDrawScreen();
//v.clear();
//v.add("test");
ScreenFlip();
}
DxLib_End();
return 0;
}