|
I am creating an MFC based MDI type app in VS2008. I have a class structure that is mostly based on declaring objects of the lower class in the class above it - so not subclasses - but called from parents as such:
CHostApp ------------> CCommandParser
CMainFrame
COutputWnd (console type display class that I want to call a function in)
So in CMainFrame it does:
COutputWnd m_OutputWnd
and so on up the chain.
I am making a command parser class that I'm thinking really should be a static class from the at the CHostApp level. Ultimately I'm trying to call a function and pass data from
CCommandParser to COutputWnd.
What's the right syntax or methodology to do this? Do I need to make one a friend class of the other?
|
|
|
|
|
You could try the same trick done by ATL.
Make the CMainFrame class a template class.
Pass the class derived from CMainFrame as the template parameter to CMainFrame.
Something like this.
class COutputWnd : public CMainFrame<COutputWnd>
{
};
template<typename T>
class CMainFrame : public CFrameWnd
{
T m_OutputWnd;
};
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Never seen that before! I have used it for years I believe in creational patterns like factory. I'd have to go scare up some old code to verify that but I'm pretty sure.
|
|
|
|
|
Hi
I have written a downloader program that can download files from internet (with resume support).
But after I pass the file address and username and password of my account in rapidshare it can not download it, it just download a html file:
m_pHttpConnection = m_InternetSession.GetHttpConnection(sServer, nPort, sUser, sPassword);
also this function returns FALSE :
file.SendRequest(NULL);
Does anybody know how to pass username and password to rapisdhare or other sharing web sites?
Regards
Hadi
www.logicsims.ir
|
|
|
|
|
IIRC, the GetHttpConnection call lets you do URL authentication[^]. I suspect sites like rapidshare use something like basic authentication, as illustrated by this page[^], where username and password are passed in request headers.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you for your answer,
I read those article, semms to be good, I changed my code for this way, but it did not work.
It just downloads a HTML file! not the file itself!
Do you have any other idea, is there any help in rapidshare for this? I searched a lot but did not find anything helpful!
Thanks
www.logicsims.ir
|
|
|
|
|
Try monitoring the HTTP transactions using Fiddler[^] - it's a splendid debugging tool when doing low-level HTTP stuff.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
A popup menu has been created that displays a list of options for insertion into a Item>SubItem cell. The menu comes up fine, but the return value is either 0 or 1, despite the flag being set to return the menu item. It was used in a dialog only previously, and think that the hWnd is the culprit on returning the wrong item number.
Any suggestions?
Many thanks in advance.
<code>void CTab2::OnRclickListCtrl(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int i, nItem, nSubItem, nSel;
CString s;
POINT point;
HMENU hMenu = ::CreatePopupMenu();
CRect rect;
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
nItem = temp->iItem;
nSubItem = temp->iSubItem;
if( nSubItem == -1 || nItem == -1 ) return ;
if (NULL != hMenu && nSubItem == 2 && nItem < lLayer ) {
for ( i = 0; i < lBulkMax; i++ ) {
::AppendMenu ( hMenu, MF_STRING, 1, sBulk[i].desc );
}
point.x = 200; point.y = 200;
ClientToScreen(&point);
nSel = ::TrackPopupMenuEx(hMenu,
TPM_LEFTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON,
point.x,
point.y,
temp->hdr.hwndFrom,
NULL);
::DestroyMenu(hMenu);
s.Format ("item selected is number %d", nSel);
AfxMessageBox ( s );
if ( nSel > 0 && nSel <= lBulkMax ) {
m_cListCtrl.SetItemText( nItem, nSubItem, sBulk[ nSel - 1 ].desc );
}
}
/*
typedef struct tagNMHDR
{
HWND hwndFrom;
UINT idFrom;
UINT code; // NM_ code
} NMHDR;
typedef NMHDR FAR * LPNMHDR;
*/
*pResult = 0;
}
|
|
|
|
|
The third parameter to AppendMenu in your loop is 1. This gives all the mnu options this ID. If you cancel the menu you will get 0 returned, any option you select will return 1. You need to add each item to the menu with a different id number.
Try changing it to i+1
If you vote me down, my score will only get lower
|
|
|
|
|
Thanks. A single append line was clipped from another program that had hard-coded ids, and neglected to change it to a loop based id.
|
|
|
|
|
Hello
I am working on VS2003 and using the above mentioned functions, but the compiler gives me warning saying those functions are #pragma depreciated.
I know VS2008 has functions like sprintf_s, but unfortunately i will not be able to upgrade to 2008.
So now i want to use a wrapper function around sprintf, which will do the additional work that sprintf_s will do and there by making sure that i call sprintf only once.
This new wrapper function should be able to check for buffer over run and then i will call sprintf inside this function.
What it will do is, it will make sure that, i only need to call sprintf once and that will bring down compiler warning to just one.
Is anyone aware of such a wrapper function? Or can anyone help write a wrapper?
Thanks in advance.
|
|
|
|
|
Hi,
here are some thoughts and pointers:
1. for a very long time there have been some string functions that limit the number of bytes written to a buffer. Depending on vendor and compiler they got different names, most often things such as snprintf, strncat, strncpy, ... You really don't need VS2008 to get some of those. The main problem is the names and signatures have not been standardized successfully,
so choose one and locate it or implement it.
2.
snprintf-like stuff from Microsoft:
http://msdn.microsoft.com/en-us/library/2ts7cx93(VS.71).aspx[^]
http://msdn.microsoft.com/en-us/library/ms647541(VS.85).aspx[^]
3.
one needs the "variable arguments" technology to wrap something that takes a variable number of arguments. However accepting and passing on a list of arguments is a bit tricky, there is a special vsnprintf function[^] for that purpose.
As well as this one[^].
4.
if not found, strncpy and strncat can be written from scratch easily, at least when there is no need for maximum performance. They basically are just a loop copying one byte at a time. (Strcat needs to find the end of the current content first, either use another loop or strlen).
5.
the main problem is all these safe functions need the size of the destination buffer, which can be handled in two ways:
(a) when the only purpose is to avoid compiler warnings (sprintf, strcpy, ... being deprecated now), just pass a very large number (or implement the convention that zero means infinite)
(b) look in the source code (where sprintf used to be) for the buffer size, and pass that.
Either way, the source code needs to be changed at every location where the safe version has to be used instead of the unsafe version.
6.
possible extra safety: the safe function could implement a simple check on the destination pointer; in my experience it is useful to reject any address in the range [0, 1023] since that typically is what you get when a class/struct pointer is zero. You could use an assert to report a problem, and/or return null.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
modified on Saturday, June 20, 2009 2:55 PM
|
|
|
|
|
I turn off these warnings. Microsoft is not in a position to declare standard C++ functions deprecated.
Steve
|
|
|
|
|
Welcome [^] Steve.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I see I'm in good company.
Steve
|
|
|
|
|
dipuks wrote: I am working on VS2003 and using the above mentioned functions, but the compiler gives me warning saying those functions are #pragma depreciated.
I know VS2008 has functions like sprintf_s, but unfortunately i will not be able to upgrade to 2008.
If the compiler is telling you they are deprecated, then is it also telling you what to use instead? I find it hard to believe that the compiler would know enough to complain, yet not provide any means by which to correct the problem.
In any case, you might have to use _CRT_SECURE_NO_WARNINGS .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I have written a small dialog based application which uses Cximage class to achieve compression. The program works fine but i have a problem which arises once i use static MFC library to compile the program. I need to use the program on other computers but it fails to work because of the problem.
I get compiler errors LNK2005 like
MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _fclose already defined in libcmt.lib(fclose.obj)
these are 35 in total
I read from a forum to put libcmt.lib in Ignore Specific Library tab. The things works
but then i get 3 errors related to LNK2001 like
1>cximage.lib(ximaenc.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1>nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
1>nafxcw.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
I even tried to use the ForceLib.h file as described in msdn forums. But to no avail. Can anyone help.
The code i need to compile is present on this website by name Image Compressor.
Regards
Hassan
|
|
|
|
|
Sounds like you're using two different versions of the C run-time - MSVCRTD is a debug, dynamic link version. libcmt is a release, static link version. So, different bits of your project have different C++->Code Generation->Runtime Library options. I suspect that the way CxImage has been built is disagreeing with your project.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Try giving /FORCE:MULTIPLE in the properties in
Project Properties -> Configuration Properties -> Linker -> Command Line -> Additional Options .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I am attempting to understand how to use the class CToolBar. Therefore, I wrote some sample
code that is suppose to create a tool bar. However, the tool bar is not being displayed. The
definition of the tool bar is in my class CMainWindow and is defined as follows:
CToolBar toolBar;
Here is the code that I use to create the tool bar:
<br />
BOOL status1 = toolBar.Create( this );<br />
BOOL status2 = toolBar.LoadToolBar( IDR_TOOLBAR );<br />
toolBar.SetButtonStyle( 0, TBBS_CHECKBOX );<br />
toolBar.SetButtonStyle( 1, TBBS_CHECKBOX );<br />
toolBar.SetButtonStyle( 2, TBBS_CHECKBOX );<br />
toolBar.SetButtonStyle( 3, TBBS_CHECKBOX );<br />
toolBar.SetButtonStyle( 4, TBBS_CHECKBOX );<br />
toolBar.SetButtonStyle( 5, TBBS_CHECKBOX );<br />
<br />
const UINT idArray[] = {<br />
IDM_LINES, IDM_RECTANGLES, IDM_ELLIPSES,<br />
IDM_ENLARGE, IDM_ORG, IDM_RESET<br />
};<br />
<br />
toolBar.SetButtons( idArray, 6 );<br />
toolBar.ShowWindow( SW_SHOW );<br />
toolBar.SetSizes( CSize(48,42 ), CSize( 40, 19 ) );
The return value from Create is 1 and the return value from LoadToolBar is 1. The return value from SetButtons is 1. The return value from ShowWindow is 16. I am interpreting these return values to mean that all went well. However, the tool bar is not being displayed. I am hoping that somebody out there can tell me what I am doing wrong.
Thanks
Bob
|
|
|
|
|
hi i have a toolbar with buttons added
btnBookmark.idCommand = idCommand;
btnBookmark.fsState = TBSTATE_ENABLED;
btnBookmark.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE| BTNS_SHOWTEXT;// | BTNS_DROPDOWN;//| ;
btnBookmark.dwData = 0;
btnBookmark.iString = (INT_PTR)cstrKeyName.GetBuffer();
btnBookmark.iBitmap = -2;
but the text on the toolbar buttons is a bit high its not vertically centere
|
|
|
|
|
Hi,
I'm working on a program that reads linear equations from a file such as those:
3x+2y-2.5z=9
-2x+9y+12z=23.4
4.2x-7y+9.6z=45.3
The file is supposed to contain n equations with n variables which I would read into a 2d dynamic array of doubles and then I'm supposed to solve the resulting matrix using Gauss's method. I've already implemented Gauss's method but I can't figure out when reading from file how to get only the numbers and the signs for example from the above equations I'm supposed to have the following in the array:
[+3][+2][-2.5]
[-2][+9][+12]
[+4.2][-7][+9.6]
I need the numbers after the equal sign to be stored in a separate n sized array as well.
If anyone has any ideas I'd really appreciate it
|
|
|
|
|
here i have a rough idea.
Omar Al Qady wrote: 3x+2y-2.5z=9-2x+9y+12z=23.44.2x-7y+9.6z=45.3
fscanf(fp,"%fx%fy%fz=5f",el1,el2,el3,el4);
should fetch you the required values into el1....el4.
try it out if it does not work we shall find out some other way.
good luck.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
The problem is that the variables aren't always x,y,z because the program should solve n equations with n variables, so they can be more than 3 or less, so I can't assume when reading the data it's only three variables.
I thought about something but I just can't implement, if I can read double by double into the array until I reach the equal sign then the double after is read into a different n sized array for the solutions, and when a new line is started I'd repeat the process in the next row of the 2d array.
I don't know if what I said above is even possible but if you can help me in implementing it I'd be grateful
Thanks for your reply and thanks in advance for any additional help you can give
|
|
|
|
|