Example #1
0
Cursor::Cursor(Image* img, const IntPoint& hotspot) 
{ 
    static bool doAlpha = supportsAlphaCursors();
    BITMAPINFO cursorImage = {0};
    cursorImage.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    cursorImage.bmiHeader.biWidth = img->width();
    cursorImage.bmiHeader.biHeight = img->height();
    cursorImage.bmiHeader.biPlanes = 1;
    cursorImage.bmiHeader.biBitCount = 32;
    cursorImage.bmiHeader.biCompression = BI_RGB;
    HDC dc = GetDC(0);
    HDC workingDC = CreateCompatibleDC(dc);
    if (doAlpha) {
        OwnPtr<HBITMAP> hCursor(CreateDIBSection(dc, (BITMAPINFO *)&cursorImage, DIB_RGB_COLORS, 0, 0, 0));
        ASSERT(hCursor);

        img->getHBITMAP(hCursor.get()); 
        HBITMAP hOldBitmap = (HBITMAP)SelectObject(workingDC, hCursor.get());
        SetBkMode(workingDC, TRANSPARENT);
        SelectObject(workingDC, hOldBitmap);

        OwnPtr<HBITMAP> hMask(CreateBitmap(img->width(), img->height(), 1, 1, NULL));

        ICONINFO ii;
        ii.fIcon = FALSE;
        ii.xHotspot = hotspot.x();
        ii.yHotspot = hotspot.y();
        ii.hbmMask = hMask.get();
        ii.hbmColor = hCursor.get();

        m_impl = new SharedCursor(CreateIconIndirect(&ii));
    } else {
        // Platform doesn't support alpha blended cursors, so we need
        // to create the mask manually
        HDC andMaskDC = CreateCompatibleDC(dc);
        HDC xorMaskDC = CreateCompatibleDC(dc);
        OwnPtr<HBITMAP> hCursor(CreateDIBSection(dc, &cursorImage, DIB_RGB_COLORS, 0, 0, 0));
        ASSERT(hCursor);
        img->getHBITMAP(hCursor.get()); 
        BITMAP cursor;
        GetObject(hCursor.get(), sizeof(BITMAP), &cursor);
        OwnPtr<HBITMAP> andMask(CreateBitmap(cursor.bmWidth, cursor.bmHeight, 1, 1, NULL));
        OwnPtr<HBITMAP> xorMask(CreateCompatibleBitmap(dc, cursor.bmWidth, cursor.bmHeight));
        HBITMAP oldCursor = (HBITMAP)SelectObject(workingDC, hCursor.get());
        HBITMAP oldAndMask = (HBITMAP)SelectObject(andMaskDC, andMask.get());
        HBITMAP oldXorMask = (HBITMAP)SelectObject(xorMaskDC, xorMask.get());

        SetBkColor(workingDC, RGB(0,0,0));  
        BitBlt(andMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC, 0, 0, SRCCOPY);
    
        SetBkColor(xorMaskDC, RGB(255, 255, 255));
        SetTextColor(xorMaskDC, RGB(255, 255, 255));
        BitBlt(xorMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, andMaskDC, 0, 0, SRCCOPY);
        BitBlt(xorMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC, 0,0, SRCAND);

        SelectObject(workingDC, oldCursor);
        SelectObject(andMaskDC, oldAndMask);
        SelectObject(xorMaskDC, oldXorMask);

        ICONINFO icon = {0};
        icon.fIcon = FALSE;
        icon.xHotspot = hotspot.x();
        icon.yHotspot = hotspot.y();
        icon.hbmMask = andMask.get();
        icon.hbmColor = xorMask.get();
        m_impl = new SharedCursor(CreateIconIndirect(&icon));

        DeleteDC(xorMaskDC);
        DeleteDC(andMaskDC);
    }
    DeleteDC(workingDC);
    ReleaseDC(0, dc);
}
Example #2
0
LRESULT CALLBACK
waoWC_button0Proc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    static TRACKMOUSEEVENT tME;
    switch( msg )
    {
        case WM_CREATE:
        {
            tME.cbSize = sizeof( TRACKMOUSEEVENT );
            //tME.dwFlags = TME_HOVER;
            tME.dwHoverTime = 0;
            SendMessage( GetParent (hwnd), WAOM_TBBTNCREATED,
                    MAKEWPARAM( WAOM_TBBTNCREATED_LW,
                            GetWindowLong( hwnd, GWL_ID ) ), ( LPARAM ) hwnd );
            return FALSE;
        }
        case WM_ENABLE:
            if( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CHECKED )
                SetWindowLong( hwnd, GWL_USERDATA,
                        wParam ? ( WAO_TBBS_NORMAL | WAO_TBBS_CHECKED ) :
                        ( WAO_TBBS_DISABLED | WAO_TBBS_CHECKED ) );
            else
                SetWindowLong( hwnd, GWL_USERDATA, wParam ? WAO_TBBS_NORMAL : WAO_TBBS_DISABLED );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            return FALSE;
        case WM_MOUSEMOVE:
            if( GetWindowLong( hwnd, GWL_USERDATA ) != WAO_TBBS_NORMAL )
                return FALSE;
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_HOVERED );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            tME.dwFlags = TME_LEAVE;
            tME.hwndTrack = hwnd;
            TrackMouseEvent( &tME );
            return FALSE;
        case WM_MOUSELEAVE:
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_NORMAL );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            return FALSE;
        case WM_RBUTTONDOWN:
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_RIGHTBUTTON )
            {
                long btnStt = GetWindowLong( hwnd, GWL_USERDATA );
                SetWindowLong( hwnd, GWL_USERDATA,
                               WAO_TBBS_CLICKED | ( btnStt & WAO_TBBS_CHECKED ) );
            }
            return FALSE;
        case WM_LBUTTONDOWN:
        {
            long btnStt = GetWindowLong( hwnd, GWL_USERDATA );
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_CLICKED | ( btnStt & WAO_TBBS_CHECKED ) );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_NOTIFY )
                SetTimer( hwnd, WAO_TMR_TBRPW, WAO_TBBN_RPWTIME, NULL );
            return FALSE;
        }
        case WM_LBUTTONUP:
            // should be clicked first:
            if( !( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CLICKED ) )
                return FALSE;
        case WM_CLEAR: // tweak to check with one internal message
        {
            SetWindowLong( hwnd, GWL_USERDATA, WAO_TBBS_NORMAL );
            RedrawWindow( hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE );
            DLGPROC parProc = ( DLGPROC ) GetWindowLong ( GetParent( hwnd ), DWL_DLGPROC );
            if( msg != WM_CLEAR ) // what about making this a seperate thread?
                parProc( GetParent ( hwnd ), WM_COMMAND,
                         MAKEWPARAM( GetWindowLong( hwnd, GWL_ID ),
                         WAO_TBBN_LCLCKED ),
                         ( LPARAM ) hwnd );
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_NOTIFY )
            {
                KillTimer( hwnd, WAO_TMR_TBRPW );
                KillTimer( hwnd, WAO_TMR_TBRPT );
            }
            return FALSE;
        }
        case WM_RBUTTONUP:
            // should be clicked first:
            if( !( GetWindowLong( hwnd, GWL_USERDATA ) & WAO_TBBS_CLICKED ) )
                return FALSE;
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_RIGHTBUTTON )
            {
                DLGPROC parProc = ( DLGPROC ) GetWindowLong( GetParent( hwnd ), DWL_DLGPROC );
                parProc( GetParent( hwnd ),
                         WM_COMMAND,
                         MAKEWPARAM( GetWindowLong ( hwnd, GWL_ID ), WAO_TBBN_RCLCKED ),
                         ( LPARAM ) hwnd );
            }
            return FALSE;
        case WM_TIMER:
        {
            if( wParam == WAO_TMR_TBRPW ) // repeat wait
            {
                KillTimer( hwnd, WAO_TMR_TBRPW );
                SetTimer( hwnd, WAO_TMR_TBRPT, WAO_TBBN_RPTTIME, NULL );
            }
            DLGPROC parProc = ( DLGPROC ) GetWindowLong( GetParent( hwnd ), DWL_DLGPROC );
            parProc( GetParent( hwnd ),
                     WM_COMMAND,
                     MAKEWPARAM( GetWindowLong( hwnd, GWL_ID ), WAO_TBBN_LCLCKED ),
                     ( LPARAM ) hwnd );
            return FALSE;
        }
        case WM_PAINT:
        {
            PAINTSTRUCT paintStruct;
            BeginPaint( hwnd, &paintStruct );
            RECT rcWnd;
            GetClientRect( hwnd, &rcWnd ); // should this be calculated every time?
            int btnStt = GetWindowLong( hwnd, GWL_USERDATA );

            if( btnStt & WAO_TBBS_CHECKED )
            {
                FillRect( paintStruct.hdc, &rcWnd, CreateSolidBrush( 0x99ffff ) );
                DrawEdge( paintStruct.hdc, &rcWnd, BDR_SUNKENOUTER, BF_RECT );
            }
            else if( btnStt == WAO_TBBS_CLICKED )
            {
                DrawEdge( paintStruct.hdc, &rcWnd, BDR_SUNKENOUTER, BF_RECT );
            }
            else if( btnStt == WAO_TBBS_HOVERED )
            {
                DrawEdge( paintStruct.hdc, &rcWnd, BDR_RAISEDINNER, BF_RECT );
            }
            // drawing icon
            if( GetWindowLong( hwnd, GWL_STYLE ) & BS_ICON ) // maybe later bitmap too
            {
                HICON hIco = LoadIcon( GetModuleHandle( NULL ),
                                       MAKEINTRESOURCE( GetWindowLong( hwnd, GWL_ID ) ) );

                DrawIconEx( paintStruct.hdc,
                            ( rcWnd.right - rcWnd.left - 16 ) / 2,
                            ( rcWnd.bottom - rcWnd.top - 16 ) / 2,
                            hIco, 16, 16, 0, NULL, DI_NORMAL );
            }
            // drawing text
            else
            {
                int tmpLen = GetWindowTextLength( hwnd );
                wchar_t buffer[ tmpLen + 1 ];
                SIZE tmpSze;
                GetWindowText( hwnd, buffer, tmpLen + 1 );
                SetBkMode( paintStruct.hdc, TRANSPARENT );
                SelectObject( paintStruct.hdc, GetStockObject( DEFAULT_GUI_FONT ) );

                GetTextExtentPoint32( paintStruct.hdc, buffer, tmpLen, &tmpSze );
                DrawState( paintStruct.hdc, NULL, NULL,
                         ( LPARAM ) buffer, tmpLen,
                         ( rcWnd.right-rcWnd.left-tmpSze.cx ) / 2,
                         ( rcWnd.bottom-rcWnd.top-tmpSze.cy ) / 2,
                         tmpSze.cx, tmpSze.cy, DST_TEXT|(
                                ( btnStt & WAO_TBBS_DISABLED ) ? DSS_DISABLED : 0 ) );
            }
            EndPaint( hwnd, &paintStruct );
            return FALSE;
        }
        default:
            return DefWindowProc( hwnd, msg, wParam, lParam );
    }
}
Example #3
0
//-------------------------------------------------------------------
// ボタンの描画
// ボタン名をボタンの中に描画するバージョン
VOID DrawMsgButton(HWND hWnd,UINT uCtlID,HDC hCtlDC,
				   RECT rt,UINT uFocus,UINT uStatus){
	
	HFONT hFont,hOldFont;
	LONG width,height,pos;
	HPEN hOldPen;
	HBRUSH hBrush,hOldBrush;
	CHAR szStr[CHR_BUF];
	
	width = rt.right - rt.left;
	height = rt.bottom - rt.top;
	pos = (uStatus == MYID_PUSHBUTTON);
	GetWindowText(GetDlgItem(hWnd,uCtlID),szStr,CHR_BUF);

	// 枠描画
	hOldPen = (HPEN)SelectObject(hCtlDC,GetStockObject(BLACK_PEN));
	hOldBrush = (HBRUSH)SelectObject(hCtlDC,GetStockObject(NULL_BRUSH));
	Rectangle(hCtlDC, rt.left,rt.top,rt.right,rt.bottom);     
	SelectObject(hCtlDC, hOldPen); 
	SelectObject(hCtlDC, hOldBrush); 
	
	// 本体描画
	hOldPen = (HPEN)SelectObject(hCtlDC,GetStockObject(BLACK_PEN));
	hOldBrush = (HBRUSH)SelectObject(hCtlDC,GetStockObject(GRAY_BRUSH));
	Rectangle(hCtlDC, rt.left+pos,rt.top+pos,rt.right-1+pos,rt.bottom-1+pos);     
	SelectObject(hCtlDC, hOldPen); 
	SelectObject(hCtlDC, hOldBrush); 

	// 明るい部分
	if(uCtlID == uFocus) hBrush = CreateSolidBrush(RGB(0,255,255));
	else hBrush = CreateSolidBrush(RGB(255,255,255));
	hOldPen = (HPEN)SelectObject(hCtlDC,GetStockObject(NULL_PEN));
	hOldBrush = (HBRUSH)SelectObject(hCtlDC,hBrush);
	Rectangle(hCtlDC, rt.left+2+pos,rt.top+2+pos,rt.right-2+pos,rt.top+5+pos);
	SelectObject(hCtlDC, hOldPen); 
	SelectObject(hCtlDC, hOldBrush); 
	DeleteObject(hBrush);


	// 文字描画
	TEXTMETRIC textMet; 
	LONG nStrHeight;

	hFont=CreateFont(10,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET
			,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"MS Pゴシック");
	hOldFont = (HFONT)SelectObject(hCtlDC,hFont);	
	GetTextMetrics(hCtlDC,&textMet);
	nStrHeight = textMet.tmAscent;
	rt.top += ((height-nStrHeight)/2)+1;
	rt.left += (pos+1);
	rt.right += (pos+1);
	
	// 文字描画
	SetBkMode(hCtlDC,TRANSPARENT);			 
    SetTextColor(hCtlDC,RGB(0,0,0)) ;
	DrawText(hCtlDC,szStr,strlen(szStr),&rt,DT_CENTER);
	rt.top -= 1;rt.left -= 1;rt.right -= 1;
    SetTextColor(hCtlDC,RGB(255,255,255)) ;
	DrawText(hCtlDC,szStr,strlen(szStr),&rt,DT_CENTER);
	// フォント削除
	SelectObject(hCtlDC,hOldFont);			  
	DeleteObject(hFont);
}
Example #4
0
//---------------------------------------------------------------------
// メッセージボックスのプロシージャ
LRESULT CALLBACK MyMessageBoxProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
	
	static LPMSGBOXDATA lpMsgBoxData;
	static HICON hIcon;
	static BOOL bDrawIcon; // アイコンを貼るかどうか
	static RECT textRt;  // テキスト描画領域
	static SIZE sizeText; //  テキスト描画領域のサイズ
	static LONG width,height; // ウィンドウ幅、高さ
	static HWND hWndBt[3];
	static int nResult[3];
	static HFONT hFont; // ボタン用フォント
	static LONG nButtonNum; // ボタン数
	static BOOL bOwnerDraw; // ボタンをオーナードローするか
	static UINT uCurFocus; // 現在のフォーカスボタンID
	
	CHAR szBtStr[3][CHR_BUF];
	LONG x1,x2,x3,y;
	HINSTANCE hInst;
	HDC hDC;
	LONG nButtonSize;
	UINT uIconType,uMskType;
	DWORD dwStyle;
	COLORREF rgbStr;
	WORD i;
	
	switch (msg) {
		
	case WM_INITDIALOG:  // ダイアログ初期化
		
		lpMsgBoxData = (LPMSGBOXDATA)lp;
		hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
		
		// アイコンロード
		uIconType = lpMsgBoxData->uType & MB_ICONMASK;
		
		if(uIconType > 0) bDrawIcon = TRUE;
		else bDrawIcon = FALSE;
		
		switch(uIconType){
			
		case MB_ICONQUESTION:
			hIcon = LoadIcon(NULL,IDI_QUESTION);
			break;
			
		case MB_ICONINFORMATION:
			hIcon = LoadIcon(NULL,IDI_INFORMATION);
			break;
			
		case MB_ICONEXCLAMATION:
			hIcon = LoadIcon(NULL,IDI_EXCLAMATION);
			break;
			
		case MB_ICONERROR:
			hIcon = LoadIcon(NULL,IDI_ERROR);
		}
		
		
		// テキスト領域の幅と高さ取得
		GetTextSize(hWnd,lpMsgBoxData->lpText,&sizeText,MSGBOXTEXTSIZE);
		
		// テキスト描画領域セット
		textRt.top = MSGBOXMERGIN + (sizeText.cy > MSGBOXICONHEIGHT? 0 : (MSGBOXICONHEIGHT-sizeText.cy)/2);
		textRt.left = MSGBOXICONWIDTH*bDrawIcon+MSGBOXMERGIN;
		textRt.right = textRt.left + sizeText.cx;
		textRt.bottom = textRt.top + sizeText.cy;
		
		// タイトルセット
		SetWindowText(hWnd,lpMsgBoxData->lpCaption);
		
		// ボタン名設定
		for(i=0;i<3;i++) nResult[i] = 0;
		switch(lpMsgBoxData->uType & MB_TYPEMASK){
			
		default:
			nResult[0] = IDOK;
			wsprintf(szBtStr[0],"OK");
			
			nButtonNum = 1;
			break;
			
		case MB_OKCANCEL:
			nResult[0] = IDOK;
			wsprintf(szBtStr[0],"OK");
			
			nResult[1] = IDCANCEL;
			wsprintf(szBtStr[1],"キャンセル");
			
			nButtonNum = 2;
			break;
			
		case MB_YESNOCANCEL:
			
			nResult[0] = IDYES;
			wsprintf(szBtStr[0],"はい(&Y)");
			
			nResult[1] = IDNO;
			wsprintf(szBtStr[1],"いいえ(&N)");
			
			nResult[2] = IDCANCEL;
			wsprintf(szBtStr[2],"キャンセル");
			
			nButtonNum = 3;
			break;
			
		case MB_YESNO:
			
			nResult[0] = IDYES;
			wsprintf(szBtStr[0],"はい(&Y)");
			
			nResult[1] = IDNO;
			wsprintf(szBtStr[1],"いいえ(&N)");
			
			nButtonNum = 2;
		}
		
		// ウィンドウリサイズ
		nButtonSize =MSGBOXBTWIDTH*nButtonNum+MSGBOXMERGIN*(nButtonNum-1);
		
		width = max(nButtonSize+MSGBOXMERGIN*2,sizeText.cx+MSGBOXMERGIN*2+MSGBOXICONWIDTH*bDrawIcon);
		height = max(MSGBOXICONHEIGHT*bDrawIcon,sizeText.cy)+ MSGBOXMERGIN*3+MSGBOXBTHEIGHT;
		
		SetWindowPos(hWnd,NULL,0,0,
			width+GetSystemMetrics(SM_CXFIXEDFRAME)*2,
			height+GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYFIXEDFRAME)*2
			,SWP_NOMOVE|SWP_NOREPOSITION);
		
		
		// ボタン作成
		x1 = (width - nButtonSize)/2;
		x2 = x1 + MSGBOXBTWIDTH+MSGBOXMERGIN;
		x3 = x2 + MSGBOXBTWIDTH+MSGBOXMERGIN;
		y = height-MSGBOXBTHEIGHT - MSGBOXMERGIN;
		
		uMskType = lpMsgBoxData->uType & MB_DEFMASK;
		bOwnerDraw = lpMsgBoxData->bOwnerDraw; // オーナードローか
		
		// ボタン 1
		if((nButtonNum >=2 && uMskType == MB_DEFBUTTON2) ||
			(nButtonNum == 3 && uMskType == MB_DEFBUTTON3))
			dwStyle = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;
		else dwStyle = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;
		if(bOwnerDraw) dwStyle |= BS_OWNERDRAW;
		CreateWindow("BUTTON","bt1",dwStyle,x1,y,MSGBOXBTWIDTH,MSGBOXBTHEIGHT,hWnd,(HMENU)IDC_BT1,hInst,NULL);
		
		// ボタン 2
		if(nButtonNum >= 2){
			if(uMskType == MB_DEFBUTTON2)
				dwStyle = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;
			else dwStyle = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;
			if(bOwnerDraw) dwStyle |= BS_OWNERDRAW;
			CreateWindow("BUTTON","bt2",dwStyle,x2,y,MSGBOXBTWIDTH,MSGBOXBTHEIGHT,hWnd,(HMENU)IDC_BT2,hInst,NULL);
		}
		
		
		// ボタン 3
		if(nButtonNum == 3){
			if(uMskType == MB_DEFBUTTON3)
				dwStyle = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;
			else dwStyle = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;
			if(bOwnerDraw) dwStyle |= BS_OWNERDRAW;
			CreateWindow("BUTTON","bt3",dwStyle,x3,y,MSGBOXBTWIDTH,MSGBOXBTHEIGHT,hWnd,(HMENU)IDC_BT3,hInst,NULL);
		}
		
		
		// ボタン用フォント作成
		if(!bOwnerDraw) hFont=CreateFont(10,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET
			,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"MS Pゴシック");
		
		// ボタンにフォントと文字セット
		hWndBt[0] = GetDlgItem(hWnd,IDC_BT1);
		hWndBt[1] = GetDlgItem(hWnd,IDC_BT2);
		hWndBt[2] = GetDlgItem(hWnd,IDC_BT3);
		
		for(i=0;i<3;i++)
		{
			// フォントセット
			if(!bOwnerDraw) SendMessage(hWndBt[i],WM_SETFONT,(WPARAM)hFont,(LPARAM)MAKELPARAM(TRUE,0));
			SetWindowText(hWndBt[i],szBtStr[i]);
		}
		
		// フォーカス移動
		switch(uMskType){
			
		case MB_DEFBUTTON2:
			uCurFocus = IDC_BT2;
			SetFocus(hWndBt[1]);
			break;
			
		case MB_DEFBUTTON3:
			uCurFocus = IDC_BT3;
			SetFocus(hWndBt[2]);
			break;
			
		default:
			uCurFocus = IDC_BT1;
			SetFocus(hWndBt[0]);
		}
		
		// 中心移動
		SetDlgCenter(hWnd);

		// forgrand
		if(lpMsgBoxData->uType & MB_SETFOREGROUND) SetForegroundWindow(hWnd);
		
		break;
		
		
		case WM_CTLCOLORDLG: // 背景色を変えたい場合
			
			if(bOwnerDraw){
				SetBkMode((HDC)wp,TRANSPARENT);			 
				SetTextColor((HDC)wp,RGB(255,255,255)) ;
				return ((BOOL)GetStockObject(GRAY_BRUSH)) ;    
			}
			
			break;
			
			
		case WM_DRAWITEM: // ボタンのオーナー描画をする場合
			
			if(bOwnerDraw){
				
				UINT uCtlID,uButtonStat;
				LPDRAWITEMSTRUCT lpDrawItem;
				
				uCtlID = (UINT)wp;
				lpDrawItem = (LPDRAWITEMSTRUCT)lp;
				uButtonStat = MYID_RELEASEBUTTON;
				
				if(lpDrawItem->CtlType == ODT_BUTTON){ // ボタンならば
					
					if(lpDrawItem->itemAction & ODA_SELECT){ // 選択
						if(lpDrawItem->itemState & ODS_FOCUS) uButtonStat = MYID_PUSHBUTTON;
					}
					else if(lpDrawItem->itemAction & ODA_FOCUS){ // フォーカス
						// 自前でフォーカスの管理をする
						if(lpDrawItem->itemState & ODS_FOCUS) uCurFocus = uCtlID;
					}
					
					// ボタン描画
					DrawMsgButton(hWnd,uCtlID,lpDrawItem->hDC,lpDrawItem->rcItem,uCurFocus,uButtonStat);
					
				}
			}
			
			break;
			
		case WM_PAINT: // 描画
			
			hDC = GetDC(hWnd);
			
			if(bOwnerDraw){
				// 枠描画
				DrawMyFrame(hDC,MSGBOXMERGIN-2,MSGBOXMERGIN-2,
					width - (MSGBOXMERGIN-2)*2,height-MSGBOXBTHEIGHT - MSGBOXMERGIN-(MSGBOXMERGIN-2)*2
					,RGB(0,0,0));
				rgbStr = RGB(255,255,255);
			}
			else rgbStr = RGB(0,0,0);
			
			// アイコン
			if(bDrawIcon)
				DrawIcon(hDC,MSGBOXMERGIN+1,MSGBOXMERGIN+1,hIcon);
			
			// テキスト
			DrawMyStringJP(hDC,lpMsgBoxData->lpText,
				textRt.left,textRt.top,textRt.right-textRt.left,
				textRt.bottom-textRt.top,MSGBOXTEXTSIZE,rgbStr);
			
			
			ReleaseDC(hWnd,hDC);
			
			break;
			
			
		case WM_SETTEXT: // ダイアログのタイトル変更
			
			// DefWindowProc に処理してもらう(なんか胡散臭いやり方 (^^; )
			return(DefWindowProc(hWnd, msg, wp, lp)); 
			
			break;
			
		case WM_COMMAND:
			
			// オーナードローの時はコントロール ID をもらえないので
			// 自前でフォーカス管理をする
			if(bOwnerDraw && HIWORD(wp)== BN_CLICKED) wp = uCurFocus;
			
			switch (LOWORD(wp)) {
				
			case IDC_BT1: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, nResult[0]);
				return TRUE;
				
			case IDC_BT2: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, nResult[1]);
				return TRUE;
				
			case IDC_BT3: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, nResult[2]);
				return TRUE;
				
			case IDCANCEL: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, IDCANCEL);
				return TRUE;
				
			}
			break;
			
			default:
				break;
	}
    return FALSE;
}
Example #5
0
static void PrintPiecesThread(void* pv)
{
	CFrameWndEx* pFrame = (CFrameWndEx*)pv;
	CView* pView = pFrame->GetActiveView();
	CPrintDialog PD(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOPAGENUMS|PD_NOSELECTION, pFrame);

	if (theApp.DoPrintDialog(&PD) != IDOK)
		return; 

	if (PD.m_pd.hDC == NULL)
		return;

	Project* project = lcGetActiveProject();
	ObjArray<lcPiecesUsedEntry> PiecesUsed;

	project->GetPiecesUsed(PiecesUsed);
	PiecesUsed.Sort(PiecesUsedSortFunc, NULL);

	// gather file to print to if print-to-file selected
	CString strOutput;
	if (PD.m_pd.Flags & PD_PRINTTOFILE)
	{
		CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
		CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
		CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
		CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
		CFileDialog dlg(FALSE, strDef, strPrintDef,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
		dlg.m_ofn.lpstrTitle = strCaption;
		if (dlg.DoModal() != IDOK)
			return;
		strOutput = dlg.GetPathName();
	}

	CString DocName;
	char* Ext = strrchr(project->m_strTitle, '.');
	DocName.Format("LeoCAD - %.*s BOM", Ext ? Ext - project->m_strTitle : strlen(project->m_strTitle), project->m_strTitle);
	DOCINFO docInfo;
	memset(&docInfo, 0, sizeof(DOCINFO));
	docInfo.cbSize = sizeof(DOCINFO);
	docInfo.lpszDocName = DocName;
	CString strPortName;

	int nFormatID;
	if (strOutput.IsEmpty())
	{
		docInfo.lpszOutput = NULL;
		strPortName = PD.GetPortName();
		nFormatID = AFX_IDS_PRINTONPORT;
	}
	else
	{
		docInfo.lpszOutput = strOutput;
		AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
		nFormatID = AFX_IDS_PRINTTOFILE;
	}

	SetAbortProc(PD.m_pd.hDC, _AfxAbortProc);
	pFrame->EnableWindow(FALSE);
	CPrintingDialog dlgPrintStatus(NULL);

	CString strTemp;
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, DocName);
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD.GetDeviceName());
	AfxFormatString1(strTemp, nFormatID, strPortName);
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);
	dlgPrintStatus.ShowWindow(SW_SHOW);
	dlgPrintStatus.UpdateWindow();

	if (StartDoc(PD.m_pd.hDC, &docInfo) == SP_ERROR)
	{
		pFrame->EnableWindow(TRUE);
		dlgPrintStatus.DestroyWindow();
		AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
		return;
	}

	int ResX = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSX);
	int ResY = GetDeviceCaps(PD.m_pd.hDC, LOGPIXELSY);

	CRect RectDraw(0, 0, GetDeviceCaps(PD.m_pd.hDC, HORZRES), GetDeviceCaps(PD.m_pd.hDC, VERTRES));
	DPtoLP(PD.m_pd.hDC, (LPPOINT)(RECT*)&RectDraw, 2);
	RectDraw.DeflateRect((int)(ResX*(float)theApp.GetProfileInt("Default","Margin Left", 50)/100.0f),
	                     (int)(ResY*(float)theApp.GetProfileInt("Default","Margin Top", 50)/100.0f),
	                     (int)(ResX*(float)theApp.GetProfileInt("Default","Margin Right", 50)/100.0f),
	                     (int)(ResY*(float)theApp.GetProfileInt("Default","Margin Bottom", 50)/100.0f));

	CRect HeaderRect = RectDraw;
 	HeaderRect.top -= (int)(ResY*theApp.GetProfileInt("Default", "Margin Top", 50) / 200.0f);
	HeaderRect.bottom += (int)(ResY*theApp.GetProfileInt("Default", "Margin Bottom", 50) / 200.0f);

	int RowsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Rows", 10);
	int ColsPerPage = AfxGetApp()->GetProfileInt("Default", "Catalog Columns", 3);
	int PicHeight = RectDraw.Height() / RowsPerPage;
	int PicWidth = RectDraw.Width() / ColsPerPage;
	int TotalRows = (PiecesUsed.GetSize() + ColsPerPage - 1) / ColsPerPage;
	int TotalPages = (TotalRows + RowsPerPage - 1) / RowsPerPage;
	int RowHeight = RectDraw.Height() / RowsPerPage;
	int ColWidth = RectDraw.Width() / ColsPerPage;

	PD.m_pd.nMinPage = 1;
	PD.m_pd.nMaxPage = TotalPages + 1;

	UINT EndPage = PD.m_pd.nToPage;
	UINT StartPage = PD.m_pd.nFromPage;
	if (PD.PrintAll())
	{
		EndPage = PD.m_pd.nMaxPage;
		StartPage = PD.m_pd.nMinPage;
	}

	lcClamp(EndPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage);
	lcClamp(StartPage, PD.m_pd.nMinPage, PD.m_pd.nMaxPage);
	int StepPage = (EndPage >= StartPage) ? 1 : -1;

	VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));

	// begin page printing loop
	BOOL bError = FALSE;

	// Creating Compatible Memory Device Context
	CDC *pMemDC = new CDC;
	if (!pMemDC->CreateCompatibleDC(pView->GetDC()))
		return;

	BITMAPINFO bi;
	ZeroMemory(&bi, sizeof(BITMAPINFO));
	bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bi.bmiHeader.biWidth = PicWidth;
	bi.bmiHeader.biHeight = PicHeight;
	bi.bmiHeader.biPlanes = 1;
	bi.bmiHeader.biBitCount = 24;
	bi.bmiHeader.biCompression = BI_RGB;
	bi.bmiHeader.biSizeImage = PicWidth * PicHeight * 3;
	bi.bmiHeader.biXPelsPerMeter = 2925;
	bi.bmiHeader.biYPelsPerMeter = 2925;
	bi.bmiHeader.biClrUsed = 0;
	bi.bmiHeader.biClrImportant = 0;
	
	LPBITMAPINFOHEADER lpbi[1];

	HBITMAP hBm, hBmOld;
    hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS, (void **)&lpbi, NULL, (DWORD)0);
	if (!hBm)
		return;
	hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm);

	PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI,
			PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };
	int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd);
	DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
	SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd);
	HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc());
	wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc);

	GL_DisableVertexBufferObject();
	float Aspect = (float)PicWidth/(float)PicHeight;

	glViewport(0, 0, PicWidth, PicHeight);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(0.5f, 0.1f);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glClearColor(1, 1, 1, 1); 

	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight = -MulDiv(12, ResY, 72);
	lf.lfWeight = FW_REGULAR;
	lf.lfCharSet = DEFAULT_CHARSET;
	lf.lfQuality = PROOF_QUALITY;
	strcpy (lf.lfFaceName , "Arial");

	HFONT HeaderFont = CreateFontIndirect(&lf);
	HFONT OldFont = (HFONT)SelectObject(PD.m_pd.hDC, HeaderFont);
	SetBkMode(PD.m_pd.hDC, TRANSPARENT);
	SetTextColor(PD.m_pd.hDC, 0x000000);
	SetTextAlign(PD.m_pd.hDC, TA_CENTER|TA_NOUPDATECP);

	DWORD PrintOptions = AfxGetApp()->GetProfileInt("Settings", "Print", PRINT_NUMBERS | PRINT_BORDER/*|PRINT_NAMES*/);
	bool DrawNames = 1;//(PrintOptions & PRINT_NAMES) != 0;
	bool Horizontal = 1;//(PrintOptions & PRINT_HORIZONTAL) != 0;

	pMemDC->SetTextColor(0x000000);
	pMemDC->SetBkMode(TRANSPARENT);
