|
Hi,
I'm pretty new to C++ windows and i'm getting a little stuck. I'm trying to get a dialog based app going with a simple bitmapped ui. I dont want to use any of the skin librarys available here because they are a bit over the top for my needs.
I made a basic dialog based mfc project, stripped title bar and borders off the dialog, and use OnPaint() to bitblt a bitmap onto the background. i then call CDialog::OnPaint() which (in my understanding) has windows deal with painting of the two child buttons on the dialog.
This so far actually worked, which impressed me. Then I wanted to make the window draggable by clicking anywhere on the background. So I use a comboination of OnLButtonDown, OnLButtonUp and so on to facilitate this.
This almost works right. Mostly you can drag the window round just fine, but sometimes the child buttons on the window dissapear. this especially seems to happen if you drag the window to the top of the screen and down again.
I cannot figure out for the life of me why this occurs. i found a rather poor workaround in that calling SendMessage(WM_PAINT,0,0) at the end of OnMouseMove makes sure the buttons dont dissapear, but this slows everything down and makes the window flicker badly when being dragged.
Can anyone help me identify why the buttons sometimes dissapear?
The VC6 project and assocated files are available at:
http://www.atomichamster.org/bitmapui.zip
The download is about 50k
Looking forward to hearing your replies.
Thanks
Jon
|
|
|
|
|
first, you probably shouldn't call OnPaint yourself. a better way is to call Invalidate(FALSE); this has much the same effect as calling OnPaint directly, in fact it will end up calling your OnPaint eventually, but does some other nice thigns, too. read the help for Invalidate and InvalidateRect, they're nice functions.
second, if you're getting flickering, then you are trying to draw too much stuff at once. in OnPaint, you need to determine what needs to be drawn: call CDC::GetClipBox to get the rectangle that needs to be updated and only paint that part.
another way to reduce flickering, but this only really helps if you're doing multiple draws, and not just a single bitblt, is to render onto an off-screen dc then bitblt the whole thing at once.
yet another way to reduce flickering, and one that might help you, is to override the OnEraseBackground function (use classwizard). just return FALSE;. this tells MFC not to re-paint the window's background every time it redraws.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
i call OnPaint because I override the base class's OnPaint function in order to paint the background myself.
When i'm done there, i call the base class implementation of OnPaint to have windows carryon doing its stuff.
If I don't do this then windows never draws the child buttons at all!
Am I severly missing the point here or what?
I'll definitely try the other recommendations though. I realise that always invalidating the whole window was a bad idea, but it seemed to force the drawing of the buttons. I'm thinking that I shouldnt need to do that at all- surely windows should always draw the buttons for me?
jon h
|
|
|
|
|
one reason to call Invalidate instead of OnPaint is that there is a very good chance that there may be things that have to happen before OnPaint is called that Invalidate takes care of. so, Invalidate will do some setup, then call your OnPaint when it's ready (in effect). and, yes you should always call the base class OnPaint - so that the buttons can draw themselves, too.
another reason for not calling OnPaint directly is that painting is supposed to be asynchronous - the UI updates when it gets a chance, not when you decide it should.
overriding OnEraseBackground will take care of the background issue for you.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
The reason you're getting strange results when overriding OnPaint() is you're not handling the right message. WM_ERASEBKGND was designed specifically for what you want to do. Override OnEraseBkgnd() and paint your bitmap, and the dialog controls will come out fine. I have done exactly what you are doing with a dialog, so I know this method works.
--Mike--
http://home.inreach.com/mdunn/
The preferred snack of 4 out of 5 Lounge readers.
|
|
|
|
|
That totally works!
Thankyou very much!
The MFC approach to life it a bit confusing at the moment, but I'm beginning to get the hang of it.
Next step: adding transparency!
expect me back in a few days.
Jon h
|
|
|
|
|
Just in case, this is what is really working for me since 5 yeras! Use it if you wish!
void CxxxxxxDlg::OnPaint()
{
CPaintDC dc(this);
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDC memDC;
memDC.CreateCompatibleDC(NULL);
CBitmap Bitmap;
Bitmap.LoadBitmap(IDB_BITMAP_BACK);
memDC.SelectObject(&Bitmap);
CRect rect;
GetClientRect(&rect);
LPBITMAPINFOHEADER m_pBmInfoHeader;
UINT width = (UINT) m_pBmInfoHeader->biWidth;
UINT height = (UINT) m_pBmInfoHeader->biHeight;
dc.BitBlt(rect.left,
rect.top,
width,
height,
&memDC,
0,
0,
SRCCOPY);
CDialog::OnPaint();
}
}
And there has never been a need for WM_ERASEBACKGND so far!
PS. For your next questions, to prduce Transparency you must have Mask bitmaps and prepare either by writing code or yet simpler just produce a B&W version of your bitmap and then use it as a mask.
Keep in mind that if you are going to use bitmaps as a background to your dialog window, you must go some steps further than just tranparenting the bitmap, you gotta create a region from it and let that
region be the dialog drwaing clip regions/window.
Advice: Use the samples from codeguru or even here on codeproject and save yourself a lot of time!
However, Good Luck!
|
|
|
|
|
Does anyone know how to make those Title bar, Menu bar, Tool bar, Status bar disappear, so that I have more space for the document on the screen? My program is a SDI project.
Thanks
|
|
|
|
|
Hi,
I would like to associate an acclerator (for example Ctrl+S) to a button in a dialog window.
What do I have to do ?
I just have a function associated with the button ID.
Thanks.
Rob.
|
|
|
|
|
Hi
I have a small problem, which might seem ridicolous. I have an extended combobox and a toolbar om a dialogbar. To my surprise, I can't find any way to react when the user presses the enter button in the edit-part of the combobox. The action I want is the same as the one when the user presses a button on the toolbar.
Any hints?
|
|
|
|
|
search MSDN for "Subclassing a Combo Box". there is an example there showing how to catch the enter, esc, and tab keystrokes for comboboxes on a toolbar.
|
|
|
|
|
Using the Ultimate Grid (UG) very successfull for years, I now want do do some custom drawing.
Has anyone made an enhanced version (e.g. an OnDrawCell() handler, etc.) that I could buy/get/use?
Uwe Keim
See me: www.magerquark.de
|
|
|
|
|
Hi Uwe,
I think the correct way is to dereive a new class from "CUGCellType"
and overwrite the "OnDraw" method. I've done this in one of my projects.
If you need further information, don't hesitate to contact me.
Best regards
Holger
|
|
|
|
|
Hi,
I need to develop a plug-in for IE, that would be able to get the current URL (and detect it's changes).
The problem is that I don't even imagine where to begin!
Can anyone point me source code that:
- creates the toolbar under Internet explorer
- get the URL changes (automatic)
I looked @ the docs in MSDN, but they pointed me nowhere...
Tutorials are very welcome. The plug-in is in the style of the Google and Altavista style.
Thanks in advance!!
Marcelo Nogueira Magri
[Senior ASP Developer]
[Newbie VC++ Developer]
|
|
|
|
|
You can use my article and ATL Object Wizard. http://www.codeproject.com/atl/rbdeskband.asp. It's a little out dated. I have been notified of a few bugs in it, which I have fixed but have not posted the changes for. I have actually updated my codebase and will post the udpated article and content with some more helpful information about implementing each type later today. There are links on MSDN too maybe hard to follow.
Email me if you have any questions, and I'll try to answer them.
-Erik
|
|
|
|
|
I'm having problems withm a global windows hook created with SetWindowsHookEx.
The hook procedure is contained in a dll and the installation procedure for the hook is also contained in the same dll. I also have an application that links to the dll and calls the installation procedure.
When the application is running the hook works fine, but as soon as I quit the application the hook dissapears. I have not unhooked the hook, but it seems to uninstall it anyway.
I wanted to install the hook using the application and then have the application quit while the hook is still running, can I do this?
Thanks.
|
|
|
|
|
When you app exits, all DLLs it has loaded are unloaded. You'll need to keep your app running all the time, perhaps minimized to the tray.
--Mike--
http://home.inreach.com/mdunn/
The preferred snack of 4 out of 5 Lounge readers.
|
|
|
|
|
Is it possible to make a dialogbox appear like a form, so that when I move the whole window I also move the dialogbox. I have tried to use forms but with forms it is difficult to switch between them by pushing a button. If anyone can be at help I would be most grateful. And if anyone would take the trouble to make a program in VC++ (I am using 6.0) that changes forms if you click different buttons (between two forms/dialogs) it is important that the forms/dialogs is a part of the window. I will be extremly happy.
my e-mail is havardg8@hotmail.com
regard howie
|
|
|
|
|
I've done this before - I used one form to hold three flex grids, only one to be shown at a time and full screen, so I used ShowWindow to show and hide the items relevant to each view, creating the illusion of multiple forms.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
I need to use 100% of the screen to do drawing. However, as you know, there are "title bar, menu bar, tool bar, status bar" on the windows. How can I make them disappear? Also, because the last person doing this program started the program as SDK (single document), so I cannot open a new separate document, can someone help me?
|
|
|
|
|
There's an article in the Jan 99 Windows Developers Journal titled "Implementing Full-Screen Mode in MFC" by Adrian Hill that looks like it might help.
Or, if you just want to work in a new window, you might want to check out my Gribble1 article.
|
|
|
|
|
Can you tell me where can I find this Journal without going to library? Because I need to fix the problem now.....
Thanks
|
|
|
|
|
Well, I don't think its online - you might try Mike Blasjkdjclckw's (hope I got that right) sample FULLY.ZIP here
|
|
|
|
|
To go into a full screen mode, just resize the window so the toolbar is above the top edge, and if you have a status bar, it is below the bottom. The only problem is if a system is multi monitor and the monitors are stacks vertically (unlikely, but possible ), then the toolbar or status bar will show on the other monitor. I don't know if there is another solution, but the WJD site (www.wdj.com ) will allow you to download the source code for the month in question, so you can always have a look and see.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Hi,
I have created a TreeViwe control with the WS_EX_DLGMODALFRAME extended style.
The application of this style results in a horizontal scrollbar for this treeview window. The scroll thumb is also very small, making the treeview area about 10 times as wide as necessary.
How can I prevent this, and get e reasonable scrollbar, like the windows explorer?
TIA
|
|
|
|