|
Could someone please tell me how to make the background of a dialog a bitmap? I am using MFC on VC++ 6.0.
<marquee>Hosam Aly Mahmoud
|
|
|
|
|
Take a look at this.
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
Thank you very much!
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
like this:
void CAaDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CRect rect;
GetClientRect(&rect);
CPaintDC dc(this);
CBitmap bitmap;
BITMAP Bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
bitmap.GetObject(sizeof(BITMAP),&Bitmap);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap* poldbitmap=dcMem.SelectObject(&bitmap);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),
&dcMem,0,0,Bitmap.bmWidth,Bitmap.bmHeight,SRCCOPY);
dcMem.SelectObject(poldbitmap);
dcMem.DeleteDC();
}
}
void CAaDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
Invalidate(TRUE);
}
may be useful!
|
|
|
|
|
Thank you for your reply. But shouldn't this be handled in the WM_ERASEBKGND message (or the corresponding OnEraseBkgnd function)? Which one is better?
Thank you again.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Could you please tell me how to know how much free physical RAM exists on a system at a certain time? Also, if I have a process that allocates RAM using new, is there a way to guarantee that the allocated RAM does not go into the virtual memory, but rather stay in the physical RAM until I delete it (or the process ends)?
Sorry for my language, and thanks for your help.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
GlobalMemoryStatus() and VirtualLock()
John
|
|
|
|
|
Thank you very much. The GlobalMemoryStatus() is great. But I could not understand VirtualLock() . Could you kindly help me with it?
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
|
Thank you for your reply, and sorry for my late reply. I read the two links, and thanks a lot for the second one. The first one, however, made me rethink about using VirtualLock() . But I think that if my application does not lose focus, then it will keep my application fast. Is that right? Now I have another problem: how can I keep my application in the foreground? Should I make my process' priority "Real Time"? How can I do that?
Thank you very much.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
But I think that if my application does not lose focus, then it will keep my application fast.
Yes it will. As long as the application is not minimized it will not page out unless another process needs memory. When the application is minimized windows sets the working set size to zero thus paging out your application. Different windows versions will handle this alittle differently. I think NT4 will page all of your applicaton out immediatly causing a long delay. I am a little unsure of this. I worked on this two years ago for an application that needed to hold 256MB of images in memory at a time.
Hosam Aly Mahmoud wrote:
how can I keep my application in the foreground?
Don't allow the main window to be minimized. I made the minimize button hide the window instead of minimize and it fixed the problem.
John
|
|
|
|
|
Thanks for your efforts and time.
John M. Drescher wrote:
I made the minimize button hide the window instead of minimize and it fixed the problem
I think I will disable the minimize button. That should be enough.
John M. Drescher wrote:
As long as the application is not minimized it will not page out unless another process needs memory.
So what if another process does need memory? How can I delay all other processes and make them wait until I am finished?
Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
So what if another process does need memory? How can I delay all other processes and make them wait until I am finished?
If another process needs memory it may affect the working set of your process. When all the physical memory of the system is exausted the cpu will trim the working set of all processes (other than the one requesting additional memory).
Hosam Aly Mahmoud wrote:
How can I delay all other processes and make them wait until I am finished?
Maybe setting the process priority to real time may solve your problem.
John
|
|
|
|
|
Thank you very much for your help John! I do not know how I could thank you, but here is a try:
John M. Drescher wrote:
Maybe setting the process priority to real time may solve your problem.
I thought it would, but I do not know how to do it. Could you please tell me (or give me a link)? I would very much appreciate it.
Thank you for all your help!
Hosam Aly Mahmoud
|
|
|
|
|
Not sure about how to tell how much RAM is free off the top of my head, but you can probably find out by looking at the memory management functions in MSDN.
Regarding locking allocated memory into physical memory, take a look at the VirtualLock() and VirtualUnlock() functions. These allow you to do exactly what you want.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Thank you for your reply. I am sorry, but I could not use VirtualLock() . I am still a beginner, so I do not understand what is meant by a "memory page". Second, do I have to use VirtualAlloc() or can I allocate using new ? What is the difference?
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
I would strongly suggest that if you don't understand what memory pages are and how they work, then you should just let windows handle the virtual memory. It is very easy to screw it up, and is not recommended while you're still trying to learn the basics.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Thank you for your reply. I would have let windows handle everything in normal situations, but I am currently working on a program that needs full processor power and enough RAM to use as a buffer. I had a problem with the buffer size though, so I thought it would be adequate to ask the system how much free RAM it has and then allocate most of it. I certainly need to make sure that my buffer does not go into virtual memory, because that would buffer something from the HDD to the HDD, right? That said, I want to learn the new concepts I neaded, so please give me a link or a hint where to find the information I need.
By the way, could you please tell me how to give my process higher priority?
Thank you very much.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
I have no clue how big a buffer you are allocating but I just wanted to inform you for all practical purposes on a 32 bit version of Windows that is not advanced server or greater you can not allocate a buffer greater than about 1.2GB because of several reasons that have to do with how process memory is partitioned.
John
|
|
|
|
|
Thank you for the information.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Here is a good tutorial about Memory Management, it’s a little old and mentions 16 bit windows and RISC stuff that you should not be very concerned with:
http://www.jps.at/dev/kurs/3-2.html[^]
John
|
|
|
|
|
In the dialog box, there are 3 edit boxes. After the dialog box initialized, the first edit box is highlighted and also have focus. What I want to do is when the first edit box is not empty, set it as ready only and also set the focus to the second dialog box.
I tried
GetDlgItem(IDC_EDIT2)->SetFocus(); Not working
Also tried
CEdit *pEdit =(CEdit*)GetDlgItem(IDC_EDIT2);
pEdit->SetFocus();
still not working.
Please help me with this problem.
|
|
|
|
|
You can get into race conditions using SetFocus() in a dialog. Use PostMessage( WM_SETFOCUS,.. ) instead.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
This is the way:
In menu "Layout",you may find "Tab Order"! click it and the dialog edit will show 1,2,3,4.....,that is the focus order,change the order by click controls,you can set the focus to the second dialog ,good luck !
sorry for my language!
|
|
|
|
|
I am experiencing a very strange problem.
When my MFC app is run, all of the Tool Tips in our program, as well as all Windows Tool Tips show the tip of the *last* tool that was hovered over. Here is what happens upon program launch.
* The first toolbar button that I hover over doesn't get drawn. Actually, it's shadow gets drawn, but the tip itself doesn't draw.
* The next toolbar button that I hover over gets drawn with the text of the first button that I hovered over.
* The width of the Tool Tip is wide enough for the text of the "correct" text, not the width of the "incorrect" text which is being displayed.
* This goes on and on until you hover off of a button onto some dead space, and then hover over it again, in which case, it will show the correct tip, but goes wacky again once you hover over another button.
* All Tool Tips on the system get screwed up like this until the app is shut down.
Thus, there seems to be a "lag" or mismatch bewteen what is being displayed and what the correct tip should be.
To try and get to the bottom of this problem, I have commented out all Tool Tip related code from my app, including Tool Tip flags passed to controls such as Tree controls, etc.
I have also tried commenting out any other "non-standard" things that I am doing. All of my users are experiencing this. I have tried creating a new blank app using AppWizard, but could not duplicate the problem.
Does anyone know what this might be related to, or what I might have done wrong to screw things up? If not, does anyone have any info on how to debug something like this, or where I can even trace/step through the code to find out what is going wrong and where.
Thanks
Dario
|
|
|
|