April 26, 2024, 06:36:25 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dialog problem

Started by Bruce Peaslee, September 01, 2006, 01:23:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

I have a dialog with lots of rich edit controls that are populated by data from a file. It appears to work, but when I close it [X] it goes "thump" (the low level beep) and then the program crashes if I try to reopen the dialog.

I can't find the error. Before I have to post my project, does anyone have any suggestions?

Thanks.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

J B Wood (Zumwalt)

This is common when you have an object that is not cleaned up before you close your application.
Normally everything is destroyed, but on the minor occasion you have to null items yourself.
If you have custom items in your application, make sure you null them before trying to close your application, do your own garbage collection as it were.

I have ran across this in the 3d coding I am doing, and by destroying things myself, I avoid this issue.
Look at your instansiated objects.

Bruce Peaslee

I have no custom items, just a dialog.

If I call the dialog with DoModal(), this message box does not appear when I click the close button and I get the low beep.


MapDialog::OnClose(), int
{
ÂÃ,  MessageBox(0,"Close?","",0);
ÂÃ,  CloseDialog(1);
ÂÃ,  return false;
}


If I use ShowDialog, the message box does appear and there is no beep.

In either event, the program crashes when I try to reopen the dialog.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

I'd need to see more code of course ;).

Ionic Wind Support Team

Ionic Wind Support Team

Also if you create a debug executable and run it in debug mode you and at least tell where it is crashing when you try and reopen it.
Ionic Wind Support Team

Bruce Peaslee

Here is the code. It won't compile as is. Let me know if you need the whole thing zipped.

#AutoDefine "Off"
#include "cds_WinConstants.inc"
#include "cds_winAPI.inc"
#include "webbrowser.inc"
#include "structs.inc"

// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, STRUCTURESÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  *
// *****************************************************************************

struct LOTSTRUCTURE
{
intÂÃ,  ÂÃ,  ÂÃ, nLotNo; // lot number 1-133
intÂÃ,  ÂÃ,  ÂÃ, x; // x-coordinate of upper left corner of lot
intÂÃ,  ÂÃ,  ÂÃ, y; // y-coordinate of upper left corner of lot
intÂÃ,  ÂÃ,  ÂÃ, width; // 100 or 200, depending on orientation of lot
intÂÃ,  ÂÃ,  ÂÃ, height; // 100 or 200, depending on orientation of lot
stringÂÃ,  sPlan; // which of four floor plans
intÂÃ,  ÂÃ,  ÂÃ, bRented; // is it rented out?
intÂÃ,  ÂÃ,  ÂÃ, bForSale; // is it for sale?
floatÂÃ,  ÂÃ, fBasePrice; // what was the base price?
floatÂÃ,  ÂÃ, fUpgradePrice; // how much in upgrades?
floatÂÃ,  ÂÃ, fAskingPrice; // if for sale, what is the asking price?
stringÂÃ,  sOwner1; // who is the primary owner?
stringÂÃ,  sOwner2; // who is the second owner?
stringÂÃ,  sWorkPhone; // primary owner's work phone
stringÂÃ,  sCellPhone; // primary owner's cell phone
stringÂÃ,  sHomePhone; // primary owner's home phone
stringÂÃ,  sEmail1; // primary owner's email
stringÂÃ,  sEmail2; // second owner's email
stringÂÃ,  sAddress; // lot address
dstring sNote[2000];
}

// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  GLOBALSÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  *
// *****************************************************************************

const NUMBER_OF_LOTS = 133;
LOTSTRUCTURE Lot[NUMBER_OF_LOTS];

// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  CLASSESÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  *
// *****************************************************************************

class MapDialog:CDialog //------------------------------------ MapDialog:CDialog
{
// overridden methods
declare OnClose(), int;
declare OnHScroll(int nCommand, int nPos, int nID), int;
declare OnInitDialog(), int;
declare OnLButtonDown(int x, int y, int flags), int;
declare OnVScroll(int nCommand, int nPos, int nID), int;
}

MapDialog::OnClose(), int
{
MessageBox(0,"Close?","",0);
CloseDialog(1);
return false;
}