//	lf.lfHeight = -MulDiv(40, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
//	lf.lfWeight = FW_BOLD;
	HFONT CatalogFont = CreateFontIndirect(&lf);
	lf.lfHeight = -MulDiv(80, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
	HFONT CountFont = CreateFontIndirect(&lf);
	HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont);
	HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC, GetStockObject(BLACK_PEN));

	for (UINT CurPage = StartPage; CurPage != EndPage; CurPage += StepPage)
	{
		TCHAR szBuf[80];
		wsprintf(szBuf, strTemp, CurPage);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);
		if (::StartPage(PD.m_pd.hDC) < 0)
		{
			bError = TRUE;
			break;
		}

		// Draw header and footer.
		SelectObject(PD.m_pd.hDC, HeaderFont);

		CString Header;
		UINT Align;

		FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Header", ""), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages);
		Align |= DT_TOP|DT_SINGLELINE;

		DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align);

		FormatHeader(Header, Align, AfxGetApp()->GetProfileString("Default", "Catalog Footer", "Page &P"), project->m_strTitle, project->m_strAuthor, project->m_strDescription, CurPage, TotalPages);
		Align |= DT_BOTTOM|DT_SINGLELINE;

		DrawText(PD.m_pd.hDC, (LPCTSTR)Header, Header.GetLength(), HeaderRect, Align);

		int StartPiece = (CurPage - 1) * RowsPerPage * ColsPerPage;
		int EndPiece = lcMin(StartPiece + RowsPerPage * ColsPerPage, PiecesUsed.GetSize());

		for (int CurPiece = StartPiece; CurPiece < EndPiece; CurPiece++)
		{
			FillRect(pMemDC->m_hDC, CRect(0, PicHeight, PicWidth, 0), (HBRUSH)GetStockObject(WHITE_BRUSH));
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			PieceInfo* pInfo = PiecesUsed[CurPiece].Info;
			pInfo->ZoomExtents(30.0f, Aspect);

			pInfo->RenderPiece(PiecesUsed[CurPiece].ColorIndex);
			glFinish();

			// Draw description text at the bottom.
			CRect TextRect(0, 0, PicWidth, PicHeight);
	
			if (DrawNames)
			{
				SelectObject(pMemDC->m_hDC, CatalogFont);
				pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_CALCRECT | DT_WORDBREAK);

				TextRect.OffsetRect(0, PicHeight - TextRect.Height() - 5);
				pMemDC->DrawText(pInfo->m_strDescription, strlen(pInfo->m_strDescription), TextRect, DT_WORDBREAK);
			}

			// Draw count.
			SelectObject(pMemDC->m_hDC, CountFont);
			TextRect = CRect(0, 0, PicWidth, TextRect.top);
			TextRect.DeflateRect(5, 5);

			char CountStr[16];
			sprintf(CountStr, "%dx", PiecesUsed[CurPiece].Count);
			pMemDC->DrawText(CountStr, strlen(CountStr), TextRect, DT_BOTTOM | DT_LEFT | DT_SINGLELINE);

			LPBITMAPINFOHEADER lpbi[1];
			lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24));
			BITMAPINFO bi;
			ZeroMemory(&bi, sizeof(BITMAPINFO));
			memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER));
			SetStretchBltMode(PD.m_pd.hDC, COLORONCOLOR);

			int CurRow, CurCol;

			if (Horizontal)
			{
				CurRow = (CurPiece - StartPiece) / ColsPerPage;
				CurCol = (CurPiece - StartPiece) % ColsPerPage;
			}
			else
			{
				CurRow = (CurPiece - StartPiece) % RowsPerPage;
				CurCol = (CurPiece - StartPiece) / RowsPerPage;
			}
			
			int Left = RectDraw.left + ColWidth * CurCol + (ColWidth - PicWidth) / 2;
			int Top = RectDraw.top + RowHeight * CurRow + (RowHeight - PicHeight) / 2;

			StretchDIBits(PD.m_pd.hDC, Left, Top, PicWidth, PicHeight, 0, 0, PicWidth, PicHeight, 
			              (LPBYTE)lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD), &bi, DIB_RGB_COLORS, SRCCOPY);
			if (lpbi[0])
				GlobalFreePtr(lpbi[0]);
		}

		if (::EndPage(PD.m_pd.hDC) < 0 || !_AfxAbortProc(PD.m_pd.hDC, 0))
		{
			bError = TRUE;
			break;
		}
	}

	SelectObject(pMemDC->m_hDC, hpOld);
	SelectObject(PD.m_pd.hDC, OldFont);
	DeleteObject(HeaderFont);
	SelectObject(pMemDC->m_hDC, OldMemFont);
	DeleteObject(CatalogFont);
	DeleteObject(CountFont);

	GL_EnableVertexBufferObject();
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hmemrc);
	SelectObject(pMemDC->GetSafeHdc(), hBmOld);
	DeleteObject(hBm);
	delete pMemDC;

	if (!bError)
		EndDoc(PD.m_pd.hDC);
	else
		AbortDoc(PD.m_pd.hDC);

	pFrame->EnableWindow();
	dlgPrintStatus.DestroyWindow();

	if (PD.m_pd.hDC != NULL)
    {
		::DeleteDC(PD.m_pd.hDC);
		PD.m_pd.hDC = NULL;
    }
}
Example #6
0
LRESULT CALLBACK ChatView::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
    PAINTSTRUCT ps;
    HDC hdc;
    ChatView *p=(ChatView *) GetWindowLong(hWnd, GWL_USERDATA);

    switch (message) {
    case WM_CREATE:
        {
            p=(ChatView *) (((CREATESTRUCT *)lParam)->lpCreateParams);
            SetWindowLong(hWnd, GWL_USERDATA, (LONG) p );

            p->msgList=VirtualListView::ref(new VirtualListView(hWnd, std::string("Chat")));
            p->msgList->setParent(hWnd);
            p->msgList->showWindow(true);
            p->msgList->wrapList=false;
            p->msgList->colorInterleaving=true;

            p->editWnd=DoCreateEditControl(hWnd);
            p->calcEditHeight();

            p->msgList->bindODRList(p->contact->messageList);
            break;
        }

    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);

        {
            //p->contact->nUnread=0;
            RECT rc = {0, 0, 200, tabHeight};
            SetBkMode(hdc, TRANSPARENT);
            SetTextColor(hdc, p->contact->getColor());
            p->contact->draw(hdc, rc);

            int iconwidth= skin->getElementWidth();
            skin->drawElement(hdc, icons::ICON_CLOSE, p->width-2-iconwidth, 0);
            skin->drawElement(hdc, icons::ICON_TRASHCAN_INDEX, p->width-2-iconwidth*2, 0);

            /*SetBkMode(hdc, TRANSPARENT);
            LPCTSTR t=p->title.c_str();
            DrawText(hdc, t, -1, &rc, DT_CALCRECT | DT_LEFT | DT_TOP);
            DrawText(hdc, t, -1, &rc, DT_LEFT | DT_TOP);*/
        }

        EndPaint(hWnd, &ps);
        break;

    //case WM_KILLFOCUS:
    //    p->contact->nUnread=0;
    //    break;

    case WM_SIZE: 
        { 
            HDWP hdwp; 
            RECT rc; 

            int height=GET_Y_LPARAM(lParam);
            p->width=GET_X_LPARAM(lParam);

            int ySplit=height-p->editHeight;

            p->calcEditHeight();

            // Calculate the display rectangle, assuming the 
            // tab control is the size of the client area. 
            SetRect(&rc, 0, 0, 
                GET_X_LPARAM(lParam), ySplit ); 

            // Size the tab control to fit the client area. 
            hdwp = BeginDeferWindowPos(2);

            /*DeferWindowPos(hdwp, dropdownWnd, HWND_TOP, 0, 0, 
            GET_X_LPARAM(lParam), 20, 
            SWP_NOZORDER 
            ); */


            DeferWindowPos(hdwp, p->msgList->getHWnd(), HWND_TOP, 0, tabHeight, 
                GET_X_LPARAM(lParam), ySplit-tabHeight, 
                SWP_NOZORDER 
                );
            /*DeferWindowPos(hdwp, rosterWnd, HWND_TOP, 0, tabHeight, 
            GET_X_LPARAM(lParam), height-tabHeight, 
            SWP_NOZORDER 
            );*/

            DeferWindowPos(hdwp, p->editWnd, NULL, 0, ySplit+1, 
                GET_X_LPARAM(lParam), height-ySplit-1, 
                SWP_NOZORDER 
                ); 

            EndDeferWindowPos(hdwp); 

            break; 
        } 

    case WM_COMMAND: 
        {
            if (wParam==IDS_SEND) {
                p->sendJabberMessage();
            }
            if (wParam==IDC_COMPLETE) {
                p->mucNickComplete();
            }

            if (wParam==IDC_COMPOSING) {
                p->setComposingState(lParam!=0);
            }
            break;             
        }
        /*case WM_CTLCOLORSTATIC:
        case WM_CTLCOLORLISTBOX:
        case WM_CTLCOLOREDIT: 
        {
        //HGDIOBJ brush= GetStockObject(GRAY_BRUSH);
        //HGDIOBJ pen= GetStockObject(WHITE_PEN);
        SetBkColor(hdc, 0x808080);
        SetTextColor(hdc, 0xffffff);
        //SelectObject((HDC)wParam, brush);
        //SelectObject((HDC)wParam, pen);
        return (BOOL) GetStockObject(GRAY_BRUSH);
        break;
        }*/

    case WM_LBUTTONDOWN:
        SetFocus(hWnd);
        if ((GET_Y_LPARAM(lParam))>tabHeight) break;
        
        if (GET_X_LPARAM(lParam) > (p->width)-2-(skin->getElementWidth()) ) {
            PostMessage(GetParent(hWnd), WM_COMMAND, TabsCtrl::CLOSETAB, 0);
            break;
        }
        if (GET_X_LPARAM(lParam) > (p->width)-2-(skin->getElementWidth())*2) {
            int result=MessageBox(
                p->getHWnd(), 
                L"Are You sure want to clear this chat session?", 
                L"Clear chat", 
                MB_YESNO | MB_ICONWARNING);
            if (result==IDYES) {
                p->contact->messageList->clear();
                p->msgList->moveCursorEnd();
            }
            break;
        }
        break;

    case WM_DESTROY:
        //TODO: Destroy all child data associated eith this window

        return 0;

    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Example #7
