|
Use CreateProcess() instead of system(). This gives you far more control.
Here is some code I use in ED.
BOOL
Execute_OS_Program( char* pszCommandLine, char* pszWorkingDir, const int Run_Opts, int* const pnErrorCode )
{
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
DWORD dwCreationFlags = 0x00;
bool stat;
ZeroMemory( &siStartInfo, sizeof( STARTUPINFO ) );
siStartInfo.cb = sizeof( STARTUPINFO );
siStartInfo.dwFlags = STARTF_USESHOWWINDOW;
siStartInfo.wShowWindow = SW_SHOWNORMAL;
dwCreationFlags = CREATE_NEW_CONSOLE;
ZeroMemory( &piProcInfo, sizeof( PROCESS_INFORMATION ) );
stat = CreateProcess( NULL,
(char*)pszCommandLine,
NULL,
NULL,
FALSE,
dwCreationFlags,
NULL,
pszWorkingDir,
&siStartInfo,
&piProcInfo
) != FALSE;
if ( stat )
{
CloseHandle( piProcInfo.hThread );
*pnErrorCode = 0;
if ( Run_Opts & SE_WAIT )
WaitForSingleObject( piProcInfo.hProcess, INFINITE );
}
else
*pnErrorCode = GetLastError();
return stat;
}
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thanks - I'll take a look at this method today
|
|
|
|
|
Hello.
I have library foo.lib, which has class foo with a static member variable (see below), constuctor of class foo refers to the static member during initialization. I am using this library in my program, which has global variable of type foo.
The problem is that global_foo is initialized before foo::s_a is, so global_foo.m_var is not equall to 1 as I want it to be. How can I avoid this situation? Is there a way to force global initializations to be in a certain order?
Thank you.
P.S. I found on the net that solution could be mentioned in
Schwarz, "Initializing Static Variables in C++ Libraries", C++ Report. Vol1 No2, Feb. 89, pp1-4.
But I can not find this article online, and I do not have access to the C++ Gems book, which should have it.
--- foo.h
class foo
{
static int s_a;
int m_var;
foo(){m_var=s_a;}
}
--- foo.cpp
#include "foo.h"
int foo::s_a=1;
--- my_prog.cpp
#include "foo.h"
foo global_foo;
mian{}
Regards,
Alexander.
|
|
|
|
|
Move the ctor body to foo.cpp .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I can not move ctor. The situation is that static member should be defined in the lib file, while derivatives of the main class will be decleared as global objects in the main program.
Regards,
Alexander.
|
|
|
|
|
Ummm... try the following approach:
--- foo.h
class foo
{
static int& s_a();
int m_var;
foo(){m_var=s_a();}
}
--- foo.cpp
#include "foo.h"
int& foo::s_a()
{
static int s_a_var=1;
return s_a_var;
}
--- my_prog.cpp
#include "foo.h"
foo global_foo;
mian{}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks a lot, this method works fine. Though it looks more like a trick, rather then a way to do such things Anyway it does work.
Regards,
Alexander.
|
|
|
|
|
The technique can be deemed a trick, but it is a very common one, since it helps to solve a long standing problem that some call the static initialization order fiasco[^]. Also, it is routinely used in some implementations of the Singleton pattern.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the link, nice to have it in favorites And it does work!
Regards,
Alexander.
|
|
|
|
|
ACoording to C++ specification:
All static variables are initialized to 0(NULL) by loader before being initialized by CRT.
So, if you can changed your LIB if available and provide check in you constructor like that:
...<br />
class foo<br />
{<br />
static bool s_initialize;<br />
static int s_a;<br />
int m_var;<br />
foo()<br />
{<br />
if (!s_initialized)<br />
{<br />
s_a = 1;<br />
s_initialized = true;<br />
}<br />
m_var=s_a;<br />
}<br />
...<br />
int foo::s_initialized = false;<br />
int foo::s_a=1;<br />
...
Or just use (s_a == 0) check if 0 is not possible value...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
It looks like s_initialized will be reset to false again once "int foo::s_initialized = false;" is executed, which means that initialization will be done twice.
Regards,
Alexander.
|
|
|
|
|
How about this then?:
class foo<br />
{<br />
static bool s_initialized;<br />
static int s_a;<br />
int m_var;<br />
foo()<br />
{<br />
if (!s_initialized)<br />
{<br />
s_a = 1;<br />
s_initialized = true;<br />
} <br />
m_var=s_a;<br />
}<br />
};<br />
bool foo::s_initialized;<br />
int foo::s_a=0;
Weird and funny!...
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
I guess it will be the same. foo::s_initialized will be initialized again to something we are not sure what But I am guessing it might work as well. I am using approach suggeseted by Joaqun. But thank you for your help. It is good to know alternative ways
Regards,
Alexander.
|
|
|
|
|
how create thread into the same class?
*.h
class TheClass : CDialog
{
public:
TheClass(CWnd* pParent = NULL):
void StartThread();
UINT TheThread(LPVOID);
}
*.cpp
UINT Theclass::TheThread(LPVOID)
{
//Code for th thread
}
void TheClass::StartThread()
{
DWORD dwThreadId, dwThrdParam = 1;
HANDLE hThread;
hThread = CreateThread(NULL,0, TheThread, &dwThrdParam,0,&dwThreadId); // error c2664
}
How cast the TheThread param correctly?
Thanks you
|
|
|
|
|
This is one of the most asked issues here in CP. Take a look at the Code Project Visual C++ Forum FAQ[^], item 6.1 "Why can't I use a member function as a callback?"
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
I'm searching for a possibility to fade out a programs main window to grey while another dialog message is hanging around - as been seen when you choose Start->Shutdown in Windows XP.
Therefore I looked into the GDI+ documentation but found something for the alpha-channel (could be used to make windows transparent I guess).
What is the best way to fade a window to grey ? Did I have to make a in memory bitmap of the window and change that bitmap's color palette ?
Can somebody can give me a hint which direction I should consider ?
best regards
a
|
|
|
|
|
I don't know how to fade a window to grey, but you could use AnimateWindow() to make a window translucent.
VERIFY (AnimateWindow (GetSafeHwnd(), 10, AW_BLEND));
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi all,
my problem is a little complicated so bare with me.....
i have a MFC dll (dynamicall linking with mfc dll). there i've created my owner draw dialog class. it has a base template in the resources, but the constructor of the dialog can recevie a template ID as one of its parameters...
i've created an exe MFC application to use the dialog, i've created a dialog in the resources and then i've pass the resource ID to the constructor of the dialog instance, and then created DoModal().....
problem is , if i implement DoModal() in the base owner draw class (which is located in the MFC dll application ) and then call the AFX_MANAGE_STATE macro , then MFC dll application never receives the OnInitDialog().....
and if i don't implement the DoModal() then i get a crash........
can any1 help here? i am really desperate.....
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
AfxSetResourceHandle() should give you an answer.
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Does anyone here know how to highlight an icon ( or other image type ). I am working on a project that i want to be able to display an icon with some text and have it be able to obtain a selected state it which the image will becomes "hazed" with the system highlight color much like the icons in the windows shell when you click on them. The closest i have come on my own is using the AlphaBlend function but then i am left with a background that isn't transparent and so i can't Blt it to the Primary DC. Any ideas?
Please note that i can not use Image Lists to do this.
Joseph Dempsey
joseph_r_dempsey@yahoo.com
|
|
|
|
|
I think it can be done with DrawState , using GetSysColorBrush(COLOR_HIGHLIGHT) as the brush. If this does not work, some playing around with the parameters may get the result you desire.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You know, that was the first function that came to mind for me as well but unfortunatly there is no state flag for selected. I'll look into drawing it with a brush like you said though but i don't think i'm going to hold my breath because MSDN docs on the function say that the brush is only used for drawing the image in a monochrome state which wouldn't do me to much good
Joseph Dempsey
joseph_r_dempsey@yahoo.com
|
|
|
|
|
I'm using IE's IWebBrowser used in my dialog application.
How to force it to navigate always in this window,
even when user clicks on target="_blank" ?
(now every time on such link new IE window is created)
Thanks
rrrado
|
|
|
|
|
rrrado wrote:
How to force it to navigate always in this window,
even when user clicks on target="_blank" ?
The target="_blank" operative is supposed to open a new window. Try using target="_self" instead.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I'm creating custom web browser, user is browsing 3rd party html pages, I can't change source, just want to override this settings
rrrado
|
|
|
|