|
just create a "dialog app" from VC's App Wizard.
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Hi,
I'm trying to figure out how to access my document from my main app?
Suppose I have my CMyDocument doc and I have a member varible m_MyDocVar
and let say I want to check the value of this m_MyDocVar from my main app,
how would I get a pointer to the doc and access my variable?
Anyhelp would be greatly appriciated.
|
|
|
|
|
CMainFrame *pMF = (CMainFrame *)AfxGetMainWnd();
CMyDOcType *pDoc = (CMyDOcType *)pMF->GetActiveDocument();
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Works! Thank you!
|
|
|
|
|
hi,
i made a .chm help file.. i've create a command for it in the menu already.. i was wondering how do i load it? do i use shellexecute or is there another command in vc++ 7 that's create for loading .chm file? also, will this .chm file work in win95/98/nt/2000?
thanx in advance.
|
|
|
|
|
The fucntion
HWND HtmlHelp(
HWND hwndCaller,
LPCSTR pszFile,
UINT uCommand,
DWORD dwData) ;
can be used to display .chm files. It's declared in htmlhlp.h. I think it should work on all OS you mentioned (even if I don't really know if you need a IE > 4.0 or anything further)
|
|
|
|
|
hi,
i delcared htmlhelp.h and attempt to run HtmlHelp off one of the event handler, but i kept on getting error message saying that HtmlHelpA doesn't take 4 argument.. i've checked out the documentation on HtmlHelp, but it's not very helpful.. not much information given.. do you know where that i can find a example on hooking up .chm using HtmlHelp function? thx.
|
|
|
|
|
The problem is that both CWinApp and CWnd delcare a HtmlHelp function, too. And this function takes only 2 parameters. So I think you've to call the function as a global one, thus calling ::HtmlHelp.
If you need more information you should have a look at MSDN. There're many examples dealing with this topic.
|
|
|
|
|
Hi guys/gals,
I'm writing a class which has a pair of static ints. Pretty easy, I know...I've done this before, but it's not working right now. I'm getting the linker error for unresolved external symbols. Perhaps you'll have some ideas:
main.cpp
#include<iostream>
#include<fstream>
#include<vector>
#include"job.h"
int main(int argc, char** argv)
{
char *algor = "Recursive", *cacheFile = "testcase1.txt", *schedFile = "schedule.txt";
bool helpFlag = false;
int tempMachPerJob, tempNumOfMach, i;
Job tempJob;
vector<Job> jobs;
ifstream inFile(cacheFile);
if (inFile.fail())
{
cout << "Error opening input file!" << endl;
exit(1);
}
inFile >> tempMachPerJob >> tempNumOfMach;
Job::setMachPerJob(tempMachPerJob);
Job::setNumOfMach(tempNumOfMach);
inFile >> tempJob;
while (inFile)
{
jobs.push_back(tempJob);
inFile >> tempJob;
}
for(i = 0; i < jobs.size(); i++)
cout << jobs[i] << endl;
return 0;
}
job.h
#ifndef JOB_H
#define JOB_H
#include<iostream>
#include<vector>
using namespace std;
class Job
{
private:
static int machPerJob, numOfMach;
int startTime, endTime;
vector<char> machines;
char schedule;
public:
Job();
Job(int, int, vector<char>);
static void setMachPerJob(int);
static int getMachPerJob();
static void setNumOfMach(int);
void setSchedule(char sched);
friend ostream& operator<<(ostream& os, const Job& job);
friend istream& operator>>(istream& is, Job& job);
};
#endif
job.cpp
#include<vector>
#include"job.h"
using namespace std;
Job::Job()
{
startTime = endTime = -1;
schedule = '-';
}
Job::Job(int start, int end, vector<char> mach)
{
startTime = start;
endTime = end;
machines = mach;
schedule = '-';
}
void Job::setMachPerJob(int mpj)
{
machPerJob = mpj;
}
int Job::getMachPerJob()
{
return machPerJob;
}
void Job::setNumOfMach(int nom)
{
numOfMach = nom;
}
void Job::setSchedule(char sched)
{
schedule = sched;
}
ostream& operator << (ostream& os, const Job& job)
{
os << job.startTime << " " << job.endTime << " " << job.schedule;
return os;
}
istream& operator >> (istream& is, Job& job)
{
int start, end;
char tempMach;
is >> start >> end;
job.startTime = start;
job.endTime = end;
for (int i = 0; i < Job::getMachPerJob(); i++)
{
is >> tempMach;
job.machines.push_back(tempMach);
}
return is;
}
|
|
|
|
|
BigDaddyDrew wrote:
I'm getting the linker error for unresolved external symbols
which symbols??
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
The two static variables:
job.obj : error LNK2001: unresolved external symbol "private: static int Job::machPerJob" (?machPerJob@Job@@0HA)
job.obj : error LNK2001: unresolved external symbol "private: static int Job::numOfMach" (?numOfMach@Job@@0HA)
Andrew
|
|
|
|
|
Ooop, nevermind, I fixed it. Forgot to declard them outside of the class.
|
|
|
|
|
|
I think thats what its called. Anyway, I got the open file dialog working. Since I am a lazy bumb I have decided to make the program compatible with all files (that have text). However, I do not know how I would wright the text from the file into the edit box. Could someone help me here? I mainly want it so that it can open a .html or .htm, .c or .cpp, .h, .txt files. How would I do this I have no idea. So could some one either tell me how (prefereable with some example code) or tell me a URL that might help me.
Thanks,
orcblood
|
|
|
|
|
If I understand you right, you want to read text from file and load it into and Edit control.
If it is so then this is sample code for both reading both ANSI and UNICODE text files:
<code>
CFile f;
if(f.open("FILENAME.TXT, CFile::modeRead))
{
DWORD dwFLen = f.GetLength();
//this short will be used to get the file header
USHORT usHeader;
f.Read(&usHeader, sizeof(USHORT));
//UNICODE text files starts with value 0xFEFF
if(usHeader == 0xFEFF)
{
//we are going to load the text into a character array
wchar_t * filetxt;
//allocate a charaters array one for null terminator
filetxt = new wchar_t[dwFLen + 1];
//clear the filetxt array
memset(filetxt, 0, sizeof(wchar_t) * (dwFLen + 1));
f.Read(filetxt, dwFLen);
//use API function rather than MFC to be able
//to read UNICODE and ANSI at the same time
::SetDlgItemTextW(this->GetSafeHwnd(), IDC_EDIT1, filetxt);
}
else
{
//ANSI files does not contain any headers, so we should
//reset the file pointer
f.SeekToBegin();
//we are going to load the text into a character array
char * filetxt;
//allocate a charaters array one for null terminator
filetxt = new char[dwFLen + 1];
//clear the filetxt array
memset(filetxt, 0, sizeof(char) * (dwFLen + 1));
f.Read(filetxt, dwFLen);
//use API function rather than MFC to be able
//to read UNICODE and ANSI at the same time
::SetDlgItemTextA(this->GetSafeHwnd(), IDC_EDIT1, filetxt);
}
f.Close();
}
</code>
|
|
|
|
|
Where about would I place this? Would it be right under the open dailog?
Thanks, I believe that you understood me correctly.
orcblood
|
|
|
|
|
I am sorry there was a little syntax error in the source code I submitted and I fixed it.
The follwoing code shows how to put the file opening code after the file open dialog.
if(openDlg.DoModal() == IDOK)
{
CFile f;
if(f.open(openDlg.GetPathName(), CFile::modeRead))
.
.
.
}
|
|
|
|
|
I was wondering if anyone knew how to do this. I have made several custom dialogs from my resource file but I don't know how to use them. I don't really know the structure for inserting a custom dialog either. So, could anyone tell me?
Thanks,
orcblood
|
|
|
|
|
|
This would work for a normal windows app too, right?
orcblood
|
|
|
|
|
As you seem to be very beginner, maybe you should work your way through the "Scribble Tutorial" found on MSDN[^].
Step 3 of that tutorial gives an excellent explanation of how to add dialogs to an MFC windows application.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
How would i put a bitmap background onto my main frame and child windows?
also how would i stretch it to fit the entire window??
thanks
-perseus
|
|
|
|
|
Perseus wrote:
How would i put a bitmap background onto my main frame and child windows?
I think OnEraseBkgnd() would be the best place to draw a bitmap. Simply implement these methods in your frame and child windows.ö
The stretching could be done by using the function StretchBlt.
|
|
|
|
|
I'm working on an app that hooks the windows procedure for a given window (by using SetWindowLong() to replace the window procedure with my own). I'm unhooking my code during the processing of WM_DESTROY . All is going well for everything except modeless dialogs. For some reason a modeless dialog isn't receiving WM_DESTROY as a result of calling DefWindowProc() for WM_CLOSE .
Just to be sure I wasn't the cause of the issue, I whipped up an quick MFC test app without my code in place. In the app I create a dialog that contains nothing but the default buttons. In it, I put handlers for WM_CLOSE and WM_DESTROY , that look like this:
<br />
void CTestDlg::OnClose() <br />
{<br />
MessageBox( "Close" );<br />
<br />
CDialog::OnClose();<br />
}<br />
<br />
void CTestDlg::OnDestroy() <br />
{<br />
MessageBox( "Destroy" );<br />
CDialog::OnDestroy(); <br />
}<br />
If the dialog is created via DoModal() and I click the close box, everything goes as I'd expect it to. I see a "Close" message box, followed by a "Destroy" message box, and then my dialog disappears from the screen.
If, however, I instead create the dialog via a call to Create() and click the close box, I only see the "Close" message followed by the dialog disappering from the screen.
Just out of curiosity, I tried accessing the dialog after the processing of WM_CLOSE and discovered that the dialog window is still valid. If I call ShowWindow( SW_SHOWNORMAL ) , it returns to the screen and functions as though WM_CLOSE was never sent. For some reason, in the case of a modeless dialog, DefWindowProc() doesn't call DestroyWindow() , as it normally would.
As CDialog doesn't have an OnClose() function and the CWnd handler just passes it to Default() , I presume this behavior is bubbling up out of Windows default processing, but I haven't been able to confirm that to my satisfaction. MSDN documents (under 'Destorying the Dialog Box') that modeless dialog boxes will call DestroyWindow() in response to WM_CLOSE . This, however doesn't appear to be the case.
I've tested my sample app on Win2k and NT 4.0, with the same results.
Calling DestroyWindow() in the OnClose() of the dialog would work regardless of how the dialog was created, but since I'm injecting my code after the fact, not deriving from the dialog, that's not really an option for me.
Has anyone else encountered this / know of a work-around for it?
Dan
|
|
|
|
|
Try undoing the hooking after processing WM_NCDESTROY .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|