|
kulkarniquiet wrote: Any suggetions?
Does SHELL_PATH.exe open a console window?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Using the resource editor, I set up a menu item to call a function in a message map in a CListView class, but the menu item is greyed out and does nothing when clicked at runtime. The menu item is enabled and I added an event handler. I'm using the document/view architecture, but want to use a CListView to display a list of class objects derived from CObject, not part of the document. As far as I can tell, the message maps are all appropriate, the function to create and display the listview looks ok and the project compiles, links and runs without errors, just the menu item does nothing when clicked and the listview isn't displayed. I'm a beginner with C++/MFC and there's probably something simple I'm overlooking. Anyone have any suggestions? I can include code, but not sure what code to send. Thanks.
|
|
|
|
|
I'm using Visual C++ 6.0 on windows XP. (I'm new to C++/MFC) I want to write code that uses a spin control to increment a floating point value by some delta. When I add a spin control to my dialog window, in the class wizard I get only two choices when the IDC_SPIN (name ID I gave the spin object) is selected in Class Wizard message map - either UDN_DELTAPOS as a message or NM_OUTOFMEMORY message. If I tell class wizard to implement a function with UDN_DELTAPOS message, I get the code generated by the wizard as:
void CEditsDlg::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
That code is called each time the mouse is pressed while on the arrow, but I can't tell whether the up arrow or the down arrow is pressed. So if I use that routine, I don't know whether to increment or decrement a value like I want to.
All I want to do is when someone puts the mouse on the up arrow of the spin control in the dialog window, I want to increment a value. And if they put the mouse on the down arrow of the spin control, it decrements the value. I don't see how to code this.
Thanks ahead of time.
|
|
|
|
|
Kwanalouie wrote: That code is called each time the mouse is pressed while on the arrow, but I can't tell whether the up arrow or the down arrow is pressed. So if I use that routine, I don't know whether to increment or decrement a value like I want to.
The iDelta member of the NMUPDOWN is a signed value - positive for the up, negative for the down.
|
|
|
|
|
From MSDN:
pNMHDR is a long pointer to an NMUPDOWN structure that contains information about the position change.
The iPos member of this structure contains the current position of the control. The iDelta member of the structure is a signed integer that contains the proposed change in position. If the user has clicked the up button, this is a positive value. If the user has clicked the down button, this is a negative value.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have written the below code in the InitInstance method of application class
I have overwridden the dailog behavior by removing ok and cancel button and also by overiding the deafult behavior of esc and return virtual key down messages.
Now the problem is that I want to have control such that the lines after
dlg.DoModal();</ are executed as they are the lines that kill the dialog. he basic requirement to to kill the dialog only when a particular exe is executed. I'm waiting for this process to complete but that line is after DoModal after which the control is not going.
if (!CreateProcess(NULL, <br />
theApp.m_lpCmdLine, <br />
NULL, <br />
NULL, <br />
FALSE, <br />
CREATE_NO_WINDOW, <br />
NULL, <br />
NULL, <br />
&si, <br />
&pi)) <br />
status = GetLastError();<br />
<br />
CProgressActivityDlg dlg;<br />
m_pMainWnd = &dlg;<br />
dlg.DoModal();<br />
<br />
MessageBox(NULL, _T("Before loop"), _T("Test"), MB_OK);<br />
WaitForSingleObject(pi.hProcess, INFINITE);<br />
MessageBox(NULL, _T("Out of loop"), _T("Test"), MB_OK);<br />
<br />
CloseHandle(pi.hProcess);<br />
CloseHandle(pi.hThread);<br />
PostMessageW(dlg.GetSafeHwnd(), WM_CLOSE ,0, 0);<br />
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);<br />
return FALSE;
|
|
|
|
|
tom groezer wrote: I'm waiting for this process to complete but that line is after DoModal after which the control is not going.
This really isn't going to work as designed.
If you insist on using a modal dialog, you'd have to poll for completion
from within the dialog class...not a very good design.
As with any other lengthy process, you should be waiting for completion on another
thread so you don't block the UI thread. If you need the UI to be in a modal state
until completion, there's a variety of ways to design the code. A couple examples:
1) Wrap the waiting worker thread in a modal dialog class. When the thread completes,
it can notify the dialog (with a posted message) and the dialog can close itself.
2) Disable the UI so the user can't do anything during the process (if necessary),
create a modeless dialog, and fire off the worker thread. When the thread completes,
it can notify the UI thread, at which time the UI thread can destroy the modeless dialog
and re-enable the UI.
However you design it, the main point is - blocking the UI thread for any lengthy
process (anything over a few seconds - some would say even less) is bad design, so
lengthy processes should be done on threads separate from the UI thread.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Here's an example of method 1 in my previous post:
IDD_PROCESSWAITER DIALOGEX 0, 0, 193, 50
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
CAPTION "Waiting..."
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CTEXT "Waiting for process to complete...",IDC_STATIC,7,17,179,8
END
#pragma once
class CProcessWaiter : public CDialog
{
DECLARE_DYNAMIC(CProcessWaiter)
CString ProcessPathname;
static UINT __cdecl ProcessCreatorAndWaiterThread(LPVOID pParam);
public:
CProcessWaiter(CWnd* pParent = NULL);
virtual ~CProcessWaiter();
INT_PTR ExecuteProcessAndWait(LPCTSTR pathname);
enum { IDD = IDD_PROCESSWAITER };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
protected:
virtual BOOL OnInitDialog();
virtual void OnOK();
virtual void OnCancel();
afx_msg LRESULT OnThreadComplete(WPARAM wParam, LPARAM lParam);
};
#include "stdafx.h"
#include "ProcessWaiter.h"
#define WMX_THREADCOMPLETE (WM_APP + 42)
IMPLEMENT_DYNAMIC(CProcessWaiter, CDialog)
CProcessWaiter::CProcessWaiter(CWnd* pParent )
: CDialog(CProcessWaiter::IDD, pParent)
{
}
CProcessWaiter::~CProcessWaiter()
{
}
INT_PTR CProcessWaiter::ExecuteProcessAndWait(LPCTSTR pathname)
{
ProcessPathname = pathname;
return DoModal();
}
UINT __cdecl CProcessWaiter::ProcessCreatorAndWaiterThread(LPVOID pParam)
{
CProcessWaiter *pThis = (CProcessWaiter*) pParam;
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
memset(&StartupInfo, 0, sizeof(STARTUPINFO));
StartupInfo.cb = sizeof(STARTUPINFO);
if (0 != ::CreateProcess(pThis->ProcessPathname,
NULL,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&StartupInfo,
&ProcessInfo
))
{
::WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
::CloseHandle(ProcessInfo.hProcess);
::CloseHandle(ProcessInfo.hThread);
}
pThis->PostMessage(WMX_THREADCOMPLETE);
return 0;
}
void CProcessWaiter::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CProcessWaiter, CDialog)
ON_MESSAGE(WMX_THREADCOMPLETE, &CProcessWaiter::OnThreadComplete)
END_MESSAGE_MAP()
BOOL CProcessWaiter::OnInitDialog()
{
CDialog::OnInitDialog();
AfxBeginThread(&CProcessWaiter::ProcessCreatorAndWaiterThread, this);
return TRUE;
}
void CProcessWaiter::OnOK()
{
}
void CProcessWaiter::OnCancel()
{
}
LRESULT CProcessWaiter::OnThreadComplete(WPARAM wParam, LPARAM lParam)
{
EndDialog(0);
return 0;
}
#include "stdafx.h"
#include "ProcessWaiter.h"
...
CProcessWaiter ProcessWaiter(this);
ProcessWaiter.ExecuteProcessAndWait(_T("C:\\Windows\\system32\\notepad.exe"));
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Nice example
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Is it ok to have something like below to be posted. I just wanted to know whether passing WM_CLOSE is good enough as EndDialog();
PostMessage((((CProgressActivityApp*)lpParam)->m_pMainWnd)->GetSafeHwnd(), WM_CLOSE, 0, 0);
|
|
|
|
|
Yes it's ok. The problem is, your code will never get there to post
the message until the dialog closes, which isn't going to happen
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have written the below code in the InitInstance method of application class
I have overwridden the dailog behavior by removing ok and cancel button and also by overiding the deafult behavior of esc and return virtual key down messages.
Now the problem is that I want to have control such that the lines after
dlg.DoModal();</ are executed as they are the lines that kill the dialog. he basic requirement to to kill the dialog only when a particular exe is executed. I'm waiting for this process to complete but that line is after DoModal after which the control is not going.
if (!CreateProcess(NULL, /* No module name (use command line). */
theApp.m_lpCmdLine, /* Command line. */
NULL, /* Process handle not inheritable. */
NULL, /* Thread handle not inheritable. */
FALSE, /* Set handle inheritance to FALSE. */
CREATE_NO_WINDOW, /* Do not display console window */
NULL, /* Use parent's environment block. */
NULL, /* Use parent's starting directory. */
&si, /* Pointer to STARTUPINFO structure. */
&pi)) /* Pointer to PROCESS_INFORMATION structure. */
status = GetLastError();
CProgressActivityDlg dlg;
m_pMainWnd = &dlg;
//INT_PTR nResponse =
dlg.DoModal();
//if (nResponse == IDOK)
//{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
//}
//else if (nResponse == IDCANCEL)
//{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
//}
MessageBox(NULL, _T("Before loop"), _T("Test"), MB_OK);
WaitForSingleObject(pi.hProcess, INFINITE);
MessageBox(NULL, _T("Out of loop"), _T("Test"), MB_OK);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
PostMessageW(dlg.GetSafeHwnd(), WM_CLOSE ,0, 0);
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
AfxGetMainWnd()->PostMessage(WM_CLOSE, 0, 0);
return FALSE;
|
|
|
|
|
Logically, DoModal is going to "freeze" your application till the dialog created is closed with Esc, Ok or another other way. Are you needing NonModal Dialog?
By the way... the lines after, doesn't kill your dialog. The lines after check which value is being returned from the dialog and depending on the value executing one thing or another one.
tom groezer wrote: // TODO: Place code here to handle when the dialog is
// dismissed with OK
When dissmised by OK -> The dialog was already killed before the app starts reading here.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Hey everybody!
I've seen that in vista there is a real good API to work with TPM.
Does anyone know how can I check if there is a TPM on the system on XP (in unmanaged C++)?
Thanks!
|
|
|
|
|
Green Fuze wrote: ...with TPM.
Trusted Platform Module
Transaction Processing Monitor
Transactions Per Minute
Transport Policy Model
???
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Trusted Platform Module.
I should've expected this kind of question
|
|
|
|
|
Hi All,
I writing some application that need to be run like a service but actually the application is not a service.
I want to add to my application some ability to "run always" and take from the user the ability to shutdown the application from the task manager.
I looking for a way to remove the process from the task manager.
Is there is some way to do so ?
Thanks for any help.
|
|
|
|
|
|
In this article - we using simple manipulation on the control SysListView32.
I knew this way to remove the process from the task manager already -
But i looking form some other way to do it - maybe with some win32 API or something like that.
Maybe by changing the running process name with no touching the List View control.
|
|
|
|
|
Of course you know if your user is a programmer he knows other ways to see processes on the memory,but you can lock your process like anti viruses when you want to kill a process that its dependes to anti virus you will be got this error "The Operation not be completed. Acncess is denied.
|
|
|
|
|
1. Can you please explain witch other way ?
2. How can you "lock" some process ? how the anti viruses does it ?
|
|
|
|
|
Except Task manager you can find other programs that monitor resources of system and and you can control your system for example you can kill threads of a program or set min/max working set size of a process.
about second question some years ago I read about it and I forgot it.
|
|
|
|
|
(I'm not an expert in "services")
Can't services be started by "administrator" and/or only be stopped by administrator ?
Me think it's really bad manners to want to hide processes from the users.
|
|
|
|
|
I agree with you that this is "a bad manners" - but do you have other way to avoid killing process in crucial way and loss all your information on the way ?
I will explain ...
I have 2 processes -
1. UI process
2. simple process
(its not question about the design)
In case the second process will be killed ( in any reason ) then the UI process cant be work.
I must avoid the killing of the second process
and again... this not question of design - i just want to know how to protect the second process - and i want to do it by move it from the task manager.
|
|
|
|
|
Yanshof wrote: I agree with you that this is "a bad manners"...
Then why do you insist on doing it? Keeping your process from terminating can get in the way of Windows shutting down gracefully.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|