|
Sounds like you bound a data variable (like a double, or float) instead of a control class (like CEdit), and letting MFC do the value-to-text & text-to-value conversions for you.
Bind a CEdit to the edit control, and handle the display/conversion yourself.
Or, you could write your own DDX routine to format the value as you like. Look up "TN026" in MSDN for more information.
Peace!
-=- James.
|
|
|
|
|
Here's the scenerio
I have created a app using appwiz(VC++6) and have selected the doc/view arch. Now what i'd like to have is custom app wide properties in the CMainFrame class which are modified via dialogs. The dialog is constructed as a member of CMainFrame. I can transfer data from the dialog to CMainFrame no probs, but how can i do the same for my custom CView class. CView has it's own custom members used for drawing, but part of the drawing process requires info stored in CMainFrame. You swap data between CView and CDocumnet with the GetDocument() is there anyway to get the data(custom member) from CMainFrame. I managed to used globals, but doesn't this defeat the purpose OOP? I would like a more OOD<smiles> To do this would i have to construct CView and CDocument in CMainFrame rather than settle for the appwiz default of dynamic creation using CDocTemplate() and such...?
pardon my lack of clarity
TIA
Alex deltabravo@mb.sympatico.ca
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
You can do this in your CView derived class.
((CMainFrame*)AfxGetMainWnd())->m_yourCustomMemberVariable;
HTH
Jignesh
|
|
|
|
|
I tried the folowing, however got a compile error
'variable' is not a member of 'CWnd'
Doesn't the following return a pointer to generic CFrameWnd rather than derived?
Any suggestion...?
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
Did you try (CMainFrame*)AfxGetMainWnd()->variable; ?
Jignesh
|
|
|
|
|
I used a cast, included the header but still came up with m_Variable is not a member of CWnd.
I even tried instantiating a new CMainFrame obj(however could do it, cuz CMainFrame has protected constructor) but then it would be a differ instance right...? which would mean incorrect data.
Is is even possible to use a object that isn't constructed as a data member from that class...? If that even makes sense...<smiles>
I can use AfxGetMainWnd() but only to call CMainFrame's native functions like resize, but the methods and members i've added in my custom class don't appear in the auto-popup...
Being that the CView,CDocument and CFrameWnd object are created dynamically at runtime via the AddDocTemplate funtion in derived app InitInstance() is there any way i can get hold of pointer to any of these objects using RTTI..?
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
I think you'll just need an extra set of brackets...
int viMySetting = ((CMainFrame *)AfxGetMainWnd())->m_iMySetting;
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Try'd it and i finally got passed the compiler warning and had the popup assitance window show my custom members...
That worked so hopefully will the final result...haven't tested that yet...to excited, but soon
Thanx alot
"An expert is someone who has made all the mistakes in thier field" - Niels Bohr
|
|
|
|
|
Does anybody know how to get the number of arguments from a variable length function parameter list? I can't seem to find any documentation anywhere about how to get then number or arguments, without the number of args being a parameter itself.
|
|
|
|
|
You can't. The number (and type) of arguments has to be deduced from one of the non-variable arguments supplied, like, for instance, printf does with its first format argument.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Actually, you can.
int CountArgs(char* unused, ...)
{
int count = 0;
va_list args;
va_start(args, unused);
for (char* cp = va_arg(args, char*); cp; cp = va_arg(args, char*))
{
count++;
}
va_end(args);
return count;
}
int main()
{
int numArgs = CountArgs("blah", "1", "2", "3", "4");
return 0;
}
You could also use the first variable to indicate how many variables you are passing in.
CountArgs(int numArgs, ...);
Todd Smith
|
|
|
|
|
That the will NOT work reliably. If you look at the code generated, there isn't a NULL pushed onto the stack. Thus, just by luck does this work when it does.
19: int main()
20: {
004010B0 push ebp
004010B1 mov ebp,esp
004010B3 sub esp,44h
004010B6 push ebx
004010B7 push esi
004010B8 push edi
004010B9 lea edi,[ebp-44h]
004010BC mov ecx,11h
004010C1 mov eax,0CCCCCCCCh
004010C6 rep stos dword ptr [edi]
21: int numArgs = CountArgs("blah", "1", "2", "3", "4");
004010C8 push offset string "4" (00422030)
004010CD push offset string "3" (0042202c)
004010D2 push offset string "2" (00422028)
004010D7 push offset string "1" (00422024)
004010DC push offset string "blah" (0042201c)
004010E1 call @ILT+5(CountArgs) (0040100a)
004010E6 add esp,14h
004010E9 mov dword ptr [ebp-4],eax
22: return 0;
004010EC xor eax,eax
23: }
004010EE pop edi
004010EF pop esi
004010F0 pop ebx
004010F1 add esp,44h
004010F4 cmp ebp,esp
004010F6 call __chkesp (00401120)
004010FB mov esp,ebp
004010FD pop ebp
004010FE ret
Specifically in this case, the only reason this works is because EDI was 0.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Tim is correct.
So I would either pass the # args as the first parameter (what I usually do anyways) or if it makes sense require the last parameter to be 0.
Todd Smith
|
|
|
|
|
Yikes!!!!!!!
For a moment I thought I was in the wrong web site
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Is there a way i can change the background color or a read-only CEdit ???
i can't use any classes for a modified Edit control because the edit is already too much embedded in my app i'm not gonna change everything again.
It's a read-only edit so the background is gray by default but i want to make it white.
Kuniva
--------------------------------------------
God gave man a penis and a brain but not enough blood to make both of 'em work at the same time.
|
|
|
|
|
Mike Dunn's C++ FAQ explains how to do it for static controls here. For edit boxes it's the same but handling WM_CTLCOLOREDIT instead of WM_CTLCOLORSTATIC (if you do it the MFC way, though, it's exactly the same for both types of controls).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
If the parent dialog gets the WM_CTLCOLOR message for the edit (OnCtlColor) you should be able to identify the control and modify the background brush returned and call SetBkColor and SetTextColor on the dc passed in.
I think there's another way to do it but can't recall right now - check the July 96 MSDN C++ QA for more on this.
later
oops...I mean the July 96 MSJ - but the article should be on the MSDN lib.
|
|
|
|
|
Subject: Stored procedure ADO
Hi,
I working with Stored Procedure with a SQL Database.
I use a procedure for writing to the database 2 paramaters (a STRING and a INTEGER).
My procedure working with the STRING but not when I writing a INTEGER. It is probably in my code at pParam1.
If anyone can help me for this is great.
My code :
_ConnectionPtr pConn("ADODB.Connection");
_ParameterPtr pParam2,pParam1;
CString strFileName = "JK010104";
int iBetacart = 1;
pConn->Open("provider=sqloledb.1;database=ARCHIVES_TVI;server=100.100.100.100;uid=Me;pwd=xxx;network=dbmssocn","","",adConnectUnspecified);
_CommandPtr pCmd("ADODB.Command");
pCmd->ActiveConnection = pConn;
//Cmd->CommandText = "StartFileNum";
pCmd->CommandText = "ResetFileNum";
// pCmd->CommandText = "EndSuccesFileNum";
pCmd->CommandTimeout = 20;
pCmd->CommandType = adCmdStoredProc;
// _RecordsetPtr pRst("ADODB.Recordset");
// pRst = pCmd->Execute(NULL, NULL, adCmdStoredProc);
pParam2 = pCmd->CreateParameter ( _bstr_t ("File_Name"), adVarChar,
adParamInput, strFileName.GetLength (), (_bstr_t) strFileName);
pCmd->Parameters->Append ( pParam2);
Param1 = pCmd->CreateParameter ( _bstr_t ("AutomatNr"), adInteger,
adParamInput, sizeof (int), _variant_t ( long (iBetacart)));
pCmd->Parameters->Append ( pParam1);
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
pRecordset = pCmd->Execute(NULL, NULL, adCmdStoredProc);
youssef
|
|
|
|
|
hi guys,
how to work with SetMenuItemBitmaps() & GetSystemMetrics() with CXMENUCHECK & CYMENUCHECK params ?
example will be great !
thanx
|
|
|
|
|
I am experiencing a problem with time formatting that I'm hoping someone else has encountered and perhaps has some advice.
In a nutshell, with either CTime::Format() or strftime(), the timezone specifier does not work properly -- both %z and %Z return the full name of the time zone. (%z should represent the abbreviated name, e.g. CST and %Z should represent the full name, e.g. Central Standard Time).
In the following example, both would return the exact same string (well, OK, there would be a slight time difference):
CTime time(CTime::GetCurrentTime());
CString cstrDateA = time.Format("%a, %d %b %Y %H:%M:%S %z");
CString cstrDateB = time.Format("%a, %d %b %Y %H:%M:%S %Z");
My development setup:
Windows 2000
Visual Studio 6.0 Enterprise Edition (with latest service pack)
"If ye love wealth better than liberty, the tranquility of servitude better than the animating contest of freedom, go home from us in peace. We ask not your counsels or your arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
--Samuel Adams
|
|
|
|
|
Hello!
If you look at the source, D:\Program\Microsoft Visual Studio\VC98\CRT\SRC\STRFTIME.C, in the function _expandtime then you will see that case('z') and case('Z') is treated the same!
So the doc is wrong ...
For an another perculiar thing try this:
CTime time(CTime::GetCurrentTime());
CString cstrDateA = time.Format("%a, %d %b %Y %H:%M:%S %z");
COleDateTime ttime(COleDateTime::GetCurrentTime());
CString cstrDateB = ttime.Format("%a, %d %b %Y %H:%M:%S %z");
Strange or ??
|
|
|
|
|
Hello everybody!
I've got the following problem: my app uses a WebBrowser-Control, but I don't receive the FileDownload-Event, which would allow to suppress the Download-Dialog.
I'm using the following code:
BEGIN_EVENTSINK_MAP(CMainWnd, CFrameWnd)
ON_EVENT(CMainWnd, IDC_WEBBROWSER, 270 , OnFileDownload, VTS_PBOOL)
END_EVENTSINK_MAP()
void CMainWnd::OnFileDownload(BOOL FAR* Cancel)
{
AfxMessageBox("Why is this message never displayed?");
}
Has anybody got an idea why this doesn't work? Thanks in advance for an evetual answer!
--flo
|
|
|
|
|
Can anyone help me with how to write and read Unicode strings to and from file? I am using wifstream and wofstream and wstring. I can't find any reference material at all about how to do this. Can anyone help or point me at an example or other online resource?
Many thanks
Matthew
|
|
|
|
|
You'll find an interesting article on the subject, written by P.J. Plaugher, here:
http://www.baosys.com/work/cpp/html/17.04/plauger/plauger.htm
|
|
|
|
|
Hi,
I'm writing an MFC-application based on CRichEditDoc/View, where I need to embed files in the document (displayed as icons). Everything works just fine, except for one thing: I can't figure out how to embed an object with a custom icon (or rather, a MetaFilePict = Icon + Label), all I get is the ugly default (such as a Package icon for non-OLE objects).
I know how to properly create the custom metafilepict (it's been tested independently), but when I use COleClientItem's SetIconicMetafile() to assign it to the object, it doesn't work. This is _after_ I've called SetDrawAspect(DVASPECT_ICON), which default COleClientItem implementation resets the icon, but _before_ the view's InsertItem() method. What else do I need to do?
If anyone could give me some hints on what I need to do, I'd really appreciate it!
|
|
|
|
|