|
Please could you put <pre></pre> tags around your code so that it is readable (just edit your message and use the code block button). Also use the Preview button before you post to make sure it is all formatted correctly. Your code looks like:
int MFC::Dialog::DoModal()
{
int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
int szBoxLen = cWC + 1;
WCHAR *szBoxCaption = new WCHAR[szBoxLen];
// ...
it should look like:
int MFC::Dialog::DoModal()
{
int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
int szBoxLen = cWC + 1;
WCHAR *szBoxCaption = new WCHAR[szBoxLen];
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
DLGTEMPLATE m_DialogTemplate;
int MFC::Dialog::DoModal()
{
//For OK and Cancel buttons??
m_DialogTemplate.cy+=(DlgControls.size()*4);
AddOkCancel();
int iRet=0;
//presetting for caption in the dialog....
int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL,0);
int szBoxLen = cWC + 1;
WCHAR *szBoxCaption = new WCHAR[szBoxLen];
// Copy the string...
MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR)szBoxCaption, cWC);
szBoxCaption[cWC] = 0;
szBoxLen = (cWC) * sizeof(WCHAR);
int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) /*menu and class*/ + szBoxLen /*size of caption*/
+ sizeof(WORD) /*fontsize*/ ;//+ nFontNameLen /*size of fontname*/;
HLOCAL hLocal = LocalAlloc(LHND, nBufferSize);
if (hLocal != NULL) {
BYTE* pBuffer = (BYTE*)LocalLock(hLocal);
if (pBuffer == NULL) {
LocalFree(hLocal);
AfxMessageBox(_T("D::DoModal() : LocalLock Failed"));
}
BYTE *pdest = pBuffer;
// transfer DLGTEMPLATE structure to the buffer
memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE)); // DLGTemplate
pdest += sizeof(DLGTEMPLATE);
*(WORD*)pdest = 0; // no menu -- WORD to say it is 0 bytes
pdest += sizeof(WORD); // Increment
*(WORD*)(pdest + 1) = 0; // use default window class -- WORD to say it is 0 bytes
pdest += sizeof(WORD); // Increment
memcpy(pdest, szBoxCaption, szBoxLen);
// Caption
pdest += szBoxLen;
//These are the MFC functions, which do the job...
InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd);
iRet = CDialog::DoModal();
LocalUnlock(hLocal);
LocalFree(hLocal);
return iRet;
}
else {
AfxMessageBox(_T("D::DoModal() : LocalAllock Failed"));
return -1;
}
}
|
|
|
|
|
Well I guess you missed most of my message where I said:
1. Edit your message, i.e. the one where you posted the code.
2. Use <pre></pre> tags around your code.
3. Use the Preview button to check that what you have posted is correct.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
sorry i m posting code for the first time
int MFC::Dialog::DoModal()
{
m_DialogTemplate.cy+=(DlgControls.size()*4);
AddOkCancel();
int iRet=0;
int cWC = MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, NULL, 0);
int szBoxLen = cWC + 1;
WCHAR *szBoxCaption = new WCHAR[szBoxLen];
MultiByteToWideChar(CP_ACP, 0, m_strCaption, -1, (LPWSTR) szBoxCaption, cWC);
szBoxCaption[cWC] = 0;
szBoxLen = (cWC) * sizeof(WCHAR);
int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) + szBoxLen
+ sizeof(WORD) ;
HLOCAL hLocal = LocalAlloc(LHND, nBufferSize);
if (hLocal != NULL) {
BYTE* pBuffer = (BYTE*)LocalLock(hLocal);
if (pBuffer == NULL) {
LocalFree(hLocal);
AfxMessageBox(_T("D::DoModal() : LocalLock Failed"));
}
BYTE *pdest = pBuffer;
memcpy(pdest, &m_DialogTemplate, sizeof(DLGTEMPLATE));
pdest += sizeof(DLGTEMPLATE);
*(WORD*)pdest = 0;
pdest += sizeof(WORD);
*(WORD*)(pdest + 1) = 0;
pdest += sizeof(WORD);
memcpy(pdest, szBoxCaption, szBoxLen);
pdest += szBoxLen;
InitModalIndirect((LPDLGTEMPLATE)pBuffer, m_pParentWnd);
iRet = CDialog::DoModal();
LocalUnlock(hLocal);
LocalFree(hLocal);
return iRet;
}
else {
AfxMessageBox(_T("D::DoModal() : LocalAllock Failed"));
return -1;
}
}
|
|
|
|
|
|
I am programming a model for Process state simulation
In my model the program logic is similar to logic gates. The state of different boolean variables changes from 1 to 0 or vice versa.
Eg: The value of A, B, C and other variables changes from 0 to 1 and viceversa depending on some calculation and behaviour of the model.
There are some dependant variables X, Y, Z and other variables whose state changes accordingly the same depending on A, B and C. The dependant variables should not change immediately but with a delay that is set by the user.
My requirement is I need a function where if I call the function by passing the variable name, dependant variable name and the time delay so that the dependant variable changes according to the variable only after the set time delay. The function call should not disturb or create time delay in the model. It should only create a delay after which the dependant variable is assigned with the value.
Kindly help.
Thanks,
Mohan
|
|
|
|
|
It really depends on your program architecture. One solution which comes to my mind is to use timers, but I'm not sure if this is appropriate in your case. You said that your model similar to logic gates. Do you mean that you have some kind of "blocks" which are connected together and executed in a cycle ? If yes, then I would use another approach: as the blocks are executed at each cycle, the block can evaluate wether the timer for a certain variable has expired. This is, in my opinion, a cleaner solution that using timers.
|
|
|
|
|
Take it :
#define TICK_EXPIRED(dwActTick, dwToTick) ((long)(dwToTick - dwActTick) <= 0)
#define TICK_ELAPSED(dwTime) TICK_EXPIRED(GetTickCount(), dwTime)
template <typename T>
class DelaySetVar
{
CCriticalSection m_cLocalLock;
T m_value;
CCriticalSection m_cMapLock;
volatile bool m_bPleaseExitNow;
CMap<DWORD,DWORD,DWORD,DWORD> m_mapLiveThreads;
class SetThreadParam
{
friend class DelaySetVar;
DelaySetVar* m_pcVarObject;
const T m_SetValue;
DWORD m_dwDelay;
public:
SetThreadParam(DelaySetVar* pcVarObject,
const T& set_value,
DWORD dwMsDelay)
: m_pcVarObject(pcVarObject),
m_SetValue(set_value),
m_dwDelay(dwMsDelay) {};
};
static UINT AFX_CDECL ValueSetProc(void* pParam)
{
SetThreadParam* pSetParam = (SetThreadParam*) pParam;
if (pSetParam) {
DWORD dwTimeOut = GetTickCount() + pSetParam->m_dwDelay;
while (!pSetParam->m_pcVarObject->m_bPleaseExitNow) {
if (TICK_ELAPSED(dwTimeOut)) {
CSingleLock cLock(&pSetParam->m_pcVarObject->m_cLocalLock, TRUE);
pSetParam->m_pcVarObject->m_value = pSetParam->m_SetValue;
break;
}
Sleep(1);
}
pSetParam->m_pcVarObject->ThreadEndEvent(GetCurrentThreadId());
delete pSetParam;
}
return 0;
};
void ThreadBegEvent(DWORD dwThreadID)
{
CSingleLock cLock(&m_cMapLock, TRUE);
m_mapLiveThreads.SetAt(dwThreadID, dwThreadID);
};
void ThreadEndEvent(DWORD dwThreadID)
{
CSingleLock cLock(&m_cMapLock, TRUE);
m_mapLiveThreads.RemoveKey(dwThreadID);
};
public:
DelaySetVar()
: m_value(),
m_bPleaseExitNow(false) {};
DelaySetVar(const T& init)
: m_value(init),
m_bPleaseExitNow(false) {};
~DelaySetVar()
{
m_bPleaseExitNow = true;
while (true) {
{
CSingleLock cLock(&m_cMapLock, TRUE);
if (!m_mapLiveThreads.GetCount()) {
break;
}
}
Sleep(1);
}
}
const T& GetValue() {
CSingleLock cLock(&m_cLocalLock, TRUE);
return m_value;
};
void SetValue(const T& set_value, DWORD dwMsDelay = 0)
{
if (!m_bPleaseExitNow) {
if (dwMsDelay) {
CWinThread* pcThread = ::AfxBeginThread(ValueSetProc,
new SetThreadParam(this,
set_value,
dwMsDelay),
0, CREATE_SUSPENDED);
if (pcThread) {
pcThread->m_bAutoDelete = true;
ThreadBegEvent(pcThread->m_nThreadID);
pcThread->ResumeThread();
}
} else {
CSingleLock cLock(&m_cLocalLock, TRUE);
m_value = set_value;
}
}
};
}; Possible usage :
{
DelaySetVar<int> iVar(3);
iVar.SetValue(2, 2000);
do {
cout << iVar.GetValue() << '\n';
} while (3 == iVar.GetValue());
cout << iVar.GetValue() << '\n';
iVar.SetValue(3);
cout << iVar.GetValue() << '\n';
iVar.SetValue(4, 2000);
}
Of course, the used T must support operator=
They sought it with thimbles, they sought it with care;
They pursued it with forks and hope;
They threatened its life with a railway-share;
They charmed it with smiles and soap.
modified on Thursday, September 30, 2010 6:00 AM
|
|
|
|
|
You could try a time sorted queue of events - when you want to model a propagation delay you bung the operation into the queue and each loop around your main timing loop you can pull any relevant events off the queue and apply them. You could even use this as the basis of propagating your signals around the system being simulated to keep things clean and not have two mechanisms for transmitting state changes from subsystem to subsystem.
Cheers,
Ash
|
|
|
|
|
yes, that is the normal approach in simulation.
|
|
|
|
|
All the games I've worked on (that actually worked nicely instead of just being lashed up piles of rubbish) used it as well.
Cheers,
Ash
|
|
|
|
|
Hi All,
How to call C# APIs from C++ code. Is there any proxy/stubs comes into picture.
|
|
|
|
|
You need to expose it as COM and then as how you invoke the COM component from C++, you have to call that component. Framework creates CCW wrapper for you which makes COM call from C++ to C# easier.
Thanks,
Anand.
|
|
|
|
|
If you mean "using the .NET Framework classes in a C++ application", the answer is C++/CLI
|
|
|
|
|
Using Visual C++ 6, service pack 6 on XP. I have a set of COlePropertyPages controlled by an OCX embedded in a dialog box. On one property page I have 10 edit controls. I want the user to be able to jump from control to control using the Tab button. However, when the focus is in a control and the user hits the tab button, the focus jumps to the OK button in the dialog box. From that point on, repeatedly pressing the Tab button merely jumps between the Help, OK, and Cancel buttons on the dialog box.
Trapping the WM_KEYDOWN message in the property page doesn't help, the code isn't reached. I tried subclassing one of the edit controls. Even when that edit control has the focus, and the Tab button is pressed, the WM_KEYDOWN message isn't reached. I tried using PreTranslateMessage() in the subclass, the code isn't reached (I tested all these using a break point.)
How can I make it so that the Tab button jumps from edit control to edit control?
Thanks!
|
|
|
|
|
There should be two ways of fixing this.
One way is to go to Layout -- Tab Order. This will show all of the controls in the dialog in numerical order. To change them you just click the order in which they are to be tabbed through. Then, if some of the controls are not being tabbed to and you want them enabled, go into the resource's properties and set the Tab Stop property to true.
Secondly, you can directly modify the resource file (*.rc) by moving the resources within the dialog. The order in which they are scripted is their tab stop order. Setting WS_TABSTOP as one of the controls properties identifies it as a resource to be tabbed to.
|
|
|
|
|
Thanks for your efforts, Josh, but you don't seem to understand the question. As I mentioned, this case involves property pages embedded in the dialog box using an OCX. (Maybe the correct term is ActiveX control?) So there is an rc file for the property pages in the OCX and a separate rc file for the dialog box in my main program. The tab order for the property page in the OCX rc file is already set up to go from edit control to edit control. This tab order is ignored. No matter which one of the ten edit controls has the focus, pressing the tab button causes the focus to jump to the OK button in the dialog box. Clearly the tab order for the dialog box in the rc file of the main program is the one used by the system. In the rc file for the dialog box, there are the three buttons, OK, Help, Cancel and a Tab Control in which the OCX property pages are embedded. I can set the Tab Stop property of the Tab control to TRUE, then the tab button causes the focus to jump between the three button and the title tab of the property page open. But I don't know how to make the tab button jump between the edit controls as desired.
|
|
|
|
|
The tabbing magic handled by the IsDialogMessage[^] function; it sounds like this is being called correctly because the tab key does alter the focus. Read this[^] blog entry and the comments for some insight. To me it sounds like your problem may be related to the DS_CONTROL and WS_EX_CONTROLPARENT styles, see here[^] to learn more about these.
EDIT:
You may also want to read about the PSM_ISDIALOGMESSAGE[^] message since we're talking about property pages.
Steve
modified on Wednesday, September 29, 2010 2:51 PM
|
|
|
|
|
Thanks for your reply. Your references are to the point; although maybe not since none of them seem to apply to property pages embedded with an OCX. In the dialog box, I set the Tab Control to WS_EX_CONTROLPARENT with WS_TABSTOP, but it made no difference.
The property pages are embedded in the Tab Control using CoCreateInstance to get a ISpecifyPropertyPages pointer, which is used to get a CAUUID, which is used to get an array of IPropertyPage pointers from more calls to CoCreateInstance, one for each property page.
Probably what I need to do is trap the Tab message in the dialog box, then somehow see if the property page with the edit controls is open, see if the focus is in an edit control, and if it is, send the Tab message to the property page. I don't know how to do that yet, but your answer stimulated some thinking. It seems like a lot of work for an apparently simple task..
|
|
|
|
|
Try reading this[^]. You're doing something simple wrong, it shouldn't be hard to get what you're trying to do to work.
Steve
|
|
|
|
|
Hi All!
I am trying to playback a '.wav' file, which I have no problem with doing using the MCI. What I need to do is know when playback has finished. I have now spent a day looking in to this and not found anything anywhere - please help!!!
Is using MCI the best way of doing this - I only wish to play, stop and pause sound files (mp3, wav and spx), nothing too clever, but detecting the end of the soundfile has proven to be a problem.
I am using VC6 & Windows XP
Any help and advice would be greatly appreciated!
Regards
Mike
|
|
|
|
|
Right I have had some success, but still need a bit of advice!
I have overridden WindowProc, and when the wav file starts and stops, I recieve message 1224. I can then check the wParam and lParam to see the value. lParam is 525 when the wav file finishes playing.
Does anyone know what is the definition of message 1224, and what are returned in wparam \ lparam?
Thanks for any advice on this
Regards
Mike
|
|
|
|
|
|
Thanks for helping Cool_Dev
I did think about doing this in a similar manner - setting a 1 second timer running and checking to see the position of playback to see if the end of file had been reached. It did strike me as being a bit in-elligent. I was hoping for there to be a 'MCI_NOTIFY_PLAYBACK_FINISHED' type of message that I would need to capture. I don't know if you have seen my reply to my own post - I have had some success in getting a message, but I just have the value - it would be nice to know its definition.
Thanks for lookingg and your advice
Mike
|
|
|
|
|
I have a CComboBox control :
CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1);
and here I fill it :
pCombo->AddString("One");
pCombo->AddString("Two");
pCombo->AddString("Three");
pCombo->AddString("Four");
pCombo->AddString("Five");
and here , in drop down state I want to delete an item ( or two ) :
pCombo->ShowDropDown(TRUE);
pCombo->DeleteString(2);
pCombo->DeleteString(3);
my question is : how can I redimension the drop down window to fit remain items ?
I solve this in dirty way :
pCombo->ShowDropDown(FALSE);
pCombo->ShowDropDown(TRUE);
but is not elegant and in some systems flikering ... can you help me ?
|
|
|
|
|