|
How do I close a program that I have launched using ShellExecute()
I get an HINSTANCE back
can I use this object to close the program
?
Thanx in advance
Alfadhly
|
|
|
|
|
If you really start an EXE, use <a href="http://msdn.microsoft.com/library/psdk/winbase/prothred_9dpv.htm">::CreateProcess()</a> .
You can then e.g. wait for the program to finish and surely there is a way of getting the window-handle somehow to ::SendMessage() or ::PostMessage() a shutdown-request (WM_CLOSE or something like that).
|
|
|
|
|
Try with this code:
(then you may post a WM_QUIT message to that window)
// start an application given its full path
// and gets the main window, which is initially hidden
// NULL if some errors occurred or
// main window could not be determined
HWND StartApp(LPCTSTR path);
#define TIMEOUT 20*1000
struct ProcessWindow
{
DWORD processID;
DWORD threadID;
HWND hwnd;
};
static BOOL CALLBACK EnumWindowsProc(
HWND hwnd, // handle to the window
ProcessWindow *lParam // application-defined value
)
{
DWORD processID = NULL;
DWORD threadID = GetWindowThreadProcessId(hwnd, &processID);
if (processID == lParam->processID && threadID == lParam->threadID)
{
lParam->hwnd = hwnd;
return FALSE; // stop enum
}
return TRUE;
}
HWND StartApp(LPCTSTR path)
{
STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pi;
TCHAR buf[MAX_PATH];
lstrcpyn(buf, path, MAX_PATH);
if (!CreateProcess(NULL, buf, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE |
NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
return NULL;
if(WaitForInputIdle(pi.hProcess, TIMEOUT) != 0)
return NULL;
// get the main window
ProcessWindow pw;
pw.hwnd = NULL;
pw.processID = pi.dwProcessId;
pw.threadID = pi.dwThreadId;
if (EnumWindows((WNDENUMPROC)EnumWindowsProc, (LPARAM)(LPVOID)&pw))
return NULL;
return pw.hwnd;
}
|
|
|
|
|
use FindWindow() to obtain a handle to the window that you just launched. For instance, I have a program that opens a text file called help in Notepad:
HWND foundWindow;
foundWindow = FindWindow(NULL, "Help - Notepad");
//FindWindow returns a handle for your window,
//if it is found.
PostMessage(foundWindow, WM_DESTROY, NULL, NULL);
//now send the window that we just found a destroy message
there you go.
|
|
|
|
|
How can I change function "On Top" for a dialog from meny or a button.
|
|
|
|
|
To make the dialog always-on-top:
SetWindowPos ( hwndDialog, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
To make it no longer always-on-top, change HWND_TOPMOST to HWND_NOTOPMOST.
|
|
|
|
|
How do i get my cformviews to be centered in the CMainFrame ???
I've tried to put a routine in PreCreateWindow but that didn't work ???
If anyone has any suggestion please let me know
Thanx in advance
|
|
|
|
|
You should use a layout manager (see the Dialogs section here at codeproject) to move the controls when the view is resized.
It is also possible to resize some of the controls with the view.
|
|
|
|
|
In OnInitalUpdate just call CenterWindow();
|
|
|
|
|
>In OnInitialUpdate just call CenterWindow();
That might just work... for an MDI child window, not a SDI view!!
Yours,
Brian Hart
|
|
|
|
|
Hi folks,
I am writting a program that Encrypts/Decrypts files (using CFile). It works fine when I do Text files, but when I do an .exe (Decrypting), it puts a different char?? could this have to do with the way I'm reading in the File (mode)?
I have tried using it in Binary Mode and still the same!
NOTE: All of the characters (placement) are correct, its just that in the .exe there is NOT all of the little rectangular chars...its empty (visually) space (see below).
===========================================================
MZÿÿ¸@躴 Í!¸LÍ!This program cannot be run in DOS mode.
===========================================================
Here is some code:
// Open the file to be read
if( cfEnFile.Open( LPCTSTR(csFileName), CFile::modeReadWrite | CFile::typeBinary, &e ) ) {
// Get the length of the file
DWORD dwSize = cfEnFile.GetLength();
cfEnFile.SeekToBegin();
// fill the buffer with the information from file
UINT nBytesRead = cfEnFile.Read( szBufRead, (UINT)dwSize); //(UINT) dwSize );
...
...
...
for (int n=0; n<(int)nBytesRead; n++) {
CString csEnByte = szBufRead[n];
m_AESCrypt.TransformString(csRegUPPRead, csEnByte);
csBufBytes += csEnByte;
}
sprintf(szBufWrite, "%s", csBufBytes);
cfEnFile.SeekToBegin();
// Write the buffer to the file
cfEnFile.Write( szBufWrite, (UINT)dwSize);
}
Is there anyone who can help!!!!!
Thanks in advance!
Dan
|
|
|
|
|
Since you indicate that it works with TEXT files but not EXE files, likely there is a 7 bit character dependancy within your code. However I can not see that from the code that you have posted. Possibly something within the 'TransformString' method is not dealing with the 8th bit correctly.
HTH.
|
|
|
|
|
Hey Dan,
Not to burst your bubble or anything, but posting an encryption hash algorithm with full commenting to the Web is not going to make your program very secure.
(Or I suppose you trust us fellow programmers!) Anyway, I suppose it won't hurt, since this cryptography scheme is already published in "Applied Cryptography."
Brian Hart
|
|
|
|
|
in my program, i call a stored procedure in a SQL 7.0 database by executing an ADO command object, everything
goes well and the recordset is returned correctlly,but
i just could not update the recordset using PutCollect
method and the error complains that the provider dose
not surport the operation.
maybe someone can give me help.
|
|
|
|
|
Is there any way of printing an adobe pdf file using visual c++ 5.0 or higher?
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Erich J. Ruth (an overworked graduate student)
|
|
|
|
|
Do a ShellExecute() on the PDF file, passing a verb of "print".
|
|
|
|
|
Mike,
Thank you for your reply. I can print a pdf file. Is there any way I can print text on top of the printed pdf file? That is, the user will input certain information. I want to print that information on top of the printed pdf file as it is printing. Is this possible?
Please, please, any response you can give me will be greatly appreciated. Details are cherished.
Sincerely,
Erich J. Ruth (an overworked graduate student)
|
|
|
|
|
hmm... That sounds like it'd be tricky. Since Acrobat (or the reader) does the printing all on its own, you'd have to modify the PDF file or something for your idea to work.
Either that, or tell the user to reinsert the paper the PDF gets printed on so you can print your own text.
|
|
|
|
|
Erich,
I don't know if this is going to help you, but I noticed on http://www.activepdf.com that they offer .pdf construction and manipulation tools. I was looking at them from the ASP component (server side) perspective, but I'm sure they would have stuff you could use on the client side too. Maybe you should check them out.
|
|
|
|
|
Check out http://www.planetpdf.com . There are a lot of libraries for manipulating PDF files.
|
|
|
|
|
Can anyone recommend a class which will write to both a Windows 95 and a Windows 98 registry?
|
|
|
|
|
CRegKey in ATL.
This article: http://www.codeproject.com/system/chklm.asp
Other registry articles here and over at CodeGuru.
|
|
|
|
|
Hi
I`m in trouble with setting a bitmap in any row I want in ClistCtrl.
I have no problem to make a ImageList, but it put the same bitmap
in every row. I need to put any bitmap in any row I want.
The CListCtrl was made by MFC-Wizzard.
Can anybody help me ?
thanks,
Sascha
|
|
|
|
|
Post your code related to SetImage and imageList
|
|
|
|
|
I'm not sure, but I think that if you don't set an image explicitly for an item it gets the first from the imagelist.
Be sure to pass LVIF_IMAGE to SetItem in the 'mask' argument only for those items you want to have images.
I have no other ideas.
|
|
|
|