|
I use project CpolyBtn of Chris Losinger . when only one Dialog is ok.
When two Dialog then error in function OnPreSubClassWinDow, project is running but function SetFillColor is not running.
Thank
Hello
|
|
|
|
|
Try posting the question in the article forum from where you downloaded the project, Chris Losinger may reply you directly.
God is Real, unless declared Integer.
|
|
|
|
|
Hello!
To avoid flickering during scrolling and resizing I use next code:
<br />
BOOL CMyView::OnEraseBkgnd(CDC* pDC)<br />
{<br />
return TRUE;<br />
}<br />
<br />
void CMyView::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
<br />
CRect rcPaint = dc.m_ps.rcPaint;<br />
<br />
CBitmap bmp;<br />
bmp.CreateCompatibleBitmap(&dc, rcPaint.Width(), rcPaint.Height());<br />
CDC newDC;<br />
newDC.CreateCompatibleDC(&dc);<br />
CBitmap *pOld = newDC.SelectObject(&bmp);<br />
<br />
newDC.SetViewportOrg(-rcPaint.left, -rcPaint.top);<br />
<br />
OnPrepareDC(&newDC);<br />
OnDraw(&newDC);<br />
<br />
VERIFY(dc.BitBlt(rcPaint.left, rcPaint.top, rcPaint.Width(), rcPaint.Height(), &newDC, rcPaint.left, rcPaint.top, SRCCOPY));<br />
SelectObject(newDC, pOld);<br />
}<br />
But during scrolling the content is not repainted correctly. Could you help me to improve it?
Thank you in advance.
|
|
|
|
|
Reunion wrote:
newDC.SetViewportOrg(-rcPaint.left, -rcPaint.top);
try commenting this line and are you considering the scroll position ???
God is Real, unless declared Integer.
|
|
|
|
|
I want to download an encrypted exe file from server. Then a client app will unencrypt it to memory and execute it from memory. So the client can not get this important exe file. But I do not know how to do that. Can you tell me how I can realize it?
Thanks.
|
|
|
|
|
Save it to disk first, then use CreateProcess() or ShellExecute() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I need add a data file to a exe file,and also need make the additional data file changeable.Can i do that only by edit the exe file,and not need to rebuilt it from source code?
How can I do that?Or if you have any suggestion?
opening view with wild mind
|
|
|
|
|
Probably you can do it by placing data to resources, and using resource related functions. You should be able to both read and modify resources in executables without problems. I have never used this myself, though.
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
I would like to use the OO approach to threads that Derel Lakin uses on his article posted on this board. It subclasses CWinThread to create a class that allows multiple instances to effectively use the same thread function, safely.
I have derived a class (CMyThread)from CWinThread following his approach. This will be my base class, with all the basic members (events) and methods to start and stop a thread, from where I derived all my other classes that need to be executed on a diffent thtead.
I have a main thread on my appliaction, CMainThread derived from CMyThread. This class will act as a socket sever, it will bind to a port waiting for incoming connections. For each new conection it will create a new object of the class CWorkerThread (also derived from CMyThread) that has the functionality needed to process my business logic transactions.It basically listens to the client socket and when it has a full command it executes the transaction bussines logic. When it finish with the transaction it goes back to listen to the client socket for more incomming commads.
For debugging purpose I limit my application to only one object of the class CWorkerThread (only on client conects to it). I have the one client sending always the same command.
The problem I see is that the transaction that I have the one client sending over and over, always same exact one, varies a lot on the time it takes to execute. Some times it gets done on 10 mili seconds (what I am expecting) and other times it may go up to a couple of minutes. I'm logging plenty of degub statements to a text file to debug the problem, all lines on the log file have a time stamp, I see that the only delays on executing the transaction are when I make ADO calls to my oracle database. I have tried the ADO calls (Select statements) using TOAD (enteprise manager) and they always take around 10 mili seconds.
The virtual function Execute() of the class CWorkerThread is the entry point of execution for the thread that I want executing the bussines logic of the transaction. From this virtual function I will access the class data members and call the class methods. Can this be a problem?
Can any one give me any ideas on what is going on? Sorry for the long message. Here are the declaration of the three clases
class CMyThread : public CWinThread
{
DECLARE_DYNCREATE(CMyThread)
protected:
CMyThread(); // protected constructor used by dynamic creation
CMyThread(AFX_THREADPROC pfnThreadProc);
// Attributes
public:
//CInternalException m_SettlementException;
protected:
CLogFile *m_pLogFile; //Pointer to the logfile object that all derived threads will use
CString m_sThreadName; //Name of the thread
CString m_sFunctionName;//Name of the function being executed
CString m_sTmp;
CString m_sErrorMessage;
//Commands that the thread responds to
HANDLE m_hEventStart;
HANDLE m_hEventStop;
//Statuses of the thread
HANDLE m_hEventWorking;
HANDLE m_hEventDone;
HANDLE m_hEventReady;
HANDLE m_hEventQuit;
//this is a pointer to an array of handles to all commands (events) that this thread supports
HANDLE m_Handles[2];
long m_nThreadTimeOut; //Number of seconds the thread waits before it times out
double m_dStartTime;
double m_dNumTransDone;
double m_dTransactionTime;
double m_dTotTime;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyThread)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
//}}AFX_VIRTUAL
void SetThreadName(CString Value) {m_sThreadName = Value;};
void SetLogFile(CLogFile *Value) {m_pLogFile = Value;};
CLogFile *GetLogFile(void) {return m_pLogFile;};
void WriteToLog(CString Value);
void WriteToLog(int DebugLevel, CString Value);
void TerminateThread();
CString GetThreadName(){return m_sThreadName;};
//Member functions to send commands to the thread
void StartProcessing(void);
void StopProcessing(void);
//Member functions to get the status of the thread
HANDLE *GetDoneStatus(){return &m_hEventDone;};
HANDLE *GetWorkingStatus(){return &m_hEventWorking;};
HANDLE *GetReadyStatus(){return &m_hEventReady;};
HANDLE *GetQuitStatus(){return &m_hEventQuit;};
void SetThreadTimeOut(long Value) { m_nThreadTimeOut = Value;};
void RaiseInternalException(CInternalException &, CString);
// Implementation
static UINT ThreadFunc( LPVOID lpParam);
protected:
virtual ~CMyThread();
virtual UINT Execute();
void DealWithTheError();
void CatchComError(_com_error &, CString );
// Generated message map functions
//{{AFX_MSG(CMyThread)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class CMainThread : public CMyThread
{
private:
//Socket stuff
WSADATA m_wsaData; SOCKET m_sServerSocket;
sockaddr_in m_saddrSocketAddres;
SOCKET m_sClientSocket;
vector<cworkerthread *=""> m_vWThreadList;
CWorkerThread *m_pWorkerThread;
HANDLE *lpQuitHandles;
int m_nMaxTransactions;
int m_nNumActiveThreads;
long m_nWaitForCommands;
long m_nWTCommandTimeOut;
long m_nSTCommandTimeOut;
long m_nServerPort;
//ADO objects for the CRS database
CString m_sCRSConnString;
CString m_sORCConnString;
CString m_sFailOverList;
public:
CMainThread();
CMainThread(AFX_THREADPROC pfnThreadProc);
virtual ~CMainThread();
long InitMainThread();
int GetNumberOfActiveThreads() {return m_nNumActiveThreads;};
void SetCRSConnString(CString Value){m_sCRSConnString = Value;};
void SetORCConnString(CString Value){m_sORCConnString = Value;};
void SetFailOverList(CString Value) {m_sFailOverList = Value;};
void SetWaitForCommands(long Value) {m_nWaitForCommands = Value;};
void SetWTTimeOut(long Value) {m_nWTCommandTimeOut = Value;};
void SetSTTimeOut(long Value) {m_nSTCommandTimeOut = Value;};
void SetServerPort(long Value) {m_nServerPort = Value;};
BOOL InitInstance();
int ExitInstance();
protected:
//It will execute all the logic of this thread
virtual UINT Execute();
private:
long CreateWorkingThread();
long CheckStopCommand();
long FatalError(CString, long);
long GetOutStoppingWorkerThreads();
long GetArrayOfStopHandles( );
};
class CWorkerThread : public CMyThread
{
private:
SOCKET m_ClientSocket;
CString m_sMessage;
char m_cMessageByte;
CString m_sFunctionName;
CString m_sORCConnString;
CString m_sFailOverList;
CADOConnect *m_pORCConn;
CADOCommand *m_pORCCommand;
CADORecordset *m_pORCRs;
_ParameterPtr m_pORCParameter;
FieldPtr m_pORCFld;
//XML document object
IXMLDOMDocument2Ptr m_objDoc;
_bstr_t m_bstrCommand, m_bstrStationNo, m_bstrStoreCode, m_bstrCheckAmt, m_bstrCheckDate, m_bstrCheckNo;
_bstr_t m_bstrClaimNo, m_bstrFM, m_bstrMR, m_bstrDL, m_bstrPhone, m_bstrZip;
public:
CWorkerThread ();
CWorkerThread (AFX_THREADPROC pfnThreadProc);
virtual ~CWorkerThread ();
BOOL InitInstance();
int ExitInstance();
void SetSocket(SOCKET Value) {m_ClientSocket = Value;};
void SetOracleConnectionString(CString Value) {m_sORCConnString = Value;};
void SetOracleFailOvers(CString Value) {m_sFailOverList = Value;};
protected:
//It will execute all the logic of this thread
virtual UINT Execute();
private:
long ParseMessage();
long InitXML();
long LoadXMLRequest();
long GetXMLValue(_bstr_t *Value, _bstr_t NodeName);
long FindSingleMatch();
long FindGroupMatch();
long InitializeADOObjects();
};
|
|
|
|
|
IIRC ADO is not thread safe. If you want to manipulate database data from threads then you need to make all database calls from the main thread of the application. This effectively serialises all database access.
From the worker thread the easiest way to do this it is to post messages to the main threads message queue.
This does have some down sides. i.e. the data has to be made thread safe, also the data needs to be available when the main thread processes the thread message.
Ant.
|
|
|
|
|
How about if each worker thread has its own database connection? Wouldn't that take care of synchronizing the database.
|
|
|
|
|
Actually, if your connection etc are all in the same thread then there should not be a problem. This would obviously mean multiple connections to the database from your application.
I still have some niggling doubt in the back of my mind for some reason but for the life of me I can't think what that is.
Ant.
|
|
|
|
|
Help!
When editing text in my treeview if I try to select part of the string with the mouse I get a "ASSERT(::IsWindow(m_hWnd))" error!
Thanks!
|
|
|
|
|
Run the debug build under the debugger, look at the call stack where the assert fired, and determine what the value of m_hWnd is. Typically it means that you're trying to use a pointer to a CWnd object that was temporary (such as if you stored the return value of GetEditControl - MFC cleans up these temporary CWnd objects during idle processing), a window that's been destroyed, or a window that was never created.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
hi everyone,
i am in a console project using Visual C++ 6 where main function should receive parameter from the command line.
when i debug the project, i would like to simulate that params passing...
is there a way to do that ?
in brief, i'd like the debugged program to act as if it had been passed its parameter as the following when i push the Build|Start Debug|Go menu command :
myprogram file1 file2
thanks all
TOXCCT >>> GEII power
|
|
|
|
|
Hi there
Yes, there is.
Go to Project | Settings... (Alt + F7) on the "Debug" tab, look for the "Program arguments" field, there you can put the arguments you want to pass.
Fabian
|
|
|
|
|
|
I now how to call api functions with visual basic
I’m new with C++ ,
I cant find out how to call this function with C++
<code>
file name : APIDeclarations.bas
' Declare API calls for System access
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
How do I declare this function ?
</code>
This is the function, thats not the problem
<code>
Option Explicit
Public Sub WSHWait(ticks As Variant)
' For WSH: provide a Wait-Function
' ticks: delay time in milli seconds (must be > 0)
Dim ticks1
On Error GoTo Error
If Not IsNumeric(ticks) Then
MsgBox ticks & " illegal value for parameter ticks", vbOKOnly, _
"DaemonExt Error in method WSHWait"
Exit Sub
Else
If ticks < 0 Then ' catch negative values -> infinite wait
MsgBox ticks & " illegal value for parameter ticks", vbOKOnly, _
"DaemonExt Error in method WSHWait"
Exit Sub
End If
End If
ticks1 = ticks
Sleep (ticks) ' Wait x milli seconds
Exit Sub
Error: ' Error handling
MsgBox "Run-Time Error number " & Err.Number, vbOKOnly, _
"DaemonExt Error in method WSHWait"
End Sub
Sub Wait(x)
' provide a Wait-Function
Dim start, i
start = CInt(Second(Time))
i = 0
Do
i = i + 1
Loop While (CInt(Second(Time)) < start + CInt(x))
End Sub
</code>
Nice code, doesn't use any CPU time during wait
Greets Jeroen
|
|
|
|
|
each library indexed function has its synopsis into .h files.
to include these files, do #include <the_file_to_include.h> at the top of the file.
hum well, now tell me, you ask for C++ code, but do you think the code you wrote was C++ ?
a definitely don't think so.
anyway, you can also have a look at the MSDN for any C/C++ functions you want details about.
cheers
TOXCCT >>> GEII power
|
|
|
|
|
No its visual basic code,
I only need to now how i Declare api calls for system access
like this with visual basic code :
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Do i need a lot of code ?, for this function call ?
I dont want to use the command Sleep (3 * 1000);
its using a lot cpu time
Thanx for help
Greets Jeroen
|
|
|
|
|
Hi there,
No you do not need a lot of code, just be sure you have the right header included.
For Sleep, you need this line
#include <winbase.h>
but it could be already included, Windows.h includes Winbase.h, so you may not have to include any extra header.
Regards,
Fabian
|
|
|
|
|
even if header files are already by other headers, it worth it to include it again because it can make your code clearer.
that is beacause header are proteected by proprocessor directives such as #ifdef #ifndef #if !defined #pragma once ... and so on.
TOXCCT >>> GEII power
|
|
|
|
|
How can I do a findfile beyond MAX_PATH ?
|
|
|
|
|
MSDN:
pFileName:
[...]
Windows NT/2000: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Flirt harder, I'm a Coder
mlog || Agile Programming | doxygen
|
|
|
|
|
Yes if you know the filename that is good but otherwise you need to "find the file" ? Or is there a possibility to read a directory in some other way?
The find structure is insufficient ?
typedef struct _WIN32_FIND_DATAW {
...
WCHAR cFileName[ MAX_PATH ];
WCHAR cAlternateFileName[ 14 ];
...
} WIN32_FIND_DATAW, *PWIN32_FIND_DATAW, *LPWIN32_FIND_DATAW;
FindNextFile()
|
|
|
|