0
static void PrintCatalogThread (CWnd* pParent, CFrameWndEx* pMainFrame)
{
	CCADView* pView = (CCADView*)pMainFrame->GetActiveView();
	CPrintDialog* PD = new CPrintDialog(FALSE, PD_ALLPAGES|PD_USEDEVMODECOPIES|PD_NOSELECTION|PD_ENABLEPRINTHOOK, pParent);
	lcPiecesLibrary *pLib = lcGetPiecesLibrary();

	int bricks = 0;
	for (int j = 0; j < pLib->mPieces.GetSize(); j++)
		if (pLib->mPieces[j]->m_strDescription[0] != '~')
			bricks++;
	int rows = theApp.GetProfileInt("Default", "Catalog Rows", 10);
	int cols = theApp.GetProfileInt("Default", "Catalog Columns", 3);
	PD->m_pd.lpfnPrintHook = PrintHookProc;
	PD->m_pd.nFromPage = PD->m_pd.nMinPage = 1; 
	PD->m_pd.nMaxPage = bricks/(rows*cols);
	if (bricks%(rows*cols) != 0) PD->m_pd.nMaxPage++;
	PD->m_pd.nToPage = PD->m_pd.nMaxPage;
	PD->m_pd.lCustData= (LONG)pMainFrame;

	// bring up the print dialog and allow user to change things
	if (theApp.DoPrintDialog(PD) != IDOK) return; 
	if (PD->m_pd.hDC == NULL) return;

	// update page range
	rows = theApp.GetProfileInt("Default","Catalog Rows", 10);
	cols = theApp.GetProfileInt("Default","Catalog Columns", 3);
	PD->m_pd.nMaxPage = bricks/(rows*cols);
	if (bricks%(rows*cols) != 0) PD->m_pd.nMaxPage++;

	// gather file to print to if print-to-file selected
	CString strOutput;
	if (PD->m_pd.Flags & PD_PRINTTOFILE)
	{
		// construct CFileDialog for browsing
		CString strDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULTEXT));
		CString strPrintDef(MAKEINTRESOURCE(AFX_IDS_PRINTDEFAULT));
		CString strFilter(MAKEINTRESOURCE(AFX_IDS_PRINTFILTER));
		CString strCaption(MAKEINTRESOURCE(AFX_IDS_PRINTCAPTION));
		CFileDialog dlg(FALSE, strDef, strPrintDef,
			OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
		dlg.m_ofn.lpstrTitle = strCaption;

		if (dlg.DoModal() != IDOK)
			return;

		// set output device to resulting path name
		strOutput = dlg.GetPathName();
	}

	DOCINFO docInfo;
	memset(&docInfo, 0, sizeof(DOCINFO));
	docInfo.cbSize = sizeof(DOCINFO);
	docInfo.lpszDocName = "LeoCAD pieces catalog";
	CString strPortName;
	int nFormatID;
	if (strOutput.IsEmpty())
	{
		docInfo.lpszOutput = NULL;
		strPortName = PD->GetPortName();
		nFormatID = AFX_IDS_PRINTONPORT;
	}
	else
	{
		docInfo.lpszOutput = strOutput;
		AfxGetFileTitle(strOutput, strPortName.GetBuffer(_MAX_PATH), _MAX_PATH);
		nFormatID = AFX_IDS_PRINTTOFILE;
	}

	// setup the printing DC
	SetAbortProc(PD->m_pd.hDC, _AfxAbortProc);

	// disable main window while printing & init printing status dialog
	pParent->EnableWindow(FALSE);
	CPrintingDialog dlgPrintStatus(NULL);

	CString strTemp;
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, "LeoCAD parts catalog");
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, PD->GetDeviceName());
	AfxFormatString1(strTemp, nFormatID, strPortName);
	dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, strTemp);
	dlgPrintStatus.ShowWindow(SW_SHOW);
	dlgPrintStatus.UpdateWindow();

	// start document printing process
	if (StartDoc(PD->m_pd.hDC, &docInfo) == SP_ERROR)
	{
		pParent->EnableWindow(TRUE);
		dlgPrintStatus.DestroyWindow();
		AfxMessageBox(AFX_IDP_FAILED_TO_START_PRINT);
		return;
	}

	// Guarantee values are in the valid range
	UINT nEndPage = PD->m_pd.nToPage;
	UINT nStartPage = PD->m_pd.nFromPage;

	if (PD->PrintAll())
	{
		nEndPage = PD->m_pd.nMaxPage;
		nStartPage = PD->m_pd.nMinPage;
	}

	if (nEndPage < PD->m_pd.nMinPage) nEndPage = PD->m_pd.nMinPage;
	if (nEndPage > PD->m_pd.nMaxPage) nEndPage = PD->m_pd.nMaxPage;
	if (nStartPage < PD->m_pd.nMinPage) nStartPage = PD->m_pd.nMinPage;
	if (nStartPage > PD->m_pd.nMaxPage) nStartPage = PD->m_pd.nMaxPage;

	int nStep = (nEndPage >= nStartPage) ? 1 : -1;
	nEndPage = nEndPage + nStep;

	VERIFY(strTemp.LoadString(AFX_IDS_PRINTPAGENUM));

	// begin page printing loop
	BOOL bError = FALSE;

	// set up drawing rect to entire page (in logical coordinates)
	CRect rectDraw (0, 0, GetDeviceCaps(PD->m_pd.hDC, HORZRES), GetDeviceCaps(PD->m_pd.hDC, VERTRES));
	DPtoLP(PD->m_pd.hDC, (LPPOINT)(RECT*)&rectDraw, 2);
	rectDraw.DeflateRect(
		GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSX)*theApp.GetProfileInt("Default","Margin Left", 50)/100, 
		GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/100,
		GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSX)*theApp.GetProfileInt("Default","Margin Right", 50)/100, 
		GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/100);
	int w = rectDraw.Width()/cols;
	int h = rectDraw.Height()/rows;

	// Creating Compatible Memory Device Context
	CDC *pMemDC = new CDC;
	if (!pMemDC->CreateCompatibleDC(pView->GetDC()))
		return;

	// Preparing bitmap header for DIB section
	BITMAPINFO bi;
	ZeroMemory(&bi, sizeof(BITMAPINFO));
	
	bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bi.bmiHeader.biWidth = w;
	bi.bmiHeader.biHeight = h;
	bi.bmiHeader.biPlanes = 1;
	bi.bmiHeader.biBitCount = 24;
	bi.bmiHeader.biCompression = BI_RGB;
	bi.bmiHeader.biSizeImage = w * h * (24/8);
	bi.bmiHeader.biXPelsPerMeter = 2925;
	bi.bmiHeader.biYPelsPerMeter = 2925;
	bi.bmiHeader.biClrUsed = 0;
	bi.bmiHeader.biClrImportant = 0;
	
	LPBITMAPINFOHEADER lpbi[1];

	// Creating a DIB surface
	HBITMAP hBm, hBmOld;
	hBm = CreateDIBSection(pView->GetDC()->GetSafeHdc(), &bi, DIB_RGB_COLORS, 
		(void **)&lpbi, NULL, (DWORD)0);
	if (!hBm)
		return;

	// Selecting the DIB Surface
	hBmOld = (HBITMAP)::SelectObject(pMemDC->GetSafeHdc(), hBm);
	if (!hBmOld)
		return;

	// Setting up a Pixel format for the DIB surface
	PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),
			1,PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI,
			PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16,
			0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };
	int pixelformat = ChoosePixelFormat(pMemDC->m_hDC, &pfd);
	DescribePixelFormat(pMemDC->m_hDC, pixelformat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
	SetPixelFormat(pMemDC->m_hDC, pixelformat, &pfd);
	
	// Creating a OpenGL context
	HGLRC hmemrc = wglCreateContext(pMemDC->GetSafeHdc());
	
	// Setting up the current OpenGL context
	GL_DisableVertexBufferObject();
	wglMakeCurrent(pMemDC->GetSafeHdc(), hmemrc);
	double aspect = (float)w/(float)h;
	glMatrixMode(GL_MODELVIEW);
	glViewport(0, 0, w, h);

	// Sort pieces by description
	struct BRICKSORT {
		char name[64];
		int actual;
		struct BRICKSORT *next;
	} start, *node, *previous, *news;

	start.next = NULL;
	
	for (int j = 0; j < pLib->mPieces.GetSize(); j++)
	{
		char* desc = pLib->mPieces[j]->m_strDescription;

		if (desc[0] != '~')
			continue;

		// Find the correct location
		previous = &start;
		node = start.next;
		while ((node) && (strcmp(desc, node->name) > 0))
		{
			node = node->next;
			previous = previous->next;
		}
		
		news = (struct BRICKSORT*) malloc(sizeof(struct BRICKSORT));
		news->next = node;
		previous->next = news;
		strcpy(news->name, desc);
		news->actual = j;
	}
	
	node = start.next;

	if (PD->PrintRange())
	{
		for (int j = 0; j < (int)(nStartPage - 1)*rows*cols; j++)
			if (node)
				node = node->next;
	}

	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight = -MulDiv(12, GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY), 72);
	lf.lfWeight = FW_REGULAR;
	lf.lfCharSet = DEFAULT_CHARSET;
	lf.lfQuality = PROOF_QUALITY;
	strcpy (lf.lfFaceName , "Arial");
	HFONT HeaderFont = CreateFontIndirect(&lf);
	HFONT OldFont = (HFONT)SelectObject(PD->m_pd.hDC, HeaderFont);
	SetBkMode(PD->m_pd.hDC, TRANSPARENT);
	SetTextColor(PD->m_pd.hDC, 0x000000);
	SetTextAlign (PD->m_pd.hDC, TA_TOP|TA_LEFT|TA_NOUPDATECP);

	SetTextColor (pMemDC->m_hDC, 0x000000);
	lf.lfHeight = -MulDiv(10, GetDeviceCaps(pMemDC->m_hDC, LOGPIXELSY), 72);
	lf.lfWeight = FW_BOLD;
	HFONT CatalogFont = CreateFontIndirect(&lf);
	HFONT OldMemFont = (HFONT)SelectObject(pMemDC->m_hDC, CatalogFont);
	HPEN hpOld = (HPEN)SelectObject(pMemDC->m_hDC,(HPEN)GetStockObject(BLACK_PEN));

	for (UINT nCurPage = nStartPage; nCurPage != nEndPage; nCurPage += nStep)
	{
		// write current page
		TCHAR szBuf[80];
		wsprintf(szBuf, strTemp, nCurPage);
		dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, szBuf);

		// attempt to start the current page
		if (StartPage(PD->m_pd.hDC) < 0)
		{
			bError = TRUE;
			break;
		}

		int printed = 0;
		// page successfully started, so now render the page
		for (int r = 0; r < rows; r++)
		for (int c = 0; c < cols; c++)
		{
			if (node == NULL) continue;
			printed++;
			glDepthFunc(GL_LEQUAL);
			glClearColor(1,1,1,1); 
			glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
			glEnable(GL_COLOR_MATERIAL);
			glDisable(GL_DITHER);
			glShadeModel(GL_FLAT);

			lcSetColor(lcGetActiveProject()->GetCurrentColor());

//			dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, node->name);
			node = node->next;
			PieceInfo* pInfo = pLib->mPieces[node->actual];
			pInfo->ZoomExtents(30.0f, (float)aspect);

			float pos[4] = { 0, 0, 10, 0 };
			glLightfv(GL_LIGHT0, GL_POSITION, pos);

			glEnable(GL_LIGHTING);
			glEnable(GL_LIGHT0);
			glEnable(GL_DEPTH_TEST);

			FillRect(pMemDC->m_hDC, CRect(0,h,w,0), (HBRUSH)GetStockObject(WHITE_BRUSH));
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			pInfo->RenderPiece(lcGetActiveProject()->GetCurrentColor());
			glFlush();

			TextOut (pMemDC->m_hDC, 5, 5, pInfo->m_strDescription, strlen(pInfo->m_strDescription));
//			BitBlt(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), w, h, pMemDC->m_hDC, 0, 0, SRCCOPY);

			LPBITMAPINFOHEADER lpbi[1];
			lpbi[0] = (LPBITMAPINFOHEADER)GlobalLock(MakeDib(hBm, 24));
			BITMAPINFO bi;
			ZeroMemory(&bi, sizeof(BITMAPINFO));
			memcpy (&bi.bmiHeader, lpbi[0], sizeof(BITMAPINFOHEADER));
			SetStretchBltMode(PD->m_pd.hDC, COLORONCOLOR);
			StretchDIBits(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), 
				w, h, 0, 0, w, h, (LPBYTE) lpbi[0] + lpbi[0]->biSize + lpbi[0]->biClrUsed * sizeof(RGBQUAD),
				&bi, DIB_RGB_COLORS, SRCCOPY);
			if (lpbi[0]) GlobalFreePtr(lpbi[0]);
		}

		DWORD dwPrint = theApp.GetProfileInt("Settings","Print", PRINT_NUMBERS|PRINT_BORDER);
		if (dwPrint & PRINT_BORDER)
		for (int r = 0; r < rows; r++)
		for (int c = 0; c < cols; c++)
		{
			if (printed == 0) continue;
			printed--;
			if (r == 0)
			{
				MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), NULL);
				LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*r));
			}
			if (c == 0)
			{
				MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*r), NULL);
				LineTo(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*(r+1)));
			}
			
			MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*r), NULL);
			LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*(r+1)));
			MoveToEx(PD->m_pd.hDC, rectDraw.left+(w*c), rectDraw.top+(h*(r+1)), NULL);
			LineTo(PD->m_pd.hDC, rectDraw.left+(w*(c+1)), rectDraw.top+(h*(r+1)));
		}

		CRect r2 = rectDraw;
		r2.top -= GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Top", 50)/200;
		r2.bottom += GetDeviceCaps(PD->m_pd.hDC, LOGPIXELSY)*theApp.GetProfileInt("Default","Margin Bottom", 50)/200;
		pView->PrintHeader(FALSE, PD->m_pd.hDC, r2, nCurPage, nEndPage, TRUE);
		pView->PrintHeader(TRUE, PD->m_pd.hDC, r2, nCurPage, nEndPage, TRUE);

		if (EndPage(PD->m_pd.hDC) < 0 || !_AfxAbortProc(PD->m_pd.hDC, 0))
		{
			bError = TRUE;
			break;
		}
	}

	SelectObject(pMemDC->m_hDC, hpOld);
	SelectObject(PD->m_pd.hDC, OldFont);
	DeleteObject(HeaderFont);
	SelectObject(pMemDC->m_hDC, OldMemFont);
	DeleteObject(CatalogFont);

	node = start.next;
	while (node)
	{
		previous = node;
		node = node->next;
		free(previous);
	}

	GL_EnableVertexBufferObject();
	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hmemrc);
	SelectObject(pMemDC->GetSafeHdc(), hBmOld);
	DeleteObject(hBm);
	delete pMemDC;

	// cleanup document printing process
	if (!bError)
		EndDoc(PD->m_pd.hDC);
	else
		AbortDoc(PD->m_pd.hDC);

	pParent->EnableWindow();
	dlgPrintStatus.DestroyWindow();

    if (PD != NULL && PD->m_pd.hDC != NULL)
    {
        ::DeleteDC(PD->m_pd.hDC);
        PD->m_pd.hDC = NULL;
    }
    delete PD;
}
Example #8
0
HRESULT CSwatchesList::OnDraw(ATL_DRAWINFO& di)
{
	RECT& rc = *(RECT*)di.prcBounds;
	HDC hDC = di.hdcDraw;

	if (m_swatches)
	{
		Draw3DRect(hDC, m_areaRect.left-1, m_areaRect.top-1, m_areaRect.Width()+2, m_areaRect.Height()+2, RGB(0,0,0), RGB(0,0,0));

		long scrollposY; m_vert->get_pos(&scrollposY);

		if (IntersectClipRect(hDC, m_areaRect.left, m_areaRect.top, m_areaRect.right, m_areaRect.bottom))
		{
			POINT oldOrg;
			SetViewportOrgEx(hDC, m_areaRect.left, m_areaRect.top - scrollposY, &oldOrg);
		// For CMYK conversion
			/*
			TCHAR colorDirectory[MAX_PATH];
			DWORD cbSize = sizeof(colorDirectory);
			GetColorDirectory(NULL, colorDirectory, &cbSize);

			HPROFILE hDestProfile = NULL;
			{
				TCHAR profilePath[MAX_PATH];
				_makepath(profilePath, NULL, colorDirectory, "sRGB Color Space Profile.ICM", NULL);

				PROFILE profile = {0};
				profile.dwType = PROFILE_FILENAME;
				profile.pProfileData = profilePath;
				profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR);
				hDestProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING);
				ATLASSERT(hDestProfile);
			}

			HPROFILE hTargetProfile = NULL;
			{
				TCHAR profilePath[MAX_PATH];
				_makepath(profilePath, NULL, colorDirectory, targetProfile, NULL);

				PROFILE profile = {0};
				profile.dwType = PROFILE_FILENAME;
				profile.pProfileData = profilePath;
				profile.cbDataSize = (_tcslen(profilePath)+1)*sizeof(TCHAR);
				hTargetProfile = OpenColorProfile(&profile, PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING);
				ATLASSERT(hTargetProfile);
			}

			LOGCOLORSPACE lcp = {0};
			lcp.lcsSignature = LCS_SIGNATURE;
			lcp.lcsVersion = 0x400;
			lcp.lcsSize = sizeof(lcp);
			lcp.lcsCSType = LCS_sRGB;
			lcp.lcsFilename;// = NULL; // ??

			HTRANSFORM hTransform = CreateColorTransform(&lcp, hDestProfile, hTargetProfile, BEST_MODE);
			ATLASSERT(hTransform);
			*/

		// Pattern for drawing ColorType symbols
			WORD bmdata[8] =
			{
				0xaaaa,
				0x5555,
				0xaaaa,
				0x5555,
				0xaaaa,
				0x5555,
				0xaaaa,
				0x5555,
			};

			HBITMAP hPatBitmap = CreateBitmap(8, 8, 1, 1, bmdata);
			ATLASSERT(hPatBitmap);

			HBRUSH hPatBrush = CreatePatternBrush(hPatBitmap);
			ATLASSERT(hPatBrush);
			DeleteObject(hPatBitmap);

		//
			HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);

			LOGFONT lf;
			GetObject(hFont, sizeof(lf), &lf);
			lf.lfWeight = FW_BOLD;

			HFONT hFontSelected = CreateFontIndirect(&lf);
			HFONT hOldFont = (HFONT)GetCurrentObject(hDC, OBJ_FONT);

			long nswatches;
			m_swatches->get_length(&nswatches);

			int y = 0;

			for (int i = 0; i < nswatches; i++)
			{
				CComPtr<IPDSwatch> swatch;
				m_swatches->item(i, &swatch);

				//Rectangle(hDC, itemrect.left, itemrect.top, itemrect.right+1, itemrect.bottom+1);
				MoveToEx(hDC, 0, y+m_itemHeight, NULL);
				LineTo(hDC, m_areaRect.Width()+1, y+m_itemHeight);

				CRect itemrect(0, y+1, m_areaRect.Width(), y+m_itemHeight-1);
	//			itemrect.top += 1;
	//			itemrect.bottom -= 1;

				bool bSelected = IsSwatchSelected(swatch);

				if (bSelected)
					FillSolidRect(hDC, itemrect.left, itemrect.top+1, itemrect.Width(), itemrect.Height()-1, (bSelected)? GetSysColor(COLOR_HIGHLIGHT): GetSysColor(COLOR_WINDOW));

				int swatchSize = m_itemHeight-4;
				int swatchTop = (m_itemHeight-swatchSize)/2;
		//		CRect swatchRect(itemrect.left + 4, itemrect.top+itemrect.Height()/2-8, itemrect.left + 4 + 16, itemrect.top+itemrect.Height()/2-8+16);
				CRect swatchRect(itemrect.left + 4, itemrect.top+swatchTop, itemrect.left + 4 + swatchSize, itemrect.top+swatchTop+swatchSize);

				if (bSelected)
				{
					SelectObject(hDC, hFontSelected);
					SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
				}
				else
				{
					SelectObject(hDC, hFont);
					SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
				}

				SetBkMode(hDC, TRANSPARENT);

				BSTR bname;
				swatch->get_name(&bname);
				_bstr_t name = _bstr_t(bname, false);

				PDSwatchType swatchType;
				swatch->get_swatchType(&swatchType);

				CRect trect = itemrect;
				trect.left = swatchRect.right + 4;
				trect.right -= 30;

				if (swatchType == SWATCH_NONE)
				{
					FillSolidRect(hDC, &swatchRect, RGB(255, 255, 255));

					HPEN hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
					HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);

					MoveToEx(hDC, swatchRect.left+1, swatchRect.bottom-1, NULL);
					LineTo(hDC, swatchRect.right-1, swatchRect.top+1);

					SelectObject(hDC, hOldPen);
					DeleteObject(hPen);

					HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));
					Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom);
					SelectObject(hDC, hOldBrush);
				}
				else if (swatchType == SWATCH_COLOR ||
							swatchType == SWATCH_TINT)
				{
					CComPtr<IPDColor> color;
					CComQIPtr<IPDSwatchColor> swatchColor;

					if (swatchType == SWATCH_COLOR)
					{
						swatchColor = swatch;
						swatchColor->get_color(&color);
					}
					else
					{
						CComQIPtr<IPDSwatchTint> swatchTint = swatch;
						swatchTint->get_swatchColor(&swatchColor);

						swatchTint->get_finalColor(&color);

						CRect trect2 = trect;
						trect.right -= 28;
						trect2.left = trect.right;

						double tint;
						swatchTint->get_tint(&tint);

						CUString str;
						str.Format("%d %%", (int)(tint*100));

						DrawText(hDC, str, str.GetLength(), &trect2, DT_SINGLELINE | DT_VCENTER);
					}

					PDColorMode colorMode;
					color->get_colorMode(&colorMode);

					COLORREF clr;

					if (colorMode == COLORMODE_RGB)
					{
						double red; color->getChannel(0, &red);
						double green; color->getChannel(1, &green);
						double blue; color->getChannel(2, &blue);

						clr = RGB(red, green, blue);
					}
					else if (colorMode == COLORMODE_CMYK)
					{
	/*					if (hTransform)
						{
							double cyan; color->getChannel(0, &cyan);
							double magenta; color->getChannel(1, &magenta);
							double yellow; color->getChannel(2, &yellow);
							double black; color->getChannel(3, &black);

							COLOR incolor;
							incolor.cmyk.cyan = cyan*65535/255;
							incolor.cmyk.magenta = magenta*65535/255;
							incolor.cmyk.yellow = yellow*65535/255;
							incolor.cmyk.black = black*65535/255;

							COLOR outcolor;
							BOOL bSuccess = TranslateColors(hTransform, &incolor, 1, COLOR_CMYK, &outcolor, COLOR_RGB);
							ATLASSERT(bSuccess);

							clr = RGB(
								outcolor.rgb.red*255.0/65535,
								outcolor.rgb.green*255.0/65535,
								outcolor.rgb.blue*255.0/65535);
						}
						else
						*/
							clr = -1;
					}

					if (clr != -1)
					{
						HBRUSH hBrush = CreateSolidBrush(clr);
						HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);

						Rectangle(hDC, swatchRect.left, swatchRect.top, swatchRect.right, swatchRect.bottom);

						SelectObject(hDC, hOldBrush);
						DeleteObject(hBrush);
					}

					{
						CRect rc(itemrect.right-15, itemrect.top+4, itemrect.right-15+10, itemrect.top+4+10);

						if (colorMode == COLORMODE_RGB)
						{
							Rectangle(hDC, rc.left, rc.top-1, rc.right+1, rc.bottom+1);

							FillSolidRect(hDC, rc.left+1, rc.top, 3, rc.Height(), RGB(255, 0, 0));
							FillSolidRect(hDC, rc.left+4, rc.top, 3, rc.Height(), RGB(0, 255, 0));
							FillSolidRect(hDC, rc.left+7, rc.top, 3, rc.Height(), RGB(0, 0, 255));
						}
						else if (colorMode == COLORMODE_CMYK)
						{
							//
							{
								HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 255));
								HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);

								POINT pts[3] =
								{
									rc.left, rc.top,
									rc.left+rc.Width(), rc.top,
									rc.left+rc.Width()/2, rc.top+rc.Height()/2,
								};

								Polygon(hDC, pts, 3);

								SelectObject(hDC, hOldBrush);
								DeleteObject(hBrush);
							}

							//
							{
								HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 0));
								HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);

								POINT pts[3] =
								{
									rc.right, rc.top,
									rc.right, rc.top+rc.Height(),
									rc.right-rc.Width()/2, rc.top+rc.Height()/2,
								};

								Polygon(hDC, pts, 3);

								SelectObject(hDC, hOldBrush);
								DeleteObject(hBrush);
							}

							//
							{
								HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0));
								HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);

								POINT pts[3] =
								{
									rc.left, rc.bottom,
									rc.left+rc.Width(), rc.bottom,
									rc.left+rc.Width()/2, rc.bottom-rc.Height()/2,
								};

								Polygon(hDC, pts, 3);

								SelectObject(hDC, hOldBrush);
								DeleteObject(hBrush);
							}

							//
							{
								HBRUSH hBrush = CreateSolidBrush(RGB(0, 255, 255));
								HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);

								POINT pts[3] =
								{
									rc.left, rc.top,
									rc.left, rc.top+rc.Height(),
									rc.left+rc.Width()/2, rc.top+rc.Height()/2,
								};

								Polygon(hDC, pts, 3);

								SelectObject(hDC, hOldBrush);
								DeleteObject(hBrush);
							}
						}
					}

					{
						CRect rc(m_areaRect.right-28, y+4, m_areaRect.right-28+10, y+4+10);

						PDColorType colorType;
						swatchColor->get_colorType(&colorType);

						int oldBkMode = SetBkMode(hDC, OPAQUE);
						COLORREF oldTextClr = SetTextColor(hDC, RGB(100,100,100));
						COLORREF oldBkClr = SetBkColor(hDC, RGB(255,255,255));

						if (colorType == COLORTYPE_PROCESS)
						{
							HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush);
							Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
							SelectObject(hDC, hOldBrush);
						}
						else if (colorType == COLORTYPE_SPOT)
						{
							Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);

							HPEN hPen = CreatePen(PS_SOLID, 1, RGB(120, 120, 120));
							HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, hPatBrush);
							HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);

							Ellipse(hDC, rc.left+2, rc.top+2, rc.right-2, rc.bottom-2);

							SelectObject(hDC, hOldBrush);
							SelectObject(hDC, hOldPen);
							DeleteObject(hPen);
						}
						else
							ATLASSERT(0);

						SetBkMode(hDC, oldBkMode);
						SetTextColor(hDC, oldTextClr);
						SetBkColor(hDC, oldBkClr);
					}
				}
				else if (swatchType == SWATCH_GRADIENT)
				{
					Gdiplus::Graphics graphics(hDC);

					CComQIPtr<IPDSwatchGradient> swatchGradient = swatch;

					CComPtr<IPDGradient> gradient;
					swatchGradient->get_gradient(&gradient);

					PDGradientType gradientType;
					gradient->get_type(&gradientType);

					Gdiplus::Rect rc(swatchRect.left, swatchRect.top, swatchRect.Width(), swatchRect.Height());

					CArray<Gdiplus::REAL, Gdiplus::REAL> offsets;
					CArray<Gdiplus::Color,Gdiplus::Color&> colors;

					CreateGradient(offsets, colors, gradient);

					if (gradientType == GRADIENT_LINEAR)
					{
						Gdiplus::LinearGradientBrush brush(rc, Gdiplus::Color(0,0,0), Gdiplus::Color(0,0,0), Gdiplus::LinearGradientModeHorizontal);
						brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize());

						graphics.FillRectangle(&brush, rc);
					}
					else if (gradientType == GRADIENT_RADIAL)
					{
						Gdiplus::GraphicsPath path;
						path.AddEllipse(rc);

						Gdiplus::PathGradientBrush brush(&path);
						brush.SetInterpolationColors(colors.GetData(), offsets.GetData(), colors.GetSize());

						graphics.FillRectangle(&brush, rc);
					}
					else
						ATLASSERT(0);
				}
				else if (swatchType == SWATCH_PATTERN)
				{
					Gdiplus::Graphics graphics(hDC);

					CComQIPtr<IPDSwatchPattern> swatchPattern = swatch;

					CComPtr<IPDObjectGroup> objectGroup;
					swatchPattern->get_objectGroup(&objectGroup);

					RectD bbox;
					objectGroup->getExpandedBBox(&bbox);

					int width = swatchRect.Width();
					int height = (bbox.Height * width/bbox.Width);//+0.5;

					if (height > swatchRect.Height())
					{
						height = swatchRect.Height();
						width = (bbox.Width * height/bbox.Height);//+0.5;
					}
					ATLASSERT(width <= bbox.Width);

					double magnify = width/bbox.Width;

					int left = (swatchRect.Width()-width)/2;
					int top = (swatchRect.Height()-height)/2;

					CComPtr<IPDRenderer> renderer;
					renderer.CoCreateInstance(CLSID_PDRenderer);
					if (renderer)
					{
						Gdiplus::Bitmap bitmap(width, height);
						{
							Gdiplus::Graphics bmgraphics(&bitmap);
							bmgraphics.FillRectangle(&Gdiplus::SolidBrush(Gdiplus::Color(255, 255, 255)), 0, 0, width, height);

						//	Gdiplus::Graphics& bmgraphics = graphics;

						//	CComQIPtr<IPDObjectTransformable> transformable = objectGroup;
						//	RectD bounds;
						//	transformable->get_bounds(&bounds);

						//	bmgraphics.TranslateTransform(swatchRect.left+left, swatchRect.top+top);

							bmgraphics.ScaleTransform(magnify, magnify);
							bmgraphics.TranslateTransform(-bbox.X, -bbox.Y);
						//	bmgraphics.TranslateTransform(-bounds.X, -bounds.Y);

							renderer->put_magnify(magnify);
							renderer->put_targetHDC((HDC)&bmgraphics);

							renderer->RenderObject(objectGroup);
						}

						graphics.DrawImage(&bitmap, swatchRect.left+left, swatchRect.top+top);
					}
				}

				DrawText(hDC, name, name.length(), &trect, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);

				y += m_itemHeight;
			}

			SelectObject(hDC, hOldFont);

			DeleteObject(hFontSelected);
			DeleteObject(hPatBrush);
	/*
			if (hTransform) DeleteColorTransform(hTransform);
			if (hDestProfile) CloseColorProfile(hDestProfile);
			*/

			SetViewportOrgEx(hDC, oldOrg.x, oldOrg.y, NULL);
		}
	}

	return S_OK;
}
Example #9
0
LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
    NPP instance = (NPP)GetWindowLongPtr(hWnd, GWLP_USERDATA);
    
    if (uiMsg == WM_PAINT)
    {
        InstanceData *data = (InstanceData *)instance->pdata;
        
        PAINTSTRUCT ps;
        HDC hDC = BeginPaint(hWnd, &ps);
        HBRUSH brushBg = CreateSolidBrush(COL_WINDOW_BG);
        HFONT hFont = GetSimpleFont(hDC, L"MS Shell Dlg", 14);
        bool isRtL = IsLanguageRtL(gTranslationIdx);
        
        // set up double buffering
        RectI rcClient = ClientRect(hWnd);
        DoubleBuffer buffer(hWnd, rcClient);
        HDC hDCBuffer = buffer.GetDC();
        
        // display message centered in the window
        FillRect(hDCBuffer, &rcClient.ToRECT(), brushBg);
        hFont = (HFONT)SelectObject(hDCBuffer, hFont);
        SetTextColor(hDCBuffer, RGB(0, 0, 0));
        SetBkMode(hDCBuffer, TRANSPARENT);
        DrawCenteredText(hDCBuffer, rcClient, data->message, isRtL);
        
        // draw a progress bar, if a download is in progress
        if (0 < data->progress && data->progress <= 1)
        {
            SIZE msgSize;
            RectI rcProgress = rcClient;
            
            HBRUSH brushProgress = CreateSolidBrush(RGB(0x80, 0x80, 0xff));
            GetTextExtentPoint32(hDCBuffer, data->message, (int)str::Len(data->message), &msgSize);
            rcProgress.Inflate(-(rcProgress.dx - msgSize.cx) / 2, -(rcProgress.dy - msgSize.cy) / 2 + 2);
            rcProgress.Offset(0, msgSize.cy + 4 + 2);
            FillRect(hDCBuffer, &rcProgress.ToRECT(), GetStockBrush(WHITE_BRUSH));
            RectI rcProgressAll = rcProgress;
            rcProgress.dx = (int)(data->progress * rcProgress.dx);
            FillRect(hDCBuffer, &rcProgress.ToRECT(), brushProgress);
            DeleteObject(brushProgress);
            
            ScopedMem<WCHAR> currSize(FormatSizeSuccint(data->currSize));
            if (0 == data->totalSize || data->currSize > data->totalSize)
            {
                // total size unknown or bogus => show just the current size
                DrawCenteredText(hDCBuffer, rcProgressAll, currSize, isRtL);
            }
            else
            {
                ScopedMem<WCHAR> totalSize(FormatSizeSuccint(data->totalSize));
                ScopedMem<WCHAR> s(str::Format(_TR("%s of %s"), currSize, totalSize));
                DrawCenteredText(hDCBuffer, rcProgressAll, s, isRtL);
            }
        }
        
        // draw the buffer on screen
        buffer.Flush(hDC);
        
        DeleteObject(SelectObject(hDCBuffer, hFont));
        DeleteObject(brushBg);
        EndPaint(hWnd, &ps);
        
        HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL);
        if (hChild)
            InvalidateRect(hChild, NULL, FALSE);
    }
    else if (uiMsg == WM_SIZE)
    {
        HWND hChild = FindWindowEx(hWnd, NULL, NULL, NULL);
        if (hChild)
        {
            ClientRect rcClient(hWnd);
            MoveWindow(hChild, rcClient.x, rcClient.y, rcClient.dx, rcClient.dy, FALSE);
        }
    }
    else if (uiMsg == WM_COPYDATA)
    {
        COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam;
        if (cds && 0x4C5255 /* URL */ == cds->dwData)
        {
            plogf("sp: NPN_GetURL %s", cds->dwData, (const char *)cds->lpData);
            gNPNFuncs.geturl(instance, (const char *)cds->lpData, "_blank");
            return TRUE;
        }
    }
    
    return DefWindowProc(hWnd, uiMsg, wParam, lParam);
}
Example #10
0
HWND CreateProgressDialog(TCHAR* text) {

  static int yFontSize, xFontSize;
  HDC	hTempDC = NULL;


  if (doinitprogress) {

	doinitprogress=false;

	DWORD Style=0;
	Style = WS_CHILD | ES_MULTILINE | ES_CENTER | ES_READONLY | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;

	hStartupWindow=CreateWindow(TEXT("STATIC"), TEXT("\0"), Style, 0, 0, ScreenSizeX, ScreenSizeY, hWndMainWindow, NULL, hInst, NULL);
	if (hStartupWindow==NULL) {
		StartupStore(_T("***** CRITIC, no startup window!%s"),NEWLINE);
		return NULL;
	}
	if (!(hStartupDC = GetDC(hStartupWindow))) {
		StartupStore(_T("------ Cannot state startup window%s"),NEWLINE);
		return(NULL);
	}
/*
	SHFullScreen(hProgress, SHFS_HIDETASKBAR |SHFS_HIDESIPBUTTON |SHFS_HIDESTARTICON);
	SetWindowPos(hProgress,HWND_TOP,0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
*/
	//RECT rt;
	//GetClientRect(hStartupWindow,&rt);
	//FillRect(hStartupDC,&rt,(HBRUSH)GetStockObject(BLACK_BRUSH));
	//SetWindowPos(hStartupWindow,HWND_TOP,0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
	//SHFullScreen(hStartupWindow, SHFS_HIDETASKBAR |SHFS_HIDESIPBUTTON |SHFS_HIDESTARTICON); 
	//SetForegroundWindow(hStartupWindow);
	//UpdateWindow(hStartupWindow);

	ShowWindow(hStartupWindow,SW_SHOWNORMAL);
	BringWindowToTop(hStartupWindow);

	// Load welcome screen bitmap
	HBITMAP hWelcomeBitmap=NULL;
	TCHAR sDir[MAX_PATH];
        TCHAR srcfile[MAX_PATH];
        LocalPath(sDir,TEXT(LKD_BITMAPS));

	// first look for lkstart_480x272.bmp for example
	_stprintf(srcfile,_T("%s\\LKSTART_%s.BMP"),sDir, GetSizeSuffix() );

        if (  GetFileAttributes(srcfile) == 0xffffffff ) {
		// no custom file, get a generic one
		switch(ScreenSize) {
			case ss800x480:
			case ss640x480:
			case ss720x408:
			case ss896x672:
				_stprintf(srcfile,_T("%s\\LKSTART_LB.BMP"),sDir);
				break;

			case ss480x272:
			case ss480x234:
			case ss400x240:
			case ss320x240:
				_stprintf(srcfile,_T("%s\\LKSTART_LS.BMP"),sDir);
				break;

			case ss480x640:
			case ss480x800:
				_stprintf(srcfile,_T("%s\\LKSTART_PB.BMP"),sDir);
				break;

			case ss240x320:
			case ss272x480:
				_stprintf(srcfile,_T("%s\\LKSTART_PS.BMP"),sDir);
				break;

			default:
				_stprintf(srcfile,_T("%s\\LKSTART_DEFAULT.BMP"),sDir);
				break;
		}
	}
	#if (WINDOWSPC>0)
	hWelcomeBitmap=(HBITMAP)LoadImage(GetModuleHandle(NULL),srcfile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
	#else
	hWelcomeBitmap=(HBITMAP)SHLoadDIBitmap(srcfile);
	#endif
	// still nothing? use internal (poor man) resource
	if (hWelcomeBitmap==NULL)
		hWelcomeBitmap=LoadBitmap(hInst, MAKEINTRESOURCE(IDB_SWIFT));

	hTempDC = CreateCompatibleDC(hStartupDC);

	// AA
	HBITMAP oldBitmap = (HBITMAP)SelectObject(hTempDC, hWelcomeBitmap);
        SelectObject(hTempDC, LKSTARTBOTTOMFONT);
	SIZE TextSize;
        GetTextExtentPoint(hTempDC, _T("X"),1, &TextSize);
        yFontSize = TextSize.cy;
        xFontSize = TextSize.cx;

	BITMAP bm;
	GetObject(hWelcomeBitmap,sizeof(bm), &bm);

	StretchBlt(hStartupDC,0,0, 
		ScreenSizeX,ScreenSizeY-1, 
		hTempDC, 0, 0, 
		2,2,
		BLACKNESS);

	if ( (bm.bmWidth >ScreenSizeX)||(bm.bmHeight>ScreenSizeY)) {
		StretchBlt(hStartupDC,0,0, 
			ScreenSizeX,ScreenSizeY-NIBLSCALE(2)-(yFontSize*2)-1, 
			hTempDC, 0, 0, 
			bm.bmWidth,bm.bmHeight,
			SRCCOPY);
	} else {
		BitBlt(hStartupDC,(ScreenSizeX-bm.bmWidth)/2,0,bm.bmWidth,bm.bmHeight,hTempDC, 0, 0, SRCCOPY);
	}



	// AA


	SelectObject(hTempDC, oldBitmap);
	DeleteObject(hWelcomeBitmap);
	if (DeleteDC(hTempDC)==0) StartupStore(_T("**** Cannot delete hTempDC\n"));
  }

  BringWindowToTop(hStartupWindow); // we shall return here also on shutdown and file reloads

  // RECT is left, top, right, bottom
  RECT PrintAreaR; 
  PrintAreaR.left   = NIBLSCALE(2);
  PrintAreaR.bottom = ScreenSizeY-NIBLSCALE(2);
  PrintAreaR.top    = PrintAreaR.bottom - (yFontSize*2);
  PrintAreaR.right  = ScreenSizeX - NIBLSCALE(2);

  HFONT oldFont=(HFONT)SelectObject(hStartupDC,LKSTARTBOTTOMFONT);

  HBRUSH hB=LKBrush_Petrol;
  FillRect(hStartupDC,&PrintAreaR, hB);

  // Create text area

  // we cannot use LKPen here because they are not still initialised for startup menu. no problem
  HPEN hP=(HPEN)  CreatePen(PS_SOLID,NIBLSCALE(1),RGB_GREEN);
  SelectObject(hStartupDC,hP);
  SelectObject(hStartupDC,hB);
  Rectangle(hStartupDC, PrintAreaR.left,PrintAreaR.top,PrintAreaR.right,PrintAreaR.bottom);
  DeleteObject(hP);

  hP=(HPEN)  CreatePen(PS_SOLID,NIBLSCALE(1),RGB_BLACK);
  SelectObject(hStartupDC,hP);
  Rectangle(hStartupDC, PrintAreaR.left+NIBLSCALE(2),PrintAreaR.top+NIBLSCALE(2),PrintAreaR.right-NIBLSCALE(2),PrintAreaR.bottom-NIBLSCALE(2));

  SetTextColor(hStartupDC,RGB_WHITE);
  SetBkMode(hStartupDC,TRANSPARENT);

  unsigned int maxchars= (ScreenSizeX/xFontSize)-1;
  if (_tcslen(text) <maxchars) {
	maxchars=_tcslen(text);
  }
  ExtTextOut(hStartupDC,PrintAreaR.left+(xFontSize/2),PrintAreaR.top + ((PrintAreaR.bottom - PrintAreaR.top)/2)-(yFontSize/2),
	ETO_OPAQUE,NULL,text,maxchars,NULL);

  SelectObject(hStartupDC,oldFont);
  // Sleep(300); // Slow down display of data? No because in case of important things, Sleep is set by calling part

  DeleteObject(hP);


  return hStartupWindow;
}
Example #11
0
static INT_PTR CALLBACK
DlgProc(HWND hDlg,
        UINT Message,
        WPARAM wParam,
        LPARAM lParam)
{
    PINFO pInfo;

    /* Get the window context */
    pInfo = (PINFO)GetWindowLongPtrW(hDlg,
                                     GWLP_USERDATA);
    if (pInfo == NULL && Message != WM_INITDIALOG)
    {
        goto HandleDefaultMessage;
    }

    switch(Message)
    {
        case WM_INITDIALOG:
            OnMainCreate(hDlg, (PRDPSETTINGS)lParam);
        break;

        case WM_COMMAND:
        {
            if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
            {
                if (LOWORD(wParam) == IDOK )
                {
                    SaveAllSettings(pInfo);
                    SaveRdpSettingsToFile(NULL, pInfo->pRdpSettings);
                }
                Cleanup(pInfo);
                EndDialog(hDlg, LOWORD(wParam));
            }

            break;
        }

        case WM_NOTIFY:
        {
            INT idctrl;
            LPNMHDR pnmh;
            idctrl = (int)wParam;
            pnmh = (LPNMHDR)lParam;
            if (//(pnmh->hwndFrom == pInfo->hSelf) &&
                (pnmh->idFrom == IDC_TAB) &&
                (pnmh->code == TCN_SELCHANGE))
            {
                OnTabWndSelChange(pInfo);
            }

            break;
        }

        case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc;

            hdc = BeginPaint(hDlg, &ps);
            if (hdc != NULL)
            {
                HDC hdcMem = CreateCompatibleDC(hdc);
                if (hdcMem)
                {
                    WCHAR szBuffer[32];
                    RECT bmpRc, txtRc;
                    LOGFONTW lf;
                    HFONT hFont, hFontOld;
                    HBITMAP hBmpOld;

                    GetClientRect(pInfo->hSelf, &bmpRc);

                    hBmpOld = SelectObject(hdcMem, pInfo->hHeader);
                    StretchBlt(hdc,
                               0,
                               0,
                               bmpRc.right,
                               pInfo->headerbitmap.bmHeight,
                               hdcMem,
                               0,
                               0,
                               pInfo->headerbitmap.bmWidth,
                               pInfo->headerbitmap.bmHeight,
                               SRCCOPY);

                    SelectObject(hdcMem, hBmpOld);
                    txtRc.left = bmpRc.right / 4;
                    txtRc.top = 10;
                    txtRc.right = bmpRc.right * 3 / 4;
                    txtRc.bottom = pInfo->headerbitmap.bmHeight / 2;

                    ZeroMemory(&lf, sizeof(LOGFONTW));

                    if (LoadStringW(hInst,
                                    IDS_HEADERTEXT1,
                                    szBuffer,
                                    sizeof(szBuffer) / sizeof(WCHAR)))
                    {
                        lf.lfHeight = 24;
                        lf.lfCharSet = OEM_CHARSET;
                        lf.lfQuality = DEFAULT_QUALITY;
                        lf.lfWeight = FW_MEDIUM;
                        wcscpy(lf.lfFaceName, L"Tahoma");

                        hFont = CreateFontIndirectW(&lf);
                        if (hFont)
                        {
                            hFontOld = SelectObject(hdc, hFont);

                            DPtoLP(hdc, (PPOINT)&txtRc, 2);
                            SetTextColor(hdc, RGB(255,255,255));
                            SetBkMode(hdc, TRANSPARENT);
                            DrawTextW(hdc,
                                      szBuffer,
                                      -1,
                                      &txtRc,
                                      DT_BOTTOM | DT_SINGLELINE | DT_NOCLIP);
                            SelectObject(hdc, hFontOld);
                            DeleteObject(hFont);
                        }
                    }

                    txtRc.left = bmpRc.right / 4;
                    txtRc.top = txtRc.bottom - 5;
                    txtRc.right = bmpRc.right * 3 / 4;
                    txtRc.bottom = pInfo->headerbitmap.bmHeight * 9 / 10;

                    if (LoadStringW(hInst,
                                    IDS_HEADERTEXT2,
                                    szBuffer,
                                    sizeof(szBuffer) / sizeof(WCHAR)))
                    {
                        lf.lfHeight = 30;
                        lf.lfCharSet = OEM_CHARSET;
                        lf.lfQuality = DEFAULT_QUALITY;
                        lf.lfWeight = FW_EXTRABOLD;
                        wcscpy(lf.lfFaceName, L"Tahoma");

                        hFont = CreateFontIndirectW(&lf);
                        if (hFont)
                        {
                            hFontOld = SelectObject(hdc, hFont);

                            DPtoLP(hdc, (PPOINT)&txtRc, 2);
                            SetTextColor(hdc, RGB(255,255,255));
                            SetBkMode(hdc, TRANSPARENT);
                            DrawTextW(hdc,
                                      szBuffer,
                                      -1,
                                      &txtRc,
                                      DT_TOP | DT_SINGLELINE);
                            SelectObject(hdc, hFontOld);
                            DeleteObject(hFont);
                        }
                    }

                    DeleteDC(hdcMem);
                }

                EndPaint(hDlg, &ps);
            }

            break;
        }

        case WM_CLOSE:
        {
            Cleanup(pInfo);
            EndDialog(hDlg, 0);
        }
        break;

HandleDefaultMessage:
        default:
            return FALSE;
    }

    return FALSE;
}
Example #12
0
DWORD CALLBACK AboutBoxProc (HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lParam) 
{
	static HBITMAP hbmpBackgroundTop = NULL;
	static HBITMAP hbmpBackgroundBottom = NULL;
	static HBITMAP hbmpBackgroundMiddle = NULL;
	static HFONT   hPageHeadingFont = NULL;
	static HFONT   hTextFont = NULL;
	static HFONT   hAuthorFont = NULL;

	switch (uMsg) {
	case WM_INITDIALOG:
		{
			enum { ROUND_EDGE = 15 };

			DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
			dwStyle &= ~(WS_CAPTION|WS_SIZEBOX);
			SetWindowLong(hWnd, GWL_STYLE, dwStyle);

			// Use the size of the image
			hbmpBackgroundTop    = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_ABOUT_TOP)); 
			hbmpBackgroundBottom = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_ABOUT_BOTTOM)); 
			hbmpBackgroundMiddle = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_ABOUT_MIDDLE)); 
			
			BITMAP bmTL;
			GetObject(hbmpBackgroundTop, sizeof(BITMAP), &bmTL);

			hCloseButton               = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_CLOSE_NORMAL)); 
			pfnWndAboutBoxCancelProc   = (WNDPROC)::GetWindowLongPtr(GetDlgItem(hWnd,IDCANCEL), GWLP_WNDPROC);
			::SetWindowLongPtr(GetDlgItem(hWnd,IDCANCEL), GWLP_WNDPROC,(LONG_PTR)AboutBoxCancelProc);


			if (hbmpBackgroundTop)
			{
//				int iHeight = bmTL.bmHeight;
				int iWidth  = bmTL.bmWidth;

				RECT rect;
				GetWindowRect(hWnd, &rect);
				rect.left -= rect.left;
				rect.bottom -= rect.top;
				rect.top -= rect.top;

				// Tweaked
				HRGN hWindowRegion= CreateRoundRectRgn
				(
					rect.left,
					rect.top,
					rect.left+iWidth+GetSystemMetrics(SM_CXEDGE)-1,
					rect.bottom+GetSystemMetrics(SM_CYEDGE)-1,
					ROUND_EDGE,
					ROUND_EDGE
				);

				if (hWindowRegion)
				{
					SetWindowRgn(hWnd, hWindowRegion, TRUE);
					DeleteObject(hWindowRegion);
				}
			}

			hTextFont = ::CreateFont
			(
				18, 
				0,
				0, 
				0, 
				FW_NORMAL,
				0,
				0,
				0,
				DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS,
				CLIP_DEFAULT_PRECIS,
				PROOF_QUALITY,
				DEFAULT_PITCH|FF_DONTCARE,
				_T("Arial")
			);

			hAuthorFont = ::CreateFont
			(
				18, 
				0,
				0, 
				0, 
				FW_BOLD,
				0,
				0,
				0,
				DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS,
				CLIP_DEFAULT_PRECIS,
				PROOF_QUALITY,
				DEFAULT_PITCH|FF_DONTCARE,
				_T("Arial")
			);

			hPageHeadingFont = ::CreateFont
			(
				24, 
				0,
				0, 
				0, 
				FW_BOLD,
				0,
				FALSE, //Show underlined?
				0,
				DEFAULT_CHARSET,
				OUT_DEFAULT_PRECIS,
				CLIP_DEFAULT_PRECIS,
				PROOF_QUALITY,
				DEFAULT_PITCH|FF_DONTCARE,
				_T("Arial Bold")
			);

			SendDlgItemMessage(hWnd,IDC_VERSION,WM_SETFONT,(WPARAM)hTextFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_TEAM,WM_SETFONT,(WPARAM)hPageHeadingFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_THANKS,WM_SETFONT,(WPARAM)hPageHeadingFont,TRUE);

			SendDlgItemMessage(hWnd,IDC_ZILMAR,WM_SETFONT,(WPARAM)hAuthorFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_JABO,WM_SETFONT,(WPARAM)hAuthorFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_SMIFF,WM_SETFONT,(WPARAM)hAuthorFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_GENT,WM_SETFONT,(WPARAM)hAuthorFont,TRUE);

			SendDlgItemMessage(hWnd,IDC_ZILMAR_DETAILS,WM_SETFONT,(WPARAM)hTextFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_JABO_DETAILS,WM_SETFONT,(WPARAM)hTextFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_SMIFF_DETAILS,WM_SETFONT,(WPARAM)hTextFont,TRUE);
			SendDlgItemMessage(hWnd,IDC_GENT_DETAILS,WM_SETFONT,(WPARAM)hTextFont,TRUE);
			
			SendDlgItemMessage(hWnd,IDC_THANK_LIST,WM_SETFONT,(WPARAM)hTextFont,TRUE);

			//SetCapture(hWnd);
			stdstr_f VersionDisplay("Version: %s", VER_FILE_VERSION_STR);
			SetWindowText(GetDlgItem(hWnd,IDC_VERSION),VersionDisplay.c_str());
		}
		break;
	case WM_NCHITTEST:
		{
			int xPos = LOWORD(lParam); 
			int yPos = HIWORD(lParam); 
			RECT client, a;
			GetClientRect(hWnd,&a);
			GetClientRect(hWnd,&client);
			ClientToScreen(hWnd,(LPPOINT)&client);
			client.right += client.left;
			client.bottom += client.top;


			int nCaption = GetSystemMetrics(SM_CYCAPTION)*4;

			LRESULT lResult = HTCLIENT;

			//check caption
			if (xPos <= client.right && xPos >= client.left && 
				(yPos >= client.top+ 0)&& (yPos <= client.top + 0+nCaption))
			{
				lResult = HTCAPTION;
			}
			SetWindowLong(hWnd, DWLP_MSGRESULT, lResult);
			return TRUE;
		}
		break;
	case WM_CTLCOLORSTATIC:
		{
			HDC hdcStatic = (HDC)wParam;
			SetTextColor(hdcStatic, RGB(0, 0, 0));
			SetBkMode(hdcStatic, TRANSPARENT);
			return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH));
		}
		break;
	case WM_PAINT:
		{
			PAINTSTRUCT ps;

			if (BeginPaint(hWnd,&ps))
			{
				RECT rcClient;
				GetClientRect(hWnd, &rcClient);

				BITMAP bmTL_top, bmTL_bottom, bmTL_Middle;
				GetObject(hbmpBackgroundTop, sizeof(BITMAP), &bmTL_top);
				GetObject(hbmpBackgroundBottom, sizeof(BITMAP), &bmTL_bottom);
				GetObject(hbmpBackgroundMiddle, sizeof(BITMAP), &bmTL_Middle);

				HDC     memdc	= CreateCompatibleDC(ps.hdc);
				HGDIOBJ save	= SelectObject(memdc, hbmpBackgroundTop);
				BitBlt(ps.hdc, 0, 0, bmTL_top.bmWidth, bmTL_top.bmHeight, memdc, 0, 0, SRCCOPY);
				SelectObject(memdc, save);
				DeleteDC(memdc);

				
				memdc	= CreateCompatibleDC(ps.hdc);
				save	= SelectObject(memdc, hbmpBackgroundMiddle);
				for (int x = bmTL_top.bmHeight; x < rcClient.bottom; x += bmTL_Middle.bmHeight)
				{
					//BitBlt(ps.hdc, 0, bmTL_top.bmHeight, bmTL_Middle.bmWidth, rcClient.bottom - (bmTL_bottom.bmHeight + bmTL_top.bmHeight), memdc, 0, 0, SRCCOPY);
					BitBlt(ps.hdc, 0, x, bmTL_Middle.bmWidth, bmTL_Middle.bmHeight, memdc, 0, 0, SRCCOPY);
				}
				SelectObject(memdc, save);
				DeleteDC(memdc);

				BITMAP ;
				memdc	= CreateCompatibleDC(ps.hdc);
				save	= SelectObject(memdc, hbmpBackgroundBottom);
				BitBlt(ps.hdc, 0, rcClient.bottom - bmTL_bottom.bmHeight, bmTL_bottom.bmWidth, bmTL_bottom.bmHeight, memdc, 0, 0, SRCCOPY);
				SelectObject(memdc, save);
				DeleteDC(memdc);

				BITMAP ;

				EndPaint(hWnd,&ps);
			}
		}
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
		case IDCANCEL:
			if (hbmpBackgroundTop)
			{
				DeleteObject(hbmpBackgroundTop);
			}
			if (hbmpBackgroundBottom)
			{
				DeleteObject(hbmpBackgroundBottom);
			}
			if (hbmpBackgroundMiddle)
			{
				DeleteObject(hbmpBackgroundMiddle);
			}
			if (hTextFont)
				::DeleteObject(hTextFont);
			if (hPageHeadingFont)
				::DeleteObject(hPageHeadingFont);
			if (hAuthorFont)
				::DeleteObject(hAuthorFont);


			//ReleaseCapture();
			EndDialog(hWnd,0);
			break;
		}
	default:
		return FALSE;
	}
	return TRUE;
}
Example #13
0
//===========================================================================
ST void PaintToolbar(HDC hdc, RECT *rcPaint)
{
	RECT r;
	int i;
	const char *label = Toolbar_CurrentWindow;
	StyleItem *pSI;

#ifdef BBOPT_MEMCHECK
	// Display some statistics.
#pragma message("\n"__FILE__ "(397) : warning 0: MEMCHECK enabled.\n")
	/*
		if (NULL==Toolbar_hFont)
		{
			LOGFONT logFont;
			SystemParametersInfo(SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
			Toolbar_hFont = CreateFontIndirect(&logFont);
		}
	*/
	extern int g_menu_count;
	extern int g_menu_item_count;
	char temp[256];
	if (alloc_size && false == Toolbar_ShowingExternalLabel)
	{
		sprintf(temp,"Menus %d  MenuItems %d  Memory %d", g_menu_count, g_menu_item_count, alloc_size);
		label = temp;

	}
#endif

	int tbW = TBInfo.width;
	int tbH = TBInfo.height;
	HDC buf = CreateCompatibleDC(NULL);
	HGDIOBJ bufother = SelectObject(buf, CreateCompatibleBitmap(hdc, tbW, tbH));

	if (NULL==Toolbar_hFont) Toolbar_hFont = CreateStyleFont(&mStyle.Toolbar);
	HGDIOBJ other_font = SelectObject(buf, Toolbar_hFont);

	// Get width of clock...
	SIZE size;

	GetTextExtentPoint32(buf, Toolbar_CurrentTime, strlen(Toolbar_CurrentTime), &size);
	size.cx += 6;
	if (tbClockW < size.cx) tbClockW = size.cx + 6;

	GetTextExtentPoint32(buf, Toolbar_WorkspaceName, strlen(Toolbar_WorkspaceName), &size);
	int tbLabelW = size.cx + 6;

	// The widest sets the width!
	tbLabelW = tbClockW = imax(tbH * 2, imax(tbLabelW, tbClockW));

	int margin = tbMargin;
	int border = mStyle.Toolbar.borderWidth;
	int border_margin = margin + border;
	int button_padding = (tbH - tbButtonWH) / 2 - border;

	int tbLabelX = border_margin;
	int tbClockX = tbW - tbClockW - border_margin;
	int two_buttons = 2*tbButtonWH + 3*button_padding;
	int tbWinLabelX = tbLabelX + tbLabelW + two_buttons;
	int tbWinLabelW = tbClockX - tbWinLabelX - two_buttons;
	if (tbWinLabelW < 0) tbWinLabelW = 0;

	Toolbar_Button[0].r.left = tbLabelX + tbLabelW + button_padding;
	Toolbar_Button[1].r.left = Toolbar_Button[0].r.left + tbButtonWH + button_padding;
	Toolbar_Button[2].r.left = tbClockX - 2*tbButtonWH - 2*button_padding;
	Toolbar_Button[3].r.left = Toolbar_Button[2].r.left + tbButtonWH + button_padding;

	Toolbar_Button[4].r.left = tbClockX;
	for (i = 0; i<5; i++)
	{
		Toolbar_Button[i].r.top    = (tbH - tbButtonWH) / 2;
		Toolbar_Button[i].r.bottom = Toolbar_Button[i].r.top + tbButtonWH;
		Toolbar_Button[i].r.right  = Toolbar_Button[i].r.left + tbButtonWH;
	}
	Toolbar_Button[4].r.right = tbClockX + tbClockW;

	//====================

	// Paint toolbar Style
	r.left = r.top = 0;
	r.right = tbW;
	r.bottom = tbH;
	pSI = &mStyle.Toolbar;
	MakeStyleGradient(buf, &r, pSI, true);

	//====================
	// Paint unpressed workspace/task buttons...

	r.left = r.top = 0;
	r.right = r.bottom = tbButtonWH;
	{
		HPEN activePen   = CreatePen(PS_SOLID, 1, mStyle.ToolbarButtonPressed.picColor);
		HPEN inactivePen = CreatePen(PS_SOLID, 1, mStyle.ToolbarButton.picColor);
		HDC src = CreateCompatibleDC(NULL);
		HGDIOBJ srcother = SelectObject(src, CreateCompatibleBitmap(hdc, tbButtonWH, tbButtonWH));
		int yOffset = tbH / 2;
		int xOffset;
		int f1 = -1;
		for (i=0; i<4; i++)
		{
			int f2 = Toolbar_Button[i].pressed || (Toolbar_force_button_pressed && i&1);
			pSI = f2 ? &mStyle.ToolbarButtonPressed : &mStyle.ToolbarButton;

			if (pSI->parentRelative)
			{
				CreateBorder(buf, &r, pSI->borderColor, pSI->borderWidth);
			}
			else
			{
				if (f1 != f2)
					MakeStyleGradient(src, &r, pSI, pSI->bordered), f1 = f2;

				BitBlt(buf,
					   Toolbar_Button[i].r.left,
					   Toolbar_Button[i].r.top,
					   tbButtonWH, tbButtonWH, src, 0, 0, SRCCOPY
					  );
			}

			xOffset = Toolbar_Button[i].r.left + (tbButtonWH / 2);
			HGDIOBJ penother = SelectObject(buf, f2 ? activePen : inactivePen);
			arrow_bullet(buf, xOffset, yOffset, (i&1)*2-1);
			SelectObject(buf, penother);
		}

		DeleteObject(SelectObject(src, srcother));
		DeleteDC(src);
		DeleteObject(inactivePen);
		DeleteObject(activePen);
	}

	//====================

	r.top = (tbH - tbLabelH)/2;
	r.bottom = r.top + tbLabelH;
	SetBkMode(buf, TRANSPARENT);
	int justify = mStyle.Toolbar.Justify | (DT_VCENTER|DT_SINGLELINE|DT_WORD_ELLIPSIS|DT_NOPREFIX);

	// Paint workspaces background...
	r.right = (r.left = tbLabelX) + tbLabelW;
	pSI = &mStyle.ToolbarLabel;
	MakeStyleGradient(buf, &r, pSI, pSI->bordered);
	r.left  += 3;
	r.right -= 3;
	SetTextColor(buf, mStyle.ToolbarLabel.TextColor);
	BBDrawText(buf, Toolbar_WorkspaceName, -1, &r, justify, pSI);

	// Paint window label background...
	r.right = (r.left = tbWinLabelX) + tbWinLabelW;
	pSI = &mStyle.ToolbarWindowLabel;
	MakeStyleGradient(buf, &r, pSI, pSI->bordered);
	r.left  += 3;
	r.right -= 3;
	SetTextColor(buf, mStyle.ToolbarWindowLabel.TextColor);
	BBDrawText(buf, label, -1, &r, justify, pSI);

	// Paint clock background...
	r.right = (r.left = tbClockX) + tbClockW;
	pSI = &mStyle.ToolbarClock;
	MakeStyleGradient(buf, &r, pSI, pSI->bordered);
	r.left  += 3;
	r.right -= 3;
	SetTextColor(buf, mStyle.ToolbarClock.TextColor);
	BBDrawText(buf, Toolbar_CurrentTime, -1, &r, justify, pSI);

	//====================

	BitBltRect(hdc, buf, rcPaint);

	SelectObject(buf, other_font);
	DeleteObject(SelectObject(buf, bufother));
	DeleteDC(buf);
}
Example #14
0
//================================================================================================
// --------------------------------------------------+++--> Message Processor for Stopwatch Dialog:
static INT_PTR CALLBACK Window_Stopwatch(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)   //------+++-->
{
	switch(msg) {
	case WM_INITDIALOG:
		OnInit(hwnd);
		api.PositionWindow(hwnd,21);
		return TRUE;
	case WM_DESTROY:{
		// save pos & size
		RECT rc; GetWindowRect(hwnd,&rc);
		rc.bottom = rc.bottom-rc.top;
		if(rc.bottom != m_rezCY){
			api.SetInt(L"Timers", L"SwSize", rc.bottom);
		}else{
			api.DelValue(L"Timers", L"SwSize");
		}
		// cleaup elapsed font
		{HFONT hfont = (HFONT)SendDlgItemMessage(hwnd, IDC_SW_ELAPSED, WM_GETFONT, 0, 0);
		SendDlgItemMessage(hwnd, IDC_SW_ELAPSED, WM_SETFONT, 0, 0);
		DeleteObject(hfont);
		// cleanup button font
		hfont = (HFONT)SendDlgItemMessage(hwnd, IDC_SW_START, WM_GETFONT, 0, 0);
		SendDlgItemMessage(hwnd, IDC_SW_START, WM_SETFONT,0,0);
		SendDlgItemMessage(hwnd, IDC_SW_RESET, WM_SETFONT,0,0);
		DeleteObject(hfont);}
		break;}
	/// handling
	case WM_ACTIVATE:
		if(LOWORD(wParam)==WA_ACTIVE || LOWORD(wParam)==WA_CLICKACTIVE){
			SetWindowPos(hwnd,HWND_TOPMOST_nowarn,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
		}else{
			SetWindowPos(hwnd,HWND_NOTOPMOST_nowarn,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
			// actually it should be lParam, but that's "always" NULL for other process' windows
			SetWindowPos(GetForegroundWindow(),HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
		}
		break;
	case WM_CTLCOLORSTATIC:
		if((HWND)lParam!=GetDlgItem(hwnd,IDC_SW_ELAPSED))
			break;
		SetTextColor((HDC)wParam,0x00000000);
		SetBkColor((HDC)wParam,0x00FFFFFF);
		SetBkMode((HDC)wParam, TRANSPARENT);
		return (INT_PTR)GetStockObject(WHITE_BRUSH);
	/// resizing
	case WM_WINDOWPOSCHANGING:{
		WINDOWPOS* info=(WINDOWPOS*)lParam;
		if(!(info->flags&SWP_NOSIZE)){
			if(info->cx!=m_rezCX || info->cy<m_rezCY){
				RECT rc; GetWindowRect(hwnd,&rc);
				if(info->cx!=m_rezCX){
					info->cx=m_rezCX;
					info->x=rc.left;
				}
				if(info->cy<m_rezCY){
					info->cy=m_rezCY;
					info->y=rc.top;
				}
			}
		}
		return TRUE;}
	case WM_WINDOWPOSCHANGED:{
		WINDOWPOS* info=(WINDOWPOS*)lParam;
		if(!(info->flags&SWP_NOSIZE)){
			int diff=info->cy-m_rezCY;
			int idx;
			for(idx=IDC_SW_START; idx<=IDC_SW_EXPORT; ++idx){
				HWND control = GetDlgItem(hwnd, idx);
				RECT rc; GetWindowRect(control, &rc);
				ScreenToClient(hwnd, (POINT*)&rc);
				SetWindowPos(control, HWND_TOP, rc.left, m_rezYcontrols+diff, 0, 0, (SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER));
			}
			SetWindowPos(GetDlgItem(hwnd,IDC_SW_LAPS), HWND_TOP, 0, 0, m_rezCXlist, m_rezCYlist+diff, (SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER));
		}
		return TRUE;}
	/// user interaction
	case WM_TIMER:
		if(!m_paused)
			OnTimer(hwnd);
		return TRUE;
	case WM_COMMAND: {
			WORD id = LOWORD(wParam);
			switch(id) {
			case IDC_SW_START: // Start/Stop
				StopWatch_TogglePause(hwnd);
				break;
			case IDC_SW_RESET:
				StopWatch_Reset(hwnd);
				break;
			case IDC_SW_EXPORT:
				DialogBox(0, MAKEINTRESOURCE(IDD_STOPWATCH_EXPORT), hwnd, Window_StopwatchExportDlg);
				break;
			case IDC_SW_LAP:
				StopWatch_Lap(hwnd,0);
				break;
			case IDCANCEL:
				KillTimer(hwnd, 1);
				g_hDlgStopWatch = NULL;
				DestroyWindow(hwnd);
			}
			return TRUE;
		}
	}
	return FALSE;
}
Example #15
0
// static
LRESULT CALLBACK IGraphicsWin::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg == WM_CREATE)
  {
    LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
    SetWindowLongPtr(hWnd, GWLP_USERDATA, (LPARAM) (lpcs->lpCreateParams));
    int mSec = int(1000.0 / sFPS);
    SetTimer(hWnd, IPLUG_TIMER_ID, mSec, NULL);
    SetFocus(hWnd); // gets scroll wheel working straight away
    return 0;
  }

  IGraphicsWin* pGraphics = (IGraphicsWin*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
  char txt[MAX_PARAM_LEN];
  double v;

  if (!pGraphics || hWnd != pGraphics->mPlugWnd)
  {
    return DefWindowProc(hWnd, msg, wParam, lParam);
  }
  if (pGraphics->mParamEditWnd && pGraphics->mParamEditMsg == kEditing)
  {
    if (msg == WM_RBUTTONDOWN || (msg == WM_LBUTTONDOWN))
    {
      pGraphics->mParamEditMsg = kCancel;
      return 0;
    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
  }

  switch (msg)
  {

    case WM_TIMER:
    {
      if (wParam == IPLUG_TIMER_ID)
      {

        if (pGraphics->mParamEditWnd && pGraphics->mParamEditMsg != kNone)
        {
          switch (pGraphics->mParamEditMsg)
          {
            case kCommit:
            {
              SendMessage(pGraphics->mParamEditWnd, WM_GETTEXT, MAX_PARAM_LEN, (LPARAM) txt);

              if(pGraphics->mEdParam)
              {
                IParam::EParamType type = pGraphics->mEdParam->Type();

                if ( type == IParam::kTypeEnum || type == IParam::kTypeBool)
                {
                  int vi = 0;
                  pGraphics->mEdParam->MapDisplayText(txt, &vi);
                  v = (double) vi;
                }
                else
                {
                  v = atof(txt);
                  if (pGraphics->mEdParam->DisplayIsNegated())
                  {
                    v = -v;
                  }
                }
                pGraphics->mEdControl->SetValueFromUserInput(pGraphics->mEdParam->GetNormalized(v));
              }
              else
              {
                pGraphics->mEdControl->TextFromTextEntry(txt);
              }
              // Fall through.
            }
            case kCancel:
            {
              SetWindowLongPtr(pGraphics->mParamEditWnd, GWLP_WNDPROC, (LPARAM) pGraphics->mDefEditProc);
              DestroyWindow(pGraphics->mParamEditWnd);
              pGraphics->mParamEditWnd = 0;
              pGraphics->mEdParam = 0;
              pGraphics->mEdControl = 0;
              pGraphics->mDefEditProc = 0;
            }
            break;
          }
          pGraphics->mParamEditMsg = kNone;
          return 0; // TODO: check this!
        }

        IRECT dirtyR;
        if (pGraphics->IsDirty(&dirtyR))
        {
          RECT r = { dirtyR.L, dirtyR.T, dirtyR.R, dirtyR.B };

          InvalidateRect(hWnd, &r, FALSE);

          if (pGraphics->mParamEditWnd)
          {
            IRECT* notDirtyR = pGraphics->mEdControl->GetRECT();
            RECT r2 = { notDirtyR->L, notDirtyR->T, notDirtyR->R, notDirtyR->B };
            ValidateRect(hWnd, &r2); // make sure we dont redraw the edit box area
            UpdateWindow(hWnd);
            pGraphics->mParamEditMsg = kUpdate;
          }
          else
          {
            UpdateWindow(hWnd);
          }
        }
      }
      return 0;
    }

    case WM_RBUTTONDOWN:
    case WM_LBUTTONDOWN:
    case WM_MBUTTONDOWN:
      pGraphics->HideTooltip();
      if (pGraphics->mParamEditWnd)
      {
        pGraphics->mParamEditMsg = kCommit;
        return 0;
      }
      SetFocus(hWnd); // Added to get keyboard focus again when user clicks in window
      SetCapture(hWnd);
#ifdef RTAS_API
      // pass ctrl-start-alt-click or ctrl-start-click to host window (Pro Tools)
      if ((IsControlKeyDown() && IsOptionKeyDown() && IsCommandKeyDown() ) || (IsControlKeyDown() && IsCommandKeyDown()))
      {
        HWND rootHWnd = GetAncestor( hWnd, GA_ROOT);

        union point
        {
          long lp;
          struct
          {
            short x;
            short y;
          } s;
        } mousePoint;

        // Get global coordinates of local window
        RECT childRect;
        GetWindowRect(hWnd, &childRect);

        // Convert global coords to parent window coords
        POINT p;
        p.x = childRect.left;
        p.y = childRect.top;

        ScreenToClient(rootHWnd, &p);

        // offset the local click-event coordinates to the parent window's values
        mousePoint.lp = lParam;
        mousePoint.s.x += p.x;
        mousePoint.s.y += p.y;

        if( pGraphics->GetParamIdxForPTAutomation(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)) > -1)
        {
          // Send converted coords to parent window's event handler for regular processing
          LRESULT result = SendMessage(rootHWnd, msg, wParam, mousePoint.lp);
        }

        return 0;
      }
#endif
      pGraphics->OnMouseDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &GetMouseMod(wParam));
      return 0;

    case WM_MOUSEMOVE:
    {
      if (!(wParam & (MK_LBUTTON | MK_RBUTTON)))
      {
        if (pGraphics->OnMouseOver(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &GetMouseMod(wParam)))
        {
          TRACKMOUSEEVENT eventTrack = { sizeof(TRACKMOUSEEVENT), TME_LEAVE, hWnd, HOVER_DEFAULT };
          if (pGraphics->TooltipsEnabled()) 
          {
            int c = pGraphics->GetMouseOver();
            if (c != pGraphics->mTooltipIdx) 
            {
              if (c >= 0) eventTrack.dwFlags |= TME_HOVER;
              pGraphics->mTooltipIdx = c;
              pGraphics->HideTooltip();
            }
          }

          TrackMouseEvent(&eventTrack);
        }
      }
      else if (GetCapture() == hWnd && !pGraphics->mParamEditWnd)
      {
        pGraphics->OnMouseDrag(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &GetMouseMod(wParam));
      }

      return 0;
    }
    case WM_MOUSEHOVER: 
    {
      pGraphics->ShowTooltip();
		  return 0;
    }
    case WM_MOUSELEAVE:
    {
      pGraphics->HideTooltip();
      pGraphics->OnMouseOut();
      return 0;
    }
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
    {
      ReleaseCapture();
      pGraphics->OnMouseUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &GetMouseMod(wParam));
      return 0;
    }
    case WM_LBUTTONDBLCLK:
    {
      if (pGraphics->OnMouseDblClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &GetMouseMod(wParam)))
      {
        SetCapture(hWnd);
      }
      return 0;
    }
    case WM_MOUSEWHEEL:
    {

      if (pGraphics->mParamEditWnd)
      {
        pGraphics->mParamEditMsg = kCancel;
        return 0;
      }
      else
      {
        int d = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
        int x = GET_X_LPARAM(lParam), y = GET_Y_LPARAM(lParam);
        RECT r;
        GetWindowRect(hWnd, &r);
        pGraphics->OnMouseWheel(x - r.left, y - r.top, &GetMouseMod(wParam), d);
        return 0;
      }
    }

    case WM_KEYDOWN:
    {
      bool handle = true;
      int key;

      if (wParam == VK_SPACE) key = KEY_SPACE;
      else if (wParam == VK_UP) key = KEY_UPARROW;
      else if (wParam == VK_DOWN) key = KEY_DOWNARROW;
      else if (wParam == VK_LEFT) key = KEY_LEFTARROW;
      else if (wParam == VK_RIGHT) key = KEY_RIGHTARROW;
      else if (wParam >= '0' && wParam <= '9') key = KEY_DIGIT_0+wParam-'0';
      else if (wParam >= 'A' && wParam <= 'Z') key = KEY_ALPHA_A+wParam-'A';
      else if (wParam >= 'a' && wParam <= 'z') key = KEY_ALPHA_A+wParam-'a';
      else handle = false;

      if (handle)
      {
        POINT p;
        GetCursorPos(&p);
        ScreenToClient(hWnd, &p);
        handle = pGraphics->OnKeyDown(p.x, p.y, key);
      }

      if (!handle)
      {
        HWND rootHWnd = GetAncestor( hWnd, GA_ROOT);
        SendMessage(rootHWnd, WM_KEYDOWN, wParam, lParam);
        return DefWindowProc(hWnd, msg, wParam, lParam);
      }
      else
        return 0;
    }
    case WM_KEYUP:
    {
      HWND rootHWnd = GetAncestor(hWnd, GA_ROOT);
      SendMessage(rootHWnd, msg, wParam, lParam);
      return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    case WM_PAINT:
    {
      RECT r;
      if (GetUpdateRect(hWnd, &r, FALSE))
      {
        IRECT ir(r.left, r.top, r.right, r.bottom);
        pGraphics->Draw(&ir);
      }
      return 0;
    }

    case WM_CTLCOLOREDIT:
    {

      if(!pGraphics->mEdControl)
        return 0;

      IText* pText = pGraphics->mEdControl->GetText();
      HDC dc = (HDC) wParam;
      SetBkColor(dc, RGB(pText->mTextEntryBGColor.R, pText->mTextEntryBGColor.G, pText->mTextEntryBGColor.B));
      SetTextColor(dc, RGB(pText->mTextEntryFGColor.R, pText->mTextEntryFGColor.G, pText->mTextEntryFGColor.B));
      SetBkMode(dc, OPAQUE);
      return (BOOL)GetStockObject(DC_BRUSH);
    }

    case WM_CLOSE:
    {
      pGraphics->CloseWindow();
      return 0;
    }
#ifdef RTAS_API
    case WM_MEASUREITEM :
    {
      HWND rootHWnd =  GetAncestor( hWnd, GA_ROOT );
      LRESULT result = SendMessage(rootHWnd, msg, wParam, lParam);
      return result;
    }
    case WM_DRAWITEM :
    {
      HWND rootHWnd =  GetAncestor( hWnd, GA_ROOT );
      LRESULT result = SendMessage(rootHWnd, msg, wParam, lParam);
      return result;
    }
#endif
    case WM_SETFOCUS:
    {
      return 0;
    }
    case WM_KILLFOCUS:
    {
      return 0;
    }
  }
  return DefWindowProc(hWnd, msg, wParam, lParam);
}
Example #16
0
static LRESULT MDescButton_OnPaint(HWND hwndDlg, MDescButtonCtrl *dat)
{
	PAINTSTRUCT ps;
	HDC hdc = BeginPaint(hwndDlg, &ps);
	HDC tempDC = CreateCompatibleDC(hdc);

	SIZE titleSize = { 0 };

	HBITMAP hBmp = CreateCompatibleBitmap(hdc, dat->width, dat->height);
	HBITMAP hOldBmp = (HBITMAP)SelectObject(tempDC, hBmp);

	RECT temprc;
	temprc.left = 0;
	temprc.right = dat->width;
	temprc.top = 0;

	// Draw background
	if (dat->bMouseInside || (GetFocus() == hwndDlg)) {
		MDescButton_FillRect(tempDC, 0, 0, dat->width, dat->height, dat->clSelBorder);
		MDescButton_DrawGradient(tempDC, 1, 1, dat->width - 2, dat->height - 2, &dat->rgbSelTop, &dat->rgbSelBottom);
		SetTextColor(tempDC, dat->clSelText);
	}
	else {
		MDescButton_FillRect(tempDC, 0, 0, dat->width, dat->height, dat->clBackground);
		SetTextColor(tempDC, dat->clText);
	}

	if (dat->hIcon)
		DrawIcon(tempDC, DBC_BORDER_SIZE, DBC_BORDER_SIZE, dat->hIcon);

	HFONT hfntSave = (HFONT)SelectObject(tempDC, dat->hFont);
	SetBkMode(tempDC, TRANSPARENT);

	if (dat->lpzTitle) {
		LOGFONT lf;
		GetObject(dat->hFont, sizeof(lf), &lf);
		lf.lfWeight = FW_BOLD;
		lf.lfHeight *= 1.5;
		HFONT hOldFont = (HFONT)SelectObject(tempDC, CreateFontIndirect(&lf));

		RECT textRect;
		textRect.left = DBC_BORDER_SIZE + (dat->hIcon ? 32 + DBC_VSPACING : 0);
		textRect.right = dat->width - DBC_BORDER_SIZE;
		textRect.top = DBC_BORDER_SIZE;
		textRect.bottom = dat->height - DBC_BORDER_SIZE;
		DrawText(tempDC, dat->lpzTitle, -1, &textRect, DT_TOP | DT_LEFT | DT_END_ELLIPSIS);
		GetTextExtentPoint32(tempDC, dat->lpzTitle, (int)mir_tstrlen(dat->lpzTitle), &titleSize);

		DeleteObject(SelectObject(tempDC, hOldFont));
	}

	if (dat->lpzDescription) {
		RECT textRect;
		textRect.left = DBC_BORDER_SIZE + (dat->hIcon ? 32 + DBC_VSPACING : 0);
		textRect.right = dat->width - DBC_BORDER_SIZE;
		textRect.top = DBC_BORDER_SIZE + titleSize.cy ? titleSize.cy + DBC_HSPACING : 0;
		textRect.bottom = dat->height - DBC_BORDER_SIZE;
		DrawText(tempDC, dat->lpzDescription, -1, &textRect, DT_TOP | DT_LEFT | DT_WORDBREAK | DT_END_ELLIPSIS);
		GetTextExtentPoint32(tempDC, dat->lpzTitle, (int)mir_tstrlen(dat->lpzTitle), &titleSize);
	}

	SelectObject(tempDC, hfntSave);

	//Copy to output
	BitBlt(hdc, dat->rc.left, dat->rc.top, dat->width, dat->height, tempDC, 0, 0, SRCCOPY);
	SelectObject(tempDC, hOldBmp);
	DeleteObject(hBmp);
	DeleteDC(tempDC);
	EndPaint(hwndDlg, &ps);

	return TRUE;
}
Example #17
0
LRESULT CLogListBox::OnDrawitem(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
	LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT) lParam;
	if(!dis) return FALSE;
      
	LogListBoxItem * item = (LogListBoxItem *)dis->itemData;
	if(!item) return FALSE;
	
   CDCHandle dc = dis->hDC;

   if(dis->itemAction & (ODA_DRAWENTIRE|ODA_SELECT))
   {
		dc.SetBkColor(GetSysColor(COLOR_WINDOW));
		dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
      CRect r(dis->rcItem);
		if(!(dis->itemState & ODS_SELECTED ))
		{
			CBrush br;
			br.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
			dc.FillRect(r,br);
		}
		CRect rct;
      GetClientRect(&rct);

		if(dis->itemState & ODS_SELECTED )
		{
			CRect rd(dis->rcItem);
			GuiTools::FillRectGradient(dis->hDC,rd,0xEAE2D9, 0xD3C1AF, false);
		}
		else if(dis->itemID != GetCount()-1) // If it isn't last item
		{
			CPen pen;
			pen.CreatePen(PS_SOLID, 1, RGB(190,190,190));
			SelectObject(dc.m_hDC, pen);
			dc.MoveTo(rct.left, r.bottom-1);
			dc.LineTo(rct.right, r.bottom-1);
		}
			  
		SetBkMode(dc.m_hDC,TRANSPARENT);

		SIZE TimeLabelDimensions;
		SelectObject(dc.m_hDC, NormalFont);
		GetTextExtentPoint32(dc, item->Time, item->Time.GetLength(), &TimeLabelDimensions);
		
		// Writing error time
		
		ExtTextOutW(dc.m_hDC, rct.right-5-TimeLabelDimensions.cx, r.top + LLB_VertMargin, ETO_CLIPPED, r, item->Time, item->Time.GetLength(), 0);
		// Writing error title
		SelectObject(dc.m_hDC, UnderlineFont);
		ExtTextOutW(dc.m_hDC, r.left+56, r.top + LLB_VertMargin, ETO_CLIPPED, r, item->strTitle, wcslen(item->strTitle), 0);
		
		// Writing some info
		SelectObject(dc.m_hDC, NormalFont);
		RECT ItemRect={r.left+56, r.top + LLB_VertMargin + LLB_VertDivider + item->TitleHeight, 
							r.right - 10, r.bottom-LLB_VertMargin};
		dc.DrawText(item->Info, item->Info.GetLength() , &ItemRect, DT_NOPREFIX);
			
		// Writing error text with bold (explication of error)
		SelectObject(dc.m_hDC, BoldFont);
		RECT TextRect = {r.left+56, LLB_VertMargin +r.top+ item->TitleHeight+LLB_VertDivider+((item->Info.GetLength())?(item->InfoHeight+LLB_VertDivider):0), r.right - 10, r.bottom-LLB_VertMargin};
		dc.DrawText(item->strText,  wcslen(item->strText), &TextRect, DT_NOPREFIX);

		if(item->Type == logError)
			dc.DrawIcon(12,r.top+8,ErrorIcon);
		else if(item->Type == logWarning)
			dc.DrawIcon(12,r.top+8,WarningIcon);
	}
  
	bHandled = true;
	return 0;
}
Example #18
0
/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND checks[10];
    static int  IDs[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int x = 400,y = 500;
    static HDC hdcCat1, hdcCat2;

    static BITMAP bitmapCat1, bitmapCat2;
    static HBITMAP hbmpImg1 = NULL ;
    static HBITMAP hbmpImg2 = NULL;

    static HFONT font_forte, text_font, font_forte1, text_font1;;
    static RECT area  = {400, 80, 707, 470};
    static RECT write = {45, 501, 282, 522};

    PAINTSTRUCT Ps;
    HDC hdc = GetDC(hwnd);
    HBRUSH hbrush;


    static RECT diff[30];
    char* current_img = Images[random];
    char* current_story = Story[random];
    char str[15];

    if(toRender)
    {
       sprintf(str,"%s1.bmp",current_img);
    // load bitmaps
    hbmpImg1 = (HBITMAP)LoadImage(hInst, str, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hbmpImg1, sizeof(bitmapCat1), &bitmapCat1);

    sprintf(str,"%s2.bmp",current_img);
    hbmpImg2 = (HBITMAP)LoadImage(hInst, str, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hbmpImg2, sizeof(bitmapCat2), &bitmapCat2);
    toRender = false;
    }


    //Static variables for mouse Coordinates
    static int xMouse, yMouse;
	xMouse = GET_X_LPARAM(lParam);
	yMouse = GET_Y_LPARAM(lParam);



    //Coordinates of the differences
    diff[0] = {508,122,569,165};
    diff[1] = {511,161,568,180};  //sprincene
    diff[2] = {540, 197, 560, 217 };//ochi
    diff[3] = {583, 228, 614, 245};//mustata dreapta
    diff[4] = {645, 328, 685, 348};//coada
    diff[5] = {586, 292, 630, 327};//fluture
    diff[6] = {498, 359, 526, 388};//hand
    diff[7] = {520, 289, 557, 305};//piept
    diff[8] = {540, 390, 550, 400 };//flowerbottom
    diff[9] = {450, 310, 470, 330};//left

    diff[10] = {467, 155 , 489, 190 }; //acc
    diff[11] =  {503, 175,522, 192 } ;// paplivoc
    diff[12] = {521,123, 558, 155};// circioc
    diff[13] = {578, 140, 600, 163 }; //circioc dreapta
    diff[14] = {630,290, 653, 312}; //mina
    diff[15] = {471, 444,495, 464 };//ass
    diff[16] = {429, 292, 468, 325};//mp3
    diff[17] = {464, 265,481, 279 };//sunnglass
    diff[18] = {478, 305,494, 316 };//bunghi linga mp3
    diff[19] = {585, 400, 608, 419}; //bumb picior dreapta

    diff[20] ={416, 100, 494, 128};//nour stinga
    diff[21] ={619, 124, 638, 137}; //nour dreapta
    diff[22] ={678, 109, 700, 124 }; //sun
    diff[23] ={534, 207, 565, 245}; //wolf hands
    diff[24] ={637, 202,655, 215}; //barba
    diff[25] ={595, 405, 615, 417}; //picior Wolf
    diff[26] ={514,399,531,409 };//picior fetita
    diff[27] ={511,344, 526, 360 }; //fata jacketa
    diff[28] ={400,325,455,353};//deal
    diff[29] ={425,351,446,368};//floare



    switch (message)                  /* handle the messages */
    {
    case WM_GETMINMAXINFO:
        {
            LPMINMAXINFO pInfo = (LPMINMAXINFO)lParam;
            pInfo -> ptMaxTrackSize.x = 750;
            pInfo -> ptMaxTrackSize.y = 700;

            pInfo -> ptMinTrackSize.x= 750;
            pInfo -> ptMinTrackSize.y = 700;
        }
    break;

    case WM_COMMAND:
        {
        switch(LOWORD(wParam))
            {
             case IDI_EXIT:      //Exit Coammand
                {
                    PostQuitMessage (0);
                break;
                }

            case IDI_NEW:
                {
                    toRender  = true;
                    InvalidateRect(hwnd, &area, FALSE);
                    InvalidateRect(hwnd, &area, TRUE);

                    InvalidateRect(hwnd, &write, FALSE);
                    InvalidateRect(hwnd, &write, TRUE);
                    random = GetRandom(3);
                    for (int i=0; i<11; i++)
                    {
                        CheckDlgButton(hwnd, IDs[i], BST_UNCHECKED);
                    }
                break;
                }

            case IDI_ABOUT:
                {
                    DialogBox(hInst, MAKEINTRESOURCE(IDI_DIALOG), hwnd, AboutDlgProc);
                break;
                }

            case IDI_RULE:
                {
                    DialogBox(hInst, MAKEINTRESOURCE(IDI_DIALOG_RULE), hwnd, AboutDlgProc);
                break;
                }
            }
        break;
        }
    break;

    case WM_CREATE:
        {
           for(int i=0; i<sizeof(checks)/sizeof(HWND); i++)
            {
                checks[i] = CreateWindow(TEXT("button"), TEXT(""),
                        WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
                        x, 500, 12, 12,
                        hwnd, (HMENU) IDs[i], hInst, NULL);
                x+=33;
            }
       break;
        }

    //Work with LButton
    case WM_LBUTTONDOWN:
        {
            if(random == 0)
            {
                coeficient = 3 ;
            }
            if(random == 1)
                coeficient = 1.5;
            if(random == 2)
                coeficient = 1;

            for (int i = 0+ random * 10; i < (sizeof(diff)/sizeof(diff[0]))/coeficient  ; i++)
            {
                if(diff[i].left < xMouse && xMouse < diff[i].right && diff[i].top < yMouse && yMouse < diff[i].bottom )
                {
                    if(coeficient == 3)
                    PlaySound("Meow.wav", NULL, SND_ASYNC);
                    if(coeficient == 1.5)
                    PlaySound("goofy.wav", NULL, SND_ASYNC);
                    if(coeficient == 1)
                    PlaySound("Wolf.wav", NULL, SND_ASYNC);

                    DrawEdge(hdc, &diff[i], BDR_RAISEDOUTER | BDR_SUNKENINNER, BF_RECT);
                    CheckDlgButton(hwnd, IDs[i], BST_CHECKED);
                    nr_differences ++;
                    CheckDlgButton(hwnd, IDs[i - + (random * 10)], BST_CHECKED);
                   // MessageBoxA(NULL,"You found it! Good Job", "Congrats", MB_OK | MB_ICONINFORMATION);

                        if (nr_differences == 10)
                        {
                            PlaySound("Level.wav", NULL, SND_ASYNC);
                            MessageBoxA(NULL,"You won! Go to File->New game", "Congrats", MB_OK | MB_ICONINFORMATION);
                        }
                    notFound = false;
                }
            }
            if(notFound)
                PlaySound("FailSound.wav", NULL, SND_ASYNC);
            notFound = true;
        }
    break;

    case WM_LBUTTONDBLCLK:
        {
                     char str [256];
                    POINT pt;
                    pt.x = LOWORD(lParam);
                    pt.y = HIWORD(lParam);

                     wsprintf(str, "Co-ordinates are \nX=%i and Y=%i", pt.x, pt.y);
                    MessageBoxA(NULL,str, "Message", MB_OK | MB_ICONINFORMATION);
        }
    break;

    case WM_PAINT:
        {
            BeginPaint(hwnd, &Ps);

            hdcCat1 = CreateCompatibleDC(hdc);
            SelectObject(hdcCat1, hbmpImg1);
            BitBlt(hdc, 37, 80, bitmapCat1.bmWidth, bitmapCat1.bmHeight, hdcCat1, 0, 0, SRCCOPY);
            DeleteObject(hdcCat1);

            hdcCat2 = CreateCompatibleDC(hdc);
            SelectObject(hdcCat2, hbmpImg2);
            BitBlt(hdc, 400, 80, bitmapCat2.bmWidth, bitmapCat2.bmHeight, hdcCat2, 0, 0, SRCCOPY);
            DeleteObject(hdcCat2);

            // create the title
            font_forte   = CreateFont(30, 27.5, 0, 0, FW_DONTCARE, false, false, false,
                              DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                              DEFAULT_QUALITY, FF_DONTCARE, "Forte");
            font_forte1  = CreateFont(0, 0, 0, 0, FW_DONTCARE, false, false, false,
                              DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                              DEFAULT_QUALITY, FF_DONTCARE, "Forte");

            text_font  = (HFONT)SelectObject(hdc, font_forte);   // setting new font for text
            SetTextColor(hdc, TITLE_COLOR);                     // setting new text color
            TextOut( hdc, 115, 20,  "Find the difference", 19);

            text_font1  = (HFONT)SelectObject(hdc, font_forte1);
            TextOut(hdc, 45, 501, current_story, 42);
            TextOut(hdc, 45, 520, "And have changed, it needs your ", 32);
            TextOut(hdc, 45, 539, "help to find differences!", 25);

            DeleteObject(font_forte);
            DeleteObject(text_font);
            DeleteObject(font_forte1);
            DeleteObject(text_font1);

            EndPaint(hwnd, &Ps);

        }
    break;

    case WM_CTLCOLORSTATIC:
        {
            SetBkMode((HDC)wParam,TRANSPARENT);                                // transparent background
            hbrush=(HBRUSH)GetStockObject(NULL_BRUSH);                         // handle to brush, no background color
            return(LRESULT) hbrush;
        }
    break;

    case WM_DESTROY:
        {
            DeleteFont(font_forte);
            DeleteFont(text_font);
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        }
    break;
   // InvalidateRect(hwnd, &all_area, FALSE);


        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
Example #19
0
static void Paint(HWND hWnd, LPPAINTSTRUCT lpPS) {

    GetClientRect(hWnd, &rc);

    hdcMem = CreateCompatibleDC(lpPS->hdc);
    hbmMem = CreateCompatibleBitmap(lpPS->hdc, rc.right-rc.left, rc.bottom-rc.top);
    hbmOld = (HBITMAP) SelectObject(hdcMem, hbmMem);
    hbrBkGnd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));

    FillRect(hdcMem, &rc, hbrBkGnd);

    for(int i = 0; i < vectorSize; i++){
        x = vec[i].getX();
        y = vec[i].getY();
        hbrBkGnd = CreateSolidBrush(RGB(vec[i].getR(), vec[i].getG(), vec[i].getB()));
        SelectObject(hdcMem, hbrBkGnd);


        for(int j = 0; j < vectorSize; j++){
            if(j != i){
                if(vec[i].trueCollision(vec[j].getX(), vec[j].getY())){
                    vec[i].setColor(rand()%250, rand()%250, rand()%250);
                    vec[j].setColor(rand()%250, rand()%250, rand()%250);

                }
            }
        }

        vec[i].collision(rect.right, rect.bottom);


        switch(vec[i].getDir()) {
            case 0:
                x += vec[i].getVelocity() + velocity;
                y += vec[i].getVelocity() + velocity;
                break;
            case 1:
                x -= vec[i].getVelocity() + velocity;
                y += vec[i].getVelocity() + velocity;
                break;
            case 2:
                x += vec[i].getVelocity() + velocity;
                y -= vec[i].getVelocity() + velocity;
                break;
            case 3:
                x -= vec[i].getVelocity() + velocity;
                y -= vec[i].getVelocity() + velocity;
                break;
        }

        vec[i].setPosition(x, y);
        if(vec[i].trueCircle()){
            Ellipse(hdcMem, vec[i].getX(), vec[i].getY(), vec[i].getX() + vec[i].getWidth(),
                    vec[i].getY() + vec[i].getHeight());
        }else{
            Rectangle(hdcMem, vec[i].getX(), vec[i].getY(), vec[i].getX() + vec[i].getWidth(),
                      vec[i].getY() + vec[i].getHeight());
        }
    }
    DeleteObject(hbrBkGnd);
    SetBkMode(hdcMem, BACKGROUND_BLUE);
    SetTextColor(hdcMem, GetSysColor(COLOR_WINDOWTEXT));


    if (hfntOld) {
        SelectObject(hdcMem, hfntOld);
    }

    BitBlt(lpPS->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdcMem, 0, 0, SRCCOPY);

    SelectObject(hdcMem, hbmOld);
    DeleteObject(hbmMem);
    DeleteDC(hdcMem);

}
Example #20
0
//Basic Init, create the font, backbuffer, etc
WINDOW *initscr(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    BITMAPINFO bmi;
    lastchar=-1;
    inputdelay=-1;
    std::string typeface;
char * typeface_c;
std::ifstream fin;
fin.open("data\\FONTDATA");
 if (!fin.is_open()){
     MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.",
                NULL, NULL);
     fontheight=16;
     fontwidth=8;
 } else {
     getline(fin, typeface);
     typeface_c= new char [typeface.size()+1];
     strcpy (typeface_c, typeface.c_str());
     fin >> fontwidth;
     fin >> fontheight;
     if ((fontwidth <= 4) || (fontheight <=4)){
         MessageBox(WindowHandle, "Invalid font size specified!",
                    NULL, NULL);
        fontheight=16;
        fontwidth=8;
     }
 }
    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS[OPT_VIEWPORT_X] * 2 + 1)) * fontwidth;
    WindowHeight= (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1) *fontheight;
    WindowX=(GetSystemMetrics(SM_CXSCREEN) / 2)-WindowWidth/2;    //center this
    WindowY=(GetSystemMetrics(SM_CYSCREEN) / 2)-WindowHeight/2;   //sucker
    WinCreate();    //Create the actual window, register it, etc
    CheckMessages();    //Let the message queue handle setting up the window
    WindowDC = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);
    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = WindowWidth;
    bmi.bmiHeader.biHeight = -WindowHeight;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount=8;
    bmi.bmiHeader.biCompression = BI_RGB;   //store it in uncompressed bytes
    bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed=16;         //the number of colors in our palette
    bmi.bmiHeader.biClrImportant=16;    //the number of colors in our palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

 int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
   if (nResults>0){
    font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, typeface_c);   //Create our font

  } else {
      MessageBox(WindowHandle, "Failed to load default font, using FixedSys.",
                NULL, NULL);
       font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, "FixedSys");   //Create our font
   }
    //FixedSys will be user-changable at some point in time??
    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS[OPT_VIEWPORT_Y] * 2 + 1),(55 + (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
};
Example #21
0
void CDrawCheckbox::Draw(HDC hDC)
{
    RECT rcWnd = {};
    GetClientRect(m_hWnd, &rcWnd);
    int nWidth = rcWnd.right - rcWnd.left;
    int nHeight = rcWnd.bottom - rcWnd.top;

    HDC hMemDC = CreateCompatibleDC(hDC);
    HBITMAP hBmpMem = CreateCompatibleBitmap(hDC, nWidth, nHeight);
    HBITMAP hOldBmpMem = (HBITMAP)SelectObject(hMemDC, hBmpMem);

    Image *pDrawImg = NULL;
    if(!m_fLight)
    {
        pDrawImg = m_pNormalStateImg;
    }
    else
    {
        pDrawImg = m_pLightStateImg;
    }

    int nBmpWidth = pDrawImg->GetWidth();
    int nBmpHeight = pDrawImg->GetHeight();

    if (m_bkimState == BKLS_HORIZONTAL)
    {
        nBmpWidth = pDrawImg->GetWidth() / 8;
        nBmpHeight = pDrawImg->GetHeight();
    }
    else
    {
        nBmpWidth = pDrawImg->GetWidth();
        nBmpHeight = pDrawImg->GetHeight() / 8;
    }

    //绘制父窗口背景图
	BitBlt(hMemDC, 0, 0, nWidth, nHeight, m_DrawBackgroundDC.m_hDC, 0, 0, SRCCOPY);

    //绘制背景图,高宽一样大小
    //StretchBlt(hDC, 0, nYPos, nWidth, nHeight - nYPos, hMemDC, nXBmpPos,\
    //    0, nBmpWidth, nBmpHeight, SRCCOPY);
    SetBkMode(hMemDC, TRANSPARENT);
    Graphics graphics(hMemDC); // Create a GDI+ graphics object
    RectF gRect; 
    gRect.X = (REAL)0;
    gRect.Y = (REAL)0; 
    gRect.Width = (REAL)nHeight; 
    gRect.Height = (REAL)nHeight;

    if (m_bkimState == BKLS_HORIZONTAL)
    {
        graphics.DrawImage(pDrawImg, gRect, (REAL)nBmpWidth * m_nCtrlState + m_bCheck * 4 * nBmpWidth, 0, (REAL)nBmpWidth, (REAL)nBmpHeight, UnitPixel);
    }
    else
    {
        graphics.DrawImage(pDrawImg, gRect, 0, (REAL)nBmpHeight * m_nCtrlState + m_bCheck * 4 * nBmpWidth, (REAL)nBmpWidth, (REAL)nBmpHeight, UnitPixel);
    }

    //  绘制文本
    //  当前绘制文本为单行,若绘制多行,可修改一下源码
    TCHAR szCaption[g_nCaptionLen] = {};
    GetWindowText(m_hWnd, szCaption, g_nCaptionLen - 1);
    if(_tcslen(szCaption) > 0)
	{
		HFONT hOldFont = (HFONT)SelectObject(hMemDC, m_hFont);
		rcWnd.left += nHeight + 2;
		rcWnd.top ++;
		SetTextColor(hMemDC, m_colorText);
		DrawText(hMemDC, szCaption, _tcslen(szCaption), &rcWnd, DT_VCENTER|DT_SINGLELINE);
		SelectObject(hMemDC, hOldFont);
	}

	BitBlt(hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);

	SetBkMode(hMemDC, OPAQUE);
	graphics.ReleaseHDC(hMemDC);
    SelectObject(hMemDC, hOldBmpMem);
    DeleteObject(hBmpMem);
    DeleteDC(hMemDC);
}
Example #22
0
LRESULT CALLBACK
WndPauseProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	RECT rect;
	TEXTMETRIC tm;
	LPPW lppw;
	int cxChar, cyChar, middle;

	lppw = (LPPW)GetWindowLongPtr(hwnd, 0);

	switch(message) {
		case WM_KEYDOWN:
			if (wParam == VK_RETURN)
				SendMessage(hwnd, WM_COMMAND, lppw->bDefOK ? IDOK : IDCANCEL, 0L);
			else if (wParam == VK_ESCAPE)
				SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
			return 0;
		case WM_COMMAND:
			if ((LOWORD(wParam) == IDCANCEL) || (LOWORD(wParam) == IDOK)) {
				lppw->bPauseCancel = LOWORD(wParam);
				lppw->bPause = FALSE;
				break;
			}
			return 0;
		case WM_SETFOCUS:
			SetFocus(lppw->bDefOK ? lppw->hOK : lppw->hCancel);
			return 0;
		case WM_PAINT: {
			hdc = BeginPaint(hwnd, &ps);
			SelectObject(hdc, GetStockObject(SYSTEM_FONT));
			SetTextAlign(hdc, TA_CENTER);
			GetClientRect(hwnd, &rect);
			SetBkMode(hdc,TRANSPARENT);
			TextOut(hdc, (rect.right + rect.left) / 2, (rect.bottom + rect.top) / 6,
				lppw->Message, strlen(lppw->Message));
			EndPaint(hwnd, &ps);
			return 0;
		}
		case WM_CREATE: {
			int ws_opts = WS_CHILD | WS_TABSTOP;

#ifdef USE_MOUSE
			if (!paused_for_mouse) /* don't show buttons during pausing for mouse or key */
				ws_opts |= WS_VISIBLE;
#endif
			lppw = (LPPW) ((CREATESTRUCT *)lParam)->lpCreateParams;
			SetWindowLongPtr(hwnd, 0, (LONG_PTR)lppw);
			lppw->hWndPause = hwnd;
			hdc = GetDC(hwnd);
			SelectObject(hdc, GetStockObject(SYSTEM_FONT));
			GetTextMetrics(hdc, &tm);
			cxChar = tm.tmAveCharWidth;
			cyChar = tm.tmHeight + tm.tmExternalLeading;
			ReleaseDC(hwnd, hdc);
			middle = ((LPCREATESTRUCT) lParam)->cx / 2;
			lppw->hOK = CreateWindow((LPSTR)"button", (LPSTR)"OK",
					ws_opts | BS_DEFPUSHBUTTON,
					middle - 10 * cxChar, 3 * cyChar,
					8 * cxChar, 7 * cyChar / 4,
					hwnd, (HMENU)IDOK,
					((LPCREATESTRUCT) lParam)->hInstance, NULL);
			lppw->bDefOK = TRUE;
			lppw->hCancel = CreateWindow((LPSTR)"button", (LPSTR)"Cancel",
					ws_opts | BS_PUSHBUTTON,
					middle + 2 * cxChar, 3 * cyChar,
					8 * cxChar, 7 * cyChar / 4,
					hwnd, (HMENU)IDCANCEL,
					((LPCREATESTRUCT) lParam)->hInstance, NULL);
			lppw->lpfnOK = (WNDPROC) GetWindowLongPtr(lppw->hOK, GWLP_WNDPROC);
			SetWindowLongPtr(lppw->hOK, GWLP_WNDPROC, (LONG_PTR)PauseButtonProc);
			lppw->lpfnCancel = (WNDPROC) GetWindowLongPtr(lppw->hCancel, GWLP_WNDPROC);
			SetWindowLongPtr(lppw->hCancel, GWLP_WNDPROC, (LONG_PTR)PauseButtonProc);
			if (GetParent(hwnd))
				EnableWindow(GetParent(hwnd), FALSE);
			return 0;
		}
		case WM_DESTROY:
			GetWindowRect(hwnd, &rect);
			lppw->Origin.x = (rect.right + rect.left) / 2;
			lppw->Origin.y = (rect.bottom + rect.top) / 2;
			lppw->bPause = FALSE;
			if (GetParent(hwnd))
				EnableWindow(GetParent(hwnd), TRUE);
			break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}
Example #23
0
void Graphics::setBkMode(bool transparent)
{
  SetBkMode(m_dc->m_dc, transparent ? TRANSPARENT : OPAQUE);
}
static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint)
{
    if (hdcPaint) {
        HDC hdcMem;
        HBITMAP hbmMem;
        HBITMAP hbmOld = 0;
        RECT rcClient;
        HFONT hOldFont = 0;
        int xOffset = 0;
        
        GetClientRect(ctl->hwnd, &rcClient);
        hdcMem = CreateCompatibleDC(hdcPaint);
        hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
        hbmOld = reinterpret_cast<HBITMAP>(SelectObject(hdcMem, hbmMem));

        hOldFont = reinterpret_cast<HFONT>(SelectObject(hdcMem, ctl->hFont));
    // If its a push button, check to see if it should stay pressed
        if (ctl->pushBtn && ctl->pbState)
            ctl->stateId = PBS_PRESSED;

    // Draw the flat button
        if (ctl->flatBtn) {
            if (ctl->hThemeToolbar && ctl->bThemed) {
                RECT rc = rcClient;
                int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
                SkinDrawBg(ctl->hwnd, hdcMem);
                if (API::pfnIsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) {
                    API::pfnDrawThemeParentBackground(ctl->hwnd, hdcMem, &rc);
                }
                API::pfnDrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rc, &rc);
            } else {
                HBRUSH hbr;
                RECT rc = rcClient;

                if(ctl->buttonItem) {
                    RECT rcParent;
                    POINT pt;
                    HWND hwndParent = pcli->hwndContactList;
                    ImageItem *imgItem = ctl->stateId == PBS_HOT ? ctl->buttonItem->imgHover : (ctl->stateId == PBS_PRESSED ? ctl->buttonItem->imgPressed : ctl->buttonItem->imgNormal);
                    LONG *glyphMetrics = ctl->stateId == PBS_HOT ? ctl->buttonItem->hoverGlyphMetrics : (ctl->stateId == PBS_PRESSED ? ctl->buttonItem->pressedGlyphMetrics : ctl->buttonItem->normalGlyphMetrics);

                    //if(ctl->stateId == PBS_HOT && glyphMetrics[2] <= 1 && glyphMetrics[3] <= 1)
                    //    glyphMetrics = ctl->lastGlyphMetrics;

                    GetWindowRect(ctl->hwnd, &rcParent);
                    pt.x = rcParent.left;
                    pt.y = rcParent.top;

                    ScreenToClient(pcli->hwndContactList, &pt);

                    BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
                    if(imgItem)
                        DrawAlpha(hdcMem, &rc, 0, 0, 0, 0, 0, 0, 0, imgItem);
                    if(g_glyphItem) {
                    	API::pfnAlphaBlend(hdcMem, (rc.right - glyphMetrics[2]) / 2, (rc.bottom - glyphMetrics[3]) / 2,
                                   glyphMetrics[2], glyphMetrics[3], g_glyphItem->hdc,
                                   glyphMetrics[0], glyphMetrics[1], glyphMetrics[2],
                                   glyphMetrics[3], g_glyphItem->bf);
                        //CopyMemory(ctl->lastGlyphMetrics, glyphMetrics, 4 * sizeof(LONG));
                    }
                }
                else if(ctl->bSkinned) {      // skinned
                    RECT rcParent;
                    POINT pt;
                    HWND hwndParent = pcli->hwndContactList;
                    StatusItems_t *item;
                    int item_id;
                    
                    GetWindowRect(ctl->hwnd, &rcParent);
                    pt.x = rcParent.left;
                    pt.y = rcParent.top;
                    
                    ScreenToClient(pcli->hwndContactList, &pt);
                    
                    if(HIWORD(ctl->bSkinned))
                        item_id = ctl->stateId == PBS_HOT ? ID_EXTBKTBBUTTONMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKTBBUTTONSPRESSED : ID_EXTBKTBBUTTONSNPRESSED);
                        //GetItemByStatus(ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKTBBUTTONSPRESSED : ID_EXTBKTBBUTTONSNPRESSED), &item);
                    else
                        item_id = ctl->stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : (ctl->stateId == PBS_PRESSED ? ID_EXTBKBUTTONSPRESSED : ID_EXTBKBUTTONSNPRESSED);
                    item = &StatusItems[item_id - ID_STATUS_OFFLINE];
                        //GetItemByStatus(ctl->stateId == PBS_PRESSED ? ID_EXTBKBUTTONSPRESSED : ID_EXTBKBUTTONSNPRESSED, &item);
                    SetTextColor(hdcMem, item->TEXTCOLOR);
                    if(item->IGNORED) {
                        if(pt.y < 10 || cfg::dat.bWallpaperMode)
                            //SkinDrawBg(ctl->hwnd, hdcMem);
                            BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
                        else
                            FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE));
                    }
                    else {
                        if(pt.y < 10 || cfg::dat.bWallpaperMode)
                            //SkinDrawBg(ctl->hwnd, hdcMem);
                            BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);
                        else
                            FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE));
                        rc.top += item->MARGIN_TOP; rc.bottom -= item->MARGIN_BOTTOM;
                        rc.left += item->MARGIN_LEFT; rc.right -= item->MARGIN_RIGHT;
                        DrawAlpha(hdcMem, &rc, item->COLOR, item->ALPHA, item->COLOR2, item->COLOR2_TRANSPARENT, item->GRADIENT,
                                  item->CORNER, item->BORDERSTYLE, item->imageItem);
                    }
                }
                else {
                    if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT)
                        hbr = GetSysColorBrush(COLOR_3DFACE);
                    else {
                        HDC dc;
                        HWND hwndParent;

                        hwndParent = GetParent(ctl->hwnd);
                        dc = GetDC(hwndParent);
                        hbr = (HBRUSH) SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM) dc, (LPARAM) hwndParent);
                        ReleaseDC(hwndParent, dc);
                    }
                    if (hbr) {
                        FillRect(hdcMem, &rc, hbr);
                        DeleteObject(hbr);
                    }
                }
                if(!ctl->bSkinned && ctl->buttonItem == 0) {
                    if (ctl->stateId == PBS_HOT || ctl->focus) {
                        if (ctl->pbState)
                            DrawEdge(hdcMem, &rc, EDGE_ETCHED, BF_RECT | BF_SOFT);
                        else
                            DrawEdge(hdcMem, &rc, BDR_RAISEDOUTER, BF_RECT | BF_SOFT);
                    } else if (ctl->stateId == PBS_PRESSED)
                        DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT | BF_SOFT);
                }
            }
        } else {
    // Draw background/border
            if (ctl->hThemeButton && ctl->bThemed) {
                int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED;
                POINT pt;
                RECT rcParent;
                
                GetWindowRect(ctl->hwnd, &rcParent);
                pt.x = rcParent.left;
                pt.y = rcParent.top;
                ScreenToClient(pcli->hwndContactList, &pt);
                BitBlt(hdcMem, 0, 0, rcClient.right, rcClient.bottom, cfg::dat.hdcBg, pt.x, pt.y, SRCCOPY);

                if (API::pfnIsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) {
                    API::pfnDrawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient);
                }
                API::pfnDrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient);
            } else {
                UINT uState = DFCS_BUTTONPUSH | ((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0) | ((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0);
                if (ctl->defbutton && ctl->stateId == PBS_NORMAL)
                    uState |= DLGC_DEFPUSHBUTTON;
                DrawFrameControl(hdcMem, &rcClient, DFC_BUTTON, uState);
            }

    // Draw focus rectangle if button has focus
            if (ctl->focus) {
                RECT focusRect = rcClient;
                InflateRect(&focusRect, -3, -3);
                DrawFocusRect(hdcMem, &focusRect);
            }
        }

    // If we have an icon or a bitmap, ignore text and only draw the image on the button
        if (ctl->hIcon || ctl->hIconPrivate || ctl->iIcon) {
            int ix = (rcClient.right - rcClient.left) / 2 - (g_cxsmIcon / 2);
            int iy = (rcClient.bottom - rcClient.top) / 2 - (g_cxsmIcon / 2);
            HICON hIconNew = ctl->hIconPrivate != 0 ? ctl->hIconPrivate : ctl->hIcon;
            if (lstrlen(ctl->szText) == 0) {
                if (ctl->iIcon)
                    ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
                else
                    DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
                ctl->sLabel.cx = ctl->sLabel.cy = 0;
            } else {
                GetTextExtentPoint32(hdcMem, ctl->szText, lstrlen(ctl->szText), &ctl->sLabel);

                if(g_cxsmIcon + ctl->sLabel.cx + 8 > rcClient.right - rcClient.left)
                    ctl->sLabel.cx = (rcClient.right - rcClient.left) - g_cxsmIcon - 8;
                else
                    ctl->sLabel.cx += 4;
                
                ix = (rcClient.right - rcClient.left) / 2 - ((g_cxsmIcon + ctl->sLabel.cx) / 2);
                if (ctl->iIcon)
                    ImageList_DrawEx(ctl->hIml, ctl->iIcon, hdcMem, ix, iy, g_cxsmIcon, g_cysmIcon, CLR_NONE, CLR_NONE, ILD_NORMAL);
                else
                    DrawState(hdcMem, NULL, NULL, (LPARAM) hIconNew, 0, ix, iy, g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED);
                xOffset = ix + g_cxsmIcon + 4;
            }
        } else if (ctl->hBitmap) {
            BITMAP bminfo;
            int ix, iy;

            GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo);
            ix = (rcClient.right - rcClient.left) / 2 - (bminfo.bmWidth / 2);
            iy = (rcClient.bottom - rcClient.top) / 2 - (bminfo.bmHeight / 2);
            if (ctl->stateId == PBS_PRESSED) {
                ix++;
                iy++;
            }
            DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->hBitmap, 0, ix, iy, bminfo.bmWidth, bminfo.bmHeight, IsWindowEnabled(ctl->hwnd) ? DST_BITMAP : DST_BITMAP | DSS_DISABLED);
        }
        if (GetWindowTextLength(ctl->hwnd)) {
    // Draw the text and optinally the arrow
            RECT rcText;

            CopyRect(&rcText, &rcClient);
            SetBkMode(hdcMem, TRANSPARENT);
    // XP w/themes doesn't used the glossy disabled text.  Is it always using COLOR_GRAYTEXT?  Seems so.
            if(!ctl->bSkinned)
                SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton ? GetSysColor(COLOR_BTNTEXT) : GetSysColor(COLOR_GRAYTEXT));
            if (ctl->arrow)
                DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->arrow, 0, rcClient.right - rcClient.left - 5 - g_cxsmIcon + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), (rcClient.bottom - rcClient.top) / 2 - g_cysmIcon / 2 + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), g_cxsmIcon, g_cysmIcon, IsWindowEnabled(ctl->hwnd) ? DST_ICON : DST_ICON | DSS_DISABLED);
            DrawState(hdcMem, NULL, NULL, (LPARAM) ctl->szText, 0, xOffset + (!ctl->hThemeButton && ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->hThemeButton ? (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + 1 : (rcText.bottom - rcText.top - ctl->sLabel.cy) / 2 + (ctl->stateId == PBS_PRESSED ? 1 : 0), ctl->sLabel.cx, ctl->sLabel.cy, IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED);
        }
        if (hOldFont)
            SelectObject(hdcMem, hOldFont);
        BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
        SelectObject(hdcMem, hbmOld);
        DeleteObject(hbmMem);
        DeleteDC(hdcMem);
        DeleteObject(hbmOld);
    }
}
Example #25
0
int Init_ConsoleWin(void)
{
    HDC conDC;
    WNDCLASS wndclass;
    TEXTMETRIC metrics;
    RECT cRect;
    int width,height;
    int scr_width,scr_height;
    HINSTANCE hInstance;
    char titlebuffer[2048];

    if (con_hWnd)
      return TRUE;
    hInstance = GetModuleHandle(NULL);
    Init_Console();
    /* Register the frame class */
    wndclass.style         = CS_OWNDC;
    wndclass.lpfnWndProc   = (WNDPROC)ConWndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hInstance;
    wndclass.hIcon         = LoadIcon (hInstance, IDI_WINLOGO);
    wndclass.hCursor       = LoadCursor (NULL,IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)GetStockObject (BLACK_BRUSH);
    wndclass.lpszMenuName  = szConName;
    wndclass.lpszClassName = szConName;

    if (!RegisterClass(&wndclass))
        return FALSE;

    width=100;
    height=100;
    strcpy(titlebuffer,PACKAGE);
    strcat(titlebuffer," ");
    strcat(titlebuffer,VERSION);
    strcat(titlebuffer," console");
    con_hWnd = CreateWindow(szConName, titlebuffer,
             WS_CAPTION | WS_POPUP,
             0, 0, width, height,
             NULL, NULL, hInstance, NULL);
    conDC=GetDC(con_hWnd);
    OemFont = GetStockObject(OEM_FIXED_FONT);
    SelectObject(conDC, OemFont);
    GetTextMetrics(conDC, &metrics);
    OemWidth = metrics.tmAveCharWidth;
    OemHeight = metrics.tmHeight;
    GetClientRect(con_hWnd, &cRect);
    width += (OemWidth * 80) - cRect.right;
    height += (OemHeight * 25) - cRect.bottom;
    // proff 11/09/98: Added code for centering console
    scr_width = GetSystemMetrics(SM_CXFULLSCREEN);
    scr_height = GetSystemMetrics(SM_CYFULLSCREEN);
    MoveWindow(con_hWnd, (scr_width-width)/2, (scr_height-height)/2, width, height, TRUE);
    GetClientRect(con_hWnd, &cRect);
    ConWidth = cRect.right;
    ConHeight = cRect.bottom;
    SetTextColor(conDC, RGB(192,192,192));
    SetBkColor(conDC, RGB(0,0,0));
    SetBkMode(conDC, OPAQUE);
    ReleaseDC(con_hWnd,conDC);
    ShowWindow(con_hWnd, SW_SHOW);
    UpdateWindow(con_hWnd);
    return TRUE;
}
Example #26
0
//Yeah this truly turned into a mess with the latest additions.. but it sure looks nice ;)
void CtrlDisAsmView::onPaint(WPARAM wParam, LPARAM lParam)
{
	struct branch
	{
		int src,dst,srcAddr;
	};
	branch branches[256];
	int numBranches=0;


	GetClientRect(wnd, &rect);
	PAINTSTRUCT ps;
	HDC hdc;
	
	hdc = BeginPaint(wnd, &ps);
	// TODO: Add any drawing code here...
	int width = rect.right;
	int numRows=(rect.bottom/rowHeight)/2+1;
	//numRows=(numRows&(~1)) + 1;
	SetBkMode(hdc, TRANSPARENT);
	DWORD bgColor = 0xffffff;
	HPEN nullPen=CreatePen(0,0,bgColor);
	HPEN currentPen=CreatePen(0,0,0);
	HPEN selPen=CreatePen(0,0,0x808080);

	LOGBRUSH lbr;
	lbr.lbHatch=0; lbr.lbStyle=0; 
	lbr.lbColor=bgColor;
	HBRUSH nullBrush=CreateBrushIndirect(&lbr);
	lbr.lbColor=0xFFEfE8;
	HBRUSH currentBrush=CreateBrushIndirect(&lbr);
	lbr.lbColor=0x70FF70;
	HBRUSH pcBrush=CreateBrushIndirect(&lbr);

	HPEN oldPen=(HPEN)SelectObject(hdc,nullPen);
	HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush);

   
	HFONT oldFont = (HFONT)SelectObject(hdc,(HGDIOBJ)font);
	HICON breakPoint = (HICON)LoadIcon(hMod,(LPCWSTR)IDI_BRKPT);
	HICON breakPointDisable = (HICON)LoadIcon(hMod,(LPCWSTR)IDI_BRKPTDIS);
	int i;
	for (i=-numRows; i<=numRows; i++)
	{
		unsigned int address=curAddress + i*align;

		int rowY1 = rect.bottom/2 + rowHeight*i - rowHeight/2;
		int rowY2 = rect.bottom/2 + rowHeight*i + rowHeight/2;
		wchar temp[256];
		swprintf(temp,L"%08X",address);

		TCHAR desc[256]=L"";
		wcscpy(desc,debugger->getDescription(address));	// do this before getColor()
		lbr.lbColor=debugger->getColor(address);

		//SelectObject(hdc,currentBrush);
		SelectObject(hdc,nullPen);
		Rectangle(hdc,0,rowY1,16,rowY2);

		if (selecting && address == (u32)selection)
			SelectObject(hdc,selPen);
		else
			SelectObject(hdc,i==0 ? currentPen : nullPen);

		HBRUSH mojsBrush=CreateBrushIndirect(&lbr);
		SelectObject(hdc,mojsBrush);

		if (address == debugger->getPC())
			SelectObject(hdc,pcBrush);
		//else
		//	SelectObject(hdc,i==0 ? currentBrush : nullBrush);

		Rectangle(hdc,16,rowY1,width,rowY2);
		SelectObject(hdc,currentBrush);
		DeleteObject(mojsBrush);
		SetTextColor(hdc,0x600000);
		TextOut(hdc,17,rowY1,temp,(int)wcslen(temp));
		SetTextColor(hdc,0x000000);
		
		TCHAR *dis = debugger->disasm(address);
		TCHAR *dis2=_tcschr(dis,'\t');
		if (dis2)
		{
			*dis2=0;
			dis2++;
			wchar *mojs=wcsstr(dis2,L"0x8");
			if (mojs)
			for (int i=0; i<8; i++)
			{
				bool found=false;
				for (int j=0; j<22; j++)
				{
					if (mojs[i+2]==L"0123456789ABCDEFabcdef"[j])
						found=true;
				}
				if (!found)
				{
					mojs=0;
					break;
				}
			}
			if (mojs)
			{
				int offs;
				swscanf(mojs+2,L"%08X",&offs);
				branches[numBranches].src=rowY1 + rowHeight/2;
				branches[numBranches].srcAddr=address/align;
				branches[numBranches++].dst=(int)(rowY1+((__int64)offs-(__int64)address)*rowHeight/align + rowHeight/2);
			//	sprintf(desc,"-->%s", debugger->getDescription(offs));
				SetTextColor(hdc,0x600060);
			}
			else
				SetTextColor(hdc,0x000000);
			TextOut(hdc,198,rowY1,dis2,(int)wcslen(dis2));
		}

		SetTextColor(hdc,0x007000);
		TextOut(hdc,90,rowY1,dis,(int)wcslen(dis));

		SetTextColor(hdc,0x0000FF);
		//char temp[256];
		//UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE);
		if (wcslen(desc))
			TextOut(hdc,320,rowY1,desc,(int)wcslen(desc));

		if (debugger->isBreakpoint(address))
		{
			DrawIconEx(hdc,2,rowY1,breakPoint,32,32,0,0,DI_NORMAL);
		}
	}
	SelectObject(hdc,currentPen);
	for (i=0; i<numBranches; i++)
	{
		int x=250+(branches[i].srcAddr%9)*8;
		MoveToEx(hdc,x-2,branches[i].src,0);

		if (branches[i].dst<rect.bottom+200 && branches[i].dst>-200)
		{
			LineTo(hdc,x+2,branches[i].src);
			LineTo(hdc,x+2,branches[i].dst);
			LineTo(hdc,x-4,branches[i].dst);
			
			MoveToEx(hdc,x,branches[i].dst-4,0);
			LineTo(hdc,x-4,branches[i].dst);
			LineTo(hdc,x+1,branches[i].dst+5);
		}
		else
		{
			LineTo(hdc,x+4,branches[i].src);
			//MoveToEx(hdc,x+2,branches[i].dst-4,0);
			//LineTo(hdc,x+6,branches[i].dst);
			//LineTo(hdc,x+1,branches[i].dst+5);
		}
		//LineTo(hdc,x,branches[i].dst+4);

		//LineTo(hdc,x-2,branches[i].dst);
	}

	SelectObject(hdc,oldFont);
	SelectObject(hdc,oldPen);
	SelectObject(hdc,oldBrush);
	
	DeleteObject(nullPen);
	DeleteObject(currentPen);
	DeleteObject(selPen);

	DeleteObject(nullBrush);
	DeleteObject(pcBrush);
	DeleteObject(currentBrush);
	
	DestroyIcon(breakPoint);
	DestroyIcon(breakPointDisable);
	
	EndPaint(wnd, &ps);
}
Example #27
0
// ********************************
//	IfDcDraw
// ********************************
bool CDcdRectangle::DcDraw( IfDcdTarget* pIfDcdTarget ) 
{
	int		iRv = 0 ;
	bool	bRv = false ;
	

	// --------------------------------
	//	ペン・ブラシの生成
	// --------------------------------
	HPEN	hPen = NULL ;
	if ( iRv >= 0 ){
		hPen = pIfDcdTarget->CreatePen( m_CdPenProp ) ;
		if ( hPen == NULL ){
			iRv = -1 ;	//	ペンの作成に失敗しました。	\n
		}
	}
	HBRUSH	hBrush = NULL ;
	if ( iRv >= 0 ){
		hBrush = pIfDcdTarget->CreateBrush( m_CdBrushProp ) ;
		if ( hBrush == NULL ){
			iRv = -2 ;	//	ブラシの作成に失敗しました。	\n
		}
	}
	HBRUSH		hBrushSid = NULL ;
	if ( iRv >= 0 ){
		hBrushSid = (HBRUSH)SelectObject( pIfDcdTarget->getHdc() , hBrush ) ;
	}
	HPEN		hPenSid = NULL ;
	if ( iRv >= 0 ){
		hPenSid = (HPEN)SelectObject( pIfDcdTarget->getHdc() , hPen ) ;
	}
	int iBkModeSid = -1 ;
	if ( iRv >= 0 ){
		 iBkModeSid = SetBkMode( pIfDcdTarget->getHdc() , TRANSPARENT ) ;
	}
	// --------------------------------
	if ( iRv >= 0 ){
		CdDcdZoneXy	aCdDcdZoneXy = pIfDcdTarget->getZone() ;
		RECT	LRect ;
		LRect.left   = aCdDcdZoneXy.getX().getPos() + 
					m_CdPenProp.getLogicalunitWidth() / 2 ;
		LRect.top    = aCdDcdZoneXy.getY().getPos() +
					m_CdPenProp.getLogicalunitWidth() / 2 ;
		LRect.right  = aCdDcdZoneXy.getX().getEndPos() -
					m_CdPenProp.getLogicalunitWidth() / 2 ;
		LRect.bottom = aCdDcdZoneXy.getY().getEndPos() -
					m_CdPenProp.getLogicalunitWidth() / 2 ;
		
		Rectangle( pIfDcdTarget->getHdc() , 
			LRect.left , LRect.top , LRect.right , LRect.bottom ) ;
		
	}
	if ( iRv >= 0 ){
		bRv = true ;
	}
	// --------------------------------
	if ( iBkModeSid != -1 ) {
		SetBkMode( pIfDcdTarget->getHdc() , iBkModeSid ) ;
	}
	if ( hBrushSid != NULL ){
		SelectObject( pIfDcdTarget->getHdc() , hBrushSid ) ;
		hBrushSid = NULL ;
	}
	if ( hPenSid != NULL ){
		SelectObject( pIfDcdTarget->getHdc() , hPenSid ) ;
		hPenSid = NULL ;
	}
	return ( bRv ) ;
}
Example #28
0
static LRESULT MHeaderbar_OnPaint(HWND hwndDlg, MHeaderbarCtrl *mit, UINT  msg, WPARAM wParam, LPARAM lParam)
{
	int iTopSpace = IsAeroMode() ? 0 : 3;
	PAINTSTRUCT ps;
	HBITMAP hBmp, hOldBmp;

	int titleLength = GetWindowTextLength(hwndDlg) + 1;
	TCHAR *szTitle = (TCHAR *)mir_alloc(sizeof(TCHAR) * titleLength);
	GetWindowText(hwndDlg, szTitle, titleLength);

	TCHAR *szSubTitle = _tcschr(szTitle, _T('\n'));
	if (szSubTitle) *szSubTitle++=0;

	HDC hdc = BeginPaint(hwndDlg, &ps);
	HDC tempDC = CreateCompatibleDC(hdc);

	BITMAPINFO bmi;
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth = mit->width;
	bmi.bmiHeader.biHeight = -mit->height; // we need this for DrawThemeTextEx
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biBitCount = 32;
	bmi.bmiHeader.biCompression = BI_RGB;
	hBmp = CreateDIBSection(tempDC, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);

	hOldBmp = (HBITMAP)SelectObject(tempDC, hBmp);

	if (IsAeroMode()) {
		RECT temprc;
		temprc.left = 0;
		temprc.right = mit->width;
		temprc.top = 0;
		temprc.bottom = mit->width;
		FillRect(tempDC, &temprc, (HBRUSH)GetStockObject(BLACK_BRUSH));

		MARGINS margins = {0, 0, mit->height, 0};
		dwmExtendFrameIntoClientArea(GetParent(hwndDlg), &margins);

		WTA_OPTIONS opts;
		opts.dwFlags = opts.dwMask = WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON;
		setWindowThemeAttribute(GetParent(hwndDlg), WTA_NONCLIENT, &opts, sizeof(opts));
	}
	else {
		if (IsVSMode())
			MHeaderbar_FillRect(tempDC, 0, 0, mit->width, mit->height, GetSysColor(COLOR_WINDOW));
		else
			MHeaderbar_DrawGradient(tempDC, 0, 0, mit->width, mit->height, &mit->rgbBkgTop, &mit->rgbBkgBottom);

		MHeaderbar_FillRect(tempDC, 0, mit->height-2, mit->width, 1, GetSysColor(COLOR_BTNSHADOW));
		MHeaderbar_FillRect(tempDC, 0, mit->height-1, mit->width, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
	}

	HFONT hFont = mit->hFont;
	SetBkMode(tempDC, TRANSPARENT);
	SetTextColor(tempDC, mit->clText);

	LOGFONT lf;
	GetObject(hFont, sizeof(lf), &lf);
	lf.lfWeight = FW_BOLD;
	HFONT hFntBold = CreateFontIndirect(&lf), hOldFont;

	if (mit->hIcon)
		DrawIcon(tempDC, 10, iTopSpace, mit->hIcon);
	else {
		HICON hIcon = (HICON)SendMessage(GetParent(hwndDlg), WM_GETICON, ICON_BIG, 0);
		if (hIcon == NULL)
			hIcon = (HICON)SendMessage(GetParent(hwndDlg), WM_GETICON, ICON_SMALL, 0);
		DrawIcon(tempDC, 10, iTopSpace, hIcon);
	}

	RECT textRect;
	textRect.left = 50;
	textRect.right = mit->width;
	textRect.top = 2 + iTopSpace;
	textRect.bottom = GetSystemMetrics(SM_CYICON)-2 + iTopSpace;

	if (IsAeroMode()) {
		DTTOPTS dto = {0};
		dto.dwSize = sizeof(dto);
		dto.dwFlags = DTT_COMPOSITED|DTT_GLOWSIZE;
		dto.iGlowSize = 10;

		HANDLE hTheme = OpenThemeData(hwndDlg, L"Window");
		textRect.left = 50;
		hOldFont = (HFONT)SelectObject(tempDC, hFntBold);

		wchar_t *szTitleW = mir_t2u(szTitle);
		drawThemeTextEx(hTheme, tempDC, WP_CAPTION, CS_ACTIVE, szTitleW, -1, DT_TOP|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX|DT_NOCLIP|DT_END_ELLIPSIS, &textRect, &dto);
		mir_free(szTitleW);

		if (szSubTitle) {
			textRect.left = 66;
			SelectObject(tempDC, hFont);

			wchar_t *szSubTitleW = mir_t2u(szSubTitle);
			drawThemeTextEx(hTheme, tempDC, WP_CAPTION, CS_ACTIVE, szSubTitleW, -1, DT_BOTTOM|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX|DT_NOCLIP|DT_END_ELLIPSIS, &textRect, &dto);
			mir_free(szSubTitleW);
		}
		CloseThemeData(hTheme);
	}
	else {
		textRect.left = 50;
		hOldFont = (HFONT)SelectObject(tempDC, hFntBold);
		DrawText(tempDC, szTitle, -1, &textRect, DT_TOP|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX|DT_NOCLIP|DT_END_ELLIPSIS);

		if (szSubTitle) {
			textRect.left = 66;
			SelectObject(tempDC, hFont);
			DrawText(tempDC, szSubTitle, -1, &textRect, DT_BOTTOM|DT_LEFT|DT_SINGLELINE|DT_NOPREFIX|DT_NOCLIP|DT_END_ELLIPSIS);
		}
	}

	DeleteObject(hFntBold);

	mir_free(szTitle);

	//Copy to output
	if (mit->nControlsToRedraw)
	{
		RECT temprc;
		temprc.left = 0;
		temprc.right = mit->width;
		temprc.top = 0;
		temprc.bottom = mit->width;
		HRGN hRgn = CreateRectRgnIndirect(&temprc);

		for (int i=0; i < mit->nControlsToRedraw; i++)
		{
			GetWindowRect(mit->controlsToRedraw[i], &temprc);
			MapWindowPoints(NULL, hwndDlg, (LPPOINT)&temprc, 2);
			HRGN hRgnTmp = CreateRectRgnIndirect(&temprc);
			CombineRgn(hRgn, hRgn, hRgnTmp, RGN_DIFF);
			DeleteObject(hRgnTmp);
		}
		SelectClipRgn(hdc, hRgn);
		DeleteObject(hRgn);
	}

	BitBlt(hdc, mit->rc.left, mit->rc.top, mit->width, mit->height, tempDC, 0, 0, SRCCOPY);

	SelectClipRgn(hdc, NULL);

	SelectObject(tempDC, hOldBmp);
	DeleteObject(hBmp);
	SelectObject(tempDC,hOldFont);
	DeleteDC(tempDC);

	EndPaint(hwndDlg, &ps);

	return TRUE;
}
Example #29
0
static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			hwndSettingsDlg = hwndDlg;
			LCID locale = Langpack_GetDefaultLocale();
			SendDlgItemMessage(hwndDlg, IDC_ICON_HEADER, STM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon("AutoShutdown_Header"));
			{
				HFONT hBoldFont;
				LOGFONT lf;
				if (GetObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_GETFONT, 0, 0), sizeof(lf), &lf)) {
					lf.lfWeight = FW_BOLD;
					hBoldFont = CreateFontIndirect(&lf);
				}
				else hBoldFont = NULL;
				SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_SETFONT, (WPARAM)hBoldFont, FALSE);
			}
			/* read-in watcher flags */
			{
				WORD watcherType = db_get_w(NULL, "AutoShutdown", "WatcherFlags", SETTING_WATCHERFLAGS_DEFAULT);
				CheckRadioButton(hwndDlg, IDC_RADIO_STTIME, IDC_RADIO_STCOUNTDOWN, (watcherType&SDWTF_ST_TIME) ? IDC_RADIO_STTIME : IDC_RADIO_STCOUNTDOWN);
				CheckDlgButton(hwndDlg, IDC_CHECK_SPECIFICTIME, (watcherType&SDWTF_SPECIFICTIME) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, (watcherType&SDWTF_MESSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg, IDC_CHECK_FILETRANSFER, (watcherType&SDWTF_FILETRANSFER) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg, IDC_CHECK_IDLE, (watcherType&SDWTF_IDLE) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg, IDC_CHECK_STATUS, (watcherType&SDWTF_STATUS) != 0 ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hwndDlg, IDC_CHECK_CPUUSAGE, (watcherType&SDWTF_CPUUSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
			}
			/* read-in countdown val */
			{
				SYSTEMTIME st;
				if (!TimeStampToSystemTime((time_t)db_get_dw(NULL, "AutoShutdown", "TimeStamp", SETTING_TIMESTAMP_DEFAULT), &st))
					GetLocalTime(&st);
				DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), GDT_VALID, &st);
				DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), GDT_VALID, &st);
				SendMessage(hwndDlg, M_CHECK_DATETIME, 0, 0);
			}
			{
				DWORD setting = db_get_dw(NULL, "AutoShutdown", "Countdown", SETTING_COUNTDOWN_DEFAULT);
				if (setting < 1) setting = SETTING_COUNTDOWN_DEFAULT;
				SendDlgItemMessage(hwndDlg, IDC_SPIN_COUNTDOWN, UDM_SETRANGE, 0, MAKELPARAM(UD_MAXVAL, 1));
				SendDlgItemMessage(hwndDlg, IDC_EDIT_COUNTDOWN, EM_SETLIMITTEXT, (WPARAM)10, 0);
				SendDlgItemMessage(hwndDlg, IDC_SPIN_COUNTDOWN, UDM_SETPOS, 0, MAKELPARAM(setting, 0));
				SetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, setting, FALSE);
			}
			{
				HWND hwndCombo = GetDlgItem(hwndDlg, IDC_COMBO_COUNTDOWNUNIT);
				DWORD lastUnit = db_get_dw(NULL, "AutoShutdown", "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT);
				SendMessage(hwndCombo, CB_SETLOCALE, (WPARAM)locale, 0); /* sort order */
				SendMessage(hwndCombo, CB_INITSTORAGE, _countof(unitNames), _countof(unitNames) * 16); /* approx. */
				for (int i = 0; i < _countof(unitNames); ++i) {
					int index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(unitNames[i]));
					if (index != LB_ERR) {
						SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)unitValues[i]);
						if (i == 0 || unitValues[i] == lastUnit) SendMessage(hwndCombo, CB_SETCURSEL, index, 0);
					}
				}
			}
			{
				DBVARIANT dbv;
				if (!db_get_ts(NULL, "AutoShutdown", "Message", &dbv)) {
					SetDlgItemText(hwndDlg, IDC_EDIT_MESSAGE, dbv.ptszVal);
					mir_free(dbv.ptszVal);
				}
			}
			/* cpuusage threshold */
			{
				BYTE setting = DBGetContactSettingRangedByte(NULL, "AutoShutdown", "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100);
				SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETRANGE, 0, MAKELPARAM(100, 1));
				SendDlgItemMessage(hwndDlg, IDC_EDIT_CPUUSAGE, EM_SETLIMITTEXT, (WPARAM)3, 0);
				SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETPOS, 0, MAKELPARAM(setting, 0));
				SetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, setting, FALSE);
			}
			/* shutdown types */
			{
				HWND hwndCombo = GetDlgItem(hwndDlg, IDC_COMBO_SHUTDOWNTYPE);
				BYTE lastShutdownType = db_get_b(NULL, "AutoShutdown", "ShutdownType", SETTING_SHUTDOWNTYPE_DEFAULT);
				SendMessage(hwndCombo, CB_SETLOCALE, (WPARAM)locale, 0); /* sort order */
				SendMessage(hwndCombo, CB_SETEXTENDEDUI, TRUE, 0);
				SendMessage(hwndCombo, CB_INITSTORAGE, SDSDT_MAX, SDSDT_MAX * 32);
				for (BYTE shutdownType = 1; shutdownType <= SDSDT_MAX; ++shutdownType)
					if (ServiceIsTypeEnabled(shutdownType, 0)) {
						TCHAR *pszText = (TCHAR*)ServiceGetTypeDescription(shutdownType, GSTDF_TCHAR); /* never fails */
						int index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)pszText);
						if (index != LB_ERR) {
							SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)shutdownType);
							if (shutdownType == 1 || shutdownType == lastShutdownType) SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)index, 0);
						}
					}
				SendMessage(hwndDlg, M_UPDATE_SHUTDOWNDESC, 0, (LPARAM)hwndCombo);
			}
			/* check if proto is installed that supports instant messages and check if a message dialog plugin is installed */
			if (!AnyProtoHasCaps(PF1_IMRECV) || !ServiceExists(MS_MSG_SENDMESSAGE)) { /* no srmessage present? */
				CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_MESSAGE), FALSE);
				EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_MESSAGE), FALSE);
			}
			/* check if proto is installed that supports file transfers and check if a file transfer dialog is available */
			if (!AnyProtoHasCaps(PF1_FILESEND) && !AnyProtoHasCaps(PF1_FILERECV)) {  /* no srfile present? */
				CheckDlgButton(hwndDlg, IDC_CHECK_FILETRANSFER, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_FILETRANSFER), FALSE);
			}
			/* check if cpu usage can be detected */
			if (!PollCpuUsage(DisplayCpuUsageProc, (LPARAM)GetDlgItem(hwndDlg, IDC_TEXT_CURRENTCPU), 1800)) {
				CheckDlgButton(hwndDlg, IDC_CHECK_CPUUSAGE, BST_UNCHECKED);
				EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_CPUUSAGE), FALSE);
			}
		}
		SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
		Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "AutoShutdown", "SettingsDlg_");
		return TRUE; /* default focus */

	case WM_DESTROY:
		Utils_SaveWindowPosition(hwndDlg, NULL, "AutoShutdown", "SettingsDlg_");
		{
			HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_GETFONT, 0, 0);
			SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_SETFONT, 0, FALSE); /* no return value */
			if (hFont != NULL)
				DeleteObject(hFont);
			hwndSettingsDlg = NULL;
		}
		return TRUE;

	case WM_CTLCOLORSTATIC:
		switch (GetDlgCtrlID((HWND)lParam)) {
		case IDC_ICON_HEADER:
			SetBkMode((HDC)wParam, TRANSPARENT);

		case IDC_RECT_HEADER:
			/* need to set COLOR_WINDOW manually for Win9x */
			SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
			return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);

		case IDC_TEXT_HEADER:
		case IDC_TEXT_HEADERDESC:
			SetBkMode((HDC)wParam, TRANSPARENT);
			return (INT_PTR)GetStockObject(NULL_BRUSH);
		}
		break;

	case M_ENABLE_SUBCTLS:
		{
			BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_MESSAGE) != 0;
			EnableDlgItem(hwndDlg, IDC_EDIT_MESSAGE, checked);
			checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) != 0;
			EnableDlgItem(hwndDlg, IDC_RADIO_STTIME, checked);
			EnableDlgItem(hwndDlg, IDC_RADIO_STCOUNTDOWN, checked);
			checked = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg, IDC_RADIO_STTIME));
			EnableDlgItem(hwndDlg, IDC_TIME_TIMESTAMP, checked);
			EnableDlgItem(hwndDlg, IDC_DATE_TIMESTAMP, checked);
			checked = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg, IDC_RADIO_STCOUNTDOWN));
			EnableDlgItem(hwndDlg, IDC_EDIT_COUNTDOWN, checked);
			EnableDlgItem(hwndDlg, IDC_SPIN_COUNTDOWN, checked);
			EnableDlgItem(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, checked);
			checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_IDLE) != 0;
			EnableDlgItem(hwndDlg, IDC_URL_IDLE, checked);
			checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_CPUUSAGE) != 0;
			EnableDlgItem(hwndDlg, IDC_EDIT_CPUUSAGE, checked);
			EnableDlgItem(hwndDlg, IDC_SPIN_CPUUSAGE, checked);
			EnableDlgItem(hwndDlg, IDC_TEXT_PERCENT, checked);
			EnableDlgItem(hwndDlg, IDC_TEXT_CURRENTCPU, checked);
			checked = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) || IsDlgButtonChecked(hwndDlg, IDC_CHECK_MESSAGE) ||
				IsDlgButtonChecked(hwndDlg, IDC_CHECK_IDLE) || IsDlgButtonChecked(hwndDlg, IDC_CHECK_STATUS) ||
				IsDlgButtonChecked(hwndDlg, IDC_CHECK_FILETRANSFER) || IsDlgButtonChecked(hwndDlg, IDC_CHECK_CPUUSAGE));
			EnableDlgItem(hwndDlg, IDOK, checked);
		}
		return TRUE;

	case M_UPDATE_SHUTDOWNDESC: /* lParam=(LPARAM)(HWND)hwndCombo */
		{
			BYTE shutdownType = (BYTE)SendMessage((HWND)lParam, CB_GETITEMDATA, SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0), 0);
			SetDlgItemText(hwndDlg, IDC_TEXT_SHUTDOWNTYPE, (TCHAR*)ServiceGetTypeDescription(shutdownType, GSTDF_LONGDESC | GSTDF_TCHAR));
		}
		return TRUE;

	case WM_TIMECHANGE: /* system time changed */
		SendMessage(hwndDlg, M_CHECK_DATETIME, 0, 0);
		return TRUE;

	case M_CHECK_DATETIME:
		{
			SYSTEMTIME st, stBuf;
			time_t timestamp;
			DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), &stBuf);
			DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), &st);
			st.wDay = stBuf.wDay;
			st.wDayOfWeek = stBuf.wDayOfWeek;
			st.wMonth = stBuf.wMonth;
			st.wYear = stBuf.wYear;
			GetLocalTime(&stBuf);
			if (SystemTimeToTimeStamp(&st, &timestamp)) {
				/* set to current date if earlier */
				if (timestamp < time(NULL)) {
					st.wDay = stBuf.wDay;
					st.wDayOfWeek = stBuf.wDayOfWeek;
					st.wMonth = stBuf.wMonth;
					st.wYear = stBuf.wYear;
					if (SystemTimeToTimeStamp(&st, &timestamp)) {
						/* step one day up if still earlier */
						if (timestamp < time(NULL)) {
							timestamp += 24 * 60 * 60;
							TimeStampToSystemTime(timestamp, &st);
						}
					}
				}
			}
			DateTime_SetRange(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), GDTR_MIN, &stBuf);
			DateTime_SetRange(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), GDTR_MIN, &stBuf);
			DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), GDT_VALID, &st);
			DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), GDT_VALID, &st);
		}
		return TRUE;

	case WM_NOTIFY:
		switch (((NMHDR*)lParam)->idFrom) {
		case IDC_TIME_TIMESTAMP:
		case IDC_DATE_TIMESTAMP:
			switch (((NMHDR*)lParam)->code) {
			case DTN_CLOSEUP:
			case NM_KILLFOCUS:
				PostMessage(hwndDlg, M_CHECK_DATETIME, 0, 0);
				return TRUE;
			}
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_CHECK_MESSAGE:
		case IDC_CHECK_FILETRANSFER:
		case IDC_CHECK_IDLE:
		case IDC_CHECK_CPUUSAGE:
		case IDC_CHECK_STATUS:
		case IDC_CHECK_SPECIFICTIME:
		case IDC_RADIO_STTIME:
		case IDC_RADIO_STCOUNTDOWN:
			SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
			return TRUE;

		case IDC_EDIT_COUNTDOWN:
			if (HIWORD(wParam) == EN_KILLFOCUS) {
				if ((int)GetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, NULL, TRUE) < 1) {
					SendDlgItemMessage(hwndDlg, IDC_SPIN_COUNTDOWN, UDM_SETPOS, 0, MAKELPARAM(1, 0));
					SetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, 1, FALSE);
				}
				return TRUE;
			}
			break;

		case IDC_EDIT_CPUUSAGE:
			if (HIWORD(wParam) == EN_KILLFOCUS) {
				WORD val = (WORD)GetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, NULL, FALSE);
				if (val < 1) val = 1;
				else if (val>100) val = 100;
				SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETPOS, 0, MAKELPARAM(val, 0));
				SetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, val, FALSE);
				return TRUE;
			}
			break;

		case IDC_URL_IDLE:
			{
				OPENOPTIONSDIALOG ood;
				ood.cbSize = sizeof(ood);
				ood.pszGroup = "Status"; /* autotranslated */
				ood.pszPage = "Idle"; /* autotranslated */
				ood.pszTab = NULL;
				Options_Open(&ood);
				return TRUE;
			}

		case IDC_COMBO_SHUTDOWNTYPE:
			if (HIWORD(wParam) == CBN_SELCHANGE)
				SendMessage(hwndDlg, M_UPDATE_SHUTDOWNDESC, 0, lParam);
			return TRUE;

		case IDOK: /* save settings and start watcher */
			ShowWindow(hwndDlg, SW_HIDE);
			/* message text */
			{
				HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT_MESSAGE);
				int len = GetWindowTextLength(hwndEdit) + 1;
				TCHAR *pszText = (TCHAR*)mir_alloc(len*sizeof(TCHAR));
				if (pszText != NULL && GetWindowText(hwndEdit, pszText, len + 1)) {
					TrimString(pszText);
					db_set_ts(NULL, "AutoShutdown", "Message", pszText);
				}
				mir_free(pszText); /* does NULL check */
			}
			/* timestamp */
			{
				SYSTEMTIME st;
				time_t timestamp;
				DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), &st); /* time gets synchronized */
				if (!SystemTimeToTimeStamp(&st, &timestamp))
					timestamp = time(NULL);
				db_set_dw(NULL, "AutoShutdown", "TimeStamp", (DWORD)timestamp);
			}
			/* shutdown type */
			{
				int index = SendDlgItemMessage(hwndDlg, IDC_COMBO_SHUTDOWNTYPE, CB_GETCURSEL, 0, 0);
				if (index != LB_ERR)
					db_set_b(NULL, "AutoShutdown", "ShutdownType", (BYTE)SendDlgItemMessage(hwndDlg, IDC_COMBO_SHUTDOWNTYPE, CB_GETITEMDATA, (WPARAM)index, 0));
				index = SendDlgItemMessage(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, CB_GETCURSEL, 0, 0);
				if (index != LB_ERR)
					db_set_dw(NULL, "AutoShutdown", "CountdownUnit", (DWORD)SendDlgItemMessage(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, CB_GETITEMDATA, (WPARAM)index, 0));
				db_set_dw(NULL, "AutoShutdown", "Countdown", (DWORD)GetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, NULL, FALSE));
				db_set_b(NULL, "AutoShutdown", "CpuUsageThreshold", (BYTE)GetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, NULL, FALSE));
			}
			/* watcher type */
			{
				WORD watcherType = (WORD)(IsDlgButtonChecked(hwndDlg, IDC_RADIO_STTIME) ? SDWTF_ST_TIME : SDWTF_ST_COUNTDOWN);
				if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME)) watcherType |= SDWTF_SPECIFICTIME;
				if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_MESSAGE)) watcherType |= SDWTF_MESSAGE;
				if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_FILETRANSFER)) watcherType |= SDWTF_FILETRANSFER;
				if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_IDLE)) watcherType |= SDWTF_IDLE;
				if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_STATUS)) watcherType |= SDWTF_STATUS;
				if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_CPUUSAGE)) watcherType |= SDWTF_CPUUSAGE;
				db_set_w(NULL, "AutoShutdown", "WatcherFlags", watcherType);
				ServiceStartWatcher(0, watcherType);
			}
			DestroyWindow(hwndDlg);
			return TRUE;
			// fall through 

		case IDCANCEL: /* WM_CLOSE */
			DestroyWindow(hwndDlg);
			SetShutdownToolbarButton(false);
			SetShutdownMenuItem(false);
			return TRUE;
		}
		break;
	}
	return FALSE;
}
Example #30
-1
/* Render a character. */
int
win_render_char(gx_xfont * xf, gx_xglyph xg, gx_device * dev,
		int xo, int yo, gx_color_index color, int required)
{
    char chr = (char)xg;
    int code;

#ifdef NOTUSED			/* we don't own any windows so we can no longer do this */
    if (dev->dname == gs_mswin_device.dname &&
	wdev->hdctext != NULL && !wxf->invert_y
	) {			/* Display the character directly */
	HDC hdc = wdev->hdctext;
	PALETTEENTRY *pal = &wdev->limgpalette->palPalEntry[color];

	if ((code = win_select_font(hdc, wxf)) < 0)
	    return code;
	SetTextColor(hdc, RGB(pal->peRed, pal->peGreen, pal->peBlue));
	SetBkMode(hdc, TRANSPARENT);
	TextOut(hdc, xo, yo - wxf->y_offset, &chr, 1);
    } else
#endif
    if (!required)
	code = -1;		/* too hard */
    else {			/* Display on an intermediate bitmap, then copy the bits. */
	gs_point wxy;
	gs_int_rect bbox;
	int w, h, wbm, raster;
	gx_device_win *fdev = wxf->dev;
	HBITMAP hbm;
	byte *bits;

	code = (*xf->common.procs->char_metrics) (xf, xg, 0,
						  &wxy, &bbox);
	if (code < 0)
	    return code;
	w = bbox.q.x - bbox.p.x;
	h = bbox.q.y - bbox.p.y;
	wbm = ROUND_UP(w, align_bitmap_mod * 8);
	raster = wbm >> 3;
	bits = gs_malloc(dev->memory, h, raster, "win_render_char");
	if (bits == 0)
	    return gs_error_limitcheck;
	hbm = CreateBitmap(wbm, h, 1, 1, NULL);
	if (hbm == NULL) {
	    code = gs_error_limitcheck;
	} else {
	    HDC hdcwin = win_get_dc(fdev);
	    HDC hdcbit = CreateCompatibleDC(hdcwin);

	    dev_proc_copy_mono((*copy_mono)) =
		dev_proc(dev, copy_mono);
	    int y = yo - wxf->y_offset;

	    SetMapMode(hdcbit, GetMapMode(hdcwin));
	    win_select_font(hdcbit, wxf);
	    SelectObject(hdcbit, hbm);
	    PatBlt(hdcbit, 0, 0, wbm, h, rop_write_0s);
	    SetTextColor(hdcbit, 0xffffffL);	/* 1 */
	    SetBkMode(hdcbit, TRANSPARENT);
	    TextOut(hdcbit, 0, 0, &chr, 1);
	    GetBitmapBits(hbm, (DWORD) raster * h, bits);
	    DeleteDC(hdcbit);
	    win_release_dc(fdev, hdcwin);
	    DeleteObject(hbm);
	    if (!wxf->invert_y)
		code = (*copy_mono) (dev, bits, 0,
				     raster, gx_no_bitmap_id,
				     xo, y, w, h,
				     gx_no_color_index, color);
	    else {		/* Copy scan lines in reverse order. */
		int i;

		y += h - 1;
		for (i = 0; i < h; i++)
		    (*copy_mono) (dev, bits + i * raster,
				  0, raster, gx_no_bitmap_id,
				  xo, y - i, w, 1,
				  gx_no_color_index, color);
	    }
	}
	gs_free(dev->memory, bits, h, raster, "win_render_char");
    }
    return (code < 0 ? code : 0);
}