|
You might find the FindExecutable function useful.
|
|
|
|
|
OK, thanks to all you folks giving me help, I think I have it.
I now use FindExecutable() to get the default program, then CreateProcess() to spawn it:
char *filename = "C:\\src\\IOGuides\\PDF Files\\751018a.pdf";
TCHAR szExe[MAX_PATH];
::FindExecutable(filename, _T(""), szExe);
HANDLE hProcess = NULL;
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;
::ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
::ZeroMemory(&processInfo, sizeof(processInfo));
char cmd[MAX_PATH + MAX_PATH + 5];
sprintf(cmd,"\"%s\" \"%s\"", szExe, filename);
BOOL startedOK = CreateProcess(
NULL,
cmd,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&startupInfo,
&processInfo);
if(!startedOK)
{
ShowLastError(filename);
return;
}
hProcess = processInfo.hProcess;
WaitForInputIdle(hProcess,INFINITE);
I then get the process ID from processInfo.dwProcessId and enumerate all the windows, using GetWindowThreadProcessId() to get the associated process ID.
BOOL CIOGuidesView::enumwndfn(CWnd * wnd)
{
WININFO wininfo(wnd);
wnd->GetWindowText(wininfo.title);
DWORD ProcessId;
GetWindowThreadProcessId (wnd->GetSafeHwnd(), &ProcessId );
wininfo.Pid = ProcessId;
m_WinInfoArray.Add(wininfo);
return TRUE;
}
Comparing processInfo.dwProcessId against the value from GetWindowThreadProcessId() gives me the match-up I needed.
Unfortunately, AcroRd32.exe is cutesy and allows only one instance to run at a time. If I already have the Reader running, the new process just closes down. Presumably after talking to its counterpart and giving the new filename.
Sigh.
I guess I can kill the old one first, but that won't alway work if the user manually started up AcroRd32.
Thanks for all your help. I'll probably make a "beginner" level article showing all of this in the next few weeks since doing this is not so obvious. I suspect the trick in making the article will be coming up with keywords and phrases to allow people to find it when they are looking to do this kind of thing. All the information I needed was in the articles; I just couldn't find it.
Again, many thanks for all of your patience and help. Now my one-day project (now in its fourth day) can be completed.
|
|
|
|
|
I feel like I should know this question, but it seems to me to be harder than I want it too.
Preface: I am working on a windows GUI interface for a embedded system. My boss wants to save off the current state of the system in to a file. However he has laid some requirements on the file format 1) it should be hand editable, 2) other applications should be able to open it, and 3) we don't need to rely on the having an outside application. My boss understands enough about software to be annoying and he is insisting that the file save be ODBC, however I admit I am not familiar enough with it. I do realize that you need to register a datasource and I am not sure how to do this on a different machine. My predecessor wrote the GUI in VB and he saved the file in Access format which was not hand editable.
I have cruised the site here and found some nice demonstrations. I had orginally thought that I would save the file in an Excel format. I noticed it used ODBC and my boss would be pleased. However I began to be concerned that it might fail on machines that don't have excel. We cannot require installation of Excel on a machine to run our GUI.
I think automation solutions I found on Microsofts site will also have this problem. I am not sure how the orginal VB code got around this problem with the Access format file using type libraries. (Not real familiar with those either.)
Does anyone have any advice on what to do and where to find documentation on doing it? I mean I can use ODBC if I can find a way to automate the registration of the data source.. but I need to brush up on this stuff again..
Thanks for any help,
Brian
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|
|
I seem to recall seeing a recent article that addressed creating a .XLS file even if there wasn't an ODBC driver for Excel installed. However, all I can find was the following:
http://www.codeproject.com/database/excel_odbc_write.asp
Try that other site, codeguru.com, too.
|
|
|
|
|
Thanks for the suggestion, but I checked out the "other site" and the articles on Excel. They all require excel ODBC drivers to read and write files.
I need to learn how to automated create ODBC or DAO drivers. I just need a method of letting others use additional software to edit the file outside of the actual GUI program.
I will keep looking...
Brian
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|
|
It depends on how complicated the state information is. Simple options would be:
1. Use ini files (WriteProfileXxxx and GetProfileXxxx)
2. Write csv files. They can be opened in Notepad, Excel, Access etc., etc. Get some code from CP to handle csv files or write your own, it's pretty easy.
3. Use XML. There are several examples on CP of loading and saving configuration to XML. It's not so easy to hand edit (and fairly easy to screw it up) but it can be done.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Phil J Pearson wrote:
. Use XML. There are several examples on CP of loading and saving configuration to XML. It's not so easy to hand edit (and fairly easy to screw it up) but it can be done.
you can use MC++ and DataSet
but then you need to use MC++
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Requirement 3 would seem to limit you to flat ASCII files
that could be viewed/edited in Notepad or Wordpad.
You can then create an ODBC data source that will let you
manipulate the file via ODBC and satisfy that requirement.
Strange though. The requirements seem to have arisen from
different goals: hand editability and independence from
outside application vs. standardization of the interface
allowing substitution in the data source.
|
|
|
|
|
Tell me about it. My boss laid down the requirments at just the right level to be dangerous without exactly knowing what he wants. Now I am just researching what I can actually give and then counter proposal time...
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|
|
Just write to a plain ASCII text file.
It can be edited with notepad, wordpad, UltraEdit, ... you name it.
Then tell your boss that you use something like Online Dirty Binary Conversion (=ODBC) logic (or invent a nice acronym yourself).
Enjoy life, this is not a rehearsal !!!
|
|
|
|
|
I have a CListView where I want to set the top index explicitly.
How can I do that?
/Per
|
|
|
|
|
Here's one way to do it. I'm not sure why MS didn't include a SetTopIndex with the SysListView, but it seems silly...
void CYourListView::SetTopIndex( int p_iDesiredTopIndex )
{
CListCtrl & a_roList = GetListCtrl();
CRect a_oRect( 0, 0, 0, 0 );
a_roList.GetItemRect( 0, &a_oRect, LVIR_BOUNDS );
a_roList.Scroll( CSize( 0, p_iDesiredTopIndex * a_oRect.Height() ) );
}
Chris Richardson
|
|
|
|
|
Hello again,
I have a bunch of dialogs that I use as modals but I want to now bunch them together as child windows in one big dialog. In the process of doing this (without even getting to the make my dialog a child window yet), I am trying to alter the properties of my dialog at run-time. My problem is that when I change the properties by ModifyStyle() and ModifyStyleEx() it behaves (when I click the mouse etc..) as though the properties have changed but it still has the border and title etc. What am I doing wrong?
heres a snippet of the code thats causing the prob. I have tried all sorts of permutations and combinations of ModifyStyle(). It works if I change all the properties in the resource editor..
m_pProjInfoDlg = new CProjInfoDlg(this,m_pDoc);<br />
m_pProjInfoDlg->Create(IDD_PROJINFO,this);<br />
m_pProjInfoDlg->ModifyStyle(WS_POPUP|WS_CAPTION|WS_BORDER|WS_DLGFRAME|WS_THICKFRAME|WS_BORDER,0,SWP_NOACTIVATE);<br />
m_pProjInfoDlg->ShowWindow(SW_SHOW);
help!! Steadily going bananas.
thanks!
Adam.
www.beachwizard.com/travelogue[^]
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
I´m trying to convert a float to a char with the following code:
double Total;
char buffer[50];
Total = GetDouble(dbf, 2) + GetDouble(dbf, 3) + GetDouble(dbf, 4);
_gcvt(Total,10,buffer);
But the result is allways the same, even if the value of Total equals cero.
Can some body help me.
|
|
|
|
|
I think you probably want to be using sprintf(). See MSDN.
Signature space for rent. Apply by email to....
|
|
|
|
|
std::ostringstream could help you.
You can stream almost anything into it using operator<< and get the text using the ostringstream s str() function.
|
|
|
|
|
I have tried to test an application i have found into microsoft support, it's Q186120: "Use MFC to automate excel and fill a range with an array"
I have a problem when i try to run it at the following line:
saRet.PutElement(index, &d);
or
saRet.PutElement(index, v.bstrVal);
(it depends on checkbox is false or true)
when i try to debug it tell me that there's a problem in the function AfxCallWndProc.
So, i would like if someone have tested this application and if he could tell me what could be wrong?
thanks in advance
gerald
|
|
|
|
|
hey, in my program when someone hits the update button, it used to update but the UI would not respond etc. so i use a thread and it works good, but i set the waitcursor before i start the thread but it never stays up, any ideas on how to keep the curors as the wait cursor?
i have have this when the button is pushed:
CWinApp *pApp = (CWinApp*) AfxGetApp();
pApp->DoWaitCursor(true);
AfxBeginThread(startThread, this);
then when the thread is done it posts a message and then i set the cursor back to normal, but the cursor never changes, hope someone can help.
Also how do i go about making a button on the toolbar disabled?
thnkas
luke.
|
|
|
|
|
You will need to create an OnSetCursor handler for your main window that wants to set the wait cursor. You will want to create a variable that holds the current state that the cursor should be in. Then in your OnSetCursor function you should call ::SetCursor();
The reason that you need to do it this way is that every time you move the cursor over your window, a mouse message is generated, then a WM_NCHITTEST message is generated from that, and the WM_SETCURSOR message is then called to allow the mouse cursor to be updated when you move the cursor over the different regions in your window.
DoWaitCursor is only meant for a single function call, or single message handler where the operation could take a long time. However it does not work across message handling boundaries for the reason that I explained above.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
And its confounding me...
I have an array Arr in which I stored the values of 1 row of a database, and the size of this is the number of fields n. Now I want to send this off to a function in a parameter list like
myFunc(Arr[0], Arr[1], Arr[2],....,Arr[n-1])
I cant do a for n =0, n++ type loop since I need them all at once> So what is the way to go here?
Appreciate your help,
ns
|
|
|
|
|
why can't you just pass in the entire array to myFunc? Seems like that what you want....
Just trying to keep the forces of entropy at bay
|
|
|
|
|
The function demands that the parameters be fed in as I showed....I cant change that. Otherwise your idea is great!
Appreciate your help,
ns
|
|
|
|
|
does the function takes a limited or variable number of parameters?
i mean is it like printf ??
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Nope, fixed number of variables
Appreciate your help,
ns
|
|
|
|
|
you could change it from this
myFunc(Arr[0], Arr[1], Arr[2],....,Arr[n-1])
to this
i=0 ;<br />
myFunc(Arr[i], Arr[++i], Arr[++i],....,Arr[++i])
I'm new here, pardon the n00bing
|
|
|
|
|