|
If you were using a rich edit control instead, you could just stream the data in.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi,
How can i get the path of the file opened, if i know that window handle.Is there any API for this.
Thanks
|
|
|
|
|
revanth1985 wrote: if i know that window handle
you can't find the name of file if you have window/FILE handle.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
If you are asking how to get the filename of an executable by knowing a window handle then this is how you do it. This code will tell you the PID of the executable even if you pass a child handle such as a button handle.
#pragma comment(lib, "psapi")
DWORD dwPID = -1;
BOOL CALLBACK EnumChildWindowsProc(HWND hWnd, LPARAM lParam)
{
if(hWnd == (HWND)lParam)
{
GetWindowThreadProcessId(hWnd,&dwPID);
}
return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
if(hWnd == (HWND)lParam)
{
GetWindowThreadProcessId(hWnd,&dwPID);
}
else
{
EnumChildWindows(hWnd,EnumChildWindowsProc,lParam);
}
return TRUE;
}
BOOL FindWindowProcessModule(HWND Hwnd, TCHAR *szName,size_t iMaxLen)
{
EnumWindows(EnumWindowsProc,(LPARAM)Hwnd);
if(-1 != dwPID)
{
HMODULE hModule = NULL;
DWORD dwNeeded = NULL;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,dwPID);
if (NULL != hProcess)
{
if(EnumProcessModules(hProcess,&hModule,sizeof(hModule),&dwNeeded))
{
GetModuleFileNameEx(hProcess,hModule,szName,iMaxLen);
}
else
{
GetProcessImageFileName(hProcess,szName,iMaxLen);
}
CloseHandle(hProcess);
}
}
return NULL != szName[0];
}
Here is how you would use it:
TCHAR szName[MAX_PATH] = {0};
HWND Hwnd = (HWND)::FindWindow(_T("SciCalc"),_T("Calculator"));
if(FindWindowProcessModule(Hwnd,szName,MAX_PATH))
{
MessageBox(szName);
}
else
{
MessageBox(_T("Calculator is not running."));
}
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
Thanks for your reply.I don't want the path of the executable file,i want the working station of that file(for ex: D:\Work\New Text Document.txt).
|
|
|
|
|
You want the name of the process which has the file opened?
|
|
|
|
|
What i want is if a file is opened from D:\work\New Text Document.txt ,i want to get the path as stated before not the process name notepad.exe or excel.exe or some thing.can you help me out in this.
|
|
|
|
|
You can use function _getcwd(char* buffer,int maxlen) which will give you current directory. I hope this is you are looking for.Following simple code shows you how to use it.
char* buff,buffer[255];
buff = _getcwd(NULL,0);
cout<<buff<<endl;
|
|
|
|
|
SRKSHOME wrote: You can use function _getcwd(char* buffer,int maxlen) which will give you current directory.
How does that even come close to being a helpful answer?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
If you are asking how to find the filename/path from a FILE handle then perhaps the following code will help. Unfortunately it involves usage of some advanced undocumented functions. The following code is for Windows 2000 and above and completely unsupported.
typedef LONG NTSTATUS;
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0 && Status < 0x3FFFFFFF)
typedef struct _IO_STATUS_BLOCK {
union {
NTSTATUS Status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef struct _UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
typedef enum _FILE_INFORMATION_CLASS
{
FileNameInformation=9,
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
typedef struct _FILE_NAME_INFORMATION
{
ULONG FileNameLength;
WCHAR FileName[MAX_PATH];
} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
NTSTATUS (NTAPI *NtQueryInformationFile)(HANDLE,PIO_STATUS_BLOCK,PVOID,LONG,FILE_INFORMATION_CLASS);
CString GetFileNameFromHandle(HANDLE hFile)
{
wchar_t wszFilename[MAX_PATH];
IO_STATUS_BLOCK stb;
FILE_NAME_INFORMATION str;
*(FARPROC*)&NtQueryInformationFile = GetProcAddress(GetModuleHandle(_T("ntdll.dll")),"NtQueryInformationFile");
DWORD Status=NtQueryInformationFile(hFile,&stb,&str,MAX_PATH,FileNameInformation);
return NT_SUCCESS(Status)?CString(str.FileName, str.FileNameLength / sizeof(WCHAR)):NULL;
}
Sample MFC usage:
CFile f;
f.Open(_T("C:\\Test.txt"),CFile::modeRead,0);
HANDLE hFile = f.m_hFile;
MessageBox(GetFileNameFromHandle(hFile));
f.Close();
Best Wishes,
-David Delaune
|
|
|
|
|
#include <cstdlib>
#include <iostream>
//#include<conio>
//#include<math>
//#include<stdio>
#define NumberOfTasks 50 // easy change number of tasks
#define MaxClock 100 // easy change clock interval for tasks to run
#define MaxTaskTime 0.001 // easy change randomazing for tasking
#define NumerOfCPUs 5 // number of multiple pc's used
#define MaxQSize 10
using namespace std;
struct t
{
int id; int runprocess; int duration;
}task[NumberOfTasks];
struct c{
int idle;
int nextideltime;
}cpu[NumerOfCPUs];
struct queue{
// int Qcounter;
// int termcounter;
// int Qcounter==L;
// int empty
// { if (int L=0; Qcounter<maxqsize;l++)>
t task;
}q[MaxQSize];
int main(int argc, char *argv[])
{
int clock=0;
int qindex=0;
int i;
// cpus
for(int ik=0;ik<numerofcpus;ik++)>
{cpu[ik].idle=0;cpu[ik].nextideltime=0;}
// tasks
for(i=0;i<numberoftasks;i++)>
{
task[i].runprocess=int(MaxTaskTime*rand());
cout<<"task:"<< task[i].runprocess << "\n";
}
// system
while(clock<=MaxClock)
{
cout <<"clock:" << clock << endl;
for(int ij=0;ij<numberoftasks;ij++)>
{if(task[i].runprocess==clock)
{}
// if -- for enter the system
} // for -tasks
for(int ik=0;ik<numerofcpus;ik++)>
{if(cpu[ik].nextideltime==clock) cpu[ik].idle=0;
} // for make cpu idle
for(int ik=0;ik<numerofcpus;ik++)>
{if ( cpu[ik].idle==0 && qindex!=0)
{
}
} // for q - enter one task from q to cpu
clock++;
} //while
system("PAUSE");
return EXIT_SUCCESS;
}
here i am suppose to create a queuing and statistics box.. showing how many task get queue or terminated if queue is full... i just don't have any idea how to do that part..
help!!
|
|
|
|
|
The code you've shown is full of syntax errors. Fix those, and make use of the <pre> tags to make it more readable.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
ok leave the code ...i was able to make a working one in C#
just help me in how to make counter which can count how many get queued.. and to make a counter that would count any thing over the queue limit...which would be terminated
an example or reference would be nice
don't mind C++ answer since i just need the idea.. its simple but i can't just grasp that part
thanks for replying
|
|
|
|
|
thanks
i just got it... sooo simple........... )))))) )))
good luck to others, sorry very busy with last sem exams, n major project stuffs or would have tried to help around a little
|
|
|
|
|
Hi I am new VC++. Currently i am java application that will make use of COM(Component Object Model) to get Interface information. Basically I am using a IDispatch interface object to get a pointer to LTypeInfo. And I am using the function 'GetTypeInfo'. The problem is the function returns 'S_OK' but still pTypeInfo (pointer) is null. Can somebody help me out. In which scenario GetTypeInfo will return 'S_OK' but still the pointer will be null.
Following is the code snippet
===================================
ITypeInfo* pTypeInfo;
m_hRet = m_pDisp->GetTypeInfo(0,LOCALE_SYSTEM_DEFAULT,&pTypeInfo);
if(m_hRet!=S_OK || pTypeInfo==NULL)
{
#ifdef DISPDRIVER_DEBUG
_tprintf(_T("GetTypeInfo failed: %x\n"),m_hRet);
#endif
if(pTypeInfo==NULL && m_hRet==S_OK )
MessageBox(NULL, "Error : pTypeInfo is null", "1", MB_OK);
return false;
}
===================================
Please help me,since i am totally stuck at this point. Thanks In advance.
|
|
|
|
|
I want to convert doc/txt file to PDF using C++ win32(Don't want any third party Library) console app.
Final o/p exe should be used as follows.
ConvertDocToPdf.exe source.doc tar.pdf
Thanks & Regards,
|
|
|
|
|
Member 4708266 wrote: Don't want any third party Library
Sounds like you should build your own. It's actually pretty easy once you get your first postscript file put together programmatically and start to understand the Adobe PDF Reference. It takes about 6 months to build a full GDI/GDI+ compatible interface but if you only want text then you can shave off a couple of months since you won't be interested in scraping bitmap information into image resources and the like.
PDF Reference 1.7, Sixth Edition[^]
(I recommend downloading this reference if your going to view it as it tends to download resources as they are needed if you view it online in the IE window) 1000+ pages
Note: Everything you need is in this reference. However, it is very mathematical and not user-friendly at first glance but if you stay your course, it all comes together nicely in a few weeks and you make the most progress (coding-wise) after that. There are not any real support groups unfortunately. Most forums are maintained by people who have built their own products and are trying to get you to give up building your own and use theirs (for a price of course).
|
|
|
|
|
You forgot to point him to the DOC reference, which is equally easy
-Saurabh
|
|
|
|
|
???
|
|
|
|
|
Member 4708266 wrote: Don't want any third party Library
Why the reason for this ? You really want to rewrite everything yourself ?
|
|
|
|
|
Hi everyone, I have been trying to send data through windows messaging from a dialog to a windows service, both of which I have created. I can send data from the service to the dialog fine, I just let OnCopyData handle it. My windows service, with my limited knowledge, doesn't have anything like that, I think. I created a thread in my windows service to look for messages. I know I can't cast the datastructure to a LPARAM or cast back the LPARAM to my datastructure, the code below just shows as an example what I want to do. If there is a way, please let me know. I look forward to be educated by you.
void myMessageThread( VOID *)
{
MSG l_msgMessage;
hWndMain = ::CreateWindow( _T("STATIC"), _T("Sample"), 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
CString c_CopyDataMessage;
l_msgMessage.hwnd = hWndMain;
PCOPYDATASTRUCT l_newdata;
while( GetMessage(&l_msgMessage, hWndMain, 0, 0) !=100 ){
if( l_msgMessage.message == WM_myCopyData ){
l_newdata = (PCOPYDATASTRUCT)l_msgMessage.lParam;
}
TranslateMessage( &l_msgMessage );
DispatchMessage( &l_msgMessage );
}
}
modified on Monday, November 17, 2008 9:30 PM
|
|
|
|
|
*bump*
I know how to use shared memory and named pipes, but I want to know how to do it with Windows Messaging and for a Win 32 console app. Any help would be appreciated, even if its an answer telling me its impossible.
|
|
|
|
|
I have an application that connects to a Sound Level Meter. A new feature request is to be able to provide a live streaming audio of what the instrument is recording. The data coming from the instrument is in a raw PCM format and I request a new packet of data every second.
Right now, I am saving the data into a .wav file by creating a RIFF header based on the channels, bits per sample, and sample rate configured on the instrument and calculating an arbitrary size based on 10 minutes of data. I then start writing each packet of data to the file. My plan was to then start a playback after 5 seconds using the default wave player. So far, nothing has worked. Windows Media Player complains that the file is in use (since I am still writing to it) and Nero complains that the header is invalid (most likely since the size data is not actually correct). I have also tried mciSendString() without success.
I have absolutely no experience with streaming audio so I am not sure I am even going down the correct path. If anyone has any thoughts or suggestions, I would be grateful.
Thanks,
-LG
|
|
|
|
|
Was just looking through Charles Pretzold's "Programming Windows, Fifth Edition" the other day and I noticed a section that dealt with wave form audio. All I've done is compile the example code, which dynamically creates a sine wave of desired frequency and outputs it to the sound-card.
I suppose the only real difference would be the way in which the buffer containing the sound bytes is created.
Hope this link helps. sineWAV.zip
|
|
|
|
|
|