gdi

Prevent Flickering When Drawing

折月煮酒 提交于 2019-12-11 14:24:59
问题 So I have this code to draw a rectangle on my screen: LOGBRUSH m_LogBrush; HBRUSH m_hBrush; HPEN m_hPen; HDC m_hDC; void DrawBox(int x, int y, int r, int g, int b, int size, int thickness) { // Brush style to hollow m_LogBrush.lbStyle = BS_NULL; // Create a logical brush and select into the context m_hBrush = CreateBrushIndirect(&m_LogBrush); SelectObject(m_hDC, m_hBrush); // Create a logical pen and select into the context m_hPen = CreatePen(PS_SOLID, thickness, RGB(r, g, b)); SelectObject(m

GetRoundedRegion exception

╄→гoц情女王★ 提交于 2019-12-11 12:29:44
问题 I made a custom button with rounded edges, i use CreateRoundRectRgn for this, in the paint event this is called to round all the edges, when i run my program everything works fine until after about one minute, then i get the following exception(the value of p = 0): one thing to add is that the button is undergoing about 50 paint events per second because of a color fade (blinking) this is my paint event: protected override void OnPaint(PaintEventArgs e) { this.SuspendLayout(); this.Region =

Copy contents of one DeviceContext to another DeviceContext

独自空忆成欢 提交于 2019-12-11 11:41:53
问题 I've never done any GDI programming and despite taking several shots in the dark and searching the documentation I haven't found the correct way to do copy the contents of one DC to another DC. The code I have at the moment is below. I don't understand why it's not working (the window remains just remains blank after creation). SIZE srcSize; // ... Get size of source DC HDC destDC = ...; // from GetDC(myWindow), myWindow was // sized before this to properly contain source HDC sourceDC = ...;

Win32 GDI: AlphaBlend() not using constant alpha value correctly

老子叫甜甜 提交于 2019-12-11 09:47:38
问题 The code provided at the end draws a grid of red 3x3px rectangles with a random constant alpha value using AlphaBlend() . The output however, turns out not "quite" random: Notice runs of constant alpha along x-axis. What might be causing this? P.S. Stepping though the debugger produces the expected output. Code to produce output: void draw_mark(HDC hdc, int x, int y, COLORREF mark_clr, int mark_w, int mark_h, BYTE alpha); void produce_output(HWND hWnd) { InvalidateRect(hWnd, NULL, TRUE);

What is the fastest way of taking a screenshot in Windows?

我的梦境 提交于 2019-12-11 09:23:15
问题 What is the fastest way to capture a screenshot in Windows? A driver? Using DirectX? 回答1: The fastest way would be to read mapped region of video card memory I think... Just an idea, never tried that. 回答2: A while back I timed the win32 api and the .net wrapper. Here is the complete blog post: http://blog.bobcravens.com/2009/04/fastest-screen-capture-using-c-vista-vs-win7/ The upshot is that the .net wrapper in the latest version of Win7 is as fast as the native win32 api. I have never tried

Odd MFC/GDI behaviour (blank image) that doesn't appear when screen is recorded

梦想的初衷 提交于 2019-12-11 08:42:33
问题 There is this weird bug in my program that I'm trying to fix, but I'm really at a loss for what it could be. This part of my program has a dialog which shows previews of various items using MFC/GDI. When I scroll through different items, sometimes the preview image just disappears and goes blank. However, it: Only happens on some machines Apparently happens on both Windows 7 and XP Doesn't happen on the same item every time Item IS STILL THERE when one takes a screenshot, but it is blank when

Drawing Polyline results in pixelated line

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:27:07
问题 I am trying to create my own Native win32 C++ Checkbox that can have a transparent background. The idea is to make the window/widget look exactly like the Windows XP style checkbox except that it can have a transparent background. My Problem: When I draw the tick for my textbox, the 'tick' line looks pixelated and jagged - see my picture below for how it looks. It does not look smooth like the actual checkbox tick. The left checkbox is mine, the right is the default windows one I am trying to

Saving Bitmaps on Windows 10 with GDI scaling active

女生的网名这么多〃 提交于 2019-12-11 07:33:28
问题 I have a MFC application with toolbars (using CMFCToolbar). I create the toolbar bitmap on the fly using bitmaps from files and resources. The DIBs have different color formats. So I create an empty bitmap toolbar image compatible to screen DC. Then I open all the bitmaps and blit the content to the toolbar bitmap (GDI does colorspace conversion and stretching for me). Then I save the bitmap to a 24-bit DIB file. Then I create the toolbar object and load the image. That has worked for ages

Rotate Text by 90 degrees with GDI

北城余情 提交于 2019-12-11 07:24:53
问题 I want to draw text to a GDI Surface and rotate this text by 90 degrees counter clockwise. I would prefer to use DrawText to draw the text because it supports carriage return. I tried to use a font with lfEscapement (see the code below) but the line is not rotated - one line gets rendered over the other. Is there any possibility to rotate the text? Or to render without rotation and rotate the whole device context? Normal text layout: Rotated (desired result): case WM_PAINT: { hdc = BeginPaint

What size of ImageList icons do I need to make & load for my app (considering higher DPI)?

强颜欢笑 提交于 2019-12-11 06:04:34
问题 I have a CListCtrl control (or a ListView in Win32) that is created with LVS_REPORT style. I am intending to display icons in its items as such: But the question is what size of icons do I need to make and load? Let me explain. From the old Win32 samples, I can see that everyone creates image lists with 15x15 pixel icons. But the issue with those is that it looks horribly pixelated on any modern PC with higher DPI settings. Thus I was looking for a dynamic way to determine the appropriate