|
Do the drawing of the image in the window in the OnEraseBackgrnd handler.
Happy programming!!
|
|
|
|
|
Still i have the same problem.
|
|
|
|
|
Try to detect when the drag is finished and and force a redraw by calling Invalidate for the window in question.
Failing that a look at your code would help.
Happy programming!!
|
|
|
|
|
Hi all, I'm kind of new at MFC and I need to make an application that would be able to graph points. I can make a dialog that does this, but now I would like to place it in an MDI architechture. How can I display dialog boxes as children of my MDI window that would be able to be viewed side by side (Replacing the Document views by my dialog)?
Thanks!
|
|
|
|
|
You can use a class of your own writing that is derived from CFormView to do this.
There are also a few classes on this site that handle graph displays that might prove helpful.
|
|
|
|
|
Hello Cpians,
I'v been working on a personal off time project and I'm at lost how to implement an idea. What I'm doing is displaying a BMP, then what I need to do is set a few regions that are hidden and will respond to the mouse events. Then displaying a set of smaller bmps the size of an icon around the screen that i can move at will and not destroy the first original bmp. Sort of layering everything . Would I use multiple CDC's(if that's possible) and treat the smaller bmps as objects? I'v looked into GDI+ and that will be my choice. Just not sure how to actually implement my idea yet. I'm new to this graphics stuff since straight text got boring for me.
Namaste
|
|
|
|
|
A CDC, or a Device Context, really only acts like a surface for you to draw on, it is not really meant for you to interact with. If what you are doing is all in the context of one window here is what I would suggest.
1. you will only use the one CDC that you receive from the client window where your display will go. All of your painting will be done on that DC.
2. All of your hidden regions could be represented by HRGN objects created with the region functions, CreateRectRgn, CreateEllipseRgn and so on, there are between 5 and 10 different ways to create regions.
3. In your window handler you can handle the WM_MOUSEMOVE and WM_LBUTTONDOWN messages to determine if the user is clicking in one of your hidden regions. To test if a certain point is in one of your regions you can use the PtInRegion function.
If you need more information or this solution will not work for you please write back.
|
|
|
|
|
kilowatt wrote:
2. All of your hidden regions could be represented by HRGN objects created with the region functions, CreateRectRgn, CreateEllipseRgn and so on, there are between 5 and 10 different ways to create regions.
Hello Kilowatt!
Does this mean when creating regions there is a HRGN object associated with each one that I can access to move or redraw the selected region?
What I need to do is create any number of regions on the fly and then some how access any one of those regions and move them or repaint them.
Thanks in advance.
|
|
|
|
|
//******************** Stocks.cpp ********************/
#include "Stocks.h"
#include <string.h>
//========================================================
int Stocks::numOfStocks = 0;
Stocks:: Stocks()
{
numOfStocks++;
}
Stocks:: ~Stocks()
{
}
void Stocks:: addStock( Stock* st, int i)
{
i = numOfStocks;
Stock& myStocks[i] = st;
}
Compiling...
Stocks.cpp
C:\My Documents\DataStru\Stocks.cpp(21) : error C2057: expected constant expression
C:\My Documents\DataStru\Stocks.cpp(21) : error C2466: cannot allocate an array of constant size 0
C:\My Documents\DataStru\Stocks.cpp(21) : error C2234: '<unknown>' : arrays of references are illegal
C:\My Documents\DataStru\Stocks.cpp(21) : error C2440: 'initializing' : cannot convert from 'class Stock *' to 'class Stock *[]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
Error executing cl.exe.
Stocks.obj - 4 error(s), 0 warning(s)
can any one tell me what is wrong with this piece of code
thank you
|
|
|
|
|
Marwan wrote:
Stock& myStocks[i] = st;
You're assigning to an element of the array, right? Take out the Stock& because you're not declaring a new variable.
--Mike--
"Everyone has figured out what 'service pack' really means, so they had to go and change the language. Perhaps this is what Bill was talking about in the 'security is top priority' letter."
-- Daniel Ferguson, 1/31/2002
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
Big fan of Alyson Hannigan.
|
|
|
|
|
void Stocks:: addStock( Stock* st, int i)
{
i = numOfStocks;
Stock& myStocks[i] = st;
}
You reassign a value from an input parameter?
|
|
|
|
|
I've got a file browsing list control inside a custom Outlook Control. The problem is that when I remove all the items in the list control and fill them with a new list (as in the user selects a different folder to browse), a bunch of blank space gets left at the top. Below is a screenshot:
(dunno why this image doesn't want to display)
This seems about the same amount of space as the scroll offset before the list items were updated. I've tried a calling a bunch of functions to see if I can get rid of this, but can't. (The attemps are shown below under the //!!! part.
void
cPkpPhotoListControl::OnRightClick(NMHDR* pNMHDR, LRESULT* pResult)
{
cResId PopupMenuResId = GetPopupMenuResId();
//!!!
CListCtrl::SetWorkAreas(0, NULL);
CListCtrl::Arrange(LVA_ALIGNTOP | LVA_ALIGNLEFT);
CListCtrl::SetWorkAreas(0, NULL);
SetScrollPos(SB_VERT, 0);
if(!PopupMenuResId.IsVoid())
{
cPoint ScreenPoint;
GetCursorPos(&ScreenPoint);
//!!!!
cPoint sss = ScreenPoint;
ScreenToClient(&sss);
cWindowHelper Helper(this);
Helper.HandlePopupMenu(PopupMenuResId, ScreenPoint);
}
*pResult = 0;
}
Now I've hooked this into the right mouse click handler so I they are called whenever I hit the right mouse button (just for debugging).
I've also tried clicking the top of this space, and that point comes out as near 0 in client coordinates, so I know that white space is part of the list control. I can also drag a selection box in this white space.
Anyone have any ideas? Any other commands I can try?
Cheers,
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Such a thing as a class prototype? Im sure there is... I need to know how to use it since I have a class that needs to derive an object from another class and use it but the other class is defined after it and if i define it before it I will hit the same problem with its class.
-- Remember your are but a lowly hair on my s*r*t*m
|
|
|
|
|
For example, the class prototype for CString would be:
class CString;
But you can only use pointers and references to a prototyped class if it's not defined yet (just declared with the prototype). So you'll have to create instances of it off the heap with the new operator, and store data members as pointers.
cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
And make sure you don't use the old C casting operation on pointers prior to the class being defined. That will cause nasty problems. If you use static_cast, it will error if the class hasn't been defined.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
new CString;
my_val = CString.whatever(); ?
-- Remember your are but a lowly hair on my s*r*t*m
|
|
|
|
|
That doesn't make any sense.
in the header file (for example):
class CString;
class CStringUser
{
public:
CStringUser(void);
private:
CString* m_Member;
};
In the cpp file:
#include "StdAfx.h"
#include "CString.h"
CStringUser::CStringUser(void)
{
m_Member = new CString;
}
...but of course that's assuming "CString" is the class you want to forward declare.
Cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
Hi,
I have some data in my app which is manipulated by the user which should automagically be saved upon exit, in order to be available when launching the app next time.
The amount of data is too big for storing them in the registry so I thought they could be serialized to a file.
But I want to do it without prompting the user for a filename.
Any ideas how I could achieve this?
Thanks.
Pepe
|
|
|
|
|
You could save it in the user's settings folder. For example, "c:\Documents and Settings\Matus\Application Data". But you should use the windows functions to make sure you are retrieving the right folders. I think its SHGetSpecialFolderLocation() or SHGetSpecialFolderPath().
Cheers,
swinefeaster
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
yeah, but AFAIAC the Serialize function is called by the system when the user clickes save or open in the file menu.
How can I trigger the above call without any user interaction, and how can I give the location without having to deal with CFileDialog?
Thanks
Pepe
|
|
|
|
|
Basically, CArchive just uses a CFile object as its internal file access class. The Serialize function for your object is passed a CArchive automatically by the framework, but you can do it manually also.
----------------------------------------
to serialize your data to disk:
----------------------------------------
CFile fp;
fp.Open(somefilename,CFile::modeWrite | CFile::modeCreate | CFile::shareExclusive);
CArchive ar(&fp, CArchive::store);
obj.Serialize(ar);
ar.Close();
fp.Close();
----------------------------------------
to load data from disk
----------------------------------------
CFile fp;
fp.Open(somefilename,CFile::modeRead | CFile::shareExclusive);
CArchive ar(&fp, CArchive::load);
obj.Serialize(ar);
ar.Close();
fp.Close();
----------------------------------
to automatically determine a file name
----------------------------------
Often, what I do is to save the file in the same path as the EXE, but I use the users computer name and user-name as the file name. If I want the user to be able to log in from different computers, I just use their user name.
char szAppPath[2000];
char szDrive[200];
char szDir[200];
char szComputer[2000];
char szUser[2000];
DWORD dwTempSize = 0;
CString strFileName;
memset(szAppPath, 0, 2000);
memset(szDrive, 0, 200);
memset(szDir, 0, 200);
memset(szComputer, 0, 2000);
memset(szUser, 0, 2000);
::GetModuleFileName(AfxGetInstanceHandle(), szAppPath);
_splitpath(szAppPath, szDrive, szDir, NULL, NULL);
dwTempSize = 2000;
::GetUserName(szUser, &dwTempSize);
dwTempSize = 2000;
::GetComputerName(szComputer, &dwTempSize);
strFileName = szDrive;
strFileName += szDir;
strFileName += szComputer;
strFileName += "-";
strFileName += szUser;
strFileName += ".dat";
---------------------------------------
PS. I wrote the above code from memory so there might be some typos, etc.
Matt Gullett
|
|
|
|
|
I need to allow users to run more than one instance of my app. Unfortunately I have to use Netbios functions. I have found that my app locks up the entire machine if one instance is deleting the name from the name table at the same time the other one resetting the lanas or adding the name. So I thought I could use a mutex to have the second one wait if the first one is deleting the name. Unfortunately it doesn't seem to work. Here is the code:
CMutex mutex(TRUE, "application name - Stopping or starting network stuff");
CSingleLock lock(&mutex);
lock.Lock();
The first one exectutes this and has not exited the function (so the mutex has not been deleted) when the second one executes this. The second one does not wait.
What am I doing wrong?
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Are you checking the return state of the Lock ?
You might want to have a look at the MUTEXES sample app from MSDN to see how to use CMutex correctly.
|
|
|
|
|
Thanks. I will look at the return value to see if it failed and look at the MSDN sample. The documentation sounded pretty straitforward. I read someone's comments somewhere saying the first version of MFC's critical section class was buggy. So I thought maybe this one is too. So I was hoping to hear from someone who had used it before and could tell me whether or not it worked.
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
Actually, my first attempts with it were not successful so I just wrote my own little thing using the Win32 mutex functions. They seemed a bit more straight forward to me. The API functions used are CreateMutex, WaitForSingleObject, ReleaseMutex, and CloseHandle. They are invoked in that order.
My jokes page
|
|
|
|