|
How about GetDesktopWindow() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I just tried that in my dialog's constructor, but I guess I'm doing something wrong.
CChatDlg::CChatDlg(CString str,int nUserID,CWnd* pParent ) <br />
: CDialog(CChatDlg::IDD, GetDesktopWindow())
[insert witty comment here]
bdiamond
|
|
|
|
|
It might be that you are being plagued by the fact that MFC does not have real modal dialogs. They are all modeless. It simulates a modal dialog by disabling the parent. See here and here.
Going back to your original problem, though, I'm curious why minimizing the main window causes either, let alone both, windows to disappear.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Let me rephrase that. I don't mean 'disappear', I just mean they both are no longer viewable when I minimize the main app. The main app is then iconic and visible in the taskbar, but the modeless dialog is also no longer visible. I have my app set up where if the user clicks the close button, the app is minimized to the system tray. The modeless dialog then stays up. But if I click minimize, then it doesn't
[insert witty comment here]
bdiamond
|
|
|
|
|
Hi guys !
I have developed one application which continuously runs on server. But because of some memory leaks in my code it hangs out after certain time period. Can any one can help it out plz. Or any other function that can show the current memory or Total Commit memory or Memory Usage. Plz. My code is also pasted here. If you can show me some change in my code it will be worth while.
------------------------------------------------------------------
int __stdcall CompressEncode (char* sIn, char* sKey, char** sOut, long* lOutlen)
{
int iResult = 0;
if (strlen(sIn) > 400)
{
iResult = CompressData(sIn, sKey, sOut, lOutlen);
}
else
{
iResult = 1;
AES_EncodeForService(sIn, sKey, sOut, lOutlen);
if (!strstr(*sOut, "<AES_ENCODE>"))
iResult = -4;
}
return iResult;
}
int CompressData (char* sIn, char* sKey, char** sOut, long* lOutlen)
{
Byte *compr, *uncompr;
uLong comprLen = 16384*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;
if (zlibVersion()[0] != myVersion[0])
return -1;
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
if (compr == Z_NULL || uncompr == Z_NULL)
return -2;
uncomprLen = strlen (sIn);
int iResult = test_compress(compr, &comprLen, (Bytef*)sIn, uncomprLen);
if (iResult != 0)
return -3;
byte *buffer, key[32];
unsigned int bufLen;
unsigned int err;
ailaes demo;
char s2[33] = "";
int len = strlen(sKey);
if (len > 64)
len = 64;
for (int i = 0, j = 0; i < len; i ++, j ++)
{
char sTemp[2] = "";
sTemp[0] = sKey[i];
sTemp[1] = 0;
int c = 0;
if (!stricmp(sTemp, "0") || !stricmp(sTemp, "1") || !stricmp(sTemp, "2") || !stricmp(sTemp, "3") || !stricmp(sTemp, "4") || !stricmp(sTemp, "5") || !stricmp(sTemp, "6") || !stricmp(sTemp, "7") || !stricmp(sTemp, "8") || !stricmp(sTemp, "9"))
c = atol(sTemp) * 16;
else if (!stricmp(sTemp, "A") || !stricmp(sTemp, "a"))
c = 10 * 16;
else if (!stricmp(sTemp, "B") || !stricmp(sTemp, "b"))
c = 11 * 16;
else if (!stricmp(sTemp, "C") || !stricmp(sTemp, "c"))
c = 12 * 16;
else if (!stricmp(sTemp, "D") || !stricmp(sTemp, "d"))
c = 13 * 16;
else if (!stricmp(sTemp, "E") || !stricmp(sTemp, "e"))
c = 14 * 16;
else if (!stricmp(sTemp, "F") || !stricmp(sTemp, "f"))
c = 15 * 16;
sTemp[0] = sKey[i + 1];
sTemp[1] = 0;
i ++;
if (!stricmp(sTemp, "0") || !stricmp(sTemp, "1") || !stricmp(sTemp, "2") || !stricmp(sTemp, "3") || !stricmp(sTemp, "4") || !stricmp(sTemp, "5") || !stricmp(sTemp, "6") || !stricmp(sTemp, "7") || !stricmp(sTemp, "8") || !stricmp(sTemp, "9"))
c += atol(sTemp);
else if (!stricmp(sTemp, "A") || !stricmp(sTemp, "a"))
c += 10;
else if (!stricmp(sTemp, "B") || !stricmp(sTemp, "b"))
c += 11;
else if (!stricmp(sTemp, "C") || !stricmp(sTemp, "c"))
c += 12;
else if (!stricmp(sTemp, "D") || !stricmp(sTemp, "d"))
c += 13;
else if (!stricmp(sTemp, "E") || !stricmp(sTemp, "e"))
c += 14;
else if (!stricmp(sTemp, "F") || !stricmp(sTemp, "f"))
c += 15;
s2[j] = c;
}
s2[j] = 0;
// pad out the input string to be an even block size
err = demo.strToBlock((char*)compr, comprLen, &buffer, &bufLen);
memmove(key, s2, 32);
demo.init(CBC, key);
// encript the buffer
err = demo.encrypt(buffer, bufLen);
if (err != 0)
return -4;
// encode the crypto buffer so it can pass as a null terminated string
*sOut = ESCencode( (char*)buffer, bufLen);
*lOutlen = strlen(*sOut);
free (buffer);
free (compr);
free (uncompr);
buffer = NULL;
compr = NULL;
uncompr = NULL;
return 1;
}
int test_compress(Byte *compr, uLong *comprLen, Byte *uncompr, uLong uncomprLen)
{
int err;
err = compress(compr, comprLen, (const Bytef*)uncompr, uncomprLen);
// CHECK_ERR(err, "compress");
return err;
}
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
|
|
|
|
|
For every call to calloc() , regardless of the execution path, there needs to be a corresponding call to free() . You do not have that here. For example:
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
if (compr == Z_NULL || uncompr == Z_NULL)
return -2;
uncomprLen = strlen (sIn);
int iResult = test_compress(compr, &comprLen, (Bytef*)sIn, uncomprLen);
if (iResult != 0)
return -3;
Until you can get these type of problems addressed, the symptoms you describe are not surprising.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Why are you doing so many string compares on strings of one byte ? A simple character comparison would be quite a bit faster.
Also - stricmp is a case-insensitive string compare so there is no need to evaluate with both the upper and lower case versions of strings.
Your code could be optimized considerably.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Friends,
I am doing some database work using Visual C++. For the first time i am using 'DataGrid Control'. Problem is that, i am unable to "edit" datagrid text if the query i execuated consists of "joins". Can anyone tell me that how can i overcome this problem. Can you tell me whether "Hierarichal Flex grid is the solution ??
|
|
|
|
|
Last time I checked, JOINs weren't editable.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Friend,
I am doing database work for first time in VC++. There is lots of hardwork involved as compared to Visual Basic. But i feel that i am not following right path. Are "data controls" i am using are good solution, or there is some better solution. Can i insert combo box in the cells of datagrid control or other such controls. If not then how can i make my life easy for doing database programming in Visual C++. Please suggest me the right way to follow ??
|
|
|
|
|
While many ways exist, some better than others, I tend to use ODBC and CDatabase /CRecordset objects. Give this section of CP a try.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I write custom ActiveX controls for an application that has been slow to support ActiveX completely. In fact, only the recent release of the software claims to support the ability to modify and save ActiveX control properties during design time. So, I plopped my custom controls on a form, but no properties.
The application developers informed me that the design tools only look for properties by scanning the "methods" section of a control's type library rather than the "properties" section. Of course, my properties are all listed on "properties" because VC++ 6.0 does this automatically when you add properties via the Class Wizard.
Example: here's what my property looks like:
dispinterface _DMyControl
{
properties:
[id(1)] BSTR Caption;
methods:
[id(DISPID_ABOUTBOX)] void AboutBox();
};
But, here's what the application would prefer:
dispinterface _DMyControl
{
properties:
methods:
[id(0x00000001), propget] BSTR Caption();
[id(0x00000001), propput] void Caption([in] BSTR lpszNewValue);
[id(DISPID_ABOUTBOX)] void AboutBox();
};
My question is: does anyone have information or an opinion on which method is preferrable? I ask because the application developers refuse to support straight "properties" on the grounds that so few controls use this paradigm. I want to know if there is a reason I should conform to using purely methods or if I should push the company to support properties.
Kevin Fournier
SRP Computer Solutions, Inc.
|
|
|
|
|
Pls somebudy give me that,pls don't give any refrence of MS gina stub or MSgina hook i want real gina code
thanks in advance
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
|
Yes,With all due Respect,
sir,
I am including the Smartcard functionality to the login dialog that why i need real source code of MSGINA,as i come to know MS is giving it for free.
thanks
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
ThatsAlok wrote:
...as i come to know MS is giving it for free.
Seems to me that if you knew it was being given away for free (if that is indeed accurate), you'd also know how to obtain it. Yes?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
HI there,
Sorry i late to response to this message, i already got the mSGINA dll code in Visual STudio samples
thanks for Replying
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hello All excel Automation expert,
I'm having trouble closing excel application. It physically closed.. but the TaskManager Process shows the Excel Process is still running.
The program wait for the excel application to be close by user.. it is waiting forever since the Excel process is still running. How to close the excel application totally?
Is there anyway, not closing excel application and waiting for the user to finish formating or whatever he/she has to do with the worksheet then let the user close the excel file (not excel application). As soon as program knows the user just close the excel ( again , not excel application), the program can open new excel file in the same application?
Thank you.
<br />
ReleaseAllDispatch();<br />
WaitForExcelToClose();<br />
<br />
<br />
void CDlg::WaitForExcelToClose()<br />
{<br />
HWND hWnd;<br />
char buf[1024];<br />
hWnd = ::FindWindow(TEXT("XLMain"),NULL);<br />
if(NULL==hWnd)<br />
{<br />
return;<br />
}<br />
<br />
DWORD pid;<br />
DWORD dThread;<br />
DWORD dwReason;<br />
dThread = ::GetWindowThreadProcessId(hWnd,&pid);<br />
HANDLE hProcess;<br />
hProcess = ::OpenProcess(SYNCHRONIZE|PROCESS_ALL_ACCESS,TRUE,pid);<br />
pid = NULL;<br />
dwReason = ::WaitForSingleObject(hProcess,INFINITE);<br />
::CloseHandle(hProcess); <br />
}
<br />
void CDlg::ReleaseAllDispatch(){<br />
range.DetachDispatch(); <br />
pagesetup.DetachDispatch();<br />
sheet.DetachDispatch(); <br />
sheets.DetachDispatch();<br />
book.DetachDispatch(); <br />
app.DetachDispatch();<br />
<br />
book.ReleaseDispatch(); <br />
books.ReleaseDispatch(); <br />
range.ReleaseDispatch(); <br />
pagesetup.ReleaseDispatch(); <br />
sheet.ReleaseDispatch(); <br />
sheets.ReleaseDispatch(); <br />
app.Quit(); <br />
<br />
app=NULL; <br />
pagesetup = NULL;<br />
range = NULL;<br />
book = NULL;<br />
books = NULL;<br />
sheet = NULL;<br />
sheets = NULL;<br />
<br />
CoUninitialize();
}<br />
|
|
|
|
|
pnpfriend wrote:
hWnd = ::FindWindow(TEXT("XLMain"),NULL);
Not a good idea to use FindWindow() as the target window could be in a blocked state, thus rendering your code "dead."
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi Dave,
what should I use? any suggestion?
|
|
|
|
|
Did you use CreateProcess() or ShellExecuteEx() to start Excel?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Then, how am I going to format the excel if I used ShellExecuteEx() or CreateProcess()?
the following way is to open the excel application. If I used ShellExecuteEx() how to get an app object? if I dont have app obj, I can't get workbooks, no workbooks there will not be no workbook, sheets or sheet. I thought about using ShellExecuteEx() but I don't know how to get workbooks back after that. Any suggestion please?
<br />
CApplication app; <br />
<br />
if(!app.CreateDispatch(TEXT("Excel.Application")))<br />
{<br />
AfxMessageBox(TEXT("Could not create Excel Application Object."));<br />
open = false;<br />
}<br />
else<br />
{<br />
app.put_Visible(TRUE);
app.put_WindowState(2);
app.put_UserControl(TRUE);
<br />
books = app.get_Workbooks();
book = books._Open(fileName, covOptional,covOptional, covOptional, covOptional, covOptional, covOptional,covOptional,covOptional,covOptional,covOptional,covOptional,covOptional);
<br />
sheets = book.get_Sheets();<br />
<br />
int numofSheets =(int) sheets.get_Count(); <br />
int index=1;<br />
<br />
<br />
for( index=1;index <= numofSheets;index++)<br />
{<br />
lpDisp = sheets.get_Item(COleVariant ((short)(index)));
ASSERT(lpDisp);<br />
}<br />
}<br />
|
|
|
|
|
pnpfriend wrote:
If I used ShellExecuteEx() how to get an app object?
You couldn't, hence my reason for clarifying exactly how you were starting the Excel application.
When I use automation with any of the Office products or Internet Explorer, I do so with the intent of there being no user interaction. If I wanted user interaction, I would use CreateProcess() or ShellExecuteEx() . What you have here seems to be the need for both automation and user interaction. Is this a fair assessment?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
True.. I need both automation and user interaction to preview the file first then user print the file manually.
It is hard right?
|
|
|
|
|
I have a VC++ 6 MDI application using the conventional MFC Doc/View architecture. At any given time there can be several different views of several different document types open.
I want to be able to programmatically "activate" one of these Views, i.e. if it is hidden by other Views then I want it to become visible, just as if the User clicked on the relevent numbered item in the Windows menu (NB this does work correctly). The specific View that is to be activated does not directly depend on User input, e.g. it could be as a result of a message from another thread.
This seems to be an obvious thing to be able to do yet I cannot make it work. I am inside a message handler within my CMainFrame class; I have a CMyView* to the View I want to activate. MDIActivate(pMyView) seems to do nothing; I can't get CMDIChildWnd::MDIActivate() to work for me.
Perhaps it is something to do with me using the above functions with a CView* not a CWnd*. Can I deduce the latter from the former in a way that will make this work? What else may be wrong?
All assistance appreciated.
|
|
|
|
|