|
If you manually call OnSize() from your OnInitDialog() (or OnCreate() ) method, then they will be positioned correctly after they've been created in their initial positions.
To have them created initially in the correct place, either have them placed correctly in your dialog template, or create the controls in code instead of on a dialog template.
Shog9
nightdrivin'withoutheadlights...
|
|
|
|
|
I tried calling OnSize()manually from within my OnInitDialog() handler - both before and after CDialog::OnInitDialog() was called with the following:
BOOL CPeriodicTableDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
Table.InitGroups();
Table.InitElements();
m_SliderRed.SetRange (0, 255, TRUE);
m_SliderGreen.SetRange(0, 255, TRUE);
m_SliderBlue.SetRange (0, 255, TRUE);
m_GroupList.SetCurSel(0);
SetSliderPositions();
SetSliderValueText();
CRect r;
GetWindowRect(&r);
OnSize(SIZE_RESTORED, r.Width(), r.Height());
return TRUE;
}
and the app hangs. No errors, just an endless loop that I have to terminate with the Task Manager.
|
|
|
|
|
That's odd... Can you break into the debugger and see where it's hanging?
Oh, one thing - donno if this is it or not, but you don't need to call CDialog::OnSize() from within your handler - normally it does nothing useful, but in this case it may call Default() or something similar (can't remember of the top of my head) which could have unwanted results.
Shog9
nightdrivin'withoutheadlights...
|
|
|
|
|
I think the reason it happened is that, child controls are created after the parent window(your dialog) is created.
As soon as your dialog is created it will be sized to the initial dimensions thus a call to CDlg::OnSize() is issued right away. However, at this moment the child control has not been created yet, so you get an assertion falilure when you try to move that control since it's not a window yet. I think you should add a verification if (::IsWindow(m_ListBox.m_hWnd)) before calling m_ListBox.MoveWindow() and you should be OK.
|
|
|
|
|
Though the other answers give methods that will work and might be safer, I have always just checked the values of cx and cy. i.e.
void CDlg::OnSize(UINT nType, int cx, int cy) <br />
{<br />
if ( cx > 0 || cy > 0 )<br />
{<br />
m_ListBox.MoveWindow(10, 10, 50, 50, TRUE);<br />
}<br />
CDialog::OnSize(nType, cx, cy);<br />
}
which also does the trick.
|
|
|
|
|
Is there a way to free memory from struct?
|
|
|
|
|
Not sure what your asking...
If you allocated memory with "new", then use "delete" and set the pointer to NULL. If you did it with "malloc", then use "free" and set the pointer.
What you could do, is create a destructor for a struct and clean up there.
Example:
struct Stuff
{
Stuff() { p = NULL, i = 0; }
~Stuff() { delete [] p; p = NULL; }
int i;
char* p;
};
using:
{
Stuff x;
x.p = new char[10];
ASSERT( x.p );
x.i = 10;
< other usage >
} // cleanup, item will be destroyed.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
I just recently got back into C++ been a few years since I have done anyhting with C++ due to RL issues. I bought the book "C++ from the ground up" and it is using features I have never used before or seen and says these are now standard C++ features. So i googled and found that Visual Studio C++ does not work well at all with this new(to me atleast) standard. I was wondering if there is a update to Visual C++ to make it compliant with the standard C++ as that is what I want to learn. Oh I almost forgot I have version 6.0. All i have found is that it is all fixed in .net. Just trying to find out if there is a update to make it compliant with standard C++ features.
RanBlade
aka Eric Ranaldi
"Passion is what drive you to stay until 4am ficing that minor bug that hardly anyone would notice...Passion is where great games come from. If you don'l live and breath games, you shouldn't be in the gaming industry" - Dave Pottinger, Ensemble Studios
|
|
|
|
|
Not that I'm aware of. I'd love to see it but it ain't never going to happen.
MS only recently gave a rat's ass about C++ standards compliance recently and took onboard several high-profile C++ gurus.
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.2 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
So what compiler would you recommend to go with standard C++???
RanBlade
aka Eric Ranaldi
"Passion is what drive you to stay until 4am ficing that minor bug that hardly anyone would notice...Passion is where great games come from. If you don'l live and breath games, you shouldn't be in the gaming industry" - Dave Pottinger, Ensemble Studios
|
|
|
|
|
Is Visual C++.net compliant with Standard C++? or any of them ?
RanBlade
aka Eric Ranaldi
"Passion is what drive you to stay until 4am ficing that minor bug that hardly anyone would notice...Passion is where great games come from. If you don'l live and breath games, you shouldn't be in the gaming industry" - Dave Pottinger, Ensemble Studios
|
|
|
|
|
There are no 100%-compliant compilers, it's just a question of degree. VC7 is supposed to be significantly better than VC6 (which is not hard to do ).
If you Google around, there are comparative reviews. The C++ Users Journal usually has good ones.
"Sucks less" isn't progress - Kent Beck [^]
Awasu 1.1.2 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
Visual C++ 7.1 is one of the most C++ standard compliant compilers available. It still lacks some of the more esoteric features, but the odds of you finding that to be a problem is extremely slim (moreover, most compilers aren't compliant with these features.)
Incidentally, VC++ 6.0 was fairly compliant. It did have problems with some template specifications like partial specialization, but it was still more compliant than many alternatives, all claims to the contrary.
In the meantime, it will take a while of learning C++ before you start stumbling with those parts of VC++ 6.0 that aren't compliant with the standard. Then you can move to VC++ 7.1. And if you want a compiler that is 100% compliant, forget it, one doesn't exist.
Joe Woodbury
When all else fails, there's always delusion.
- Conan O'Brien
|
|
|
|
|
Hello everyone
I'll try to explain what I want my program to do.
I'll use another program to make it easier to understand, let's say Microsoft Word.
So I minimize Microsoft Word and then run my program. Microsoft Word is running, but not active.
What I'd want my program to do, is to keep sending message strings to microsoft word.... let's say
hello [10 second pause]
world [10 second pause]
hello [10 second pause]
world [10 second pause]
and so on, while Microsoft Word is still minimized. And the program would stop sending strings to Microsoft Word until it's either stopped or paused.
Can anyone tell me how I could do this?
Thanks a lot,
~Michael
|
|
|
|
|
Lets see, how do I explain this. I need to read in a char and a double for each struct and print out its binary representation within that struct. For some reason when I read in the char and double for each struct all at once (like it is coded below) the binary representation gets messed up. If I only read in for one struct it seems to print out the binary rep. just fine, whether or not packed or unpacked.
There seems to be a memory problem when reading from all the structs at once.
Maybe one of you more experienced programmers can make some sense of this code and what might be the problem with printing out the binaries like they should be.
Thank you all for you help.
#include <stdio.h>
typedef unsigned int DWORD32;
#pragma pack(push,4)
typedef struct
{
char i;
double x;
}unPacked;
#pragma pack(pop)
typedef struct {
char i;
double x;
}packed_structure_t;
typedef struct
{
DWORD32
i :8,
x :23;
}bitField32;
void PrintBits(int size, unsigned char *bytes)
{
int j=0;
int on = 1;
int off = 0;
int t;
char *b = ((char *) &bytes);
int i;
for (i=0; i<size; ++i)
{
printf("\nByte%d ",j++);
for(t=7; t>=0; --t)
if(bytes[i] & (1 << t))
printf("%d",on);
else
printf("%d",off);
}
printf("\n\n");
}
int main(int argc, char *argv[])
{
bitField32 s;
unPacked n;
packed_structure_t p;
for(;;) {
int i;
double x;
printf("\n");
printf("Type in an int and a double: ");
scanf(" %d %lf", &i, &x);
printf("\n");
p.i=i;
p.x=x;
printf("Packed binary representation of a structure:\n");
PrintBits(sizeof(p),(unsigned char*)&p);
n.i=i;
n.x=x;
printf("Unpacked binary representation of a structure:\n");
PrintBits(sizeof(n),(unsigned char*)&n);
s.i=i;
s.x=x;
printf("Bit Field representation of a structure:\n");
PrintBits(sizeof(s),(unsigned char*)&s);
}
}
|
|
|
|
|
A double is 64 bits. A float is 32 bits.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
Yes, a double is 64 and a float is 32. And...?
|
|
|
|
|
Your bitfield is too small.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
Hi !
I have a small MFC SDI application, with "App -> Frame Window -> Form View" structure. Now, Form View has a member - a modeless dialog object. When the form view is created, it creates the modeless dialog, use it's controls, get stuff from there and so on.. Everything works fine..
But then, the PROBLEM
How can I access this very same modeless dialog from the Frame Window's level ? The modeless dialog is a child window of the Frame Window, but I have no clue about it's ID, which would be needed for CWnd::GetDescendant. I used the CDialog::Create with a resource ID to construct the dialog in the first place. So couldn't specify an ID there either.. Any clues on finding it ?
Greets,
Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Note to self: "Experiment more before asking"
FindWindow was the answer. Although it's a bit "odd" way of doing it, it works. Accompanied with a test to 'IsChild', and sure match is made.
-Antti
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I have the following code to draw something:
void pteTable::Draw(CPaintDC* dc)<br />
{<br />
CBrush Brush;<br />
CBrush* OldBrush;<br />
<br />
Brush.CreateSolidBrush(RGB(0, 0, 0)); <br />
<br />
OldBrush = (CBrush*)dc->SelectObject(Brush);
<br />
dc->Rectangle(1, 1, 100, 100);<br />
<br />
dc.SelectObject(OldBrush);
Brush.DeleteObject();<br />
}
I have simply commented out the line where it crashes and stressed it by calling this function hundreds of times and my resource indicator doesn't show me losing any available resources.
Is it safe to simply not select the old brush back into the CPaintDC?
If not, does anyone know why this code is crashing?
The debugger showed that OldBrush was not NULL.
|
|
|
|
|
How does it crash? Have you traced into the MFC code to see where exactly it's happening?
BTW, I recommend you use dc->FillRect (or even FillSolidRect if you just need a black box) instead of Rectangle. If I remember correctly, FillRect is much faster and it doesn't need you to call SelectObject.
Regards,
Alvaro
Can I ask you a question?
|
|
|
|
|
It crashes in afxwin1.inl :
_AFXWIN_INLINE HGDIOBJ CGdiObject::GetSafeHandle() const<br />
{ return this == NULL ? NULL : m_hObject; }
I need to use Rectangle because need the border around the rectangle. All of my CGDIObjects are crashing when I try to restore the old objects (CFont). I just showed you the smallest piece of code that still produces the unhandled exception.
I am passing the function a CPaintDC* from within the OnPaint handler.
Does the fact that it is a CPaintDC mean I don't need to restore the old CGDIObjects?
I indicated in a comment on my first post the exact line where it is crashing. It is crashing when I try to restore the old CBrush.
Is it because the old CBrush was declared as CBrush* but never initialized with CreateSolidBrush?
I didn't think I needed to do that since it's value would be assigned by the return value of dc->SelectObject(NewBrush).
Everything is working fine, but I have a nagging feeling that something isn't right.
|
|
|
|
|
|
That did it. I made the assumption that because the SelectObject took my CBrush without complaining that all was OK. WHen I was looking at it (the actual brushes are in an array) I was somehow thinking that they were being treated as pointers because they were array elements. I know - dumb. But I have been up 38+hours and everytime I looked at it I saw a CBrush* because I was thinking of the array and not its array elements:
CBrush GroupBrushes[NUM_GROUPS];<br />
CBrush* OldBrush;<br />
<br />
for(int x = 0; x < NUM_GROUPS; x++)<br />
GroupBrushes[x].CreateSolidBrush(GetGroupBGColor(x)); <br />
<br />
for(x = 0; x < NUM_ELEMENTS; x++)<br />
{<br />
OldBrush = (CBrush*)dc->SelectObject(GroupBrushes[Elements[x].GetGroupNumber()]);<br />
<br />
dc->Rectangle(<br />
((Elements[x].GetColumn() - 1) * CellWidth) + TableBorderWidth, <br />
((Elements[x].GetRow() - 1) * CellWidth) + TableBorderWidth, <br />
((Elements[x].GetColumn() - 1) * CellWidth) + CellWidth + TableBorderWidth, <br />
((Elements[x].GetRow() - 1) * CellWidth) + CellWidth + TableBorderWidth);<br />
<br />
dc->SelectObject(OldBrush);<br />
}
I just added the & where appropriate and all is good in the world now.
|
|
|
|