|
I've noticed a (bad?) habit from some colleagues of mine to void -cast unused return values, as in
(void)::SystemTimeToFileTime(&st, &ft) I've personally never ever done that in C/C++, but something like it when scripting bash back in my dark Linux days (don't ask...)
Why on earth are they doing it and is it even necessary? I hope someone will say it's not recommended and provide a good link to Bjarne etc...
--
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. (Douglas Adams)
|
|
|
|
|
it could be some kind of convention they're using. There're many awkward conventions my friend, most of them nobody knows about; it's like politics.
Phil
|
|
|
|
|
It's basically a semantic marker: it says 'Yes, I know that this function has a return value, but I'm deliberately ignoring it.' Some style manuals suggest doing this, I believe - if a function returns a value, you should either use the value, or cast to void.
From the compiler's perspective, it should compile exactly the same code whether or not this cast is here.
Personally, although I've done it on a couple of occasions, I don't normally bother. It's more typing for no real value.
In the case of SystemTimeToFileTime , the function could fail if the SYSTEMTIME structure contains duff information (e.g. 31st of February, or a year before 1601).
|
|
|
|
|
This style used to be used by UNIX programmers to state "yes i know the function returns 'x', but i have no use for the return value".
This was a bit of a fallout from the belief that if a function returned a value the value should be checked (religiously).
It was most often used for things like printf(), or when the function returned an error code, but that there was nothing usefull the program could do in case of an error (e.g. testing if malloc() returned null).
It is purely stylistic.
...cmk
Rosencrantz: I don't believe in it anyway.
Guildenstern: What
Rosencrantz: England
Guildenstern: Just a conspiracy of cartographers then.
Save the whales - collect the whole set
|
|
|
|
|
While it is stylistic, and I loathe it, many, many years ago, there were C compilers that emitted a warning if the return value from a function wasn't either checked or used to set a variable.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I'm trying to use CHeaderCtrl standalone (without a CListCtrl) but it insists on making its text bold, which looks totally stupid. I can't for the life of me figure out how to make it use the non-bold system font that it uses when it's part of a CListCtrl (the same one menus, edit controls, etc. use).
The CHeaderCtrl is a member of my CMainFrame class, and I create the control in CMainFrame::OnCreate. I tried calling the control's SetFont member, before and after creating the columns, with and without redraw, and with every type of CFont I could think of, all to no avail. Is this a bug in MFC?
~CK
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// create header control above CFormView
CRect r;
GetClientRect(r);
r.bottom = HEADER_HEIGHT;
m_Hdr.Create(WS_CHILD | WS_VISIBLE, r, this, 0);
// try to get rid of stupid bold font WHY DOESN'T THIS WORK?!?
CFont *pFont = (CFont *)GetDC()->SelectStockObject(DEFAULT_GUI_FONT);
SetFont(pFont, TRUE);
// populate header
HDITEM hdi;
const cols = 3;
LPCSTR str[cols] = {"Volume", "Pan", "Pitch"};
int wid[cols] = {172, 172, 172};
hdi.mask = HDI_TEXT | HDI_WIDTH | HDI_FORMAT;
hdi.fmt = HDF_LEFT | HDF_STRING;
for (int i = 0; i < cols; i++) {
hdi.pszText = (char *)str[i];
hdi.cchTextMax = strlen(str[i]);
hdi.cxy = wid[i];
m_Hdr.InsertItem(i, &hdi);
}
return 0;
}
|
|
|
|
|
This is because of the setting of "Display properties".
Change your setting of display in the control panel and set the header text font as non-bold font.
|
|
|
|
|
I'm not sure. First of all I don't see a setting for header text in the display properties, not in Windows 2000. I even tried selecting the Windows Classic BIG FONT setting, and it changed a lot of text all over the place, but not CHeaderCtrl's text.
And in any case, it makes no sense that a CHeaderCtrl should use non-bold when it's embedded in a CListCtrl (i.e. in just about every MFC app in the world) and bold when it's embedded in a CFrameWnd.
It seems to me it's either an MFC bug, or there's something magical that CListCtrl does to its CHeaderCtrl that I haven't figured out how to do.
~CK
|
|
|
|
|
Assuming m_Hdr is a member variable of type CHeaderCtrl, in whatever function creates m_Hdr, immediately after m_Hdr.Create(...), add this line:
m_Hdr.SendMessage(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT));
***NOTE*** that the following does *NOT* work:
m_Hdr.SetFont((CFont *)GetStockObject(DEFAULT_GUI_FONT));
Why? I don't know. Maybe because SetFont posts the message, instead of sending it, so that the temporary font pointer returned by GetStockObject is already garbage by the time the header control receives the message?
~CK
|
|
|
|
|
Hello Guys,
i need some help regarding loading icons from a local directory in VC++, in my app there is a combo box... if i pass an directory name to the app.. then all the file names of the icon's in that directory should be loaded in the Combo Box.
post with some sample code toooo for the above question
Thanks in advance
Hariharan.S.N
ravi
|
|
|
|
|
1. construct the CFileFind class
2. Call FindFile()
3. enter a loop that ends if you can't do 4
4. Call FindNextFile()
5. use CFileFind's get procs to filter out the icons
and do whatever you want with those filenames
Phil
|
|
|
|
|
Hi guys
i have made resizable combo box. i need to display a bmp in the scroll bar.
Can any body tell me whch api to use
I have a handle of HDC in my combo box
Regards
Suneet Chandok
|
|
|
|
|
bhai phat legi is kaam me
you will have to derive a class from CScrollWnd and in onpaint call CScrollWnd's Onpaint and then paint ur bitmap , then use this new class and add scroll support to CCmboBox
|
|
|
|
|
How do you do to accomplish an object-oriented desing in a pure Win32 API written application? No, MFC, WTL or any other frameworks.
And don't post dummy questions and ask why I wanna do this etc etc etc...
Thanks!
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
I presume what you mean is actually
"How do I encapsulate the HWND in a C++ class and make a proper class hierarchy?"
Otherwise stop read here.
How you design the hierarchy depends on your own ability to design - if you have done it in another area, then you can do here also.
The tricky part encapsulating the HWND and maintaining window procedures is to associate a class instance with a particular physical window, i.e., HWND with this . This can be done in many ways: ATL/WTL uses thunking and MFC a hash map, but it can be as simple as stashing the this pointer in the userdata section of the window with ::SetWindowLong() or setting this as a window property with ::SetProp() or even using a global variable (but that would not get us very far...)
I would, however, recommend WTL.
--
Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so. (Douglas Adams)
|
|
|
|
|
|
Is there a such message for a dialog based program like "WM_SHOW" that indicates that the dialog has been shown on the screen ?
I would like perform a certain task just when the dialog has bee n displayed to the user. Cant use OnPaint (and have a "do once" flag) since the task waits for the user to put his finger on a fingerprint scanner. So if he then moves the window or something the program will hang ...
OnCreate, OnInitDialog, OnShowWindow all runs before the dialog is shown ... any ideas ?
Thanks, Daniel
|
|
|
|
|
What about OnActivate or OnFocus? (not 100% sure these are the exact names).
|
|
|
|
|
Hello there, I am Dennis.
I wanna ask you guys if you have any idea or suggestion on how to implement graphics interaction into c++.
What i mean is how do we put in the graphical interaction show a real time interaction within a network. (let say base station and few terminals, I want to show the interaction with base station and terminal. Where if i click the terminal button, it can show status like Qos or how much bytes sent/received. )
The graphical interaction can show how the process is going one.
If anyone have any idea what I am saying, please give me idea. ok? suggestion.I am very appreciated if you give me some ideas. Thanks.
|
|
|
|
|
I beginner programmer,
My problem is that i wont save a file associated at myView with a new name
I have used OnSaveDocument(newName) but a empy file is created how so?
can i take a Cfile associated at myView
My code is
void myView ::OnFileSave()
{
CString nomeFile= GetDocument ()->GetTitle();
CString szFilter = "All Files (*.*)|*.*||";
CFileDialog fd( FALSE, NULL, nomeFile ,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_FILEMUSTEXIST |OFN_PATHMUSTEXIST |OFN_EXPLORER ,szFilter, AfxGetMainWnd());
if(fd.DoModal()==IDOK)
{
CString pathNomeFile =fd.GetPathName();
myViewerDoc *appoDoc = GetDocument();
appoDoc->OnSaveDocument(fd.GetPathName ());
appoDoc->SetPathName(fd.GetPathName());
}
}
The file in myView already exist and at runtime it is modified maybe
Sorry for my English
|
|
|
|
|
That all looks OK. I suspect that you haven't implemented myViewerDoc::Serialize .
|
|
|
|
|
i have implemented the myViewerDoc::Serialize but in the Carchive object
i haven't the information about the file in the myView and i dont know as attack the record into the new file
|
|
|
|
|
hi,
i wish to change the size of the drawing area(black background in my case) so that can distinguish between this area and the grey background for putting dialog controls, is it possible? i do not want to use splitter windows... any solution will appreciate
|
|
|
|
|
Hi Friends!
I am creating an VC++ application (Microsoft Visual studio Ver 6), OS is Win2K, for getting the mac address from local and remote machine. I am using UuidCreateSequential() for getting the MAC address. As per the msdn and from different sites, I have included rpc.h ,rpcdce.h and added link to the library rpcrt4.lib.
But I get Compilation error as
error C2065: 'UuidCreateSequential' : undeclared identifier
Does any body knows the cause for this?
The above function I am using for creating license key for my software products. Is there any other easy way to create the unique license key?
Thanking in advance.
Best Regards
Smita Duraphe
Keep your hearts free from hate, your mind from worry. Live
simply, expect little, and give much. Fill your life with love. Scatter sunshine. Forget self, think of others. Do as you would be done by.
|
|
|
|
|
You're probably trying to compile using the header files included with Visual C++ 6.0. This function didn't exist then. You'll need to get the current version of the SDK from Platform SDK Update[^]. You may need to update the directories in Tools > Options > Directories once the SDK has installed (I can't remember if this is done automatically).
This API was added in Windows 2000; if you call this function in your code, and try to run your application on Windows NT 4.0, it will not load.
|
|
|
|