|
::fopen("c:\\temp\\out.txt", "rw");
In this example file name is hardcoded, which assumes 1.)you never want to create file anywhere else. 2.) name of the file never changes 3.) directory "C:\temp" exists on the user computer.
It is considered bad practice even for debugging purposes.
|
|
|
|
|
In my opinion the term "hardcoded" implies that a value or an algorithm can only be changed by changing the source code.
Ivor S. Sargoytchev
|
|
|
|
|
i use the words hardcoded and dynamic.. hardcoded means something can't be changed without recompiling, whereas something that is dynamic can be adjusted on the fly.
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Hi,
I have a requirement to complete, but i'm not sure how to do it. I know I'll have to use a CFormView interface. The thing is, i have to get fonts to work within this view. It's basically a listing output of some technical information. However, my boss wants it to have font & color capability. I've already ruled out using CListCtrl, as that's just a listbox basically. I've thought about CRichEditCtrl's, but that's editable by the user right? And we don't want that to be a possibility... Does anyone have any ideas?
|
|
|
|
|
|
Could you be more specific as to what to do? I'm rather new to windows programming. Thank you!
|
|
|
|
|
See MSDN article Q85518. It Shows how to set font for individual control, but you can apply that to any CWnd derivative(CFormView in your case).
|
|
|
|
|
I've searched msdn.microsoft.com all over for this "Q85518", and I can't find a darn thing. Am I looking in the wrong place?
|
|
|
|
|
Sorry, name of the article is "INFO: Correct Use of the SetFont() Function in MFC"
in case you do not have it here is the code( I hope MS will not sue me
/*
* Compiler options needed: None
*/ class CMyAboutBox : public CDialog
{
CFont m_font; public:
// Constructor -- This code assumes a dialog box
// template named "ABOUTDLG" in the application's .RC file. CMyAboutBox(CWnd* pParentWnd = NULL) :
CModalDialog("ABOUTDLG", pParentWnd) {}; BOOL OnInitDialog();
};// OnInitDialog() function -- Called after Windows creates
// the dialog box but before it is painted on the screen.BOOL CMyAboutBox::OnInitDialog()
{
LOGFONT lf; // Used to create the CFont. CDialog::OnInitDialog(); // Call default ::OnInitDialog memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 20; // Request a 20-pixel-high font
strcpy(lf.lfFaceName, "Arial"); // with face name "Arial".
m_font.CreateFontIndirect(&lf); // Create the font. // Use the font to paint a control. This code assumes
// a control named IDC_TEXT1 in the dialog box.
GetDlgItem(IDC_TEXT1)->SetFont(&m_font); return TRUE;
}
|
|
|
|
|
Yea, the person working on this app before me did something like that in the OnInitialUpdate of the CFormView class.. check this out
I posted this after your initial response....
Hi,
I need some serious help setting a font in a CFormView (with an embedded CListCtrl)class. The on initial update code looks like this...
void CTextWindow::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//size the window to the proper side that would fit the parent
CFrameWnd *pParentFrame = GetParentFrame();
pParentFrame->RecalcLayout();
ResizeParentToFit(TRUE);
//displays the window text depending on the template used to
//create an instance of this class.
if(GetDocument()->GetDocTemplate() == theApp.pOutputDocTemplate)
pParentFrame->SetWindowText("Output Window");
else
pParentFrame->SetWindowText("");
//intialize the font to be used with a constant font
font.CreateFont(14,0,0,0,0,0,0,0,0,0,0,0, FIXED_PITCH | FF_MODERN, "Courier New");
//delete all entries from the list control
m_List.DeleteAllItems();
//set up list control to contain one column
m_List.InsertColumn(0,"Text",LVCFMT_LEFT, 1600, -1);
//set a font of the list control
m_List.SetFont(&font,FALSE);
//set a boolean flag to false to indicate that no file has been loaded yet.
fFileLoaded = false;
}
Pay attention to the lines....
//intialize the font to be used with a constant font
font.CreateFont(14,0,0,0,0,0,0,0,0,0,0,0, FIXED_PITCH | FF_MODERN, "Courier New");
m_List.SetFont(&font,FALSE);
I'm trying to implement font control in this program after the initial update, but I also want to set the font before this window is created. So I'm having a lot of trouble.
I try to make a member function that looks like this.
void CTextWindow::SetScreenFont (...)
{
//same font object as before
font.CreateFont (//parameters);
m_List.SetFont (&font, FALSE);
}
I do this and I get Debug Assertion errors in the Debug configuration and crashes in the Release! Can anyone tell me how to remedy this problem and get a working font control algorithm?
Thanks,
Mike Mathers
My only guess is that a CFont object can only create a font once... but I don't know what else to do to set the font of the CListCtrl. Any ideas buddy?
|
|
|
|
|
1. tell me exactly where the assert happens
2. try font.Detach(); after each SetFont(it might create memory leak, but for now we just need it to work)
P.S. I am little bit out of date with MFC, so forgive me for guessing
|
|
|
|
|
BOOL CGdiObject::Attach(HGDIOBJ hObject)
{
ASSERT(m_hObject == NULL); // only attach once, detach on destroy
if (hObject == NULL)
return FALSE;
CHandleMap* pMap = afxMapHGDIOBJ(TRUE); // create map if not exist
ASSERT(pMap != NULL);
pMap->SetPermanent(m_hObject = hObject, this);
return TRUE;
}
It fails at ASSERT (m_hObject == NULL);
The Body of "CreateFont" looks like this...
return Attach(::CreateFont(nHeight, nWidth, nEscapement,
nOrientation, nWeight, bItalic, bUnderline, cStrikeOut,
nCharSet, nOutPrecision, nClipPrecision, nQuality,
nPitchAndFamily, lpszFacename));
When do you want me to try a font.Detach()? After each CreateFont call or after each SetFont call?
|
|
|
|
|
Is there any way of calling DLL created in C# from a C++ unmanaged application?
|
|
|
|
|
Hi all,
I was monitoring my applicaiton using the task manager for Handle creation and destructions.
I've viewed my code and where i have CreateEvent , there is CloseHandle.
plus i use GDIObject utilities to check for un-handled GDI objects and there weren't any......
what else can produce a hadnle???? how can i monitor my code for that??
can any1 help?
thanks in advanced
Yaron
Ask not what the application can do for you, ask what you can do for your application
|
|
|
|
|
|
thanks for the reply, will glowcode help me track down "HANDLE" leaks?
Ask not what the application can do for you, ask what you can do for your application
|
|
|
|
|
Yaron Nir wrote:
thanks for the reply, will glowcode help me track down "HANDLE" leaks?
From memory yes it will. There is a free trial, so you can quickly try it for yourself.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|
|
First of all what tools are you using? Sysinternals's process viewer(free)? Rational developer? Bounds checker?
Handles
threads, processes, files, registry keys, system objects (event, mutex, critical section etc.), windows, GDI objects etc (Some of them covered in MSDN under "WaitForSingleObject" and "CloseHandle").
What kind of information are you looking for? Did you check "User objects" column in Task manager?
|
|
|
|
|
thanks for the reply,
I am not using either soft u've mentined....
i only used task manager and GDIObj.exe viewer.....
i need to track down "HANDLE" leaks because my application increasing the opertating system handle counter and at somepoint it exceeds the maximum handles number.....
i can not find in my code where it happens, i need an out-side monitor....what can u recoomend?
Ask not what the application can do for you, ask what you can do for your application
|
|
|
|
|
I am taking a guess here - MFC|MDI with a lot of FormViews. If yes look through ypur dialog templates for unused controls (staics, group boxes etc.)
|
|
|
|
|
To track problem like this I would use Bounds Checker. But it is expensive and difficult to use.
www.sysinternals.com has free download Processviewer - an excellent tool to see what kind of objects are created in your app besides windows. Specifically for windows use Spy+(comes with VC)
|
|
|
|
|
thanks for reply,
i will try out the www.sysinternals.com ... and see if it helps me....
Ask not what the application can do for you, ask what you can do for your application
|
|
|
|
|
Can anyone explain to me how to insert a new row into and existing excel sheet? I am using the following code to try to do this but when ran, the program fails with "Insert method of range class failed" on the range.Insert statement.
char locn[10];
IndexToString(nRow, nCol, locn); //convert row/col to excel notation
lpDisp = objSheet.GetRange(COleVariant(locn), COleVariant(locn));
objRange.AttachDispatch(lpDisp);
range.Insert(COleVariant("xlShiftDown"));
|
|
|
|
|
Hi,
Can u help in any way for following query ????????
How can I redirect user I/O to a temporary ‘buffer’ space.
So that all changes are written to the buffer space
When the computer is rebooted, the I/O reads are redirected back to the original file location and all changes made in the previous session are discarded.
and how to create this buffer space.
---------
eg. After this program runs what ever changes u make (example change some text file , create file) it should redirect all I/O to buffer and after restarting this buffer should be deleted
Hoping for a positive response
|
|
|
|
|
See MSDN for "SetStdHandle" and related sample "Creating a Child Process with Redirected Input and Output"
|
|
|
|
|