MapDialog::OnHScroll(int nCommand, int nPos, int nID), int
{
int nMaxPos;
int nMinPos;
int nOffset;

select nCommand
{
case SBTHUMBTRACK:
nOffset = GetSBPos(ASBS_HORIZ) - nPos;
SetSBPos(ASBS_HORIZ, nPos);
ScrollWindow(this->m_hwnd,nOffset,0,null,null);

case SBLINELEFT:
GetSBRange(ASBS_HORIZ, nMinPos, nMaxPos);
if (GetSBPos(ASBS_HORIZ) == nMinPos) return true; // already at left edge
nPos = GetSBPos(ASBS_HORIZ) - 100;
if (nPos < nMinPos) nPos = nMinPos; // moving to left edge
nOffset = GetSBPos(ASBS_HORIZ) - nPos;
SetSBPos(ASBS_HORIZ, nPos);
ScrollWindow(this->m_hwnd,nOffset,0,null,null);

case SBLINERIGHT:
GetSBRange(ASBS_HORIZ, nMinPos, nMaxPos);
if (GetSBPos(ASBS_HORIZ) == nMaxPos) return true; // already at right edge
nPos = GetSBPos(ASBS_HORIZ) + 100;
if (nPos > nMaxPos) nPos = nMaxPos; // moving to right edge
nOffset = GetSBPos(ASBS_HORIZ) - nPos;
SetSBPos(ASBS_HORIZ, nPos);
ScrollWindow(this->m_hwnd,nOffset,0,null,null);

case SBPAGELEFT:
GetSBRange(ASBS_HORIZ, nMinPos, nMaxPos);
if (GetSBPos(ASBS_HORIZ) == nMinPos) return true; // already at left edge
nPos = GetSBPos(ASBS_HORIZ) - 600;
if (nPos < nMinPos) nPos = nMinPos; // moving to left edge
nOffset = GetSBPos(ASBS_HORIZ) - nPos;
SetSBPos(ASBS_HORIZ, nPos);
ScrollWindow(this->m_hwnd,nOffset,0,null,null);

case SBPAGERIGHT:
GetSBRange(ASBS_HORIZ, nMinPos, nMaxPos);
if (GetSBPos(ASBS_HORIZ) == nMaxPos) return true; // already at right edge
nPos = GetSBPos(ASBS_HORIZ) + 600;
if (nPos > nMaxPos) nPos = nMaxPos; // moving to right edge
nOffset = GetSBPos(ASBS_HORIZ) - nPos;
SetSBPos(ASBS_HORIZ, nPos);
ScrollWindow(this->m_hwnd,nOffset,0,null,null);
}

return true;
}

MapDialog::OnInitDialog(),int
{
int i;
CRichEdit *pEdit;

SetSBRange(ASBS_HORIZ,0,2000);
SetSBRange(ASBS_VERT ,0,1500);

for(i = 0; i < NUMBER_OF_LOTS; i++) // fill controls with data
{
pEdit = GetControl(i);
SendMessage(pEdit->m_hwnd,EM_SETBKGNDCOLOR,0,RGB(151, 40, 0));
pEdit -> LoadFromString(str$(Lot[i].nLotNo) + "\n\n",0);
pEdit -> SetSel(0,3);
pEdit -> SetSelColor(GREEN);
pEdit -> SetSel(7,7);
pEdit -> SetDefaultColor(YELLOW);
pEdit -> ReplaceSel(Lot[i].sAddress + "\n\n", 0);
}
ShowWindow(SWMAXIMIZED);
return true;
}

MapDialog::OnLButtonDown(int x, int y, int flags), int
{
// this method determines on which Lot the user clicked

int i;
int dx, dy;

dx = x + GetSBPos(ASBS_HORIZ); // allow for offset due to any scrolling
dy = y + GetSBPos(ASBS_VERT);

for(i = 0; i < NUMBER_OF_LOTS; i++)
{
if((dx > Lot[i].x) AND (dx < (Lot[i].x + Lot[i].width)) AND
(dy > Lot[i].y) AND (dy < (Lot[i].y + Lot[i].height)))
MessageBox(this,str$(Lot[i].nLotNo),"",0);
}
return true;
}

MapDialog::OnVScroll(int nCommand, int nPos, int nID), int
{
int nMaxPos;
int nMinPos;
int nOffset;

select nCommand
{
case SBTHUMBTRACK:
nOffset = GetSBPos(ASBS_VERT) - nPos;
SetSBPos(ASBS_VERT, nPos);
ScrollWindow(this->m_hwnd,0,nOffset,null,null);
}


return true;
}

