|
Umm - ATL has plenty of classes to help you with that. Have a look at the documentation[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
OK, I'll take a look at the documentation.
Thanks
|
|
|
|
|
Right click on the project in solutions explorer.
Select Add -> Class.
Select ATL -> Simple Object.
Following the wizard that pops up you will be able to add dual interface COM objects.
|
|
|
|
|
I developed a customized PageSetupDlg that has some additional controls including a "Restore Defaults" button. When this button is clicked the current settings for margins, orientation and paper size should be reset to certain default values without closing the dialog box. This is not a problem with margins and orientation but I haven't found a way to handle the dropdown list for paper size, i.e. to find the appropriate list entry that my app must select for the desired paper size. Parsing the text of the entries doesn't seem to be a very safe way.
I think there are at least three possible methods to achieve this but I couldn't get any of them to work:
- simply tell the dialog or list box to "select paper size x by y"
- a safe way to enumerate the paper sizes corresponding with each of the list entries (in the correct order!)
- "refresh" the dialog box with a predefined DEVMODE struct
Grateful for any clues,
hx2000
|
|
|
|
|
|
Does this have anything to do with C++?
|
|
|
|
|
Can anyone teach me how to get the process name from a process ID in C/C++ ?
I have a piece of code in C# which I am porting to C++. In C#, there is Process has .ProcessName so it was easy.
Tried to Google but couldn't find the answer.
Thanks a lot.
|
|
|
|
|
|
Oh, so process name is just the EXE filename ? I thought it was something more "important" then that. Thanks a lot for your help.
|
|
|
|
|
hongheo76 wrote: I thought it was something more "important" then that.
You could have looked at the MSDN documentation for the .NET Process.ProcessName Property[^] where it clearly states:
The ProcessName property holds an executable file name, such as Outlook, that does not include the .exe extension or the path.
Best Wishes,
-David Delaune
|
|
|
|
|
Here is a Class to use:
<br />
#if !defined(AFX_PROCESSNAMETOID_H__4217BFFA_FB96_4DAF_A665_3EF82774CD57__INCLUDED_)<br />
#define AFX_PROCESSNAMETOID_H__4217BFFA_FB96_4DAF_A665_3EF82774CD57__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
class CProcessNametoID <br />
{<br />
public:<br />
CProcessNametoID();<br />
DWORD GetProcessID(char* m_name);<br />
virtual ~CProcessNametoID();<br />
private:<br />
HANDLE m_snapshot;<br />
<br />
};<br />
<br />
#endif // !defined(AFX_PROCESSNAMETOID_H__4217BFFA_FB96_4DAF_A665_3EF82774CD57__INCLUDED_)<br />
<br />
#include "stdafx.h"<br />
#include "ProcessID.h"<br />
#include "ProcessNametoID.h"<br />
#include <Tlhelp32.h><br />
<br />
#ifdef _DEBUG<br />
#undef THIS_FILE<br />
static char THIS_FILE[]=__FILE__;<br />
#define new DEBUG_NEW<br />
#endif<br />
<br />
<br />
CProcessNametoID::CProcessNametoID()<br />
{<br />
this->m_snapshot=NULL;<br />
}<br />
<br />
CProcessNametoID::~CProcessNametoID()<br />
{<br />
<br />
}<br />
<br />
DWORD CProcessNametoID::GetProcessID (char* m_name)<br />
{<br />
DWORD m_pid=0;<br />
bool m_status=false;<br />
PROCESSENTRY32 m_ppe;<br />
::memset(&m_ppe,0,sizeof(PROCESSENTRY32));<br />
m_ppe.dwSize=sizeof(PROCESSENTRY32);<br />
__try<br />
{<br />
this->m_snapshot=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br />
if(this->m_snapshot==NULL)<br />
{<br />
__leave;<br />
}<br />
<br />
m_status=::Process32First(this->m_snapshot ,&m_ppe); <br />
int a=::GetLastError();<br />
while(m_status)<br />
{<br />
char *current;<br />
current=m_ppe.szExeFile;<br />
if(lstrcmpi(m_name,current))<br />
{<br />
m_status=::Process32Next(this->m_snapshot ,&m_ppe);<br />
}<br />
else<br />
{<br />
m_pid=m_ppe.th32ProcessID;<br />
m_status=false;<br />
}<br />
}<br />
}<br />
__finally<br />
{<br />
::CloseHandle (this->m_snapshot);<br />
return m_pid;<br />
}<br />
}<br />
Best Reguards !
|
|
|
|
|
Curious why you'd bother to make a class for this. You could have created the same GetProcessID() function without the class wrapper.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
I have a string represent the time and want to convert into time format...
ex) 135621372
I use strptime but it doesn't work ..
I don't want to use the substring method to get hour, minute, and second separtely. It is because I need to do some calculation for the time
struct tm tm;
if (strptime("135621372", "%H%M%S", &tm) != NULL)
{
// do something....
}
Anyone has an idea on how to do the conversion?
Thank you.
modified on Wednesday, November 11, 2009 3:17 PM
|
|
|
|
|
sugarandcream wrote: I have a string represent the time...
ex) 135621372
Based on what? Seconds/milliseconds since some epoch?
sugarandcream wrote: struct tm tm;
Just to be safe, I'd name your variable something other than tm .
sugarandcream wrote: I use strptime but it doesn't work ..
You failed to indicate what "doesn't work" means. If it's because the function does not exist, see here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
the string just represent a time in hour, minute, second, millisecond
135621372 --> hour is 13, minute is 56, second is 21, millisecond is 372
it doesn't work because "tm" in the if statment returns NULL
|
|
|
|
|
sugarandcream wrote: it doesn't work because "tm" in the if statment returns NULL
Can you step into strptime() to find out why?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I trying using the another string separate by ":"
ex) 13:56:21:372
for the if statement, i use
if (strptime("13:56:21:372", "%H:%M:%S:%f", &tm) != NULL)
this time, it does not return NULL
However, the string that I need to parse does not have any delimiter.
Is there any way to convert a string to time format??
thanks..
|
|
|
|
|
Have you considered something like:
char *szTime = "135621372";
strncpy(szHour, szTime, 2);
strncpy(szMinute, &szTime[2], 2);
strncpy(szSecond, &szTime[4], 2);
strcpy(szMsec, &szTime[6]);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
is that the only way i can do?
since i need to do calculation of the time, such as add and subtract...
for example
time is 001100123 (better way to see is 00:11:00:123)
if I need to subtract an hour from it, the new time is 23:11:00:123
|
|
|
|
|
sugarandcream wrote: is that the only way i can do?
There's more than one way to skin a cat.
sugarandcream wrote: since i need to do calculation of the time, such as add and subtract...
Once you get the time string into a common time structure/format, adding and subtracting is easy.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
In a C++ app I want to send a text message from the main thread to a client thread whose sole job will be to call MessageBox to display the text when it gets a message. Looks like some version of postmessage and getmessage might work, but reading about them seems more confusing than clarifying.
Initially this will be used for exception messages, so the rates would be very, very few, if any, on a given day.
Any suggestions would greatly be appreciated.
Thanks
ak
|
|
|
|
|
Alan Kurlansky wrote: ...client thread whose sole job will be to call MessageBox to display the text when it gets a message.
Not a good idea to do this from a secondary thread. What are you ultimately trying to do?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I want to send a text message from the primary thread to a secondary thread to popup to user, after which they hit ok and the popup text window will disappear. The goal is to not cause the primary thread to halt waiting for the user to click ok, because the primary thread is processing high speed, real time data.
|
|
|
|
|
Alan Kurlansky wrote: The goal is to not cause the primary thread to halt waiting for the user to click ok...
But that's exactly what will happen. The primary thread should handle all user interface items, while the secondary thread should handle all of the data processing stuff.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|