I have written "as long as I dont have leaks, I care more about performance:)";)...so my priority is to avoid memory leaks and then I optimize my code. I assume that both solutions don't cause leaks so I would like to choose faster one. (I mean CDC::CreateCompatibleDC()/DeleteDC against CDC::SaveCD()/RestoreDC() )
PatrykDabrowski
Posts
-
Multiple CDC::SelectObject() -
Multiple CDC::SelectObject()I should put 1) && 2)...in fact as long as I dont have leaks, I care more about performance:) So the order is fine:)
-
Multiple CDC::SelectObject()Yes, I delete some_bitmapX objects (when exiting the app as they are 'global'). What I care about is: 1) Performance 2) Avoid memory/resource leaks. Is CDC::CreateCompatibleDC()/DeleteDC() slower comparing to CDC::SaveDC()/RestoreDC()?? Thanks for help.
-
Multiple CDC::SelectObject()I have already tried both versions. None of them reports memory leaks in VS2003 in Debug mode. But maybe those resources are not monitored by VS... That's why I'm askng:) Thanks!
-
AlphaBlend() strange colors.Sorry, I couldn't reply as I was offline for couple of days. I was trying CDC::AlphaBlend(), CImage::AlphaBlend() and global ::AlphaBlend() with the same results. I discovered that I should premultiply r/g/b values by alpha channel. Now it works fine, but I wonder how to cope with the situation when You have very small r/g/b values and small alpha channel. When You premultiply those small values and divide by 255, You will get zeroes...Now if You want to recover almost transparent pixels by increasing their alpha value, You will get black color instead of original one?!?!? Am I correct?? Simple example: Source bitmap: ARGB(10,20,0,0) ; DARK RED After premultiply: ARGB(10,20*10/255,0,0) = ARGB(10,0,0,0); BLACK Now try to recover original color by increasing alpha ARGB(255,0,0,0) and You receive black instead of ARGB(255,20,0,0); Thanks for Your attention.
-
Multiple CDC::SelectObject()Thanks:)
-
Multiple CDC::SelectObject()Hello, Is it safe to use: CDC memDC; memDC.CreateCompatibleDC(pDC); CBitmap *m_pOld = memDC.SelectObject(&some_bitmap1); memDC.SelectObject(&some_bitmap2); memDC.SelectObject(&some_bitmap3); memDC.SelectObject(&some_bitmap4); .... memDC.SelectObject(m_pOld); memDC.DeleteDC; or I should use SelectObject(m_pOld)/DeleteDC() after each SelectObject(&some_bitmapX)??
-
AlphaBlend() strange colors.Hello:) I have a gradient-like background with an owner drawn button. I use AlphaBlend() to draw button's image. Now, the strange thing is: Background pixel = RGB(168,168,168) Source pixel = 0xFFFF0000 (AARRGGBB) After AlphaBlend() with SourceConstantAlpha=0xff the output is RGB(255,0,0) - that's correct but when I change a bit the source pixel to Source pixel = 0x00FF0000 (AARRGGBB) I receive pixel RGB(255,168,168)?!?! I should get RGB(168,168,168) because the source alpha is 0x00?!?!? After some tests with different RGB values, I noticed that my blending works like it 'thinks' that my background is white (255,255,255)?!? When I make all source pixels to have 0xFF alpha value and just play with SourceConstantAlpha value, it's working fine!?! - my button is drawn with proper transparency?!? I need to play a bit with the source pixels' alpha value for 'soft' button's border. Does anyone know what could be wrong?? I'm using winxp/vs2003 Thanks a lot!!
-
Transparency - please help, nothing works...Thanks for reply:) I've read this article... It means, I have to override WM_PAINT message and blit buttons by myself? Is there any way to 'prepare' somehow my bitmaps that Windows could draw them with transparency by its own routines, like it does for non-transparent toolbar buttons??? Ok, let's assume using WM_PAINT message, now I dont need WM_ERASEBKGND handler and should draw background and buttons in a single OnPaint handler? Thanks again:)
-
Transparency - please help, nothing works...Hello! For couple of weeks I still have a problem with transparent buttons on toolbar. Toolbar background is 24bit image, buttons are also 24bit, VS2003, WinXP. What I do (background): 1) Load standard 24bit BMP to CBitmap object 2) Create pattern brush based on bitmap from 1) 3) Use FillRect() inside OnEraseBkgnd(). Background is ok, drawing works fine. Now the buttons: Solution A: 1) Load 24bit BMP to CBitmap 2) Create CImageList based on 1) using ILC_COLOR32|ILC_MASK 3) Create mask by Add() function with proper RGB() transparent color 4) Use SetImageList() in toolbar control object RESULT -> NO transparency (round buttons have plain color in the transparent color spots) Solution B: 1) Load 24bit PNG with transparency to CImage 2) Create CBitmap based on (HBITMAP) operator from 1) 3) Continue steps 2-4 from Solution 1 RESULT -> NO transparency Solution C: 1) Use CImage like in Solution B but use directly SetBitmap() from CToolbar RESULT -> again no transparency. Is there any simple way to get it working?? Basicly I want to have transparent bitmap on buttons. That means, I want to see bankground texture in the 'holes' in buttons (where the button's color == transparent color) Please, enlighten me:) I've read many articles and found one solution but it was quite complicated and used many derived classes... ("BitmapToolBarResrch_en" project) Solution can be Win2k/XP+ for MFC. Thank a lot!!
-
CReBar border question.How to remove this 2px line on the top of ReBar control? I've found a RBS_BANDBORDERS style using spy++ but removing this style does not help (neither by calling CReBar::Create(this,0) nor by CReBar::ModifyStyle(RBS_BANDBORDERS,0) - even without this style control still has a line on the top. Any idea how to disable this line? Thanks in advance!
-
CToolBar basic questionsThanks for help but it seems not working for me... But first, my second question. I was asking how to disable this square "3d-like" frame around my buttons. Image lists do not solve this problem because they are 32x32 pixel and this box is bigger, about 38x38 pixels. I have partialy solved this problem by this code: void CToolBarEx::OnTbnHotItemChange(NMHDR *pNMHDR, LRESULT *pResult) { *pResult = (1-m_bHoverMouse); //0=no change;1=no box around buttons } and now, when I move the mouse over buttons, this box is not drawn but when I press the button it is still there...How to disable it completly?? To my last question, I have almost copy-pasted Your code to my app but the buttons are still opaque. I have a transparent color RGB(255,0,255) in my bitmap containing 6 buttons (192x32 24bit bitmap). Now the transparent color is not directly drawn but replaced by the plain gray (background) color. That would be fine, but I have a background bitmap?!? Maybe the way I'm drawing my background bitmap is wrong??? The drawing code is: BOOL CToolBarEx::OnEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(&rect); //toolbar rect CBrush *m_brOld = NULL; //Old brush m_brOld = pDC->SelectObject(&m_bgBrush); //load my background brush pDC->FillRect(&rect,&m_bgBrush); //fill the whole toolbar pDC->SelectObject(m_brOld); //restore original brush return TRUE; } Maybe I should save somehow this brush into the toolbar's DC for proper background drawing when the control draw its buttons?? How to "tell" the control to use bitmap/brush to draw its background?? Thanks again:) I'm waiting for Your response...
-
CToolBar basic questionsHi:) I have some (probably) basic questions about CToolbar class, just point me somewhere (article, code or just general idea) How to change button's position? - I would like to move them closer, without a single pixel of free space between. (or just 2 pixels right and bottom for 'press' effect) How to disable this square box around button's bitmap when I hover/press the button? And finally what message/base class member function should I override to make my bitmaps transparent? I have already handled WM_ERASEBKGND message but now my buttons have plain background instead of a bitmap. I've seen some articles about it but the solutions are not so simple (many lines of code, message handlers ect.) Is there a simple way how to draw CBitmap 24bit bitmap on a CToolBar control? Assuming some transparency RGB value in my input bitmap?? (Let's assume Windows 2000+ environment) Thanks in advance!
-
CListView columns ideal sizeYes, that's what I'm going to do - reduce last column by 2-4pixels...but that's some kind of a 'hack';) The goal is to create this listview without the scrollbar at the bottom but not by using LVS_NOSCROLL, but by resizing the columns. Of course the scrollbar should appear if I decrease the whole dialog window or change the column width using mouse.... Thanks for help anyway:)
-
CListView columns ideal sizeYes, I'm already using SetColumnWidth(). My code works like this: 1) Get listView width by calling GetClientRect() 2) Call SerColumnWidth() for each (two in my case) column, setting (1/2*width) and (width-1/2*width) ...and still a scrollbar control appears at the bottom of my ListView control...?!?
-
CListView columns ideal sizeHi:) Beginer question (I think;) - how to make my CListView columns (I use a report view) to fill in all available list width? (without adding scrollbar control at the bottom). When I use m_ListView.GetClientRect() and then set my two columns width to the 1/2 of the returned value, I still get a scroll bar at the bottom...?!? (couple of pixels, but still...) Is it possible to remove the last column's separator?? I could just shrink last column by 2-4 pixels and remove its ending separator to look nice;) How to do it?? Thanks for any help/comment.
-
.manifest problemHi:) I have a toolbar with its own background (bitmap) on a ReBar object. This ReBas has olso its own background (the same bitmap). And again, the ReBar is on a dialog window with the same background. All three objects use the same background (CBitmap object) and use ON_WM_ERASEBKGND message to paint itself. The problem is, when I place the manifest file next to the application exe, the toolbar loses its background?!?! The ReBar and dialog window remain untouched, only the toolbar becomes plain (no texture on it). What's more, this 'bug' doesn't depend on Windows themes. When I turn the XP themes on/off the toolbar remains plain...Removing manifest file helps in both cases... but I can't use XP-style controls. Do You have any idea what can be wrong??? If that could help, for toolbar I use: m_Toolbar.CreateEx(this,WS_CHILD|TBSTYLE_FLAT|WS_VISIBLE|CBRS_TOP|CBRS_SIZE_FIXED|TBSTYLE_CUSTOMERASE); and for ReBar: m_ReBar.Create(this); m_ReBar.AddBar(&m_Toolbar,NULL,NULL,RBBS_USECHEVRON|RBBS_GRIPPERALWAYS)); .... rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE | RBBIM_ID; //Bar info flags Thanks in advance!
-
How to create nice toolbar in CDialog appHi:) I want to add a toolbar to my application but when I use 'standard' CToolBar class I can't load my 32x32 24-bit bitmaps into it (Visual Studio 2003 resource editor converts them to some ugly-looking 8-colors bitmaps...) Is it possible to create nice looking toolbars (ie. like those in IE6) with handle for changing its position and locking/unlocking feature just using CToolBar class?? I also want to create my app menu "File Edit ..." on a toolbar like IE6 does. Is it possible using this base MFC control? If not, could someone point me to the article where I could find some more informations? Thanks for any help.
-
CListView selection questionI have a list view control in a report view. I can select multiple rows by pressing control+left mouse button or by pressing left mouse button on first item and move mouse up/down to select other rows (if not selecting the first item on its label). How to change this default behaviour? I mean I want to: 1) Select multiple items just by clicking on them (without control key), and 2) Select multiple items by clicking on first item (even on label, on subitem's text) and moving mouse up/down. Wow to do this? Thanks in advance.
-
CDialog based window doesn't get focus.Thanks! After couple of articles descibing this 'bug' I have successfuly tested this solufion: Instead of using plain SetForegroundWindow()/SetFocus() I use this: //Attach AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),GetCurrentThreadId(),TRUE); //Do our stuff SetForegroundWindow(); SetFocus(); //Just playing safe //Detach the attached thread AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL),GetCurrentThreadId(),FALSE); ...and it's working fine! (on winXP)