|
Please see #4 here.
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I have a console application which calculates using formulas based on the inputs it is receiving every cycle in a particular frequency and gives dynamic output values based on its input variables and constants and so on. In short its a real time application.
This application was initially developed in Visual Studio 6.0 as c++ console application. Recently we converted it to Visual Studio 2008.
It was working fine in VS 6.0. But after conversion, some of the values shows -1.#J which seems like infinite values.
When I observed, it seems like certain calculations may result in divide by 0 or complex values like square root of a negative number and these values should show the value as -1.#J.
But I wonder how there was no such values in VS6.0 whereas VS2008 shows these junk values.
Please suggest me some ways of preventing it.
modified 10-Apr-14 7:56am.
|
|
|
|
|
Please show your code.
Everything is the code !
|
|
|
|
|
Please show your code.
Everything is in the code !
|
|
|
|
|
I am posting one of the functions used in the code. There are many functions similar to this in the entire application
int CONDENSER(float Fl,float Fv,float Rc,float Gain,float DesFp,float Htcfl,
float Htcmaxfl,float Tflsh,float Fc, float Cpcw,
float Cppl, float Cppv, float Cpov,float Cpol, float DesFc,
float Tcwi,float Tpfi,float Tc,float Lhpv,float Lhv,
float Condeff,float CondHtarea,float Ambhc,
float Ambhf, float Ambt,float Mhc, float Mhf,
float Tfmax, float Tcmax,float *Liquid, float *Vapor,int IL, int IV,int OV, int OL,int FN,int CN)
{
int J,N,K,TYPE;
float Fp,SYCOMP,SXCOMP,Heatin,Heatvap,Heatliq;
float Heatloss,Hg,Hc,DELT1,DELT2,A,B,DENOM,DELT,Heatout;
float DER,MAX,MIN,FLAG,P,I,PI;
// Amount of Vapor condensed [ L = ( 1 - V/F) * F ]
Fp = Fl + Fv;
*Liquid = Rc * Fp;
// By material balance
*Vapor = Fp - (*Liquid);
// Composition of Vapor in equilibrium with Liquid Y = K * X
SYCOMP = 1.0E-10;
for(J=Esim->COMPBEG;J<=Esim->COMPEND;J++)
{
Esim->SCOMP[J][OV] = Esim->NKVAL[J][FN]*Esim->NXS[J][FN];
SYCOMP = SYCOMP + Esim->SCOMP[J][OV];
}
// Condensation rate (PI Logic)
Esim->NS1DER[FN]= 1 - (SYCOMP);
P = Gain*Esim->NS1DER[FN];
I = Esim->NS1S[FN];
I = LIMIT01(I+Esim->NODEK7[FN]*Esim->NS1DER[FN]);
PI = LIMIT01(P+I);
Esim->NS1S[FN] = LAG(PI,Esim->NS1S[FN],0.05);
Esim->NS1S[FN] = LIMIT01(Esim->NS1S[FN]);
// Condensed Liquid Composition
// FEED * Yi - VAP * Yi - LIQ * Xi = ACC * (d(Xi)/dt)*dt
// d(Xi) = (FEED * Yi - VAP * Yi - LIQ * Xi)/(ACC * dt)
SXCOMP = 1.0E-10;
for(J=Esim->COMPBEG;J<=Esim->COMPEND;J++)
{
Esim->SCOMP[J][OV] = Esim->SCOMP[J][OV]/SYCOMP;
Esim->NXDER[J][FN] = (Fl*Esim->SCOMP[J][IL]+Fv*Esim->SCOMP[J][IV] -(Fv)*Esim->NXS[J][FN]
-(Fl)*Esim->NXS[J][FN])/(10 + MAXI(Fp-(*Vapor),100.0)
*Esim->STPSIZEH/10000);
Esim->NXS[J][FN] = EULER( N, K, TYPE, DER, MAX, MIN, FLAG);
SXCOMP = SXCOMP + Esim->NXS[J][FN];
}
for(J=Esim->COMPBEG; J<=Esim->COMPEND; J++)
{
Esim->NXS[J][FN] = Esim->NXS[J][FN]/SXCOMP;
Esim->SCOMP[J][OL] = Esim->NXS[J][FN];
}
Hg = power((Fp/DesFp),0.5);
// Efficiency of the condenser
Esim->NS2[FN] = Condeff*MAXI(Htcfl*Hg,Htcmaxfl);
Esim->NHTR[FN] = Esim->NS2[FN]*(Tflsh - Tc);
if(Fc>0) // Cooling water side calculations
{
// From McCabe & Smith h=K*(Fc)**(-1/3)
Hc = power((Fc/DesFc),-0.33);
// Accounting for the overall Heat transfer coefficient
// 1/U = 1/Hg + 1/Hc
Esim->NS2[FN] = Condeff*CondHtarea*(Hg * Hc)/(Hg + Hc);
// Energy balance across the cooling node to find out temperature
// F*CP*(I/T-AMB)+HTRAN-F*CP*(O/T-AMB)-HLOSS = ACC*CP*(dT/dt)*dt
Esim->NTDER[CN]=(Heatin-Heatout)/(Mhc*Cpcw*Esim->STPSIZEH/10000);
} // Cooling water side calculations
Esim->STEMP[OV] = Esim->NTEMP[FN];
Esim->STEMP[OL] = Esim->NTEMP[FN];
Esim->SMFLOW[OV] = *Vapor;
Esim->SMFLOW[OL] = *Liquid;
return 0;
}
modified 10-Apr-14 8:26am.
|
|
|
|
|
Firstly, please indent your code properly and use <pre> tags around it so that it is readable, like:
for(J = Esim->COMPBEG; J <= Esim->COMPEND; J++)
{
Esim->SCOMP[J][OV] = Esim->SCOMP[J][OV]/SYCOMP;
Esim->NXDER[J][FN] = (Fl*Esim->SCOMP[J][IL]+Fv*Esim->SCOMP[J][IV] -(Fv)*Esim->NXS[J][FN]
-(Fl)*Esim->NXS[J][FN])/(10 + MAXI(Fp-(*Vapor),100.0)
*Esim->STPSIZEH/10000);
Esim->NXS[J][FN] = EULER( N, K, TYPE, DER, MAX, MIN, FLAG);
SXCOMP = SXCOMP + Esim->NXS[J][FN];
}
Secondly, please indicate exactly where the error occurs, and show the values of the inputs at the time.
|
|
|
|
|
You don't want to do that, you want to avoid device by zero period. If you don't know why, go back to school.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
One possible reason of many is that in the original (vc++ 6) structured exception handling was enabled and now it isn't. This would mean that divide by 0 exceptions were being thrown but not being caught (possibly). Now they are just crashing the program.
Unhandled divide by zero is bad so don't worry about why it did/did not. Just fix the problem now. Structured exception handling is a very good way of doing that.
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
|
|
|
|
|
Hello there,
I am using CDHtmlDialog in my MFC application to create a UI with HTML, CSS & JavaScript.
In my project there's one dialog created from CDHtmlDialog and a corresponding HTML file for that dialog.
Now during run time i want to change the contents of the HTML file.
Not just the HTML part, i want to change the CSS & JavaScript too.
So basically what am trying to do is, change the entire content of the default HTML file.
Is this possible? If yes, how can i do that?
Thanks in advance!
|
|
|
|
|
I have a static control area, it is about 4 lines height.
if I only have one string to display, How can I make it horizontal and vertical center?
Thanks
|
|
|
|
|
|
For the horizontal center, use SS_CENTER, there is not vertical center for CStatic ( or Cedit), you will have to do it manually.
I'd rather be phishing!
|
|
|
|
|
I use \r\n, almost got vertical center effect
|
|
|
|
|
If you want it to be exact then you need to use a different control (possibly a RichEdit) or subclass the label and do your own painting of the text.
|
|
|
|
|
Exactly what Richard said above just subclass a static text box and you can use it over and over again.
I have a standard code I use to do what you are doing and it also allows you to change the font, text color and background color as well which is all fairly trivial.
Let me know if you want to see how to code it as I wont paste that amount of code if you don't need it.
|
|
|
|
|
We have a client-server application developed using MFC. The client-server communication is via TCP/IP sockets within a LAN network.
Now we want to convert this application to a web application. Could you please provide me with any guidelines how to start and proceed.
|
|
|
|
|
|
Yo need to write a web based VM that supports the win32 spi.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
You would be much better learning ASP.NET and starting from scratch. Converting MFC to ASP.NET would be much more difficult.
|
|
|
|
|
I like the idea of building a web based VM, shouldn't take him more than a few years dint you think?
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
im using visual studio 2010.im new to this.i have a button and a text box. i want to enter a string in the text box.eg:"hello". and if i click the button it should count the number of characters in the string and return the value..eg: in this case "hello" ,when i click the button it should count each letter and display the value "5"(string "hello" contains 5 characters).can any1 help me by sending the exact code?
|
|
|
|
|
Have you looked at the WM_GETTEXTLENGTH message? If you are using MFC, check out GetWindowTextLength().
"One man's wage rise is another man's price increase." - Harold Wilson
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
He has to handle WM_COMMAND first.... then the button ID..... then get the window handle to the edit control....
This guy needs to go back and start form scratch and read some books/do some tutorials on Win32/MFC.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
Ok here is a skeleton program it does a bit more than you asked it deals with resizing the window, closing etc and is really complete enough for you to build on and get the idea.
#include <windows.h>
#include <commctrl.h>
#define IDC_TEXT 100 // Edit box ID
#define IDC_BUTTON 101 // Button ID
#define IDC_ANSWER 102 // Static text box to show answer
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:
{
CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, TEXT("SOME TEXT HERE"),
ES_LEFT | WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)IDC_TEXT, 0, NULL);
CreateWindowEx(0, WC_BUTTON, TEXT("&Count text"),
BS_PUSHBUTTON |
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)IDC_BUTTON, 0, NULL);
CreateWindowEx(0, WC_STATIC, TEXT("0"),
SS_LEFT |
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)IDC_ANSWER, 0, NULL);
}
return 0;
case WM_GETMINMAXINFO:
{
LPMINMAXINFO lpInfo = (LPMINMAXINFO)lParam;
if(lpInfo) {
lpInfo->ptMinTrackSize.x = 300;
lpInfo->ptMinTrackSize.y = 300;
};
}
return 0;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
{
HDWP hDWP;
if(hDWP = BeginDeferWindowPos(3)){
hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, IDC_TEXT), NULL,
10, 10, 250, 25, SWP_NOZORDER | SWP_NOREDRAW);
hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, IDC_BUTTON), NULL,
10, 40, 80, 25, SWP_NOZORDER | SWP_NOREDRAW);
hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, IDC_ANSWER), NULL,
10, 70, 250, 25, SWP_NOZORDER | SWP_NOREDRAW);
EndDeferWindowPos(hDWP);
RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN |
RDW_ERASE | RDW_NOFRAME | RDW_UPDATENOW);
}
}
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
long Li;
char Buffer[256];
HWND Wnd;
case IDC_BUTTON:
if (HIWORD(wParam) == BN_CLICKED){
Wnd = GetDlgItem(hWnd, IDC_TEXT);
Li = SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
_ltoa_s(Li, &Buffer[0], sizeof(Buffer), 10);
Wnd = GetDlgItem(hWnd, IDC_ANSWER);
SendMessage(Wnd, WM_SETTEXT, 0, (LPARAM)&Buffer[0]);
return (0);
};
break;
};
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nShowCmd)
{
OSVERSIONINFO lpVer;
WNDCLASSEX wcex;
DWORD dwExStyle;
HWND hWnd;
MSG msg;
RECT R;
ZeroMemory(&msg, sizeof(MSG));
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hInstance = hInst;
wcex.lpszClassName = TEXT("TESTCLASS");
wcex.lpfnWndProc = MainWindowProc;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hIconSm = wcex.hIcon;
wcex.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
if(!RegisterClassEx(&wcex))
return 1;
dwExStyle = WS_EX_APPWINDOW;
lpVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&lpVer) && (lpVer.dwMajorVersion > 5 ||
(lpVer.dwMajorVersion == 5 && lpVer.dwMinorVersion == 1)))
dwExStyle |= WS_EX_COMPOSITED;
GetClientRect(GetDesktopWindow(), &R);
hWnd = CreateWindowEx(dwExStyle, wcex.lpszClassName, TEXT("TEST APPLICATION"),
WS_OVERLAPPEDWINDOW, R.left+20, R.top+20, R.right-R.left-40, R.bottom-R.top-140,
HWND_DESKTOP, NULL, hInst, NULL);
if(hWnd){
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
if(!IsDialogMessage(hWnd, &msg)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return (int)msg.wParam;
}
modified 22-Apr-14 5:35am.
|
|
|
|
|
Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.
pStatic->GetWindowRect(&rect); ScreenToClient(&rect);
while with
/pStatic->GetClientRect(&rect);
"TEST,TEST",black background box display well.
Is anybody know the reason?
Thanks
void CStaticTextTstDlg::OnPaint()
{
if (IsIconic())
{
...
}
else
{
CDC *pDC = GetDC();
CBitmap memBmp;
CBitmap *pBmpOld;
CDC memDC;
CStatic *pStatic = (CStatic*)GetDlgItem(IDC_STATIC_TXT1);
pStatic->ModifyStyle(0, BS_OWNERDRAW);
CRect rect;
pStatic->GetWindowRect(&rect); ScreenToClient(&rect);
memBmp.CreateCompatibleBitmap(pDC,176,50);
memDC.CreateCompatibleDC(NULL);
pBmpOld = memDC.SelectObject(&memBmp);
memDC.SetTextColor(RGB(0,230,0));
memDC.SetBkMode(TRANSPARENT);
memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0));
memDC.DrawText(_T("TEST TEST"),-1,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
CPaintDC dc(this);
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);
memDC.SelectObject(pBmpOld);
memBmp.DeleteObject();
memDC.DeleteDC();
CDialog::OnPaint();
}
}
Thanks
modified 9-Apr-14 9:20am.
|
|
|
|
|