STATIC子ウィンドウの背景色を設定したい
Posted: 2011年11月20日(日) 20:48
by MoNoQLoREATOR
ウインドウを作成して文字を表示する所まではできたのですが、背景色を変更することができませんでした。
↓ソースコード
ウインドウをコントロールするクラスの汎用化や整理は後にするとして、とりあえず背景色を設定できるようにしたいです。
ご教授よろしくお願い致します。
↓ソースコード
► スポイラーを表示
#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){
HDC hdc = (HDC)wParam ;
switch(uiMsg){
case WM_CTLCOLORSTATIC:
////////////////////////////////////////////////////////////////////////////////////////////
// 背景色を水色に設定
hBrush = CreateSolidBrush(RGB(0, 255, 255) );
SelectObject(hdc, (HGDIOBJ)hBrush);
return (BOOL)0;
/////////////////////////////////////////////////////////////////////////////////////////////
default:
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}
}
class newwin{
WNDCLASSEX wc;
HWND mainWH;
HMENU childCou;
HINSTANCE hI;
char textCont[101];
public:
newwin(const string &title, int width, int height, HINSTANCE hIns, int nC){
childCou = (HMENU)100;
hI = hIns;
wc.cbClsExtra = 0;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
wc.hCursor = LoadCursor(hI,IDC_ARROW);
wc.hIcon = NULL;
wc.hIconSm = NULL;
wc.hInstance = hI;
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,hI,NULL
);
ShowWindow(mainWH,nC);
UpdateWindow(mainWH);
}
HWND child(const string &mode, const string &oput, int x, int y, int width, int height){
childCou++;
return CreateWindow(
mode.c_str(),
oput.c_str(),
WS_CHILD|WS_VISIBLE,
x,y,
width,height,
mainWH,
(HMENU)childCou,
hI,
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);
}
};
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);
newwin w("test", 320, 480, hI, nC);
HWND output = w.child("STATIC", "test", 0,0, 320,20);
HWND input = w.child("EDIT", "test", 0,20, 320,20);
while(ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0){
ClsDrawScreen();
w.sets(output, w.gets(input) );
ScreenFlip();
}
DxLib_End();
return 0;
}
ご教授よろしくお願い致します。