class MainWindow:CWindow //---------------------------------- MainWindow:CWindow
{
// Menu Constants (for program control)
const FILE_OPENÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, =ÂÃ,  1;
const FILE_CLOSEÂÃ,  ÂÃ,  ÂÃ,  =ÂÃ,  2;
const FILE_NEWÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  =ÂÃ,  3;
const FILE_EXITÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, =ÂÃ,  4;
const EDIT_CUTÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  =ÂÃ,  5;
const EDIT_COPYÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, =ÂÃ,  6;
const EDIT_PASTEÂÃ,  ÂÃ,  ÂÃ,  =ÂÃ,  7;
const TOOLS_OPTIONSÂÃ,  ÂÃ, =ÂÃ,  8;
const HELP_ABOUTÂÃ,  ÂÃ,  ÂÃ,  =ÂÃ,  9;
const HELP_HELPÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, = 10;

// overridden methods
declare OnClose(), int;
declare OnCreate(), int;
declare OnMenuPick(int nID), int;
// private methods
declare ReadData(), int;
// member variables
MapDialog m_dlgMap;
}

MainWindow::OnClose(),int
{
Destroy();
return true;
}

MainWindow::OnCreate(), int
{
int i;
ReadData(); // gets lot data from disk

// create map dialog
m_dlgMap.Create(0,0,300,202,AWS_POPUP|AWS_BORDER|AWS_DLGFRAME|AWS_VSCROLL|AWS_HSCROLL|AWS_SYSMENU|DS_MODALFRAME,
0,"Hyde Park",this);
for(i = 0; i < NUMBER_OF_LOTS; i++)
{
m_dlgMap.AddControl(CTRICHEDIT,"",Lot[i].x,Lot[i].y,Lot[i].width,Lot[i].height,
AWS_CHILD|AWS_VISIBLE|AWS_BORDER|AWS_DISABLED|AES_MULTILINE,0x0,i);
}
CenterWindow();
return true;
}

MainWindow::OnMenuPick(int nID), int
{
select nID
{
case FILE_EXIT:
Destroy();
case FILE_OPEN:
m_dlgMap.DoModal();
}
return true;
}

MainWindow::ReadData(), int
{
// reads data from disk and stores it in the array
// returns True if successful, else False
int i;
int f;
string sFileName = GetStartPath() + "LotData.txt";

f = OpenFile(sFileName, MODE_READ);
if(f)
{
for(i = 0; i < NUMBER_OF_LOTS; i++)
{
Seek(f, len(LOTSTRUCTURE) * (i-1));
Read(f, Lot[i], len(LOTSTRUCTURE));
}
CloseFile(f);
return true;
}
else
{
MessageBox(this,"File not found.","Error",0);
return false;
}
}

// *****************************************************************************
// *ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  MAIN ROUTINEÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, *
// *****************************************************************************

global sub main
{
MainWindow wMain;
CMenu m;

m.BeginMenu();
m.MenuTitle("&File");
m.MenuItem("&New",ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  AMF_GRAYED,ÂÃ,  FILE_NEW);
m.Separator();
m.MenuItem("&Open",ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, AMF_ENABLED, FILE_OPEN);
m.MenuItem("&Close",ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  AMF_GRAYED,ÂÃ,  FILE_CLOSE);
m.Separator();
m.MenuItem("E&xit",ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, AMF_ENABLED, FILE_EXIT);
m.MenuTitle("&Edit");
m.MenuItem("Cut\tCtrl+X",ÂÃ,  ÂÃ, AMF_GRAYED,ÂÃ,  EDIT_CUT);
m.MenuItem("Copy\tCtrl+C",ÂÃ,  AMF_GRAYED,ÂÃ,  EDIT_COPY);
m.MenuItem("Paste\tCtrl+V", AMF_GRAYED,ÂÃ,  EDIT_PASTE);
m.MenuTitle("&Tools");
m.MenuItem("&Options",ÂÃ,  ÂÃ,  ÂÃ,  AMF_GRAYED,ÂÃ,  TOOLS_OPTIONS);
m.MenuTitle("&Help");
m.MenuItem("&About...",ÂÃ,  ÂÃ,  ÂÃ, AMF_GRAYED,ÂÃ,  HELP_ABOUT);
m.Separator();
m.MenuItem("&Help",ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, AMF_GRAYED,ÂÃ,  HELP_HELP);
m.EndMenu();

wMain.Create(0,0,1000,500,
AWS_CAPTION|AWS_VISIBLE|AWS_BORDER|AWS_SYSMENU|AWS_SIZE|
AWS_MAXIMIZEBOX|AWS_MINIMIZEBOX,
0,"Hood Map - Hyde Park",NULL);
wMain.SetMenu(m.Detach());
wMain.SetWindowColor(GetSysColor(15));

// message loop
do
{
wait();
}until wMain.isValid() == false;
return;
}


Access violation:

