|
See this article.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks, but I saw it before and it's about changing the items' background.
I need to change the listbox window's back color, not the items'.
rechi
|
|
|
|
|
OK, how about this one then?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
If you have c-like structure in your code and you create a static member pointer to that structure in your class, what is the proper way of deleting it then? For instance, I instantiate this static member outside of my class as following CMyClass::x = new structre...
this is all part of a dialog wizard class within one of the pages. So I started by deleting this thing in my page's destructor by going delete CMyClass::x, but at times this crashes because it appears that eventhough new has been called on the structure, the structure is empty. What is the proper way of making sure that there is no left overs then, in a scenario like this?
|
|
|
|
|
You need to create an instance of the static structure outside of you class like this:
struct RECT
{
...
};
class window
{
static RECT rClient;
...
};
RECT window::rClient;
Declaring the RECT window::rClient outside of the class tells the compiler to allocate memory for the structure outside of the class, and only one instance will be allocated for the class on the stack. Since it is on the stack, you do not need to do anything else to free resources.
|
|
|
|
|
I wouldn't make a static variable be allocated with new like that probably, but if you want to safely delete it, you could do something like this:
typedef struct tagWhatever
{
int x;
int y;
}Whatever;
static Whatever * s_pstWhatever = new Whatever;
class WhateverDeleter
{
public:
WhateverDeleter()
{
}
~WhateverDeleter()
{
delete s_pstWhatever;
s_pstWhatever = NULL;
}
};
static WhateverDeleter s_oWhateverDeleter;
|
|
|
|
|
Hi !
I have several databases (in mdb format) for my MFC project. I decided to put them on a server in the network. The path is like this:
//netbackup/multimedia/erginasil.mdb
The problem is: The server (netbackup)has a password which I have but the users will not have.If I first connect there ,the program runs normally. How can I acces a password protected server in the code. I found in msdn opening a password-protected "file" but I must give the "server password" to connect normally.
Thanks in advence..
|
|
|
|
|
When I copy and paste bitmaps and pictures from my app to another like WORD, the image seems ok under 1280 by 1024. When I change screen resolutions, try to copy and past again, the pictures get distorted and or clipped
here is meta code
//------------------------------------------------------------------------------
// Create a meta record for drawing the given component.
//------------------------------------------------------------------------------
BOOL ZClipboard::setMetaFile(CRect rect, CDC *dc, ZComponent *c, HWND hWnd)
{
// Meta file DCs operate in HIMETRIC units, we
// must scale the extents to these units so that
// the object appears the same size when pasted.
double units_per_inch = 25.4 / 0.01 + 0.5; // 25.4 mm at 0.01 mm per unit.
double scale = units_per_inch / 96.0; // divide by screen units
// Now scale the extents to HIMETRIC units.
rect.left = int(rect.left * scale + 0.5);
rect.top = int(rect.top * scale + 0.5);
rect.right = int(rect.right * scale + 0.5);
rect.bottom = int(rect.bottom * scale + 0.5);
HENHMETAFILE hMF = NULL;
CMetaFileDC metadc;
if (metadc.CreateEnhanced(dc, NULL, &rect, NULL))
{
metadc.SetAttribDC(dc->m_hDC); // This must be set!
// Translate the current window origin
// to the context of the component.
// Un-translate the current window origin
// to the parent coords of the component.
{
ZGraphics meta_g(&metadc);
meta_g -= c->getLocationOnCanvas();
meta_g -= c->getLocation();
c->paintAll(meta_g);
}
hMF = metadc.CloseEnhanced(); // Close the DC.
}
else
return false;
// Open the clipboard. OpenClipboard() takes one
// parameter, the handle of the window that will temporarily
// be it's owner. If NULL is passed, the current process
// is assumed. After opening, empty the clipboard so we
// can put our metafile on it.
if (hMF)
{
OpenClipboard(hWnd);
EmptyClipboard();
SetClipboardData(CF_ENHMETAFILE,hMF);
CloseClipboard();
}
return true;
}
here is bitmap code
//------------------------------------------------------------------------------
// Get a snapshot of the screen at the location of the given rectangle
//------------------------------------------------------------------------------
BOOL ZClipboard::setBitmap(CRect rect, CDC *dc, HWND hWnd)
{
// Set the graphics context.
HDC hdc = dc->m_hDC;
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc, rect.Width(), rect.Height());
if (hBitmap)
{
// Copy the bitmap...
SelectObject(hdcMem, hBitmap);
StretchBlt(hdcMem, 0, 0, rect.Width(), rect.Height(), hdc, rect.TopLeft().x, rect.TopLeft().x, rect.Width(), rect.Height(), SRCCOPY);
// Open the clipboard. OpenClipboard() takes one
// parameter, the handle of the window that will temporarily
// be it's owner. If NULL is passed, the current process
// is assumed. After opening, empty the clipboard so we
// can put our bitmap on it.
OpenClipboard(hWnd);
EmptyClipboard();
// Place the data (Bitmap) onto the clipboard.
SetClipboardData(CF_BITMAP, hBitmap);
CloseClipboard();
// Clear the temp rect.
InvalidateRect(hWnd, NULL, true);
}
DeleteDC(hdcMem);
return TRUE;
any help appreciated
George W
Software Developer
www.zsystems.ca
|
|
|
|
|
How do I read from a file starting at a particular line. Suppose I want to start retrieving data from the third line but I don't know how much data is on the first two lines. Can I just read until I get two carriage returns?
Something like:
ifstream file(test.in);
char test;
for(int i=0; i<2; i++)
{
while(test!='\n')
file >> test;
}
I know this code is most probably not right, I just put it in to help explain what it is I want I'm trying to accomplish. Can anyone tell me the right way to do it?
|
|
|
|
|
You could use ifstream::getline(...) to remove unwanted lines.
|
|
|
|
|
I have used that approach before. Probably not the best, but it works.
Only you should take care when compiling under linux/unix...I don't think they support the same CRLF sequence I think it's just CR on those systems.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
As mentioned previously, getline() will prolly work well for you. But if you want to do it your way, you should test also for EOF, just in case there are less than two lines in the file.
Sometimes i only remember, The days when i was young Nowadays no one remembers when they were young and stupid... ADEMA, The Way You Like It
|
|
|
|
|
If you don't mind using vanilla C, you can use fgets() to read one line at a time.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Hi,
maybe a dull question...
how can I retrieve the handle to the active MDI child window (the active document within MDIClient) without using MFCs CMDIxxx-classes?
best regards,
Amar
|
|
|
|
|
GetActiveWindow()
Returns the handle to the window that has the current input.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I´ve done this before but this always returning NULL.
Any ideas?
|
|
|
|
|
GetActiveWindow() - MSDN
The active window or NULL if no window was active at the time of the call. The pointer may be temporary and should not be stored for later use.
Try setting the window's active state explicity with SetActiveWindow() somewhere in your code and then try GetActiveWindow() see what happens...
If it's a temporary pointer...you only wanna use it right after the call to GetActiveWindow(), is this perhaps causing your problem...?
I dunno why it would fail...other than what the above states.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
CMDIFrameWnd::MDIGetActive() should do the trick.
|
|
|
|
|
You could try sending the WM_MDIGETACTIVE to the MDIClient window.
|
|
|
|
|
Is possible insert icons in a ListCtrl with owner draw fixed style ? How ?
Thanks ...
Cristiano
|
|
|
|
|
I don't see why not, however you'd have to handle to the drawing of the icons.
Your associating the icons with a CImageList, not the actual CListCtrl itself.
You'd have to get the image out of the imagelist and draw it to the DC passed to you in the DrawItem().
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi,
I will set one event,if i call a messagebox after that everything works fine.Otherwise it hangs in waitforsingleobject().
I don't want to show any message box.so i did get/PostMessage+DispatchMessage.
It doesn't work..
Can anyone pl help me...
Neha
|
|
|
|
|
when i try to remove an item from a list inside of the loop it crashes.
here is my code:
list <sometype>::iterator i;
for (i=mylist.begin(); i!=mylist.end(); i++) {
if (...) {
mylist.erase(i);
}
}
|
|
|
|
|
if you want to be STL-friendly, use list::remove_if (see MSDN for a sample)
(the rest of the incorrect crap i posted earlier has been removed, to protect my good name)
-c
"Do you mind if I smoke?"
"Madam, I don't care if you burn."
-Oscar Wilde
Smaller Animals Software, Inc.
|
|
|
|
|
Chris Losinger wrote:
erase invalidates all iterators.
For std::list - are you *sure* ? My first reaction is that this is true of vector, but not list.
Remove_if is obviously a better way to go though
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|