Artifact Content

Not logged in

Artifact 983218cb4853f610d7b6de3ba62d7a8cc76c1436


     1  private import std.string;
     2  private import win32.ansi.windows;
     3  private import win32.ansi.commctrl;
     4  private import qbga32;
     5  
     6  void process_messages()
     7  {
     8  	for( MSG msg; PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ); )
     9  	{
    10  		TranslateMessage( &msg );
    11  		DispatchMessage( &msg );
    12  	}
    13  }
    14  
    15  // 実装継承(w
    16  
    17  class Dialog
    18  {
    19  public:
    20  	HWND hwnd()
    21  	{
    22  		return handle;
    23  	}
    24  
    25  protected:
    26  	void on_init()   { MessageBox(null,"xxx",null,MB_OK); }
    27  	bool on_ok()     { return false; }
    28  	bool on_cancel() { return false; }
    29  	bool on_command( UINT cmd ) { return false; }
    30  	bool on_message( UINT msg, WPARAM wp, LPARAM lp ) { return false; }
    31  
    32  	extern(Windows) private static BOOL
    33  		static_dlg_proc( HWND dlg, UINT msg, WPARAM wp, LPARAM lp )
    34  	{
    35  		if( msg == WM_INITDIALOG )
    36  		{
    37  			SetWindowLong( dlg, GWL_USERDATA, lp );
    38  
    39  			Dialog ptr = cast(Dialog) cast(Dialog*) lp;
    40  			ptr.handle = dlg;
    41  			ptr.on_init();
    42  			return FALSE;
    43  		}
    44  
    45  		Dialog ptr = cast(Dialog) cast(Dialog*) GetWindowLong(dlg,GWL_USERDATA);
    46  		if( ptr is null )
    47  			return FALSE;
    48  
    49  		if( msg == WM_COMMAND )
    50  			if( LOWORD(wp) == IDOK )
    51  				return ptr.on_ok();
    52  			else if( LOWORD(wp) == IDCANCEL )
    53  				return ptr.on_cancel();
    54  			else
    55  				return ptr.on_command( LOWORD(wp) );
    56  		return ptr.on_message(msg,wp,lp);
    57  	}
    58  
    59  protected:
    60  	HWND handle;
    61  	void BeginModeless( DLGTEMPLATE* dlg_template, HWND parent )
    62  	{
    63  		CreateDialogIndirectParam(
    64  			g_hinst,
    65  			dlg_template,
    66  			parent,
    67  			&static_dlg_proc,
    68  			cast(LPARAM) cast(Dialog*) this
    69  		);
    70  	}
    71  
    72  	int BeginModal( DLGTEMPLATE* dlg_template, HWND parent )
    73  	{
    74  		return DialogBoxIndirectParam(
    75  			g_hinst,
    76  			dlg_template,
    77  			parent,
    78  			&static_dlg_proc,
    79  			cast(LPARAM) cast(Dialog*) this
    80  		);
    81  	}
    82  
    83  	void set_item_text( int ID, char[] str )
    84  	{
    85  		SetDlgItemText( handle, ID, toStringz(str) );
    86  	}
    87  
    88  	int send_item_msg( int ID, UINT msg, WPARAM wp=0, LPARAM lp=0 )
    89  	{
    90  		return SendDlgItemMessage( handle, ID, msg, wp, lp );
    91  	}
    92  }
    93  
    94  //------------------------------------------------------------
    95  // #2025 [ファイルを操作中]
    96  //   2006 : 書庫名
    97  //   2007 : ファイル名(パス無し)
    98  //   2024 : プログレスバー
    99  //      2 : キャンセルボタン
   100  //------------------------------------------------------------
   101  
   102  class ProgressDlg : Dialog
   103  {
   104  	this( DLGTEMPLATE* dlg_template, HWND parent )
   105  	{
   106  		BeginModeless( dlg_template, parent );
   107  	}
   108  
   109  	void set_arcname ( char[] str ){ set_item_text( 2006, str ); }
   110  	void set_filename( char[] str ){ set_item_text( 2007, str ); }
   111  	void set_max( real m ) { max = m; }
   112  	void set_pos( real p ) { send_item_msg(2024,PBM_SETPOS,cast(int)(p/max*65535),0); }
   113  
   114  	bool closed()
   115  	{
   116  		return !alive;
   117  	}
   118  
   119  	void close()
   120  	{
   121  		if( !closed )
   122  			on_cancel();
   123  	}
   124  
   125  protected:
   126  	bool alive = false;
   127  	real max = 1.0;
   128  
   129  	override void on_init()
   130  	{
   131  		alive = true;
   132  		send_item_msg( 2024, PBM_SETRANGE, 0, MAKELPARAM(0,65535) );
   133  
   134  		// センタリング
   135  		RECT rc,pr;
   136  		GetWindowRect( handle, &rc );
   137  		HWND par = GetParent(handle);
   138  		if( par )
   139  			GetWindowRect( par, &pr );
   140  		else
   141  			SystemParametersInfo( SPI_GETWORKAREA, 0, &pr, 0 );
   142  		SetWindowPos( handle, null,
   143  			pr.left + ( (pr.right-pr.left)-(rc.right-rc.left) )/2,
   144  			pr.top  + ( (pr.bottom-pr.top)-(rc.bottom-rc.top) )/2,
   145  			0, 0, SWP_NOSIZE|SWP_NOZORDER );
   146  
   147  		// 表示
   148  		ShowWindow(handle,SW_SHOW);
   149  		UpdateWindow(handle);
   150  	}
   151  
   152  	override bool on_cancel()
   153  	{
   154  		alive = false;
   155  		DestroyWindow(handle);
   156  		return true;
   157  	}
   158  }
   159  
   160  //------------------------------------------------------------
   161  // #2000  [ファイルの上書き確認]
   162  //   2006 書庫内ファイル名
   163  //   2009 ファイルサイズ   564,590 Byte
   164  //   2010 更新日時         2004\08\27 03:57:18
   165  //   2007 外部ファイル名
   166  //   2011 ファイルサイズ
   167  //   2012 更新日時
   168  //
   169  //   2002:上書き  2004:日付が新しければ上書き 2003:上書きしない
   170  //
   171  //      1: OKボタン
   172  //   2005: 以降全てに適用ボタン
   173  //      2: キャンセルボタン
   174  //------------------------------------------------------------
   175