import win32.windows; import core.thread; import std.stdio; import std.string; import std.utf; COLORREF RGBA(uint r, uint g, uint b, uint a) { return cast(COLORREF)(r | (g << 8) | (b << 16) | (a<<24)); } class ProgressWindow { ProgressThread ThProgressWindow ; string classname ; string name ; this(string name){ this.name=name ; } int start(int x, int y, int w, int h){ ThProgressWindow = new ProgressThread(name) ; ThProgressWindow.setPosition(x,y,w,h) ; ThProgressWindow.start() ; return(0) ; } int close(){ while(-1){ if( ThProgressWindow.getCreateState()==true ){ SendMessage(ThProgressWindow.hwnd, WM_DESTROY, 0,0) ; break ; } } ThProgressWindow.join() ; return(0) ; } } class ProgressThread : Thread{ HWND hwnd ; WNDCLASSEX winc ; string winname ; int exstyle ; int style ; int winX,winY,winW,winH ; bool create_done=false ; this(string name){ this.winc.cbSize = WNDCLASSEX.sizeof; this.winc.lpszClassName = cast(wchar*)std.utf.toUTF16z("PROGRESS") ; this.winc.hInstance = GetModuleHandle(null) ; this.winc.lpfnWndProc = cast(WNDPROC)(&_WndProgressProc) ; this.winc.hbrBackground = null ; //CreateSolidBrush(GetSysColor(COLOR_BTNFACE)) ; this.hwnd = null ; this.winname = name ; RegisterClassEx(cast(WNDCLASSEXW*)(&this.winc)) ; style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_OVERLAPPED | WS_VISIBLE ; super( &run ) ; } void run(){ int bRet ; MSG msg ; hwnd = CreateWindowEx(exstyle, cast(wchar*)this.winc.lpszClassName, std.utf.toUTF16z(this.winname), style, winX,winY,winW,winH, null, null, this.winc.hInstance , cast(LPVOID)(this) ); create_done=true ; while( (bRet = GetMessage(&msg , null , 0 , 0)) != 0 ){ if (bRet == -1 ) break; DispatchMessage(&msg); } //MessageBox(null,"test","test",MB_OK) ; writef("run exit\n") ; } bool getCreateState(){ return(create_done) ; } int setPosition(int x, int y, int w, int h){ this.winX=x ; this.winY=y ; this.winW=w ; this.winH=h ; return(0) ; } } extern (Windows) LRESULT _WndProgressProc(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); break ; case WM_PAINT: PAINTSTRUCT ps; HDC hdc; HBRUSH COLFG , COLBG ; HPEN PCOLFG, PCOLBG ; // PCOLBG = CreatePen(PS_SOLID, 1, RGBA(128,128,128,0) & 0x00ffffff) ; // COLBG = CreateSolidBrush(RGBA(128,128,128,0) & 0x00ffffff) ; hdc = BeginPaint(hwnd, &ps); // SetBkMode(hdc,TRANSPARENT) ; // SelectObject(hdc, PCOLBG) ; // SelectObject(hdc, COLBG) ; // Rectangle(hdc, 10,10,90,90) ; // string str = format("Test") ; // TextOut(hdc, 10,10, cast(wchar*)(toUTF16z(str)) , str.length); EndPaint(hwnd, &ps); // DeleteObject(PCOLBG) ; // DeleteObject(COLBG) ; break ; default : return( DefWindowProc(hwnd , msg , wp , lp) ) ; } return(0) ; } int main() { ProgressWindow progresswin ; progresswin = new ProgressWindow("ProgressWindow") ; progresswin.start(0,0,200,200) ; for( int i=0 ; i<100 ; i++ ){ for( int j=0 ; j<10000000 ; j++ ){} } progresswin.close() ; return(0) ; }