|
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
|
|
|
|
|
now that you've forced me to look it up... i'm sure i was wrong.
but, that was the explanation for the crash that sounded best. if that wasn't it, maybe there was something wrong with calling the destructor for the object in the list. yuk.
-c
"Do you mind if I smoke?"
"Madam, I don't care if you burn."
-Oscar Wilde
Smaller Animals Software, Inc.
|
|
|
|
|
Your iterator gets invalid. Do:
list <sometype>::iterator i;
for (i=mylist.begin(); i!=mylist.end(); i++)
{
if (...) {
i = mylist.erase(i);
}
}
and your iterator will be right on track.
|
|
|
|
|
I beleive this is correct however you should also do i--; after the erase() call because erase() returns the next iterator and it will get ++'d at the top of the loop therefore skipping the item after the one you erased. Hope this makes sense.
-Jack
To an optimist the glass is half full.
To a pessimist the glass is half empty.
To a programmer the glass is twice as big as it needs to be.
|
|
|
|
|
I've made a MS Word automation project in order to print it's content
into Acrobat Distiller.
I want to print 3 pages (nPages = 3).
//---------------------------------------------------------------------------------------------------------------------------------------
So, my method is :
void _Document::PrintOut(VARIANT* Background,
VARIANT* Append,
VARIANT* Range,
VARIANT* OutputFileName,
VARIANT* From,
VARIANT* To,
VARIANT* Item,
VARIANT* Copies,
VARIANT* Pages,
VARIANT* PageType,
VARIANT* PrintToFile,
VARIANT* Collate,
VARIANT* ActivePrinterMacGX,
VARIANT* ManualDuplexPrint,
VARIANT* PrintZoomColumn,
VARIANT* PrintZoomRow,
VARIANT* PrintZoomPaperWidth,
VARIANT* PrintZoomPaperHeight )
{
static BYTE parms[] =
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT
VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT;
InvokeHelper(0x1bc, DISPATCH_METHOD, VT_EMPTY, NULL, parms, Background,
Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType,
PrintToFile, Collate, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn,
PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
And, the following call to this method produces an exception, cause of COleVariant(nPages,VT_I4)
CString text;
m_Edit.GetWindowText(text);
_Application objWord;
// Convenient values declared as ColeVariants.
COleVariant covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
// Get the IDispatch pointer and attach it to the objWord object.
if (!objWord.CreateDispatch("Word.Application"))
{
AfxMessageBox("Couldn't get Word object.");
return;
}
objWord.SetVisible(TRUE); //This shows the application.
Documents docs(objWord.GetDocuments());
_Document testDoc;
testDoc.AttachDispatch(docs.Open
(
COleVariant(text,VT_BSTR),
covFalse, // Confirm Conversion.
covFalse, // ReadOnly.
covFalse, // AddToRecentFiles.
covOptional, // PasswordDocument.
covOptional, // PasswordTemplate.
covFalse, // Revert.
covOptional, // WritePasswordDocument.
covOptional, // WritePasswordTemplate.
covOptional, covOptional, covOptional), // Format. // Last argument for Word 97
(long)1 // Encoding // New for Word 2000/2002
); // Close AttachDispatch(.)
objWord.SetActivePrinter("Acrobat Distiller");
long nPages = 3;
SCODE sc;
TRY
{
testDoc.PrintOut(covFalse, // Background.
covOptional, // Append.
covOptional, // Range.
covOptional, // OutputFileName.
covOptional, // From.
covOptional, // To.
covOptional, // Item.
covOptional, // Copies.
COleVariant(nPages,VT_I4), // Pages.
covOptional, // PageType.
covOptional, // PrintToFile.
covOptional, // Collate.
covOptional, // ActivePrinterMacGX.
covOptional, // ManualDuplexPrint.
covOptional, // PrintZoomColumn New with Word 2002
covOptional, // PrintZoomRow ditto
covOptional, // PrintZoomPaperWidth ditto
covOptional); // PrintZoomPaperHeight ditto
objWord.Quit(covFalse, // SaveChanges.
covTrue, // OriginalFormat.
covFalse // RouteDocument.
);
sc = S_OK;
}
CATCH_ALL(e)
{
sc = COleException::Process(e);
CString exp;
exp.Format("%d", e);
MessageBox(exp, "Exception !");
}
END_CATCH_ALL
How can i do ?
Thanks.
|
|
|
|
|
How would you get from a managed string to an unmannaged char array? I know there must be a more elegant way to get from point A to point B than:
sName - String
mcName - Char __gc[]
cName - char* (allocated for 256;Assert sName.Length <= 255)
mcName = sName->ToCharArray();
for(int j=0;j<mcname->Count;j++)
cName[j]=Convert::ToSByte(mcName[j]);
cName[mcName->Count]='\0';
|
|
|
|
|
I want to catch when the mouse is leaving a button.
When the mouse is or, I want to show a text in a static when the mouse is ovedr the button. And then the mouse is leaving the static will show another text. HOOOW!!!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|