ウインドウ関係の処理を行うクラスと、実際に情報を表示させる処理を行うクラスを作って、簡単に利用できるようにしようと考えたのですが、利用する際にわざわざnShowCmdを渡すのは頻雑です。
nShowCmdを取得できる関数はないのでしょうか?
► スポイラーを表示
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include "DxLib.h"
#include <string>
#include <vector>
#include <fstream>
using namespace std;
HBRUSH hBrush;
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){
SetBkColor( (HDC)wParam, wORb[childID%2]);
hBrush = CreateSolidBrush(wORb[childID%2]);
return (BOOL)hBrush;
}
default:
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}
}
class newwin{
WNDCLASSEX wc;
HWND mainWH;
int childCou;
char textCont[101];
public:
newwin(){}
void init(const string &title, int width, int height, int nC){
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,nC);
UpdateWindow(mainWH);
}
newwin(const string &title, int width, int height, int nC){ init(title, width, height, nC); }
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( (HGDIOBJ)hBrush);
}
};
class view{
newwin w;
WNDCLASSEX wc;
HWND mainWH;
HWND children[24];
int next;
public:
view(int nC){
w.init("Information", 320, 480, nC);
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){ w.sets(children[next++], str); }
void set(const string &str, int num){ 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(nC);
while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
ClsDrawScreen();
v.clear();
v.add("test");
ScreenFlip();
}
DxLib_End();
return 0;
}そして、 ウインドウを作成してからしばらく経つと、水色に設定したはずの背景が灰色になり、画面がリフレッシュされなくなります。whileループで SetWindowText() 関数を呼び出しまくっているのが原因だということはわかったのですが、これは解決できるのでしょうか?
ご教授よろしくお願い致します。