Call stack
RICHED20! RichEditANSIWndProc + 60765
RICHED20! REExtendedRegisterClass + 85445
RICHED20! RichEditANSIWndProc + 2720
RICHED20! CreateTextServices + 57538
RICHED20! RichEdit10ANSIWndProc + 101
USER32! GetDC + 109
USER32! GetDC + 335
USER32! IsWindowUnicode + 161
USER32! CallWindowProcA + 27
HoodMapNew2! InitializeControl + 1045
USER32! GetDC + 109
USER32! GetDC + 335
USER32! GetParent + 364
USER32! SendMessageA + 73
HoodMapNew2! CRichEditOnCreate + 59
HoodMapNew2! InitializeControl + 428
HoodMapNew2! CDialogShowDialog + 975
HoodMapNew2! CDialogSetDefaultFont + 594
USER32! GetDC + 109
USER32! PrivateExtractIconExW + 690
USER32! PrivateExtractIconExW + 254
USER32! DefDlgProcA + 34
USER32! GetDC + 109
USER32! GetDC + 335
USER32! GetParent + 364
USER32! GetWindowTextLengthW + 1351
USER32! DrawStateW + 479
USER32! DialogBoxIndirectParamAorW + 54
USER32! DialogBoxIndirectParamA + 27
HoodMapNew2! CDialogDoModal + 369
HoodMapNew2! MainWindowOnMenuPick + 66 File: C:\Program Files\Aurora\PROJECTS\HoodMapNew\HoodMapNew2.src, Line: 230
HoodMapNew2! CWindowOnCommand + 433
HoodMapNew2! CWindowWndProc + 1064
HoodMapNew2! CWindowDestroy + 1956
USER32! GetDC + 109
USER32! GetDC + 335
USER32! GetWindowLongW + 295
USER32! DispatchMessageA + 15
HoodMapNew2! WAIT + 1416
HoodMapNew2! main + 988 File: C:\Program Files\Aurora\PROJECTS\HoodMapNew\HoodMapNew2.src, Line: 301
HoodMapNew2! main + 48
kernel32! RegisterWaitForInputIdle + 73

Integer Registers
EAX: 0x00148130, EBX: 0x00000001
ECX: 0x00000000, EDX: 0x0000002C
EDI: 0x00000000, ESI: 0x0015B920
ESP: 0x0012E7D4, EBP: 0x0012E7D8
EIP: 0x74E5F8E4, EFL: 0x00000206
CS: 0x001B, SS: 0x0023
DS: 0x0023, ES: 0x0023
FS: 0x003B, GS: 0x0000

FP Registers
ST0: -1.#IND000000000000
ST1: 1.#INF000000000000
ST2: -1.#INF000000000000
ST3: -1.#INF000000000000
ST4: 0.0000000000000000
ST5: -1.#INF000000000000
ST6: -1.#IND000000000000
ST7: 0.0000000000000000
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Bruce Peaslee

It appears to have something to do with the RichEdit controls (?).

If a comment out the sections that create and fill the controls, the problem vanishes.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

The main thing that I see right away is this:


for(i = 0; i < NUMBER_OF_LOTS; i++)
{
        m_dlgMap.AddControl(CTRICHEDIT,"",Lot[i].x,Lot[i].y,Lot[i].width,Lot[i].height,
               AWS_CHILD|AWS_VISIBLE|AWS_BORDER|AWS_DISABLED|AES_MULTILINE,0x0,i);
}


A control ID of 0 isn't allowed in Windows, Which is what your first control is being created as.  Also certain ID's have special meanings with dialogs.  1 = OK, 2 = Cancel.  I have run into problems before if I used those two ID's for anything but buttons.

In commercial apps I use 0x100 for the starting ID of controls in a dialog,  entirely up to you of course.  For demo programs I use whatever works ;)

Ionic Wind Support Team

Bruce Peaslee

Not there yet. I have rewritten the program in a stripped down version, stopping when the problem manifests itself. In the attached ZIP I include the files necessary to compile and run (I hope  ;)  ).
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

Changing them to edit controls (CTEDIT) will make it work.  So I'll dig deeper.
Ionic Wind Support Team

Ionic Wind Support Team

Using a detailed trace shows the problem has to do with inplace OLE.  I have a solution but you'll need an update to use it since there isn't a simple workaround for user code.  Give me a few.
Ionic Wind Support Team

Bruce Peaslee

At your pleasure... I've already charged ahead with the rest of the code. I am confident you'll have a fix before I'm done.ÂÃ,  ÂÃ, 8)
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

The update was posted in the announcements forum.  Just a small zip to download.
Ionic Wind Support Team

Bruce Peaslee

Works like a charm. Thanks.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles