/////////////////////////////////////////////////////// /// /// このソースコードを引用・改変した結果如何なる /// 損害が発生しても、著者はは責任を負いません。 /// 広島大学 脳外科 橋詰顕 /// //////////////////////////////////////////////////////// #include void hnsDrawText(HWND hWindow); LRESULT CALLBACK WindowProcedure(HWND hWindow,UINT message,WPARAM wParameter,LPARAM lParameter); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow) { //WNDCLASSの設計 WNDCLASS WindowClass; WindowClass.style=CS_HREDRAW | CS_VREDRAW; WindowClass.lpfnWndProc=WindowProcedure; WindowClass.cbClsExtra=0; WindowClass.cbWndExtra=0; WindowClass.hInstance=hInstance; WindowClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); WindowClass.hCursor=LoadCursor(NULL,IDC_ARROW); WindowClass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); WindowClass.lpszMenuName=NULL; WindowClass.lpszClassName="WindowClassName"; //設計したWNDCLASSの登録 if(!RegisterClass(&WindowClass)) { MessageBox(NULL,"設計したWNDCLASSの設計に失敗しました","Error!",MB_ICONERROR); return 0; } //Windowの作成 HWND hWindow=CreateWindow( "WindowClassName", //window class name "Let's make MEG task", //title WS_POPUP | WS_VISIBLE, //Window Style CW_USEDEFAULT,CW_USEDEFAULT, //top left CW_USEDEFAULT,CW_USEDEFAULT, //width,height NULL, //parent window handle (HMENU)NULL, //window menu handle hInstance, //application handle NULL); //creation parameter ShowWindow(hWindow,SW_SHOW); MSG message; //無限ループです。 while(GetMessage(&message,NULL,0,0)) { TranslateMessage(&message); DispatchMessage(&message); } return 0; } void hnsDrawText(HWND hWindow) { //DeviceContextの作成 HDC hDeviceContext=GetDC(hWindow); //文字の設定 SetTextColor(hDeviceContext,RGB(255,255,255)); //文字は白 SetBkMode(hDeviceContext,TRANSPARENT); //背景は透明 SetBkColor(hDeviceContext,RGB(0,0,0)); //とりあえず背景は黒 int CharacterSize=100; //fontの設定 HFONT hFont=CreateFont( CharacterSize,CharacterSize/2, //高さ・幅 2byte文字は*2が必要 0,0, //角度・ベースラインの角度 FW_BOLD, //太さ FALSE, //斜体 FALSE, //下線 FALSE, //打消し線 SHIFTJIS_CHARSET, //文字セット OUT_DEFAULT_PRECIS, //出力精度 CLIP_DEFAULT_PRECIS,//クリッピング精度 DEFAULT_QUALITY, //出力品質 VARIABLE_PITCH | FF_ROMAN,//ピッチとフォントファミリ "MS ゴシック"); //書体 //fontの選択 SelectObject(hDeviceContext,hFont); //文字列の作成 char textbuffer[]="脳磁図"; //描画矩形領域の設定 RECT rect; rect.left=0; rect.right=640; rect.top=0; rect.bottom=480; //文字描画 DrawText( hDeviceContext, textbuffer, -1,//文字列の長さは自動的に計算 &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);//横中央・縦中央 1列表示 //Fontの破棄 DeleteObject(hFont); //DeviceContextの解放 ReleaseDC(hWindow,hDeviceContext); } LRESULT CALLBACK WindowProcedure(HWND hWindow,UINT message,WPARAM wParameter,LPARAM lParameter) { static int WindowWidth=640; static int WindowHeight=480; LONG lResult; //画面を640x480に変更できたかどうか switch(message) { case WM_CREATE: //画面を640x480にする DEVMODE DeviceMode; DeviceMode.dmSize =sizeof(DEVMODE); DeviceMode.dmFields =DM_PELSWIDTH | DM_PELSHEIGHT; DeviceMode.dmPelsWidth =WindowWidth; DeviceMode.dmPelsHeight =WindowHeight; lResult=ChangeDisplaySettings(&DeviceMode,CDS_FULLSCREEN); if(lResult!=DISP_CHANGE_SUCCESSFUL) { MessageBox(hWindow,"full screenの変換は失敗しました","",MB_ICONERROR); break; } SetWindowPos(hWindow,HWND_TOPMOST,0,0,WindowWidth,WindowHeight,0); break; case WM_KEYDOWN: switch(wParameter) { //ESCAPEキーをおすとWindowを破壊するWM_DESTROYメッセージを送る case VK_ESCAPE: PostMessage(hWindow,WM_DESTROY,0,0); break; } break; case WM_PAINT: hnsDrawText(hWindow); break; case WM_DESTROY: //画面モードを元に戻す ChangeDisplaySettings(&DeviceMode,NULL); PostQuitMessage(0); return 0; } return DefWindowProc(hWindow,message,wParameter,lParameter); }