|
Hello,
I'm working on a MDI project and I'd like to insert a bitmap in the background of my application, in other words, on my MainFrame window, behind the children windows. This bitmap will be always there. I'm workin with VC++ 6.0 and Windows 2000. If anybody know how to this, please, help me.
Best Regards,
Igor Kondrasovas
|
|
|
|
|
It's very easy use GDI+.Check this and this
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
It's simple task, but many steps are required:- Create a new
CWnd -derived class, say CBackgroundWnd .
- Add these two members to
CBackgroundWnd :
CBitmap m_bitmap_background;
BITMAP m_bmInfo_background; along with this piece of code in CBackgroundWnd ctor:
m_bitmap_background.LoadBitmap(IDB_BACKGROUND);
::GetObject(m_bitmap_background,sizeof(BITMAP),&m_bmInfo_background);
- Add a handler for
WM_ERASEBKGND in CBackgroundWnd and plug this code (which draws the bitmap in tesellation mode)
BOOL CBackgroundWnd::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
GetClientRect(rect);
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
HBITMAP* pBmpOld=(HBITMAP*)::SelectObject(dcMem.m_hDC,m_bitmap_background);
for(int y=rect.top;y<rect.bottom;y+=m_bmInfo_background.bmHeight){
for(int x=rect.left;x<=rect.right;x+=m_bmInfo_background.bmWidth){
pDC->BitBlt(x,y,m_bmInfo_background.bmWidth,m_bmInfo_background.bmHeight,
&dcMem,0,0,SRCCOPY);
}
}
::SelectObject(dcMem.m_hDC, pBmpOld);
return TRUE;
}
- Add a member of type
CBackgroundWnd to your CMainFrame class, say m_wndClient .
- Override
CMainFrame::OnCreateClient with this:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if(!CMDIFrameWnd::OnCreateClient(lpcs, pContext))return FALSE;
m_wndClient.SubclassWindow(m_hWndMDIClient);
return TRUE;
} That's it, I think. Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Why couldn't he just erase background in the mainframe ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Good question... I created a test MDI project and tried that approach first, to discover that my tesellation got overdrawn by the standard dark-grey background (I noticed because of the flickering). I remembered then about that funky, mostly unknown CMainFrame::m_hWndMDIClient member and how it seems to take on some of the roles people tend to ascribe to CMainFrame itself... got it subclassed and WM_ERASEBKGND -handled, and it worked. Couldn't say if this is the most direct approach. Any ideas?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Interesting - I've only ever done this in a view, so I had no idea of this problem. Sounds like it's worth a fiddle sometime.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
...so I had no idea of this problem
Neither did I Thought I'd write a test before submitting an answer, and came to this (to my surprise).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
All,
I'm minimizing my dialog to the system tray. IE. I add an icon to the tray and then ShowWindow(SW_HIDE) my dialog.
I'm set up a command handler for a left click of my icon in system tray, and I want to show the window, and put it at the front with the focus. simple stuff.
But it never works. It always has the focus (ie, it's button on the task bar is depressed), but is behind other windows!?
Has anyone seen this problem?
SetWindowPos(&wndTop,NULL,NULL,NULL,NULL,SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetFocus();
is what i'm doing.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I guess there're many ways to get this done. This particular combination
ShowWindow(SW_SHOW);
SetForegroundWindow(); seems to work fine.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Tried that, it's a step better, in that it worked properly with restoring the window when i'd got rid of it in my WM_CLOSE handler. But if i'd got rid of the window in WM_SIZE => SIZE_MINIMIZED, then the re-show of the window still didn't put it at the front. Now i'm using ShowWindow(SW_RESTORE) and that's doing the trick. Evidently it was reshowing the window but still leaving it minimised.
Thanks for your help Joaquin!
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Is there some easy way to log error output in Debug window in pure SDK programming ? I used to work with TRACE macro in MFC, but from what I gathered in the help, I can't use it in SDK.
|
|
|
|
|
OutputDebugString gives you the basic functionality. From here you can build up added flexibility in a manner similar to MFC (you can have a look at MFC AfxTrace code for inspiration.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
If i try to bind a column all works fine:
SQLBindCol(hstmt,1,SQL_C_LONG,var_ptr,0,0);
but if i try to get data like this:
SQLGetData(hstmt,1,SQL_C_LONG,var_ptr,0,0);
nothin happens...
Help please...
|
|
|
|
|
Need Help in making an Eraser Tool for our Drawing Program... please help
|
|
|
|
|
What exactly do you want it to do ? Do you have layers in your program ? Are you drawing a shape and then hoping to erase parts of it ?
I've written a paint package, so chances are good that I can help, but I need some more info on what you want it to do. Also, what is the internal structure of your image ? Are you using GDI + ? Supporting oversize images ? Using any external libraries such as FreeImage or PaintLib ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Its just like the paintbrush program in WINDOWS.... There are no layers... as soon as I erase on an area it will be erased, the area will show a white color which is the color of my drawing area...
I'm using FreeImage....
thank you for looking into this...
|
|
|
|
|
Too easy - you just want a drawing tool that always draws in white. Where are you stuck ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Can you give me a code for the eraser tool coz i really need it and i am quite new using MFC.... thanks
|
|
|
|
|
What paint tools have you written, any ? What is the architecture of your program ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Hi,
I have written a SDI based MFC Application.In that i have
((CMyAppApp*)AfxGetApp())->m_pMainWnd ->EnableWindow(FALSE);//I want to disable all the keyboard & mouse inputs for my main window.
After this
If i write
if(((CMyAppApp*)AfxGetApp())->m_pMainWnd ->IsWindowEnabled())
It returns me TRUE;//ie window is enabled.
Could any one pl tell me why it is failing to disable the window?
Thanks
Neha
|
|
|
|
|
I've just created a fresh SDI app and added a command handler where I inserted your very line of code, and everything works as expected (i.e. the main window is disabled and IsWindowEnabled returns FALSE ). Are you doing something bizzare in the processing of the WM_ENABLE message?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Neha wrote:
((CMyAppApp*)AfxGetApp())->m_pMainWnd ->EnableWindow(FALSE);//I want to disable all the keyboard & mouse inputs for my main window.
Could you tell us, where you have put this code.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
I had written that in a OnButtonClick()..
|
|
|
|
|
The frame window's OnButtonClick???
Or the view window's OnButtonClick???
Remember that the button messages go to the view and are not handled by the frame window, unless there is no view window.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|