void NativeTextfieldWin::OnNCPaint(HRGN region)
    {
        if(!textfield_->draw_border())
        {
            return;
        }

        HDC hdc = GetWindowDC();

        RECT window_rect;
        GetWindowRect(&window_rect);
        // Convert to be relative to 0x0.
        ::OffsetRect(&window_rect, -window_rect.left, -window_rect.top);

        ExcludeClipRect(hdc,
            window_rect.left+content_insets_.left(),
            window_rect.top+content_insets_.top(),
            window_rect.right-content_insets_.right(),
            window_rect.bottom-content_insets_.bottom());

        HBRUSH brush = CreateSolidBrush(bg_color_);
        FillRect(hdc, &window_rect, brush);
        DeleteObject(brush);

        int part;
        int state;

        if(base::win::GetVersion() < base::win::VERSION_VISTA)
        {
            part = EP_EDITTEXT;

            if(!textfield_->IsEnabled())
            {
                state = ETS_DISABLED;
            }
            else if(textfield_->read_only())
            {
                state = ETS_READONLY;
            }
            else if(!contains_mouse_)
            {
                state = ETS_NORMAL;
            }
            else
            {
                state = ETS_HOT;
            }
        }
        else
        {
            part = EP_EDITBORDER_HVSCROLL;

            if(!textfield_->IsEnabled())
            {
                state = EPSHV_DISABLED;
            }
            else if(GetFocus() == m_hWnd)
            {
                state = EPSHV_FOCUSED;
            }
            else if(contains_mouse_)
            {
                state = EPSHV_HOT;
            }
            else
            {
                state = EPSHV_NORMAL;
            }
            // Vista doesn't appear to have a unique state for readonly.
        }

        int classic_state =
            (!textfield_->IsEnabled() || textfield_->read_only()) ? DFCS_INACTIVE : 0;

        gfx::NativeThemeWin::instance()->PaintTextField(hdc, part, state, classic_state,
            &window_rect, bg_color_, false, true);

        // NOTE: I tried checking the transparent property of the theme and invoking
        // drawParentBackground, but it didn't seem to make a difference.

        ReleaseDC(hdc);
    }
Example #2
0
// Handles OS messages, is driven by the 'main loop' above.
LRESULT CALLBACK MainWindowProcedure(HWND windowHandle, UINT messageCode, WPARAM wParam, LPARAM lParam)
{
	switch (messageCode) {
	// On window creation.
	case WM_CREATE:
		DEBUG_OUT(TEXT("WM_CREATE message"));
		// Start game loop timer.
		DEBUG_VAL(TEXT("SetTimer()"), SetTimer(windowHandle, MAIN_CYCLE_TIMER_ID, MAIN_CYCLE_WAIT, NULL));
		break;
	
	// Upon redraw request or something else changing we draw the window.
	case WM_PAINT:
		{
			PAINTSTRUCT paintJobStruct;
			HDC deviceContextHandle = BeginPaint(windowHandle, &paintJobStruct);
			HDC bufferDeviceContextHandle = CreateCompatibleDC(deviceContextHandle);
			HBITMAP bufferBitmapHandle = CreateCompatibleBitmap(deviceContextHandle, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT);
			HGDIOBJ oldBufferBitmapHandle = SelectObject(bufferDeviceContextHandle, bufferBitmapHandle);
			Gdiplus::Graphics graphics(bufferDeviceContextHandle);
			graphics.SetSmoothingMode(GRAPHICS_SMOOTHING_MODE);
			DrawGame(graphics, *mainGameObject);
			BitBlt(deviceContextHandle, 0, 0, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, bufferDeviceContextHandle, 0, 0, SRCCOPY);
			SelectObject(bufferDeviceContextHandle, oldBufferBitmapHandle);
			DeleteDC(bufferDeviceContextHandle);
			DeleteObject(bufferBitmapHandle);
			EndPaint(windowHandle, &paintJobStruct);
		}
		break;
	
	// When a user presses a key (can be triggered by auto-repeat).
	case WM_KEYDOWN:
		DEBUG_OUT(TEXT("WM_KEYDOWN message"));
		DEBUG_VAL(TEXT("wParam"), wParam);
		switch(wParam) {
		case VK_LEFT:
		case VK_UP:
		case VK_RIGHT:
		case VK_DOWN:
			DEBUG_OUT(TEXT("Arrow key pressed"));
			mainGameObject->Input(wParam);
		}
		break;
		
	case WM_TIMER:
		if (wParam == MAIN_CYCLE_TIMER_ID) {
			// This is where the 'main game loop' kicks in.  This line should be reached at a frequency of about 60Hz.
			mainGameObject->Step(windowHandle);
			RedrawWindow(windowHandle, NULL, NULL, RDW_INVALIDATE);
			//InvalidateRect(windowHandle, NULL, TRUE);
			//UpdateWindow(windowHandle);
		}
		break;
		
	case WM_CLOSE:
		DEBUG_OUT(TEXT("WM_CLOSE message"));
		// Clean up Windows API objects and etc.
		KillTimer(windowHandle, MAIN_CYCLE_TIMER_ID);
		DestroyWindow(windowHandle);
		break;
		
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
		
	default:
		return DefWindowProc(windowHandle, messageCode, wParam, lParam);
		break;
	}
	return 0;
}
Example #3
0
static void drawbmp(fz_context *ctx, fz_document *doc, fz_page *page, fz_display_list *list, int pagenum, fz_cookie *cookie)
{
	float zoom;
	fz_matrix ctm;
	fz_irect ibounds;
	fz_rect bounds, tbounds;

	int w, h;
	fz_device *dev;
	HDC dc, dc_main;
	RECT rc;
	HBRUSH bg_brush;
	HBITMAP hbmp;
	BITMAPINFO bmi = { 0 };
	int bmp_data_len;
	unsigned char *bmp_data;
	int as_tga = !strstr(output, ".bmp");

	fz_bound_page(doc, page, &bounds);
	zoom = resolution / 72;
	fz_pre_scale(fz_rotate(&ctm, rotation), zoom, zoom);
	tbounds = bounds;
	fz_round_rect(&ibounds, fz_transform_rect(&tbounds, &ctm));

	w = width;
	h = height;
	if (res_specified)
	{
		fz_round_rect(&ibounds, &tbounds);
		if (w && ibounds.x1 - ibounds.x0 <= w)
			w = 0;
		if (h && ibounds.y1 - ibounds.y0 <= h)
			h = 0;
	}
	if (w || h)
	{
		float scalex = w / (tbounds.x1 - tbounds.x0);
		float scaley = h / (tbounds.y1 - tbounds.y0);
		fz_matrix scale_mat;
		if (w == 0)
			scalex = fit ? 1.0f : scaley;
		if (h == 0)
			scaley = fit ? 1.0f : scalex;
		if (!fit)
			scalex = scaley = min(scalex, scaley);
		fz_concat(&ctm, &ctm, fz_scale(&scale_mat, scalex, scaley));
		tbounds = bounds;
		fz_transform_rect(&tbounds, &ctm);
	}
	fz_round_rect(&ibounds, &tbounds);
	fz_rect_from_irect(&tbounds, &ibounds);

	w = ibounds.x1 - ibounds.x0;
	h = ibounds.y1 - ibounds.y0;

	dc_main = GetDC(NULL);
	dc = CreateCompatibleDC(dc_main);
	hbmp = CreateCompatibleBitmap(dc_main, w, h);
	DeleteObject(SelectObject(dc, hbmp));

	SetRect(&rc, 0, 0, w, h);
	bg_brush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF));
	FillRect(dc, &rc, bg_brush);
	DeleteObject(bg_brush);

	dev = fz_new_gdiplus_device(ctx, dc, &tbounds);
	if (list)
		fz_run_display_list(list, dev, &ctm, &tbounds, cookie);
	else
		fz_run_page(doc, page, dev, &ctm, cookie);
	fz_free_device(dev);

	bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
	bmi.bmiHeader.biWidth = w;
	bmi.bmiHeader.biHeight = as_tga ? -h : h;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biBitCount = as_tga ? 32 : 24;
	bmi.bmiHeader.biCompression = BI_RGB;

	bmp_data_len = as_tga ? w * h * 4 : ((w * 3 + 3) / 4) * 4 * h;
	bmp_data = fz_malloc(ctx, bmp_data_len);
	if (!GetDIBits(dc, hbmp, 0, h, bmp_data, &bmi, DIB_RGB_COLORS))
		fz_throw(ctx, "cannot draw page %d in PDF file '%s'", pagenum, filename);

	DeleteDC(dc);
	ReleaseDC(NULL, dc_main);
	DeleteObject(hbmp);

	if (output)
	{
		char buf[512];
		FILE *f;

		sprintf(buf, output, pagenum);
		f = fopen(buf, "wb");
		if (!f)
			fz_throw(ctx, "could not create raster file '%s'", buf);

		if (as_tga)
		{
			fz_pixmap *pix = fz_new_pixmap_with_data(ctx, fz_device_bgr, w, h, bmp_data);
			fz_write_tga(ctx, pix, buf, 0);
			fz_drop_pixmap(ctx, pix);
		}
		else
		{
			BITMAPFILEHEADER bmpfh = { 0 };
			static const int one = 1;
			if (!*(char *)&one)
				fz_throw(ctx, "rendering to BMP is not supported on big-endian architectures");

			bmpfh.bfType = MAKEWORD('B', 'M');
			bmpfh.bfOffBits = sizeof(bmpfh) + sizeof(bmi);
			bmpfh.bfSize = bmpfh.bfOffBits + bmp_data_len;

			fwrite(&bmpfh, sizeof(bmpfh), 1, f);
			fwrite(&bmi, sizeof(bmi), 1, f);
			fwrite(bmp_data, 1, bmp_data_len, f);
		}

		fclose(f);
	}

	if (showmd5)
	{
		fz_pixmap *pix = fz_new_pixmap_with_data(ctx, fz_device_bgr, bmp_data_len / 4 / h, h, bmp_data);
		unsigned char digest[16];
		int i;

		fz_md5_pixmap(pix, digest);
		printf(" ");
		for (i = 0; i < 16; i++)
			printf("%02x", digest[i]);

		fz_drop_pixmap(ctx, pix);
	}

	fz_free(ctx, bmp_data);
}
HFONT CATCodeMgr::CheckFont( HDC hdc )
{
	HFONT hRetVal = NULL;

	TEXTMETRIC tm;
	BOOL bRes = GetTextMetrics(hdc, &tm);

	// 폰트 다시 로드
	if( bRes )//&& tm.tmHeight != lLastFontHeight )
	{
		
		HFONT font = NULL;
		long lFontSize = tm.tmHeight;
		
		if(m_strFontFace.IsEmpty())
		{
			m_strFontFace = _T("궁서");
		}

		// 폰트페이스명이 바뀌었으면 맵 초기화
		if(m_strLastFontFace.Compare(m_strFontFace))
		{
			for(map<long, HFONT>::iterator iter = m_mapFonts.begin();
				iter != m_mapFonts.end();
				iter++)
			{
				font = iter->second;
				DeleteObject(font);
			}
			m_mapFonts.clear();
		}
		
		// 폰트 크기 고정인 경우
		if(m_lFontSize !=0 && m_bFixedFontSize)
		{
			lFontSize = m_lFontSize;
		}

		// 이 크기에 해당하는 폰트가 없을 경우 폰트를 생성
		if( m_mapFonts.find(lFontSize) == m_mapFonts.end() )
		{
			font = CreateFont(lFontSize, 0, 0, 0, tm.tmWeight, tm.tmItalic, tm.tmUnderlined, tm.tmStruckOut,
				HANGEUL_CHARSET,	//ANSI_CHARSET,
				OUT_DEFAULT_PRECIS,
				CLIP_DEFAULT_PRECIS,
				ANTIALIASED_QUALITY,
				DEFAULT_PITCH,		// | FF_SWISS,
				m_strFontFace);

			m_mapFonts[lFontSize] = font;

		}
		else
		{
			font = m_mapFonts[lFontSize];
		}

		hRetVal = (HFONT)SelectObject(hdc, font);

	}

	/*
	TEXTMETRIC tm;
	BOOL bRes = GetTextMetrics(hdc, &tm);

	// 폰트 다시 로드
	if( bRes )
	{
		// 폰트 크기 고정인 경우
		if(m_lFontSize !=0 && m_bFixedFontSize)
		{
			tm.tmHeight = m_lFontSize;
		}

		HFONT font = InnerCreateFont(tm.tmHeight, 0, 0, 0, tm.tmWeight, tm.tmItalic, tm.tmUnderlined, tm.tmStruckOut,
			HANGEUL_CHARSET,	//ANSI_CHARSET,
			OUT_DEFAULT_PRECIS,
			CLIP_DEFAULT_PRECIS,
			ANTIALIASED_QUALITY,
			DEFAULT_PITCH,		// | FF_SWISS,
			(LPWSTR)(LPCWSTR)m_strFontFace);

		if(font)
		{
			hRetVal = (HFONT)SelectObject(hdc, font);
		}
	}
	*/

	return hRetVal;

}
Example #5
0
/* The function makes the window visible if it is hidden
 or is not yet shown. */
