#include <windows.h>
#include "Dxlib.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
TCHAR ClassName[] = TEXT("sample");
TCHAR ClassName2[] = TEXT("sample2");
HWND Dxlib;
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst,
LPSTR lpsCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASSEX wc;
WNDCLASSEX wc2;
HWND hWnd;
hInst= hCurInst;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hCurInst;
wc.hIcon = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc.hCursor = (HCURSOR)LoadImage(
NULL, MAKEINTRESOURCE(IDC_ARROW),
IMAGE_CURSOR, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc.hbrBackground =
(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = ClassName;
wc.hIconSm = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
RegisterClassEx(&wc);
wc2.cbSize = sizeof(WNDCLASSEX);
wc2.style = CS_HREDRAW | CS_VREDRAW;
wc2.lpfnWndProc = WndProc;
wc2.cbClsExtra = 0;
wc2.cbWndExtra = 0;
wc2.hInstance = hCurInst;
wc2.hIcon = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc2.hCursor = (HCURSOR)LoadImage(
NULL, MAKEINTRESOURCE(IDC_ARROW),
IMAGE_CURSOR, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
wc2.hbrBackground =
(HBRUSH)GetStockObject(BLACK_BRUSH);
wc2.lpszMenuName = NULL;
wc2.lpszClassName = ClassName2;
wc2.hIconSm = (HICON)LoadImage(
NULL, MAKEINTRESOURCE(IDI_APPLICATION),
IMAGE_ICON, 0, 0,
LR_DEFAULTSIZE | LR_SHARED);
RegisterClassEx(&wc2);
hWnd = CreateWindow(ClassName,
TEXT("samle"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hCurInst,
NULL
);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
SetUserWindow(Dxlib), DxLib_Init();
ChangeWindowMode(TRUE),SetDrawScreen( DX_SCREEN_BACK );
while(1){
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message != WM_QUIT){
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
break;
}
}
if(ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0){
//メイン処理
DrawFormatString( 0, 0, GetColor( 255 , 255 , 255 ) , "Test" ) ;
}
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg) {
case WM_CREATE:
Dxlib = CreateWindow(ClassName2,
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,
0,0,500,600, hWnd,NULL,hInst, NULL
);
break;
case WM_DESTROY:
PostQuitMessage(0);
DxLib_End();
break;
default:
return (DefWindowProc(hWnd, msg, wp, lp));
}
return 0;
}
昨日からプログラムを簡素にしていたら、
別ウィンドウででるということはなくなったのですが、一瞬でウィンドウが消え、終了時にエラーが出てしまいますが、これがソースです。