|
You don't have to clarify your variable with the scope operator because you're already inside your class scope:
class myClass
{
static UINT m_myStatic;
void MyFunc(void) { m_myStatic = NULL; }
};
You have to declare the member variable as static in your class definition before it's really static.
The implementation file is correct to initialze m_myStatic at runtime, but NULL is usually used for pointers, not integers, did you mean to use 0 (zero) instead?
-- ian
http://www.ian-space.com/
|
|
|
|
|
I think the problem is that you have to initialize your static variables like you have shown:
<br />
UINT myClass::m_myStatic = NULL;<br />
You can also assign them in member functions with no problems. You don't even need to scope it. But they have to be declared like the above, or else the compiler whines.
Does that make sense?
Even a broken clock is right twice a day.
|
|
|
|
|
Hi Navin thanks for the reply...
I got it working, thanx again!!!
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
1.
Please tell me what’s wrong with my program?
// IDD_DIALOG1 is ID OF Dialog
GetDlgItem(IDD_DIALOG1)->SetWindowText(_T(“The Dialog Caption”);
…..
2.
How can I get the dialog windows pointer?
|
|
|
|
|
Charlady wrote:
GetDlgItem(IDD_DIALOG1)->SetWindowText(_T(“The Dialog Caption”);
Forgive me it this turns out to be wrong as I am just hashing my through dialogs as of late but
Charlady wrote:
GetDlgItem(IDD_DIALOG1)->SetWindowText(_T(“The Dialog Caption”);
return the HANDLE in question. If you wanted it as a pointer I should think you would have no prolem assigned the HANDLE to a pointer. I do hope this helps, as I said... I'm just getting around to learning the nitty gritties of dialogs myself.
-Mel
---------------------------------------------
The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?
|
|
|
|
|
Are you trying to do this within a method the dialog itself? If so, all you have to do is:
SetWindowText(_T("The Dialog Caption"));
If you're trying to do this from somewhere else in your UI, say, modifying a modeless dialog, you've probably got a pointer to the dialog instance, so just call the method on the pointer:
m_pMyDialog->SetWindowText(_T("New Caption"));
Or, if you own it as a class member and not a pointer, use the . (dot) member accessor instead of the pointer one ( -> ).
GetDlgItem() is used to get child item windows of the dialog.
-- ian
http://www.ian-space.com/
|
|
|
|
|
|
GetDlgItem() function uses to get the handle of the controls lying on a dialog. So in this way it can't be used.
You can get the dialog handle by the m_hWnd member variable of the dialog. In the following way
" this->m_hWwn"
C.R.Naik
|
|
|
|
|
Any suggestion for a better piece of code to move the focus to the next control in a dialog box? I am not using rich edits, and I tried some other things without the desired results. Somehow though, I suspect this is not the best way to go about it:
[Edit] I have this edit restricted to six characters but when I try to use the DDV max chars value to contol I get what appears an indexing problem as it moves the focus on the 7th char but that char isn't placed into the next edit which hampers continuity of the user's typing.
<br />
void CRHTC100Dlg::OnChangeId()
{<br />
CString str;<br />
GetDlgItemText(IDC_ID,str);<br />
if ( str.GetLength() == 6)<br />
NextDlgCtrl(); <br />
}
This just seems cumbersome to me and I'm just hoping to find some input that saves me from spending to much time researching as it does work this way.
-Mel
---------------------------------------------
The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?
|
|
|
|
|
What the heck am I doing wrong...?
The control isn't drawing properly when I use the following:
BOOL CEditorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
CFont myFont;
myFont.CreateFont(14, 0, 0, 0, FW_NORMAL,
0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
"Courier New");
CEdit* pControl = (CEdit*)GetDlgItem(IDC_EDIT1);
ASSERT(pControl);
pControl->SetFont(&myFont);
return TRUE;
}
Can you even change a CEdit's font....? Or are you suppose to even...? I need a fixed width font...
I know this is possible cuz notepad lets you do this...and they use the same friggen class...what am I doing wrong...?
Thanx!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
You have to make the CFont object myFont global.
Remove the declaration of myFont in the OnInitDialog function and add it to the dialog header file. The first lines in your dialog header file should read:
class CEditorDlg : public CDialog
{
public:
CEditorDlg(CWnd* pParent = NULL);
CFont myFont;
Try it, it works
-Dominik
|
|
|
|
|
Thanx for the reply...
I figured this out shortly after my post, however i'm not entirely certain why it has to be this way...
I'm assuming it has to do with each time WM_PAINT is called and it refers to some DC object like a font and crashes when the object is destroyed by being locally scoped...??
However this doesn't make sense either cuz I thought all objects were cached inside the DC as one big structure...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi, I'm building an ATL component, and using CodeSleuth, its reporting memory leaks for the following construct.
CProcess
{
bstrEXEPath = SysAllocString(NULL);
}
~CProcess
{
SysFreeString(bstrEXEPath);
}
STDMETHODIMP CProcess::get_EXEPath(BSTR *pVal)
{
CComBSTR tmp = bstrEXEPath;
*pVal = tmp.Detach();
return S_OK;
}
STDMETHODIMP CProcess::put_EXEPath(BSTR newVal)
{
SysFreeString(bstrEXEPath);
bstrEXEPath = newVal;
//SysAllocString(newVal);
return S_OK;
}
WHat is the proper approach I should be using
|
|
|
|
|
If you don't need to even bother with SysAlloc/FreeString . I'm a big fan of STL, so...
#include <string>
using namespace std;
typedef basic_string<TCHAR> tstring;
class CProcess
{
private:
tstring m_strEXEPath;
public:
LPCTSTR path(void) { return m_strEXEPath.c_str(); }
};
STDMETHODIMP CProcess::put_EXEPath(BSTR newVal)
{
USES_CONVERSION;
<br>
m_strEXEPath = BSTR2T(newVal);
<br>
return S_OK;
}
STDMETHODIMP CProcess::get_EXEPath(BSTR* pVal)
{
if (NULL == pVal) return E_POINTER;
*pVal = CComBSTR(m_strEXEPath.c_str()).Detach();
return S_OK;
}
Hope that helps.
-- ian
http://www.ian-space.com/
|
|
|
|
|
Thanks again to those of you who offered thier help with my first image post. Had I not been so tired I would of understood the responses quicker (no worries though, slept on it and was no problem this morning).
I am wondering if anyone knows if there is a way to use the logo that I currently have displayed as an image in the upper right coner of the dialog as a water mark covering the entire dialog area? By that, I was thinking it would look better if all the controls where on top of the company's logo. Basically, can I set the background to an image? Sorry if this sounds like a silly question but the few websites I've helped out with have all used water marks and I think they look a little better and I thought asking here could save me a fair amount of time with my nose poking into the books.
-Mel
---------------------------------------------
The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?
|
|
|
|
|
If I understand you correctly, you could simply create a static control with the bitmap that spreads across the entire dialog, then place your user controls on top of that. You will just need to make sure that the Z-order is in an order that will make your bitmap on the bottom of all of the controls.
You other solution is to load a bitmap into memory, and override the WM_ERASEBKGND message for the dialog. Instead of painting the normal window color, you would blt your bitmap to the background of the dialog.
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!
|
|
|
|
|
Okay, I'll be toying around with that tomorrow (in about 8 hours that is) so I'll drop a line if I get stuck (if you don't mind).
-Mel
---------------------------------------------
The greenest grass is NOT on the other side of the fence, its the grass you take care of. Have you watered your lawn lately?
|
|
|
|
|
I recently converted to MFC from Win32 programming. I need help. In Win32, you load a text file by getting a handle for it, getting it's size, and loading it's text into a text buffer. It doesn't work in MFC, and I would like to avoid CDocument. I am simply trying to keep preferences and other application startup data in text files. Windows says the program wants several Gigabytes of RAM. What is that? It's really strange. Is there a way to avoid CDocument?
-- Steve
|
|
|
|
|
SteveBob wrote:
Is there a way to avoid CDocument?
Sure. Just avoid MFC's Document/View stuff. Or maybe you'd rather use it but implement your own serialization routines (fopen() / fclose() still works BTW...). Or, you could figure out what you're doing wrong (several GB?!?) and fix it... Feel free to post a concise overview of what you're doing when loading / saving, we'll help you out...
Shog9
------
So they took me down to the gallows
And this boy, he said to me:
"Why do you smile, when the rope's around your neck?"
I said, "I tell you boy, when i get back..."
|
|
|
|
|
Well, it patially works:
HANDLE hFile;
hFile = CreateFile("C:\\settings.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, NULL, NULL);
DWORD size;
size = GetFileSize(hFile, NULL);
char *FileText;
FileText = new char[size+1];
DWORD Readd;
ReadFile(hFile, FileText, size+1, &Readd, NULL);
CloseHandle(hFile);
There's still a group of weird characters in the array:
Actual File Text:
Hello
Returns in edit field:
HelloÍýýýý
How do I get those other useless characters off of the array?
-- Steve
|
|
|
|
|
Two points:
1) you need to add a NULL terminator after the last byte read.
2) don't use CreateFile() /ReadFile() /CloseHandle() unless you're doing something very specific that requires them (you aren't). Either be old-fashioned and use fopen() and friends, *really* old fashioned and use open() et. al., or be trendy and cool with iostreams (as CG suggested).
Shog9
------
So they took me down to the gallows
And this boy, he said to me:
"Why do you smile, when the rope's around your neck?"
I said, "I tell you boy, when i get back..."
|
|
|
|
|
You should look into using iostreams, I have articles on CP and it's
a/ standard C++
b/ so much nicer than using ugly HANDLE's all over the place.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
If its just a simple text file you're wanting to read, use the MFC class CStdioFile.
CString filename = _T("txt.txt");
CString tempString;
CStdioFile file;
file.Open(filename,CFile::modeRead|CFile::typeText);
while(file.ReadString(tempString) != NULL)
{
// Do something with your tempString which holds the line of text read from the disk
}
file.Close();
Its the easiest solution when working with txt files and MFC, well as far as I know anyway.
|
|
|
|
|
Hi all!
My purpose: invoke my app from Internet Explorer's context menu, then my app must to connect to IE (IWebBrowser2) events.
Step 1: Implementing script handler:
<script language=javascript>
var oISRC = new ActiveXObject("isrc.Application");
var ieParentWin = external.menuArguments;
oISRC.Initialize(ieParentWin);
</script>
Step 2: Creating handler inside my app:
STDMETHODIMP CIsrcApp::Initialize(VARIANT *vBrowser)
{
LPDISPATCH pDisp = (LPDISPATCH) (variant_t) (*vBrowser);
CComQIPtr<IHTMLWindow2> spWin;
spWin = pDisp;
spWin->alert(bstr_t("Test!"));
spWin->moveBy(100, 100);
return S_OK;
}
Test works. Question: how to obtain IWebBrowser2* from IHTMLWindow2* ??
|
|
|
|
|
after starting a process i get hwnd of its main window by its id but when a process perform some steps it lost its hwnd and new window appear and my previous veriable that have the process hwnd become useless.
i want to always have an active process hwnd?
for that purpose i creat an object of Cwindows and i am using its methods.
is their any way
that i could get all sub process and child window hwnds by its name or id ?
r00d0034@yahoo.com
|
|
|
|