void
SplashRedrawWindow(Splash * splash)
{
    if (!SplashIsStillLooping(splash)) {
        KillTimer(splash->hWnd, 0);
    }

    if (splash->currentFrame < 0) {
        return;
    }

    SplashUpdateScreenData(splash);
    if (splash->isLayered) {
        BLENDFUNCTION bf;
        POINT ptSrc;
        HDC hdcSrc = CreateCompatibleDC(NULL), hdcDst;
        BITMAPINFOHEADER bmi;
        void *bitmapBits;
        HBITMAP hBitmap, hOldBitmap;
        RECT rect;
        POINT ptDst;
        SIZE size;

        bf.BlendOp = AC_SRC_OVER;
        bf.BlendFlags = 0;
        bf.AlphaFormat = AC_SRC_ALPHA;
        bf.SourceConstantAlpha = 0xFF;
        ptSrc.x = ptSrc.y = 0;

        memset(&bmi, 0, sizeof(bmi));
        bmi.biSize = sizeof(BITMAPINFOHEADER);
        bmi.biWidth = splash->width;
        bmi.biHeight = -splash->height;
        bmi.biPlanes = 1;
        bmi.biBitCount = 32;
        bmi.biCompression = BI_RGB;

        //      FIXME: this is somewhat ineffective
        //      maybe if we allocate memory for all frames as DIBSections,
        //      then we could select the frames into the DC directly

        hBitmap = CreateDIBSection(NULL, (BITMAPINFO *) & bmi, DIB_RGB_COLORS,
                &bitmapBits, NULL, 0);
        memcpy(bitmapBits, splash->screenData,
                splash->screenStride * splash->height);
        hOldBitmap = (HBITMAP) SelectObject(hdcSrc, hBitmap);
        hdcDst = GetDC(splash->hWnd);

        GetWindowRect(splash->hWnd, &rect);

        ptDst.x = rect.left;
        ptDst.y = rect.top;

        size.cx = splash->width;
        size.cy = splash->height;

        UpdateLayeredWindow(splash->hWnd, hdcDst, &ptDst, &size,
                hdcSrc, &ptSrc, 0, &bf, ULW_ALPHA);

        ReleaseDC(splash->hWnd, hdcDst);
        SelectObject(hdcSrc, hOldBitmap);
        DeleteObject(hBitmap);
        DeleteDC(hdcSrc);
    }
    else {
       InvalidateRect(splash->hWnd, NULL, FALSE);
       if (splash->maskRequired) {
            HRGN hRgn = CreateRectRgn(0, 0, 0, 0);

            CombineRgn(hRgn, splash->frames[splash->currentFrame].hRgn,
                    splash->frames[splash->currentFrame].hRgn, RGN_COPY);
            SetWindowRgn(splash->hWnd, hRgn, TRUE);
        } else {
            SetWindowRgn(splash->hWnd, NULL, TRUE);
        }
        UpdateWindow(splash->hWnd);
    }
    if (!IsWindowVisible(splash->hWnd)) {
        POINT cursorPos;
        ShowWindow(splash->hWnd, SW_SHOW);
        // Windows won't update the cursor after the window is shown,
        // if the cursor is already above the window. need to do this manually.
        GetCursorPos(&cursorPos);
        if (WindowFromPoint(cursorPos) == splash->hWnd) {
            // unfortunately Windows fail to understand that the window
            // thread should own the cursor, even though the mouse pointer
            // is over the window, until the mouse has been moved.
            // we're using SetCursorPos here to fake the mouse movement
            // and enable proper update of the cursor.
            SetCursorPos(cursorPos.x, cursorPos.y);
            SetCursor(LoadCursor(NULL, IDC_WAIT));
        }
    }
    if (SplashIsStillLooping(splash)) {
        int time = splash->time +
            splash->frames[splash->currentFrame].delay - SplashTime();

        if (time < 0)
            time = 0;
        SetTimer(splash->hWnd, 0, time, NULL);
    }
}
Example #6
0
HBITMAP CopyBitmapTo32(HBITMAP hBitmap)
{
	BITMAPINFO RGB32BitsBITMAPINFO; 
	BYTE * ptPixels;
	HBITMAP hDirectBitmap;

	BITMAP bmp;
	DWORD dwLen;
	BYTE *p;

	GetObject(hBitmap, sizeof(bmp), &bmp);

	dwLen = bmp.bmWidth * bmp.bmHeight * 4;
	p = (BYTE *)malloc(dwLen);
	if (p == NULL)
		return NULL;

	// Create bitmap
	ZeroMemory(&RGB32BitsBITMAPINFO, sizeof(BITMAPINFO));
	RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	RGB32BitsBITMAPINFO.bmiHeader.biWidth = bmp.bmWidth;
	RGB32BitsBITMAPINFO.bmiHeader.biHeight = bmp.bmHeight;
	RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
	RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;

	hDirectBitmap = CreateDIBSection(NULL, 
					(BITMAPINFO *)&RGB32BitsBITMAPINFO, 
					DIB_RGB_COLORS,
					(void **)&ptPixels, 
					NULL, 0);

	// Copy data
	if (bmp.bmBitsPixel != 32)
	{
		HDC hdcOrig, hdcDest;
		HBITMAP oldOrig, oldDest;
		
		hdcOrig = CreateCompatibleDC(NULL);
		oldOrig = (HBITMAP) SelectObject(hdcOrig, hBitmap);

		hdcDest = CreateCompatibleDC(NULL);
		oldDest = (HBITMAP) SelectObject(hdcDest, hDirectBitmap);

		BitBlt(hdcDest, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOrig, 0, 0, SRCCOPY);

		SelectObject(hdcDest, oldDest);
		DeleteObject(hdcDest);
		SelectObject(hdcOrig, oldOrig);
		DeleteObject(hdcOrig);

		// Set alpha
		CorrectBitmap32Alpha(hDirectBitmap, FALSE);
	}
	else
	{
		GetBitmapBits(hBitmap, dwLen, p);
		SetBitmapBits(hDirectBitmap, dwLen, p);
	}

	free(p);

	return hDirectBitmap;
}
Example #7
0
// Creation de bitmap coche
HBITMAP GetMyCheckBitmaps(UINT fuCheck) 
{ 
    COLORREF crBackground;  // background color                  
    HBRUSH hbrBackground;   // background brush                  
    HBRUSH hbrTargetOld;    // original background brush         
    HDC hdcSource;          // source device context             
    HDC hdcTarget;          // target device context             
    HBITMAP hbmpCheckboxes; // handle to check-box bitmap        
    BITMAP bmCheckbox;      // structure for bitmap data         
    HBITMAP hbmpSourceOld;  // handle to original source bitmap  
    HBITMAP hbmpTargetOld;  // handle to original target bitmap  
    HBITMAP hbmpCheck;      // handle to check-mark bitmap       
    RECT rc;                // rectangle for check-box bitmap    
    WORD wBitmapX;          // width of check-mark bitmap        
    WORD wBitmapY;          // height of check-mark bitmap       
 
    // Get the menu background color and create a solid brush 
    // with that color. 
 
    crBackground = GetSysColor(COLOR_MENU); 
    hbrBackground = CreateSolidBrush(crBackground); 
 
    // Create memory device contexts for the source and 
    // destination bitmaps. 
 
    hdcSource = CreateCompatibleDC((HDC) NULL); 
    hdcTarget = CreateCompatibleDC(hdcSource); 
 
    // Get the size of the system default check-mark bitmap and 
    // create a compatible bitmap of the same size. 
 
    wBitmapX = GetSystemMetrics(SM_CXMENUCHECK); 
    wBitmapY = GetSystemMetrics(SM_CYMENUCHECK); 
 
    hbmpCheck = CreateCompatibleBitmap(hdcSource, wBitmapX, 
        wBitmapY); 
 
    // Select the background brush and bitmap into the target DC. 
 
    hbrTargetOld = SelectObject(hdcTarget, hbrBackground); 
    hbmpTargetOld = SelectObject(hdcTarget, hbmpCheck); 
 
    // Use the selected brush to initialize the background color 
    // of the bitmap in the target device context. 
 
    PatBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, PATCOPY); 
 
    // Load the predefined check box bitmaps and select it 
    // into the source DC. 
 
    hbmpCheckboxes = LoadBitmap((HINSTANCE) NULL, 
        (LPTSTR) OBM_CHECKBOXES); 
 
    hbmpSourceOld = SelectObject(hdcSource, hbmpCheckboxes); 
 
    // Fill a BITMAP structure with information about the 
    // check box bitmaps, and then find the upper-left corner of 
    // the unchecked check box or the checked check box. 
 
    GetObject(hbmpCheckboxes, sizeof(BITMAP), &bmCheckbox); 
 
    if (fuCheck == 2 /*UNCHECK*/) 
    { 
        rc.left = 0; 
        rc.right = (bmCheckbox.bmWidth / 4); 
    } 
    else 
    { 
        rc.left = (bmCheckbox.bmWidth / 4); 
        rc.right = (bmCheckbox.bmWidth / 4) * 2; 
    } 
 
    rc.top = 0; 
    rc.bottom = (bmCheckbox.bmHeight / 3); 
 
    // Copy the appropriate bitmap into the target DC. If the 
    // check-box bitmap is larger than the default check-mark 
    // bitmap, use StretchBlt to make it fit; otherwise, just 
    // copy it. 
 
    if (((rc.right - rc.left) > (int) wBitmapX) || 
            ((rc.bottom - rc.top) > (int) wBitmapY)) 
    {
        StretchBlt(hdcTarget, 0, 0, wBitmapX, wBitmapY, 
            hdcSource, rc.left, rc.top, rc.right - rc.left, 
            rc.bottom - rc.top, SRCCOPY); 
    }
 
    else 
    {
        BitBlt(hdcTarget, 0, 0, rc.right - rc.left, 
            rc.bottom - rc.top, 
            hdcSource, rc.left, rc.top, SRCCOPY); 
    }
 
    // Select the old source and destination bitmaps into the 
    // source and destination DCs, and then delete the DCs and 
    // the background brush. 
 
    SelectObject(hdcSource, hbmpSourceOld); 
    SelectObject(hdcTarget, hbrTargetOld); 
    hbmpCheck = SelectObject(hdcTarget, hbmpTargetOld); 
 
    DeleteObject(hbrBackground); 
    DeleteObject(hdcSource); 
    DeleteObject(hdcTarget); 
 
    // Return a handle to the new check-mark bitmap.  
 
    return hbmpCheck; 
} 
Example #8
0
Brush_c34::~Brush_c34()
{
	DeleteObject(_brush);
}
Example #9
0
LPTSTR ASSISTANT::Text::GetTtfName()
{   
   static _TCHAR tszTtfName[512];


   HKEY hKeyMachine; 
   LONG regErr = RegOpenKeyEx (HKEY_LOCAL_MACHINE, 
                     _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"), NULL,KEY_READ,&hKeyMachine); 
	if ( regErr != ERROR_SUCCESS )
   {
      LONG regErr = RegOpenKeyEx (HKEY_LOCAL_MACHINE, 
                        _T("Software\\Microsoft\\Windows\\CurrentVersion\\Fonts"), NULL,KEY_READ,&hKeyMachine); 
      if ( regErr != ERROR_SUCCESS )
      {
         return NULL;
      }
	}

   DWORD subValues;
   regErr = RegQueryInfoKey(hKeyMachine, NULL, NULL, NULL, NULL, NULL, NULL, &subValues, NULL, NULL, NULL, NULL);
   if ( regErr != ERROR_SUCCESS )
   {
      return NULL;
   }

   HRESULT hr = ::CoInitialize(NULL);

   HDC hdc = ::CreateCompatibleDC(NULL);

   DWORD dwType;
   _TCHAR tszEntryName[512];
   _TCHAR tszEntryValue[512];
   
   HFONT font = CreateFontIndirect(&m_logFont);
   UINT cbData;       
   LPOUTLINETEXTMETRIC lpoltm;     
   SelectObject(hdc, font);
   cbData = GetOutlineTextMetrics (hdc, 0, NULL);
   DeleteObject(font);
   _TCHAR tszFontFace[512];
   if (cbData == 0) 
   {
      _tcscpy(tszFontFace, m_logFont.lfFaceName);
   }
   else
   {
      lpoltm = (LPOUTLINETEXTMETRIC)LocalAlloc (LPTR, cbData);
      GetOutlineTextMetrics (hdc, cbData, lpoltm);  
      _tcscpy(tszFontFace, (_TCHAR *)((DWORD) lpoltm + lpoltm->otmpFaceName));
   }

   bool bFoundFontInfo = false;
   for (int i = 0; i < subValues && !bFoundFontInfo; i++) 
   {       
      unsigned long entryNameLength = 512 * sizeof _TCHAR;
      unsigned long entryValueLength = 512 * sizeof _TCHAR;
      if (RegEnumValue(hKeyMachine, i, tszEntryName, &entryNameLength, 
         NULL, &dwType, (unsigned char *)tszEntryValue, &entryValueLength) != ERROR_SUCCESS)
      {
         continue;
      }
      
      _TCHAR tszFaceName[512];
      _tcscpy(tszFaceName, tszEntryName);
      _TCHAR *p = _tcsrchr(tszFaceName, '(');
      if (p != NULL)
         *p = '\0';

	  if (tszFaceName[_tcslen(tszFaceName) - 1] == _T(' '))
		  tszFaceName[_tcslen(tszFaceName) - 1] = _T('\0');

      if (_tcscmp(tszFontFace, tszFaceName) == 0)
      {
         bFoundFontInfo = true;
         UINT nStringLength = _tcslen(tszEntryValue);
         _tcscpy(tszTtfName, tszEntryValue);
         tszTtfName[nStringLength] = '\0';
      }

   }

   ::DeleteDC(hdc);
   ::CoUninitialize();

   RegCloseKey(hKeyMachine);

   if (bFoundFontInfo)
      return tszTtfName;
   else
      return NULL;

}
Example #10
0
ULONG FASTCALL WG32CreateDIBSection(PVDMFRAME pFrame)
{
    ULONG              ul = 0;
    STACKBMI32         bmi32;
    LPBITMAPINFO       lpbmi32;
    HBITMAP            hbm32;
    PVOID              pv16, pvBits, pvIntelBits;
    PVPVOID            vpbmi16;
    PVOID              pvBits32;
    DWORD              dwArg16;

    register PCREATEDIBSECTION16 parg16;

    GETARGPTR(pFrame, sizeof(CREATEDIBSECTION16), parg16);

    // this is performance hack so we don't generate extra code
    dwArg16 = FETCHDWORD(parg16->f4); // do it once here
    pv16 = (PVOID)GetPModeVDMPointer(dwArg16, sizeof(DWORD)); // aligned here!

    WOW32ASSERTMSG(((parg16->f5 == 0) && (parg16->f6 == 0)),
                   ("WOW:WG32CreateDIBSection, hSection/dwOffset non-null\n"));

    vpbmi16 = (PVPVOID)FETCHDWORD(parg16->f2);
    lpbmi32 = CopyBMI16ToBMI32(vpbmi16,
                               (LPBITMAPINFO)&bmi32,
                               FETCHWORD(parg16->f3));

    hbm32 = CreateDIBSection(HDC32(parg16->f1),
                             lpbmi32,
                             WORD32(parg16->f3),
                             &pvBits,
                             NULL,
                             0);

    if (hbm32 != 0)
    {
        PARM16          Parm16;
        PDIBSECTIONINFO pdi;
        ULONG           SelectorLimit;

        SelectorLimit = (ULONG)cjBitmapBitsSize(lpbmi32);
#ifndef i386
        if (!NT_SUCCESS(VdmAddVirtualMemory((ULONG)pvBits,
                                            SelectorLimit,
                                            (PULONG)&pvIntelBits))) {
            LOGDEBUG(LOG_ALWAYS,("\nWOW::WG32CreateDibSection VdmAddVirtualMemory failed\n"));
            goto cds_err;
        }

#else
        pvIntelBits = pvBits;
#endif

        // Create a selector array for the bits backed by pvIntelBits

        Parm16.WndProc.wParam = (WORD)-1;           // -1 => allocate selectors
        Parm16.WndProc.lParam = (LONG) pvIntelBits; // backing pointer
        Parm16.WndProc.wMsg = 0x10;                 // GA_NOCOMPACT
        Parm16.WndProc.hwnd = (WORD)((SelectorLimit+65535)/65536);// selector count

        CallBack16(RET_SETDIBSEL,
                   &Parm16,
                   0,
                   (PVPVOID)&pvBits32);

        // 16:16 pointer is still valid as call above makes no difference
        if (pv16 != NULL) {
            *(UNALIGNED PVOID*)pv16 = pvBits32;
        }

        if (pvBits32 == NULL) {
            LOGDEBUG(LOG_ALWAYS,("\nWOW::WG32CreateDibSection, Callback set_sel_for_dib failed\n"));
            goto cds_err;
        }

#ifndef i386 
        // okay, that was successful - map the descriptors properly

        if (!VdmAddDescriptorMapping(HIWORD(pvBits32),
                                    (USHORT) ((SelectorLimit+65535)/65536),
                                    (ULONG) pvIntelBits,
                                    (ULONG) pvBits)) {
            LOGDEBUG(LOG_ALWAYS,("\nWOW::WG32CreateDibSection VdmAddDescriptorMapping failed\n"));
            goto cds_err;
        }
#endif
        
        LOGDEBUG(LOG_ALWAYS, ("\nWOW:CreateDIBSection: [16:16 %x] [Intel %x] [Flat %x]\n", 
                             pvBits32, pvIntelBits, pvBits));

        ul = GETHBITMAP16(hbm32);

        // Add it to the list used for cleanup at DeleteObject time.

        if ((pdi = malloc_w (sizeof (DIBSECTIONINFO))) != NULL) {
            pdi->di_hbm         = (HBITMAP)(HAND16)hbm32;
            pdi->di_pv16        = pvBits32;
#ifndef i386
            pdi->di_newIntelDib = pvIntelBits;
#endif
            pdi->di_next        = pDibSectionInfoHead;
            pDibSectionInfoHead = pdi;

            // need to turn batching off since a DIBSECTION means the app can
            // also draw on the bitmap and we need synchronization.

            GdiSetBatchLimit(1);

            goto cds_ok;
        }
        else {
            // Failure, free the selector array

            Parm16.WndProc.wParam = (WORD)-1;            // -1 => allocate/free
            Parm16.WndProc.lParam = (LONG) pvBits32; // pointer
            Parm16.WndProc.wMsg = 0x10; // GA_NOCOMPACT
            Parm16.WndProc.hwnd = 0;                     // 0 => free

            CallBack16(RET_SETDIBSEL,
                       &Parm16,
                       0,
                       (PVPVOID)&ul);
#ifndef i386
            VdmRemoveVirtualMemory((ULONG)pvIntelBits);
#endif

        }
    }
    else {
        LOGDEBUG(LOG_ALWAYS,("\nWOW::WG32CreateDibSection, CreateDibSection Failed\n"));
    }

cds_err:

    if (hbm32 != 0) {
        DeleteObject(hbm32);
    }
    LOGDEBUG(LOG_ALWAYS,("\nWOW::WG32CreateDibSection returning failure\n"));
    ul = 0;

cds_ok:
    WOW32APIWARN(ul, "CreateDIBSection");

    FREEMISCPTR(pv16);
    FREEARGPTR(parg16);

    return(ul);
}
Example #11
0
/*+/csubr/TOC/internal-------------------------------------------------------
* PlPOINTPlot - plot an array of POINT structures
*
* Purpose:
*		Plots an array of POINT structures.
*
*		If the number of points is 1, then PL_LINE... gets plotted as
*		though it were PL_POINT.
*
* Return Value:
*		PL_OK, or
*		other error codes
*
*-Date     Author		Revision
* -------- ------------	--------
* 09-27-95 R. Cole		created
*--------------------------------------------------------------------------*/
int
PlPOINTPlot(
PL_CTX	*pPlot,			// I pointer to plot context structure
HDC		hDC,			// I HDC
const RECT *pRectPts,	// I pointer to rect bounding points, or NULL
const POINT *aPts,		// I array of POINT structures
int		nPts,			// I number of array elements
int		eDrawType,		// I PL_LINE... or PL_POINT or PL_... mark
float	fPts,			// I drawing thickness or mark size, in points
COLORREF rgb)			// I color to use for drawing
{
	int		retStat=PL_OK;
	HBRUSH	hBrush=0, hOldBrush=0;
	HPEN	hPen=0, hOldPen=0;
	int		stat, j;
	RECT	rectPts;

	// If the caller has told us the RECT that bounds the points to be
	// drawn, check to see if the RECT (or a part of it) lies within
	// the area of the window that needs to be drawn.  If not, just
	// exit from this routine.
	if (pRectPts != NULL) {
		rectPts = *pRectPts;
		// Make the rect follow the Windows convention.
		rectPts.right += 1;
		rectPts.bottom += 1;

		if (pPlot->hRgnPaint != 0) {
			if (!RectInRegion(pPlot->hRgnPaint, &rectPts))
				goto done;
		}
		if (!RectVisible(hDC, &rectPts))
			goto done;
	}

	// Now draw the actual data points.  There is a separate section
	// here for each drawing type.  One of the overriding objectives
	// in how this is coded is to minimize the number of subroutine
	// calls.
	if (nPts >= 2 && eDrawType >= PL_LINE &&
					eDrawType <= PL_LINE_DASHDOTDOT) {
// Draw all "line" types.
		stat = Polyline(hDC, aPts, nPts);
		if (stat == 0) {
			// In some cases (not well understood), Polyline
			// fails.  When this happens, draw the line one
			// point at a time.
			MoveToEx(hDC, aPts[0].x, aPts[0].y, NULL);
			for (j=1; j<nPts; j++) 
				LineTo(hDC, aPts[j].x, aPts[j].y);
		}
		SetPixel(hDC, aPts[nPts-1].x, aPts[nPts-1].y, rgb);
	}
	else if (eDrawType >= PL_SQUARE && eDrawType <= PL_CROSS) {
// Draw all "plot mark" types.
		int		wid, ht;

		ht = PL_YPTS_TO_YPIX(fPts);
		wid = PL_XPTS_TO_XPIX(fPts);
		for (j=0; j<nPts; j++)  {
			retStat = PlDraw_discrete(pPlot, hDC,
				aPts[j].x, aPts[j].y,
				wid, ht, eDrawType,
				0, 0, 0, 0, 0, 0,
				rgb);
			if (retStat != PL_OK) goto done;
		}
	}
	else {
// Draw PL_POINT type.
		int		nX, nY;
		nX = PL_XPTS_TO_XPIX(fPts);
		nY = PL_YPTS_TO_YPIX(fPts);
		if (nX <= 1 && nY <= 1) {
			for (j=0; j<nPts; j++)
				SetPixel(hDC, aPts[j].x, aPts[j].y, rgb);
		}
		else {
			int		xL, xR, yB, yT;
			int		iHalfWid=(nX - 1)/2;
			int		iHalfHt=(nY - 1)/2;
			if ((hPen = CreatePen(PS_SOLID, 1, rgb)) == 0) goto gdi_error;
			/* KG */
			//hOldPen = SelectObject(hDC, hPen);
			hOldPen = (HPEN)SelectObject(hDC, hPen);
			if ((hBrush = CreateSolidBrush(rgb)) == 0) goto gdi_error;
			/* KG */
			//hOldBrush = SelectObject(hDC, hBrush);
			hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);

			for (j=0; j<nPts; j++)  {
				xL = aPts[j].x - iHalfWid;
				xR = xL + nX;
				yT = aPts[j].y - iHalfHt;
				yB = yT + nY;
				Ellipse(hDC, xL, yT, xR, yB);
			}
		}
	}

done:
	if (hOldPen != 0) SelectObject(hDC, hOldPen);
	if (hPen != 0) DeleteObject(hPen);
	if (hOldBrush != 0) SelectObject(hDC, hOldBrush);
	if (hBrush != 0) DeleteObject(hBrush);
	return retStat;

gdi_error:
	retStat = PL_GDI_FAIL;
	goto done;
}
Example #12
0
static void test_setfont(DWORD style)
{
    HWND hCombo;
    HFONT hFont1, hFont2;
    RECT r;
    int i;

    if (!is_font_installed("Marlett"))
    {
        skip("Marlett font not available\n");
        return;
    }

    trace("Style %x\n", style);

    hCombo = build_combo(style);
    hFont1 = CreateFontA(10, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
    hFont2 = CreateFontA(8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");

    GetClientRect(hCombo, &r);
    expect_rect(r, 0, 0, 100, font_height(GetStockObject(SYSTEM_FONT)) + 8);
    SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
    MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
    todo_wine expect_rect(r, 5, 5, 105, 105);

    /* The size of the dropped control is initially equal to the size
       of the window when it was created.  The size of the calculated
       dropped area changes only by how much the selection area
       changes, not by how much the list area changes.  */
    if (font_height(hFont1) == 10 && font_height(hFont2) == 8)
    {
        SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
        GetClientRect(hCombo, &r);
        expect_rect(r, 0, 0, 100, 18);
        SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
        MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
        todo_wine expect_rect(r, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT)) - font_height(hFont1)));

        SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont2, FALSE);
        GetClientRect(hCombo, &r);
        expect_rect(r, 0, 0, 100, 16);
        SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
        MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
        todo_wine expect_rect(r, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT)) - font_height(hFont2)));

        SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
        GetClientRect(hCombo, &r);
        expect_rect(r, 0, 0, 100, 18);
        SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
        MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
        todo_wine expect_rect(r, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT)) - font_height(hFont1)));
    }
    else
    {
        ok(0, "Expected Marlett font heights 10/8, got %d/%d\n",
           font_height(hFont1), font_height(hFont2));
    }

    for (i = 1; i < 30; i++)
    {
        HFONT hFont = CreateFontA(i, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
        int height = font_height(hFont);

        SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont, FALSE);
        GetClientRect(hCombo, &r);
        expect_eq(r.bottom - r.top, height + 8, int, "%d");
        SendMessageA(hCombo, WM_SETFONT, 0, FALSE);
        DeleteObject(hFont);
    }

    DestroyWindow(hCombo);
    DeleteObject(hFont1);
    DeleteObject(hFont2);
}
Example #13
0
/* Функция обработки сообщения окна.
* АРГУМЕНТЫ:
* - дескриптор окна:
* HWND hWnd;
* - номер сообщения (см. WM_***):
* UINT Msg;
* - параметр сообшения ('word parameter'):
* WPARAM wParam;
* - параметр сообшения ('long parameter'):
* LPARAM lParam;
* ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ:
* (LRESULT) - в зависимости от сообщения.
*/
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam )
{
HDC hDC;
static HDC hMemDC;
static INT w, h;
static BITMAP bm;
static HBITMAP hBm;
switch (Msg)
{
case WM_CREATE:
SetTimer(hWnd, 111, 50, NULL);
/* создаем контекст в памяти */
hDC = GetDC(hWnd);
hMemDC = CreateCompatibleDC(hDC);
ReleaseDC(hWnd, hDC);
return 0;
case WM_SIZE:
w = LOWORD(lParam);
h = HIWORD(lParam);
/* создаем картинку размером с окно */
if (hBm != NULL)
DeleteObject(hBm);
hDC = GetDC(hWnd);
hBm = CreateCompatibleBitmap(hDC, w, h);
ReleaseDC(hWnd, hDC);
SelectObject(hMemDC, hBm);
SendMessage(hWnd, WM_TIMER, 111, 0);
return 0;
case WM_TIMER:
/* Clear Background */
SelectObject(hMemDC, GetStockObject(NULL_PEN));
SelectObject(hMemDC, GetStockObject(DC_BRUSH));
SetDCBrushColor(hMemDC, RGB(255, 255, 255));
Rectangle(hMemDC, 0, 0, w + 1, h + 1);
SelectObject(hMemDC, GetStockObject(NULL_PEN));
SelectObject(hMemDC, GetStockObject(DC_BRUSH));
SetDCBrushColor(hMemDC, RGB(255, 0, 0));
GlobeBuild();
GlobeDraw(hMemDC, w, h);
InvalidateRect(hWnd, NULL, TRUE);
return 0;
case WM_KEYDOWN:
if (wParam == 'F')
  FlipFullScreen(hWnd);
if (wParam == 27)
  SendMessage(hWnd, WM_CLOSE, 0, 0);
if (wParam == 'W')
  IsWire = !IsWire;
return 0;

case WM_CLOSE:
if (MessageBox(hWnd, "Are you shure to exit from program?",
"Exit", MB_YESNO | MB_ICONQUESTION) == IDNO)
return 0;
break;
case WM_ERASEBKGND:
BitBlt((HDC)wParam, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
return 0;
case WM_DESTROY:
DeleteDC(hMemDC);
DeleteObject(hBm);
KillTimer(hWnd, 111);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
Example #14
0
HICON _al_win_create_icon(HWND wnd,
   ALLEGRO_BITMAP *sprite, int xfocus, int yfocus, bool is_cursor)
{
   int x, y;
   int sys_sm_cx, sys_sm_cy;
   HDC h_dc;
   HDC h_and_dc;
   HDC h_xor_dc;
   ICONINFO iconinfo;
   HBITMAP and_mask;
   HBITMAP xor_mask;
   HBITMAP hOldAndMaskBitmap;
   HBITMAP hOldXorMaskBitmap;
   HICON icon;

   if (is_cursor) {
      /* Get allowed cursor size - Windows can't make cursors of arbitrary size */
      sys_sm_cx = GetSystemMetrics(SM_CXCURSOR);
      sys_sm_cy = GetSystemMetrics(SM_CYCURSOR);
   }
   else {
      sys_sm_cx = GetSystemMetrics(SM_CXICON);
      sys_sm_cy = GetSystemMetrics(SM_CYICON);
   }

   if ((sprite->w > sys_sm_cx) || (sprite->h > sys_sm_cy)) {
      return NULL;
   }

   /* Create bitmap */
   h_dc = GetDC(wnd);
   h_xor_dc = CreateCompatibleDC(h_dc);
   h_and_dc = CreateCompatibleDC(h_dc);

   /* Prepare AND (monochrome) and XOR (colour) mask */
   and_mask = CreateBitmap(sys_sm_cx, sys_sm_cy, 1, 1, NULL);
   xor_mask = CreateCompatibleBitmap(h_dc, sys_sm_cx, sys_sm_cy);
   hOldAndMaskBitmap = (HBITMAP) SelectObject(h_and_dc, and_mask);
   hOldXorMaskBitmap = (HBITMAP) SelectObject(h_xor_dc, xor_mask);

   /* Create transparent cursor */
   for (y = 0; y < sys_sm_cy; y++) {
      for (x = 0; x < sys_sm_cx; x++) {
	 SetPixel(h_and_dc, x, y, WINDOWS_RGB(255, 255, 255));
	 SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0));
      }
   }

   local_draw_to_hdc(h_xor_dc, sprite, 0, 0);

   /* Make cursor background transparent */
   for (y = 0; y < sprite->h; y++) {
      for (x = 0; x < sprite->w; x++) {
         ALLEGRO_COLOR c;
         unsigned char r, g, b, a;

         c = al_get_pixel(sprite, x, y);
         al_unmap_rgba(c, &r, &g, &b, &a);
         if (a != 0) {
	    /* Don't touch XOR value */
	    SetPixel(h_and_dc, x, y, 0);
	 }
	 else {
	    /* No need to touch AND value */
	    SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0));
	 }
      }
   }

   SelectObject(h_and_dc, hOldAndMaskBitmap);
   SelectObject(h_xor_dc, hOldXorMaskBitmap);
   DeleteDC(h_and_dc);
   DeleteDC(h_xor_dc);
   ReleaseDC(wnd, h_dc);

   iconinfo.fIcon = is_cursor ? false : true;
   iconinfo.xHotspot = xfocus;
   iconinfo.yHotspot = yfocus;
   iconinfo.hbmMask = and_mask;
   iconinfo.hbmColor = xor_mask;

   icon = CreateIconIndirect(&iconinfo);

   DeleteObject(and_mask);
   DeleteObject(xor_mask);

   return icon;
}
Example #15
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 #16
0
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
                              const GLFWimage* image,
                              int xhot, int yhot)
{
    HDC dc;
    HBITMAP bitmap, mask;
    BITMAPV5HEADER bi;
    ICONINFO ii;
    DWORD* target = 0;
    BYTE* source = (BYTE*) image->pixels;
    int i;

    ZeroMemory(&bi, sizeof(bi));
    bi.bV5Size        = sizeof(BITMAPV5HEADER);
    bi.bV5Width       = image->width;
    bi.bV5Height      = -image->height;
    bi.bV5Planes      = 1;
    bi.bV5BitCount    = 32;
    bi.bV5Compression = BI_BITFIELDS;
    bi.bV5RedMask     = 0x00ff0000;
    bi.bV5GreenMask   = 0x0000ff00;
    bi.bV5BlueMask    = 0x000000ff;
    bi.bV5AlphaMask   = 0xff000000;

    dc = GetDC(NULL);
    bitmap = CreateDIBSection(dc, (BITMAPINFO*) &bi, DIB_RGB_COLORS,
                              (void**) &target, NULL, (DWORD) 0);
    ReleaseDC(NULL, dc);

    if (!bitmap)
        return GL_FALSE;

    mask = CreateBitmap(image->width, image->height, 1, 1, NULL);
    if (!mask)
    {
        DeleteObject(bitmap);
        return GL_FALSE;
    }

    for (i = 0;  i < image->width * image->height;  i++, target++, source += 4)
    {
        *target = (source[3] << 24) |
                  (source[0] << 16) |
                  (source[1] <<  8) |
                   source[2];
    }

    ZeroMemory(&ii, sizeof(ii));
    ii.fIcon    = FALSE;
    ii.xHotspot = xhot;
    ii.yHotspot = yhot;
    ii.hbmMask  = mask;
    ii.hbmColor = bitmap;

    cursor->win32.handle = (HCURSOR) CreateIconIndirect(&ii);

    DeleteObject(bitmap);
    DeleteObject(mask);

    if (!cursor->win32.handle)
        return GL_FALSE;

    return GL_TRUE;
}
Example #17
0
void CMainFrame::OnFileCapture() 
{
	DlgCapture dlg;
	if (dlg.DoModal()==IDOK){
		// get the desired window from dialog box
		HWND hwnd=dlg.m_SelectedWnd;
		// get window size
		CRect r;
		::GetWindowRect(hwnd,&r);

		int xScreen,yScreen;	//check if the window is out of the screen or maximixed <Qiang>
		int xshift = 0, yshift = 0;
		xScreen = GetSystemMetrics(SM_CXSCREEN);
		yScreen = GetSystemMetrics(SM_CYSCREEN);
		if(r.right > xScreen)
			   r.right = xScreen;
		if(r.bottom > yScreen)
			   r.bottom = yScreen;
		if(r.left < 0){
			   xshift = -r.left;
			   r.left = 0;
		}
		if(r.top < 0){
			   yshift = -r.top;
			   r.top = 0;
		}
		
		CSize sz(r.Width(), r.Height());
		if(sz.cx <= 0 || sz.cy <= 0) return;

		// bring the window at the top most level
		::SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

		// prepare the DCs
		HDC dstDC = ::GetDC(NULL);
        HDC srcDC = ::GetWindowDC(hwnd); //full window (::GetDC(hwnd); = clientarea)
		HDC memDC = ::CreateCompatibleDC(dstDC);
		
		// copy the screen to the bitmap
		HBITMAP bm =::CreateCompatibleBitmap(dstDC, sz.cx, sz.cy);
		HBITMAP oldbm = (HBITMAP)::SelectObject(memDC,bm);
		::BitBlt(memDC, 0, 0, sz.cx, sz.cy, srcDC, xshift, yshift, SRCCOPY);
	
		// restore the position
		::SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		::SetWindowPos(m_hWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

		// prepare the new document
		CDemoDoc *NewDoc=(CDemoDoc*)((CDemoApp*)AfxGetApp())->demoTemplate->OpenDocumentFile(NULL); 
		if (NewDoc)	{
			CxImage *newima = new CxImage();
			newima->CreateFromHBITMAP(bm);
			NewDoc->image = newima;
			CString s;
			s.Format("Captured Image %d",((CDemoApp*)AfxGetApp())->m_nDocCount++);
			NewDoc->SetTitle(s);
			NewDoc->UpdateAllViews(0,WM_USER_NEWIMAGE);
			NewDoc->UpdateStatusBar();
		}

		// free objects
		DeleteObject(SelectObject(memDC,oldbm));
		DeleteObject(memDC);
	}
}
Example #18
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 #19
0
// Procedure de creation de menu à partir d'une clé de registre
HMENU InitLauncherMenu( char * Key ) {
	HMENU menu ;
	menu = CreatePopupMenu() ;
	char KeyName[1024] ;
	int nbitem = 0,i ;
	
	DeleteObject( bmpCheck ) ; bmpCheck = GetMyCheckBitmaps( 1 ) ;
	DeleteObject( bmpUnCheck ) ; bmpUnCheck = GetMyCheckBitmaps( 2 ) ;
	
	if( (IniFileFlag == SAVEMODE_REG)||(IniFileFlag == SAVEMODE_FILE) ) {
		sprintf( KeyName, "%s\\%s", TEXT(PUTTY_REG_POS), Key ) ;
		ReadSpecialMenu( menu, KeyName, &nbitem, 0 ) ;
		}
	else if( IniFileFlag == SAVEMODE_DIR ) {
		ReadSpecialMenu( menu, Key, &nbitem, 0 ) ;
		}

	if( GetMenuItemCount( menu ) > 0 )
		AppendMenu( menu, MF_SEPARATOR, 0, 0 ) ;

	// Creation du menu bouton gauche
	DestroyMenu( HideMenu ) ;
	HideMenu = CreatePopupMenu() ;
	if( !IsUnique ) {
		AppendMenu( HideMenu, MF_ENABLED, IDM_LAUNCHER+3, "&Hide all" ) ;
		AppendMenu( HideMenu, MF_ENABLED, IDM_LAUNCHER+4, "&Unhide all" ) ;
		//AppendMenu( HideMenu, MF_ENABLED, IDM_LAUNCHER+5, "&Refresh list" ) ;
		AppendMenu( HideMenu, MF_ENABLED, IDM_LAUNCHER+6, "&Window unique" ) ;
		CheckMenuItem( HideMenu, IDM_LAUNCHER+6, MF_BYCOMMAND | MF_UNCHECKED) ;
		}	
	else {
		AppendMenu( HideMenu, MF_ENABLED, IDM_LAUNCHER+6, "&Window unique" ) ;
		CheckMenuItem( HideMenu, IDM_LAUNCHER+6, MF_BYCOMMAND | MF_CHECKED) ;
		}
	//AppendMenu( HideMenu, MF_ENABLED, IDM_GONEXT, "&Next" ) ;
	//AppendMenu( HideMenu, MF_ENABLED, IDM_GOPREVIOUS, "&Previous" ) ;
	if( RefreshWinList( MainHwnd ) > 0 ) {
		AppendMenu( HideMenu, MF_SEPARATOR, 0, 0 ) ;
		for( i=0 ; i<NbWin ; i++ ) {
			AppendMenu( HideMenu, MF_ENABLED, IDM_GOHIDE+i, TabWin[i].name ) ;
			SetMenuItemBitmaps ( HideMenu, IDM_GOHIDE+i, MF_BYCOMMAND, bmpUnCheck, bmpCheck ) ;
			if( IsWindowVisible( TabWin[i].hwnd ) ) 
				CheckMenuItem( HideMenu, IDM_GOHIDE+i, MF_BYCOMMAND | MF_CHECKED) ;
			else 
				CheckMenuItem( HideMenu, IDM_GOHIDE+i, MF_BYCOMMAND | MF_UNCHECKED) ;
			}
		}
	AppendMenu( HideMenu, MF_SEPARATOR, 0, 0 ) ;
	AppendMenu( HideMenu, MF_ENABLED, IDM_ABOUT, "&About" ) ;
	AppendMenu( HideMenu, MF_ENABLED, IDM_QUIT, "&Quit" ) ;

	
	AppendMenu( menu, MF_POPUP, (UINT_PTR)HideMenu, "&Opened sessions" ) ;
	AppendMenu( menu, MF_SEPARATOR, 0, 0 ) ;
	
	AppendMenu( menu, MF_ENABLED, IDM_LAUNCHER+7, "&Refresh" ) ;
	AppendMenu( menu, MF_ENABLED, IDM_LAUNCHER+1, "&Configuration" ) ;
	AppendMenu( menu, MF_ENABLED, IDM_LAUNCHER+2, "&TTY-ed" ) ;
	AppendMenu( menu, MF_SEPARATOR, 0, 0 ) ;
	AppendMenu( menu, MF_ENABLED, IDM_ABOUT, "&About" ) ;
	AppendMenu( menu, MF_ENABLED, IDM_QUIT, "&Quit" ) ;

	return menu ;
	}
Example #20
0
static LICE_IBitmap *icoToBitmap(HICON icon, LICE_IBitmap *bmpOut)
{
  int icon_w = 16, icon_h=16;

#ifdef _WIN32
  ICONINFO ii={0,};
  if (GetIconInfo(icon,&ii))
  {
    bool blah=false;
    if (ii.hbmColor)
    {
      BITMAP bm={0,};
      if (GetObject(ii.hbmColor,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight)
      {
        icon_w=bm.bmWidth;
        icon_h=bm.bmHeight;
        blah=true;
      }
      DeleteObject(ii.hbmColor);
    }
    if (ii.hbmMask)
    {
      BITMAP bm={0,};
      if (!blah && GetObject(ii.hbmMask,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight)
      {
        icon_w=bm.bmWidth;
        icon_h=bm.bmHeight;
      }
      DeleteObject(ii.hbmMask);
    }
  }
#else
  BITMAP bm={0,};
  if (GetObject(icon,sizeof(bm),&bm) && bm.bmWidth && bm.bmHeight) // SWELL's GetObject() works on icons
  {
    icon_w=bm.bmWidth;
    icon_h=bm.bmHeight;
  }

#endif

  LICE_SysBitmap tempbm(icon_w*2,icon_h);
  LICE_FillRect(&tempbm,0,0,icon_w,icon_h,LICE_RGBA(0,0,0,255),1.0f,LICE_BLIT_MODE_COPY);
#ifdef _WIN32
  DrawIconEx(tempbm.getDC(),0,0,icon,icon_w,icon_h,0,NULL,DI_NORMAL);
#else
  {
    RECT r={0,0,icon_w,icon_h};
    DrawImageInRect(tempbm.getDC(),icon,&r);
  }
#endif

  LICE_FillRect(&tempbm,icon_w,0,icon_w,icon_h,LICE_RGBA(255,255,255,255),1.0f,LICE_BLIT_MODE_COPY);
#ifdef _WIN32
  DrawIconEx(tempbm.getDC(),icon_w,0,icon,icon_w,icon_h,0,NULL,DI_NORMAL);
#else
  {
    RECT r={icon_w,0,icon_w+icon_w,icon_h};
    DrawImageInRect(tempbm.getDC(),icon,&r);
  }
#endif

  if (!bmpOut) bmpOut = new LICE_MemBitmap(icon_w,icon_h);
  else bmpOut->resize(icon_w,icon_h);

  int y; // since we have the image drawn on white and on black, we can calculate the alpha channel...
  for(y=0;y<icon_h;y++)
  {
    int x;
    for(x=0;x<icon_w;x++)
    {
      LICE_pixel p = LICE_GetPixel(&tempbm,x,y);
      LICE_pixel p2 = LICE_GetPixel(&tempbm,x+icon_w,y);

      int r1=LICE_GETR(p);
      int g1=LICE_GETG(p);
      int b1=LICE_GETB(p);

      int alpha=255 - (LICE_GETR(p2)-r1);
      if (alpha>=255) alpha=255;
      else if (alpha>0)
      {
        r1 = (r1*255)/alpha; // LICE stores its alpha channel non-premultiplied, so we need to scale these up.
        g1 = (g1*255)/alpha;
        b1 = (b1*255)/alpha;
        if (r1>255)r1=255;
        if (g1>255)g1=255;
        if (b1>255)b1=255;
      }
      else alpha=0;
      LICE_PutPixel(bmpOut,x,y,LICE_RGBA(r1,g1,b1,alpha),1.0f,LICE_BLIT_MODE_COPY);
    }
  }

  return bmpOut;
}
Example #21
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
     static HRGN hRgnClip ;
     static int  cxClient, cyClient ;
     double      fAngle, fRadius ;
     HCURSOR     hCursor ;
     HDC         hdc ;
     HRGN        hRgnTemp[6] ; // HRGN just like RECT is a self-defined area.
     int         i ;
     PAINTSTRUCT ps ;
     
     switch (iMsg)
     {
     // The task of WM_SIZE case is used to create a self-defined region as valid client area. 
     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;

          hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT)) ;
          ShowCursor (TRUE) ;
          
          if (hRgnClip)
               DeleteObject (hRgnClip) ; // delete old region before create a new one.
          
          // The apis below are used to create RGN just like RECT
          // other apis including CreateRoundRectRgn & CreatePolygonRgn etc..
          // These apis will create region and be ready to be selected, after that the valid client area
          // will be changed to the region created instead of tranditional rect area.
          hRgnTemp[0] = CreateEllipticRgn (0, cyClient / 3,
                                           cxClient / 2, 2 * cyClient / 3) ;
          hRgnTemp[1] = CreateEllipticRgn (cxClient / 2, cyClient / 3,
                                           cxClient, 2 * cyClient / 3) ;
          hRgnTemp[2] = CreateEllipticRgn (cxClient / 3, 0,
                                           2 * cxClient / 3, cyClient / 2) ;
          hRgnTemp[3] = CreateEllipticRgn (cxClient / 3, cyClient / 2,
                                           2 * cxClient / 3, cyClient) ;
          hRgnTemp[4] = CreateRectRgn (0, 0, 1, 1) ;
          hRgnTemp[5] = CreateRectRgn (0, 0, 1, 1) ;
          hRgnClip    = CreateRectRgn (0, 0, 1, 1) ;

          // combie region from the second and the third regions to the first region with the fourth style.
          // and the first region should be initialized with a small region.
          // RGN_AND: inter sect
          // RGN_OR: srcRgn1 || srcRgn2
          // RGN_XOR: !RGN_AND
          // RGN_DIFF: the part belong to srcRgn1 but not belong to srcRgn2
          // RGN_COPY: srcRgn1 and ignore srcRgn2 totally.
          // Return value: NULLREGION; SIMPLEREGION; COMPLEXREGION; ERROR
          CombineRgn (hRgnTemp[4], hRgnTemp[0], hRgnTemp[1], RGN_OR) ;
          CombineRgn (hRgnTemp[5], hRgnTemp[2], hRgnTemp[3], RGN_OR) ;
          CombineRgn (hRgnClip,    hRgnTemp[4], hRgnTemp[5], RGN_XOR) ;
          
          for (i = 0 ; i < 6 ; i++)
               DeleteObject (hRgnTemp[i]) ;
          
          SetCursor (hCursor) ;
          ShowCursor (FALSE) ;
          return 0 ;
          
     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;
          
          // draw on region api
          // FillRgn, FrameRgn, InvertRgn, PaintRgn like FillRect, FrameRect ... etc.
          HBRUSH hBrush = CreateSolidBrush(RGB(255, 0, 0));
          FillRgn(hdc, hRgnClip, hBrush);
          DeleteObject(hBrush);
          
          // set the center position as the origin.
          SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ;
          
          // select self-defined region as valid client area.
          // so the painting will only happen in self-defined region.
          SelectClipRgn (hdc, hRgnClip) ; // equals to SelectObject(hdc, hRgnClip);
          
          // Use InvalidateRgn and ValidRgn instead of InvalidRect and ValidRect.
          
          fRadius = _hypot (cxClient / 2.0, cyClient / 2.0) ;
          
          for (fAngle = 0.0 ; fAngle < TWO_PI ; fAngle += TWO_PI / 360)
          {
               MoveToEx (hdc, 0, 0, NULL) ;
               LineTo (hdc, (int) ( fRadius * cos (fAngle) + 0.5),
                            (int) (-fRadius * sin (fAngle) + 0.5)) ;
          }
          EndPaint (hwnd, &ps) ;
          return 0 ;

     case WM_DESTROY:
          DeleteObject (hRgnClip) ; // destroy region
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
Example #22
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 #23
0
//////////////////////////////////////////////////////////////////////////
//
// 이전 버전과의 호환을 위한 옵션 마이그레이션
//
//////////////////////////////////////////////////////////////////////////
BOOL CATCodeMgr::AdjustOption(COptionNode* pRootNode)
{
	if(NULL == pRootNode) return FALSE;
	
	ResetOption();
	MigrateOption(pRootNode);

	//FORCEFONT,HOOK(0x00434343,TRANS([ESP+0x4],ANSI,ALLSAMETEXT))
	BOOL bRetVal = TRUE;

	int cnt = pRootNode->GetChildCount();
	for(int i=0; i<cnt; i++)
	{
		COptionNode* pNode = pRootNode->GetChild(i);
		CString strValue = pNode->GetValue().MakeUpper();
		
		// FORCEFONT 옵션
		if(strValue == _T("FORCEFONT"))
		{
			COptionNode* pLevelNode = pNode->GetChild(0);
			m_nFontLoadLevel = _ttoi(pLevelNode->GetValue().Trim());
		}
		// FIXFONTSIZE 옵션
		else if(strValue == _T("FIXFONTSIZE"))
		{
			m_bFixedFontSize = TRUE;
		}
		// FONT 옵션
		else if(strValue == _T("FONT") && pNode->GetChildCount() == 2)
		{
			// 폰트 페이스명
			COptionNode* pFontFaceNode = pNode->GetChild(0);
			if(pFontFaceNode && m_strFontFace != pFontFaceNode->GetValue())
			{
				// 현재 모아놓은 폰트 객체들 해제
				for(map<long, HFONT>::iterator iter = m_mapFonts.begin();
					iter != m_mapFonts.end();
					iter++)
				{
					DeleteObject(iter->second);
				}
				m_mapFonts.clear();

				// 새로운 폰트 페이스 설정
				m_strFontFace = pFontFaceNode->GetValue();
			}

			// 폰트 사이즈
			COptionNode* pFontSizeNode = pNode->GetChild(1);
			if(pFontSizeNode)
			{
				m_lFontSize = (long)_ttoi(pFontSizeNode->GetValue());
			}
		}
		// ENCODEKOR 옵션
		else if(strValue == _T("ENCODEKOR"))
		{
			m_bEncodeKorean = TRUE;
		}
		// HOOK 노드
		else if(strValue == _T("HOOK"))
		{
			BOOL bHookRes = HookFromOptionNode(pNode);
			if(FALSE == bHookRes) m_listRetryHook.push_back(pNode);
		} // HOOK 노드 끝
	}

	return bRetVal;
}
Example #24
0
void GraphicsCaptureSource::Render(const Vect2 &pos, const Vect2 &size)
{
    if(capture)
    {
        Shader *lastShader = GetCurrentPixelShader();

        float fGamma = float(-(gamma-100) + 100) * 0.01f;

        LoadPixelShader(drawShader);
        HANDLE hGamma = drawShader->GetParameterByName(TEXT("gamma"));
        if(hGamma)
            drawShader->SetFloat(hGamma, fGamma);

        //----------------------------------------------------------
        // capture mouse

        bMouseCaptured = false;
        if(bCaptureMouse)
        {
            CURSORINFO ci;
            zero(&ci, sizeof(ci));
            ci.cbSize = sizeof(ci);

            if(GetCursorInfo(&ci) && hwndCapture)
            {
                mcpy(&cursorPos, &ci.ptScreenPos, sizeof(cursorPos));

                ScreenToClient(hwndCapture, &cursorPos);

                if(ci.flags & CURSOR_SHOWING)
                {
                    if(ci.hCursor == hCurrentCursor)
                        bMouseCaptured = true;
                    else
                    {
                        HICON hIcon = CopyIcon(ci.hCursor);
                        hCurrentCursor = ci.hCursor;

                        delete cursorTexture;
                        cursorTexture = NULL;

                        if(hIcon)
                        {
                            ICONINFO ii;
                            if(GetIconInfo(hIcon, &ii))
                            {
                                xHotspot = int(ii.xHotspot);
                                yHotspot = int(ii.yHotspot);

                                UINT size;
                                LPBYTE lpData = GetCursorData(hIcon, ii, size);
                                if(lpData)
                                {
                                    cursorTexture = CreateTexture(size, size, GS_BGRA, lpData, FALSE);
                                    if(cursorTexture)
                                        bMouseCaptured = true;

                                    Free(lpData);
                                }

                                DeleteObject(ii.hbmColor);
                                DeleteObject(ii.hbmMask);
                            }

                            DestroyIcon(hIcon);
                        }
                    }
                }
            }
        }

        //----------------------------------------------------------
        // game texture

        Texture *tex = capture->LockTexture();

        Vect2 texPos = Vect2(0.0f, 0.0f);
        Vect2 texStretch = Vect2(1.0f, 1.0f);

        if(tex)
        {
            Vect2 texSize = Vect2(float(tex->Width()), float(tex->Height()));
            Vect2 totalSize = API->GetBaseSize();

            Vect2 center = totalSize*0.5f;

            BlendFunction(GS_BLEND_ONE, GS_BLEND_ZERO);

            if(bStretch)
            {
                if(bIgnoreAspect)
                    texStretch *= totalSize;
                else
                {
                    float xDif = fabsf(totalSize.x-texSize.x);
                    float yDif = fabsf(totalSize.y-texSize.y);
                    float multiplyVal = (xDif < yDif) ? (totalSize.x/texSize.x) : (totalSize.y/texSize.y);
                        
                    texStretch *= texSize*multiplyVal;
                    texPos = center-(texStretch*0.5f);
                }
            }
            else
            {
                texStretch *= texSize;
                texPos = center-(texStretch*0.5f);
            }

            Vect2 sizeAdjust = size/totalSize;
            texPos *= sizeAdjust;
            texPos += pos;
            texStretch *= sizeAdjust;

            RoundVect2(texPos);
            RoundVect2(texSize);

            if(bFlip)
                DrawSprite(tex, 0xFFFFFFFF, texPos.x, texPos.y+texStretch.y, texPos.x+texStretch.x, texPos.y);
            else
                DrawSprite(tex, 0xFFFFFFFF, texPos.x, texPos.y, texPos.x+texStretch.x, texPos.y+texStretch.y);

            capture->UnlockTexture();

            BlendFunction(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA);

            //----------------------------------------------------------
            // draw mouse

            if(bMouseCaptured && cursorTexture)
            {
                Vect2 newCursorPos  = Vect2(float(cursorPos.x-xHotspot), float(cursorPos.y-xHotspot));
                Vect2 newCursorSize = Vect2(float(cursorTexture->Width()), float(cursorTexture->Height()));

                newCursorPos  /= texSize;
                newCursorSize /= texSize;

                newCursorPos *= texStretch;
                newCursorPos += texPos;

                newCursorSize *= texStretch;

                bool bInvertCursor = false;
                if(invertShader)
                {
                    if(bInvertCursor = ((GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0 || (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0))
                        LoadPixelShader(invertShader);
                }

                DrawSprite(cursorTexture, 0xFFFFFFFF, newCursorPos.x, newCursorPos.y+newCursorSize.y, newCursorPos.x+newCursorSize.x, newCursorPos.y);
            }
        }

        if(lastShader)
            LoadPixelShader(lastShader);
    }
}
Example #25
0
TlevelsPage::TwidgetCurves::~TwidgetCurves()
{
    DeleteObject(br);
}
Example #26
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 #27
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static int cxChar, cyChar;
    static int xCaret, yCaret;
    static int cxClient, cyClient;
    static int cxBuffer, cyBuffer;
    static DWORD dwCharSet = DEFAULT_CHARSET;
    static TCHAR    *szBuffer;

    HDC         hdc;
    PAINTSTRUCT ps;
    TEXTMETRIC  tm;
    int         x, y;
    int         j;


    switch(uMsg)
    {
    case WM_INPUTLANGCHANGE:
    case WM_CREATE:
        if(uMsg == WM_INPUTLANGCHANGE)
        {
            dwCharSet = wParam ;
        }

        hdc = GetDC (hwnd) ;
        SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

        GetTextMetrics (hdc, &tm) ;
        cxChar = tm.tmAveCharWidth ;
        cyChar = tm.tmHeight ;

        DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
        ReleaseDC (hwnd, hdc) ;

        for (x = 0; x < cxBuffer; ++x)
            for(y=0; y < cyBuffer; ++y)
                BUFFER(x, y) = ' ';
        xCaret = 0;
        yCaret = 0;
        if (hwnd == GetFocus())
        {
            SetCaretPos(xCaret * cxChar, yCaret * cyChar);
        }
        InvalidateRect(hwnd, NULL, TRUE);
        return 0;
    case WM_SIZE:
        cxClient = LOWORD(lParam);
        cyClient = HIWORD(lParam);

        cxBuffer = cxClient / cxChar;
        cyBuffer = cyClient / cyChar;

        if (szBuffer != NULL)
        {
            free(szBuffer);
        }
        szBuffer = (TCHAR *)malloc(cxBuffer * cyBuffer * sizeof(TCHAR));

        for (x = 0; x < cxBuffer; ++x)
            for(y=0; y < cyBuffer; ++y)
                BUFFER(x, y) = ' ';
        xCaret = 0;
        yCaret = 0;
        if (hwnd == GetFocus())
        {
            SetCaretPos(xCaret * cxChar, yCaret * cyChar);
        }
        InvalidateRect(hwnd, NULL, TRUE);
        return 0;

    case WM_SETFOCUS:
        {
            CreateCaret (hwnd, NULL, cxChar, cyChar) ;
            SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
            ShowCaret (hwnd) ;
            return 0 ;
        }
    case WM_KILLFOCUS:
        {
            HideCaret (hwnd) ;
            DestroyCaret () ;
            return 0 ;
        }
    case WM_KEYDOWN:
        {
            switch(wParam)
            {
            case VK_DELETE:
                for (x = xCaret; x < cxBuffer -1; ++x)
                {
                    BUFFER(x, yCaret) = BUFFER(x+1, yCaret);
                }
                BUFFER(cxBuffer-1, yCaret) = ' ';

                hdc = GetDC(hwnd);
                HideCaret(hwnd);
                SelectObject(hdc, CreateFont(0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL));  
                TextOut(hdc, xCaret * cxChar, yCaret * cyChar, &BUFFER(xCaret, yCaret), cxBuffer - xCaret);
                DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
                ShowCaret(hwnd);
                ReleaseDC(hwnd, hdc);
                break;
            case VK_UP:
                if (yCaret > 0)
                    yCaret--;
                break;
            case VK_DOWN:
                if (yCaret < cyBuffer - 1)
                    yCaret++;
                break;
            case VK_LEFT:
                if (xCaret > 0)
                    xCaret--;
                break;
            case VK_RIGHT:
                if (xCaret < cxBuffer - 1)
                    xCaret++;
                break;
            case VK_HOME:
                xCaret = 0;
                break;
            case VK_END:
                xCaret = cxBuffer - 1;
                break;
            case VK_PRIOR:
                yCaret = 0;
                break;
            case VK_NEXT:
                yCaret = cyBuffer - 1;
                break;
            default:
                break;
            }
            SetCaretPos(xCaret*cxChar, yCaret*cyChar);
            return 0;
        }
    case WM_CHAR:
        {
            for (j = 0; j < LOWORD(lParam); ++j)
            {
                hdc = GetDC(hwnd);
                HideCaret(hwnd);
                switch(wParam)
                {
                    // Ctrl + Enter
                case '\n':
                    {
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;
                    }
                    //Enter
                case '\r':
                    {
                        xCaret = 0;
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;
                    }
                case '\t':
                    {
                        do
                        {
                            SendMessage(hwnd, WM_CHAR, ' ', 1);
                        }
                        while(xCaret % 8);
                        break;
                    }
                case '\b':      //backspace
                    {
                        if (xCaret > 0)
                        {
                            xCaret--;
                            SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1);
                        }
                        break;
                    }
                case '\x1B':    //Escape
                    {
                        for (x = 0; x < cxBuffer; ++x)
                        {
                            for (y = 0; y < cyBuffer; ++y)
                            {
                                BUFFER(x, y) = ' ';
                            }
                        }
                        xCaret = 0;
                        yCaret = 0;
                        SetCaretPos(xCaret * cxChar, yCaret * cyChar);
                        InvalidateRect(hwnd, NULL, TRUE);
                        break;
                    }
                default:
                    {
                    BUFFER(xCaret, yCaret) = (TCHAR)wParam;
                    SelectObject(hdc, CreateFont(0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL));  
                    TextOut(hdc, xCaret * cxChar, yCaret * cyChar, &BUFFER(xCaret, yCaret), sizeof(BUFFER(xCaret, yCaret))/sizeof(TCHAR));
                    DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
                    xCaret++;
                    break;
                    }
                }

                if (xCaret >= cxBuffer)
                {
                    xCaret = 0;
                    yCaret++;
                }
                if (yCaret >= cyBuffer)
                {
                    yCaret = 0;
                }
                SetCaretPos(xCaret * cxChar, yCaret * cyChar);
                ReleaseDC(hwnd, hdc);
                ShowCaret(hwnd);
            }
            return 0;
        }
    case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);
            SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;
            for (y = 0; y < cyBuffer; ++y)
            {
                TextOut(hdc, 0, y * cyChar, &szBuffer[y*cxBuffer], cxBuffer);
            }
            DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
            EndPaint(hwnd, &ps);
            break;
        }
    case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
    default:
        {
            break;
        }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Example #28
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 #29
0
void LaserStatusDialog::DrawLaserStatus(HDC hdc, COLORREF LaserColor)
{
	
	
	//HGDIOBJ originalPen=SelectObject(hdc,GetStockObject(DC_PEN));
	//SelectObject(hdc, GetStockObject(DC_PEN));
	//COLORREF oldPen=SetDCPenColor(hdc, LaserColor);
	HPEN MyPen=CreatePen(PS_SOLID,2,LaserColor);
	HGDIOBJ OldStockPen = SelectObject(hdc,MyPen);
	
	HBRUSH brush = CreateSolidBrush(LaserColor);

	RECT CenterCircle;
	int QuarterSize=(m_StaticLaserStatusRectangle.bottom-m_StaticLaserStatusRectangle.top)/2;

	int CirCenterX=m_StaticLaserStatusRectangle.left+QuarterSize;
	int CirCenterY=m_StaticLaserStatusRectangle.top+QuarterSize;
	int CircleSize =18;

	CenterCircle.top=CirCenterY-CircleSize/2;
	CenterCircle.left=CirCenterX-CircleSize/2;
	CenterCircle.right=CenterCircle.left+CircleSize;
	CenterCircle.bottom=CenterCircle.top+CircleSize;

	HGDIOBJ OldBrush = SelectObject(hdc,brush);
	Ellipse(hdc,CenterCircle.left,CenterCircle.top,CenterCircle.right,CenterCircle.bottom);
	SelectObject(hdc,OldBrush);
	DeleteObject(brush);
	// Draw spokes
	int nOriginX = CirCenterX;
	int nOriginY = CirCenterY;
	int nRadius = 16;
	int nSpokes = 16;
	double fAngle = 2*PI/nSpokes;
	LPPOINT lpPoint(0);
	for (int i =0; i<nSpokes; i++)
	{

		MoveToEx (hdc,nOriginX,nOriginY,lpPoint);
		int nX = (int)ceil(cos((fAngle)*i)*(nRadius)+nOriginX);
		int nY = (int)ceil(sin((fAngle)*i)*(nRadius)+nOriginY);
		LineTo(hdc,nX,nY);
	}


	nRadius = 20;
	nSpokes = 8;
	fAngle = 2*PI/nSpokes;

	for (int i =0; i<nSpokes; i++)
	{
		LPPOINT lpPoint(0);
		MoveToEx (hdc,nOriginX,nOriginY,lpPoint);
		int nX = (int)ceil(cos((fAngle)*i)*(nRadius)+nOriginX);
		int nY = (int)ceil(sin((fAngle)*i)*(nRadius)+nOriginY);
		LineTo(hdc,nX,nY);
	}

	MoveToEx (hdc,CirCenterX,CirCenterY,lpPoint);
	LineTo(hdc,m_StaticLaserStatusRectangle.right-5,CirCenterY);

	SelectObject(hdc,OldStockPen);
	DeleteObject(MyPen);

	m_StaticLaserStatusRectangle;
}
Example #30
0
static LRESULT CALLBACK ColourPickerWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message) {
	case WM_CREATE:
		SetWindowLongPtr(hwnd, 0, 0);
		SetWindowLongPtr(hwnd, sizeof(COLORREF), 0);
		break;

	case CPM_SETDEFAULTCOLOUR:
		SetWindowLongPtr(hwnd, sizeof(COLORREF), lParam);
		break;

	case CPM_GETDEFAULTCOLOUR:
		return GetWindowLongPtr(hwnd, sizeof(COLORREF));

	case CPM_SETCOLOUR:
		SetWindowLongPtr(hwnd, 0, lParam);
		InvalidateRect(hwnd, NULL, FALSE);
		break;

	case CPM_GETCOLOUR:
		return GetWindowLongPtr(hwnd, 0);

	case WM_LBUTTONUP:
		{
			COLORREF custColours[16] = { 0 };
			custColours[0] = GetWindowLongPtr(hwnd, sizeof(COLORREF));

			CHOOSECOLOR cc = { 0 };
			cc.lStructSize = sizeof(CHOOSECOLOR);
			cc.hwndOwner = hwnd;
			cc.hInstance = (HWND)g_hInst;
			cc.rgbResult = GetWindowLongPtr(hwnd, 0);
			cc.lpCustColors = custColours;
			cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT;
			if (ChooseColor(&cc)) {
				SetWindowLongPtr(hwnd, 0, cc.rgbResult);
				SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), CPN_COLOURCHANGED), (LPARAM)hwnd);
				InvalidateRect(hwnd, NULL, FALSE);
			}
		}
		break;

	case WM_ENABLE:
		InvalidateRect(hwnd, NULL, FALSE);
		break;

	case WM_NCPAINT:
	case WM_PAINT:
		PAINTSTRUCT ps;
		HDC hdc1 = BeginPaint(hwnd, &ps);

		RECT rc;
		GetClientRect(hwnd, &rc);
		DrawEdge(hdc1, &rc, EDGE_ETCHED, BF_RECT);
		InflateRect(&rc, -2, -2);

		HBRUSH hBrush = (IsWindowEnabled(hwnd)) ? CreateSolidBrush(GetWindowLongPtr(hwnd, 0)) : CreateHatchBrush(HS_BDIAGONAL, GetSysColor(COLOR_GRAYTEXT));
		SetBkColor(hdc1, GetSysColor(COLOR_BTNFACE));
		FillRect(hdc1, &rc, hBrush);
		DeleteObject(hBrush);

		EndPaint(hwnd, &ps);
		break;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}