|
my application only have a dialog with some other win32 windows
|
|
|
|
|
Can you post the code part that is creating the pop up dialog. Just to see how you are creating this pop-up dialog within your application.
Suhredayan
|
|
|
|
|
OK
My CApp:
InitInstance()
{
...
static CDlg dlg;
m_pMainWnd = &dlg;
//int nResponse = dlg.DoModal();
//if (nResponse == IDOK)
// ...
//
dlg.Init();
return TRUE;
}
i create win32 window in dlg.Init() and its CallBackWnd code segment :
case WM_COMMAND:
{
if (IDD_CONTROL_PANEL == wParam)
{
((CDlg*)AfxGetApp()->GetMainWnd())->DoModal();
}
}
|
|
|
|
|
This looks to me like a Dialog application, where the dialog is the main window. So when the dialog closes that is the end of the application. If you want a normal window application that uses dialogs then create a proper framewindow as the main window. If you are using Visual Studio then there are standard framewindow templates to build from.
|
|
|
|
|
Handle the WM_CLOSE message and in the handler, hide the dialog instead of calling DestroyWindow .
This way the dialog is not shown anymore but the program is running.
|
|
|
|
|
i had tried, but it happened exception-error
|
|
|
|
|
Since you said you called DoModal I assume you created a modal dialog box. When this dialog box is closed by clicking the top-right corner's close button, your application should still be running. You don't have to do anything to "keep it running".
Clicking the close button should cause the DoModal to return the value IDCANCEL (and the dialog box being closed) unless you override the handler and do something else.
|
|
|
|
|
maybe i make some wrong, if i closed the dialog box, it'll happen errors
|
|
|
|
|
Try to overwirte the virtual function OnCancel(), and call EndDialog(n) in that.
Or just call EndDialog(n) in OnClose() function.
|
|
|
|
|
i had tried, it all made errors
|
|
|
|
|
thank you for everybody, i used modeless window in last.
|
|
|
|
|
I'm building a small C app. ATM, I'm simply twiddling with a Hello World app because it seems that any app I create will not hit break points.
I opened the project settings and /DEBUG was turned off under the linker settings. I turned that on, rebuilt and located my *.opt file. I attempted to 'debug' again and VS simply skips over the breakpoints. The breakpoint settings indicate that they are set to 'break always' and I *am* running (via F5) the debug version through VS.
I've deleted all breakpoints, clean, rebuilt, adjusted settings and it still acts like it's a Release build.
If I create an MFC app, breakpoints work fine.
Anyone seen this before?
|
|
|
|
|
Like2Byte wrote: I opened the project settings and /DEBUG was turned off under the linker settings.
Are you sure it was set ON in the compiler settings?
|
|
|
|
|
Before I posted originally, I had already changed this setting: "Linker->Debugging->Generate Debug Info" to YES (/DEBUG).
I just now set "C/C++ ->General->Debug Information Format" to Program Database (/Zi). It was set to 'Disabled'.
I've never seen a VS disable all debugging in a new project before and certainly not for a 'DEBUG' build. Do I need new glasses?
Anyway, thanks for your help. I looked there before but must have missed it.
Cheers!
|
|
|
|
|
Like2Byte wrote: I looked there before but must have missed it.
Something I do too often to admit!
|
|
|
|
|
Yeah, I'm going to chock it up to what my teachers told me in high school - "You (as in I) need to slow down."
damn teachers!
|
|
|
|
|
Hello,
I have written one executable in C++ which runs from startup of 'All Users' in user's account. In order to give read and write permissions to the place where this executable reads and writes into a file and creates logs we have a service which gives the particular folder the ACL permissions. Using this concept even restricted user never faces any problem while trying to do any of its designed functionality till XP. But, in some cases starting from VISTA we get the executable visible in task manager but it does not do any thing and also not even makes the log.
I need to find why this happens. If any one knows please throw some light on this
Regards,
Kushagra
|
|
|
|
|
Kushagra Tiwari wrote: I need to find why this happens. If any one knows please throw some light on this
Have you tried running your application under the debugger to see what is happening?
|
|
|
|
|
|
Hi fellow CP-ers.
I worked with monstrous legacy C/C++ code where the GUI and business logic components are executed in the same thread. It worked fine, but the GUI is similar to Win 3.1 style: ugly clunky and yucky (sorry for hardcore 3.1-ers!).
Since then we upgraded our system with new GUI tools and processors. We decided to take this opportunity to untangle the system. We put all the biz logic in one thread (this hosts multiple apps, drawing or non-drawing), and all related GUI items (rendering loop, animations, and all its support classes) on the other thread. IMO, this is very beneficial since for example the button may animate fade in or out, etc, while the biz logic thread can still host other non-drawing applications. Note that we will try to do as much as we can locally in rendering thread if it doesn't involve biz logic (ex: highlights, international strings, etc). If it requires data, it will post to biz logic thread and retrieve it.
So this new guy came in and decided to put all the GUI classes back to the business logic thread. Rendering is still done on other thread, but now for every single little graphics primitives (think set colors, move obj to x,y, set transparency, etc) we need to send out a message. His reasoning is that it's too clumsy to post handler messages to other thread, he prefers call back, and he said it's common for most GUI frameworks to have this synchronous behavior.
Can someone help me explain why the synchronicity of button handler is so important? Am I missing something?
Don't we already have similar model of biz logic / presentation separation in present day web technology? (i.e. Fancy flash animations in your web browser sending/fetching data from the server, or AJAX heavily used by Google apps?)
|
|
|
|
|
The are two principles mixed together here:
1) Splitting business logic and GUI logic - This is good as it allows one to write unit-tests that can test the business-logic without needing to test using the GUI.
2) Using worker-threads to perform long running operations - This gives a good GUI experience, as the GUI remains responsive even when doing heavy processing.
Multi-threaded programming increases the complexity of the code. So it should only be introduced where it actually provides a performance boost.
I have no problem in understanding why your new developer wants to make synchronous requests as it is so much simpler.
I have no clue about your customer base, or the type of application you are building. But the tendency is that we work towards client/server based applications, where the client is launched through a web-browser (ASP.NET / Silverlight) and the Server is available from the Internet (Easy deployment, Centralized hosting and backup). In this scenario then the splitting of GUI and business logic should come natural.
modified on Monday, December 14, 2009 5:09 PM
|
|
|
|
|
I have a DLL that communications to COM ports (we will call dll 'A')
I would prefer to only have one instance of this dll in memory at all times
I have two projects a C# windows form project ('B') and a c++ dll ('C')
that both access the COM port dll('A')
I am going to merge the c++ dll('C') and the C# project('B') into one application('BC')
Seeing that they both access functions of the dll('A'), but are there own entity is it possible to make both projects access the same dll('A') in memory instead of loading it in twice?
the communication dll('A') has multiple threads and is quite complex, I do NOT want two instances, but need the functionality of dll('B') in project ('C')
hopefully as convoluted as that is, it makes sense
Thank you for your help
|
|
|
|
|
That is the whole idea behind DLLs, one instance in memory servicing multiple apps at one time.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
this code: define Bspline curve, when i run it, i found:
"program too big to fit in memory" (although i restart computer)
???
#include "StdAfx.h"
#include "process.h"
#ifndef _MYBSPLINE_H__
#define _MYBSPLINE_H__
#ifndef ABS
# define ABS(x) ((x<0) ? (-1*(x)) : x)
#endif
typedef struct _MYPOINT
{
double x;
double y;
} MYPOINT;
//----------------------------------------------------------------------------------------------------
class CMyBSpline
{
public:
CMyBSpline(void);
~CMyBSpline(void);
void SetDegree(int nK); // Thiet lap bac cua da thuc neu ban muon
void Generate(MYPOINT* pControl, int n); // Thuc hien sinh cac diem dua tren cac diem dieu khien
int GetPointNum(); // Tra ve so diem sinh ra
MYPOINT* GetPoints(); // Tra ve con tro tro toi dau mang chua cac diem sinh
private:
MYPOINT* m_pPoints; // Mang chua cac diem B-Spline
int m_nNum; // So diem tren B-Spline sinh ra
int m_nK; // Bac cua da thuc
int* m_pU; // Mang chua cac Knots
void AllocateBSplinePoints(int n); // Cap phat vung nho luu tru diem tren B-Spline
void FreeBSplinePoints(); // Giai phong vung nho luu tru diem tren B-Spline
void AllocateKnot(int n); // Cap phat vung nho chua diem Knot
void FreeKnot(); // Giap phong bo nho da cap phat de luu diem Knot
void ComputeKnots(int n); // Tinh toan Knots
double FactorN(int t, int k, double v); // Tinh he so da thuc Ni,k(u)
void ComputeP(MYPOINT* pControl, int n, double u, MYPOINT& pt); // Tinh gia tri da thuc P(u)
};
#endif
CMyBSpline::CMyBSpline(void)
{
m_nK = 4; // Mac dinh
m_pPoints = NULL;
m_nNum = 0;
m_pU = NULL;
}
CMyBSpline::~CMyBSpline(void)
{
FreeKnot();
FreeBSplinePoints();
}
// Cap phat vung nho luu tru diem tren B-Spline
// n: So diem can cap phat
void CMyBSpline::AllocateBSplinePoints(int n)
{
if (m_pPoints!=NULL)
FreeBSplinePoints();
m_pPoints = new MYPOINT[n];
m_nNum = n;
}
// Giai phong vung nho luu tru diem tren B-Spline
void CMyBSpline::FreeBSplinePoints()
{
if (m_pPoints!=NULL)
delete [] m_pPoints;
m_pPoints = NULL;
m_nNum = 0;
}
// Cap phat bo nho de luu diem Knot
// n: So diem control point
// So diem Knots la: n+m_nK+1
void CMyBSpline::AllocateKnot(int n)
{
if (m_pU!=NULL)
FreeKnot();
m_pU = new int[n+m_nK+1];
}
// Giai phong bo nho da cap phat de luu cac diem Knot
void CMyBSpline::FreeKnot()
{
if (m_pU!=NULL)
{
delete [] m_pU;
m_pU = NULL;
}
}
// n: So diem control point
// Mang Knots luu trong m_pU
void CMyBSpline::ComputeKnots(int n)
{
int j;
for (j=0; j<=n+m_nK; j++)
{
if (j<m_nK)
m_pU[j]=0;
else if ((m_nK<=j) && (j<=n))
m_pU[j]=j-m_nK+1;
else if (j>n)
m_pU[j]=n-m_nK+2;
}
}
// Tinh toan de quy he so da thuc: Ni,k(u)
// i: 0<=i<=n
// k: Bac cua da thuc
// u: La diem can tinh
double CMyBSpline::FactorN(int i, int k, double u)
{
double value;
if (k==1) // Dieu kien dung de quy
{
if ((m_pU[i]<=u) && (u<m_pU[i+1]))
value=1;
else
value=0;
}
else
{
if ((m_pU[i+k-1]==m_pU[i]) && (m_pU[i+k]==m_pU[i+1])) // Kiem tra dieu kien chia cho 0
value = 0;
else if (m_pU[i+k-1]==m_pU[i]) // Neu mau so bang 0 thi tinh theo cach khac
value = (m_pU[i+k] - u) / (m_pU[i+k] - m_pU[i+1]) * FactorN(i+1, k-1, u);
else if (m_pU[i+k]==m_pU[i+1]) // Neu mau so bang 0 thi tinh theo cach khac
value = (u - m_pU[i]) / (m_pU[i+k-1] - m_pU[i]) * FactorN(i, k-1, u);
else
value = (u - m_pU[i]) / (m_pU[i+k-1] - m_pU[i]) * FactorN(i, k-1, u) +
(m_pU[i+k] - u) / (m_pU[i+k] - m_pU[i+1]) * FactorN(i+1, k-1, u);
}
return value;
}
// Tinh gia tri da thuc P(u)
// pControl: Mang chua diem control point
// n: So diem control poiint
// u: Diem tinh
void CMyBSpline::ComputeP(MYPOINT* pControl, int n, double u, MYPOINT& pt)
{
double dFactor;
// Khoi tao lai cac gia tri
pt.x = 0;
pt.y = 0;
for (int i=0; i<=n; i++)
{
dFactor = FactorN(i, m_nK, u); // same blend is used for each dimension coordinate
pt.x += (pControl[i]).x * dFactor;
pt.y += (pControl[i]).y * dFactor;
}
}
// Thiet lap bac cua da thuc neu ban muon
void CMyBSpline::SetDegree(int nK)
{
m_nK = nK;
}
// Sinh ra cac diem tren B-Spline
// pControl: Mang chua cac diem dieu khien
// n: So diem dieu khien
void CMyBSpline::Generate(MYPOINT* pControl, int n)
{
// Hieu chinh lai gia tri cho phu hop
n--;
// Xoa cac diem cu
FreeBSplinePoints();
// Kiem tra dieu kien
if (n+2<=m_nK)
return; // Khong co duong cong
// Tinh so diem
// Tinh tuong doi so diem sinh B-Spline
int nNum = 0;
int nDiv = 0;
for (int i=0; i<n; i++)
{
nDiv = (int)(max(ABS(pControl[i+1].x-pControl[i].x), ABS(pControl[i+1].y-pControl[i].y))/0.5);
if (nDiv==0)
nDiv = 1;
nNum += nDiv+1;
}
// Cap phat va tinh cac diem Knots
AllocateKnot(n);
ComputeKnots(n);
// Cap phat bo nho luu diem tren B-Spline
AllocateBSplinePoints(nNum);
// Sinh cac diem tren B-Spline
MYPOINT pt;
double dInc = (double)(n-m_nK+2)/nNum;
double u = 0;
for (int nIdx=0; nIdx< nNum; nIdx++)
{
ComputeP(pControl, n, u, pt);
m_pPoints[nIdx].x = pt.x;
m_pPoints[nIdx].y = pt.y;
u += dInc;
}
FreeKnot();
}
int CMyBSpline::GetPointNum()
{
return m_nNum;
}
MYPOINT* CMyBSpline::GetPoints()
{
return m_pPoints;
}
|
|
|
|
|