|
Hi
I am invoking dialogbox from applications InitInstance(). Can I handle IDOK button message of dialog from document object?. Can you help if you can handle..
Thank you
Srinivasa Raju Bhairraju
Member - Technical
Cysphere.com Pvt Ltd
Ashoka Bhopal Chambers
S.P.Road
Secunderabad - 3
Email: sraju@cysphere.com
|
|
|
|
|
If the dialog box is modeless, then you can catch WM_COMMAND. If it's modal, then obviously you don't have a hope in hell.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I had written a dialog based application.
It contained a button named "Try"
When I clicked the "Try" button,opened an other
dialog named "Test" which contained a button named "Open".
When I first clicked "Open" button and clicked the "OK"
button in Open File Dialog,everything is ok,and then
close the "Test" Dialog.
But When I click "Try" button again,it showed me wrong.
Who can please tell me what's wrong with my code??
******************************************************************
void CFirstDlg::OnButtonTry()
{
// TODO: Add your control notification handler code here
CTestDialog* dlg;
dlg=new CTestDialog;
dlg->DoModal();
}
******************************************************************
BOOL CTestDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString sCon;
_ConnectionPtr m_pCon;
_RecordsetPtr m_pRs;
sCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=main.mdb";
CoInitialize (NULL);
HRESULT hr=S_OK;
try
{
hr=m_pCon.CreateInstance(__uuidof(Connection));
if(FAILED(m_pCon->Open(_bstr_t(sCon),"","",adModeUnknown)))
AfxMessageBox("Can not open the database!");
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Failed!\r\nError Message:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
m_pRs.CreateInstance("ADODB.Recordset");
if(FAILED(m_pRs->Open("SELECT * FROM employeer",_variant_t((IDispatch*)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText)))
AfxMessageBox("Can not open the record set!");
if((m_pRs->State & adStateOpen) == adStateOpen)
m_pRs->Close();
if ( (m_pCon->State & adStateOpen) == adStateOpen)
m_pCon->Close();
CoUninitialize();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
***********************************************************************
void CTestDialog::OnButtonOpen()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[]="Bitmap Files (*.bmp)|*.bmp||";
CFileDialog *fd;
fd=new CFileDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter,this);
if(IDOK!=fd->DoModal())
return;
else
AfxMessageBox(fd->GetFileName());
delete fd;
}
|
|
|
|
|
at a quick glance, you're not deleting the memory you allocate for CTestDialog. Why not use:
<br />
void CFirstDlg::OnButtonTry() <br />
{<br />
CTestDialog dlg;<br />
dlg.DoModal();<br />
}<br />
Also you're not freeing memory in your OnButtonOpen() if the dialog doesn't return IDOK.
What is the error message, is it a com exception or unhandled exception?
I'd also consider setting all com pointers to null before calling CreateInstance. eg.
<br />
pConnection = NULL;<br />
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));<br />
|
|
|
|
|
Because I am a beginner of VC++ from China,and the error message was showed in Chinese,I only know the error number is 0x80004005,I don't know what is means?Please Help me.
|
|
|
|
|
I've been playing with ADO a bit lately and I've found that if you pass in a bad string, it crashes, and crashes HARD.
if(FAILED(m_pRs->Open("SELECT * FROM employeer",_variant_t((IDispatch*)m_pCon,true),adOpenStatic,adLockOptimistic,adCmdText)))
Is 'employer' spelled wrong in the database as well ? If not, a typo here would cause a crash every time, and not a graceful or easily traceable one.
I'd also suggest it is poor form to name local variables m_, that indicates a member variable ( one declared in your header file and therefore visible to the entire class ).
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Do you need to end a statement with a ';' too? as in,
<br />
pCommand->CommandText = _bstr_t("SELECT `tblImages`.* FROM `tblImages` WHERE `tblImages`.`visitID` = `param1`;");<br />
|
|
|
|
|
No, I don't believe so ( the code is at home so I cannot check, but I don't think SQL wants a ; ).
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
No,I means when I click the "Try" button again,the wrong message appeared,while when I first clicked the "Try" button,everything is OK.
I tried to change my code with an other way such as:
CFirstDialog::OnButtonTry()
{
CTestDialog dlg;
dlg.DoModal();
}
It's still wrong.
Because I use Chinese,so the error message was showed in Chinese,I only know the error number is 0x80004005,what it means?
|
|
|
|
|
The following code will translate an error number for you
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
0x80004005,
0,
(LPTSTR) &lpMsgBuf,
0,
NULL
);
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
In this case it is 'unspecified error', which is what ADO always seems to give ( but it could well come from elsewhere all the same ).
Changing your code as you have done is obviously a step forward, no need for a pointer, plus an ugly memory leak. You should do the same for your FileDialog, or at least delete the thing if people press cancel.
Are you trying to run in F5 ( debug ) mode ? Are you pressing cancel and letting the debugger show you where it is crashing ? If the above code is crashing ( just a domodal() call, then it's dying in the dialog code, and I would continue to maintain in your ADO code. You should set a break point and step through the OnInitDialog as a first step. Are you closing your connection to the database ? It may well be crashing the second time because your first connection is still open.
Also your database path is not absolute, if something else in the dialog is changing the current directory, that will also mean it cannot find the file and will crash.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Thanks,you're right.
When I open the "Open/Save File Dialog",it changed the current directory.
It cannot find the database,so the wrong message appeared.
Thanks again.
|
|
|
|
|
Glad to help ADO was a nightmare for me in the first little while because it crashes so easily and my books are filled with examples which simply do not work.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Good day,
Why would this not fill the complete rectangle specified by rcHighlight? this is for a Multiline(per item) ListCtrl and in the DrawItem function.
CRect rcHighlight = GetItemRect(lpDrawItemStruct->itemID, rc);
rcHighlight.left += 1;
rcHighlight.top += 1;
rcHighlight.right -= 1;
rcHighlight.bottom = rc.bottom - 1;
if (lpDrawItemStruct->itemState & ODS_SELECTED) {
pDC->FillSolidRect(rcHighlight, GetSysColor(COLOR_HIGHLIGHT));
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
} else {
pDC->FillSolidRect(rcHighlight, GetSysColor(COLOR_WINDOW));
pDC->SetTextColor(GetSysColor(COLOR_WINDOWTEXT)) ;
}
I've verified that the rectangle is the correct rect and size but yet FillSolidRect only fills half of it. Any help is greatly appreciated.
Bret Faller,
Off-Duty programmer
|
|
|
|
|
You often have to add +1 to right and bottom. Also, line drawing does never include the last coordinate. Takes some to get used to.
|
|
|
|
|
check that nothing has set a clipping region on that DC (if you can)
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thanks for your response...how might I go about checking if something else has set the clipping region? I've looked into somem of the clipping functions but I'm actually not to familiar with the CDC. Thanks again for your response.
Bret Faller,
Off-Duty programmer
|
|
|
|
|
I might be barking up the wrong tree in the wrong forest here, but:
CRect rcHighlight = GetItemRect(lpDrawItemStruct->itemID, rc);
rcHighlight.left += 1;
rcHighlight.top += 1;
rcHighlight.right -= 1;
rcHighlight.bottom = rc.bottom - 1;
Looking at the prototype for the GetItemRect Function:
int GetItemRect( int nIndex, LPRECT lpRect ) const;
The return value is just a status code. lpRect is where the rect comes in. But, your code uses a CRect rcHighlight for a return value ?!?! and you adjust it's size a little, and then draw it.
Also, the fourth line of your code sets rcHighlight.bottom to rc.bottom, whereas the others just adjust the size of the incorrectly filled CRect object.
I don't know, maybe you just mistyped the code into the discussion forum?
Jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Actually its my own custom GetItemRect function because this is for a multiline ListCtrl that I am making and it determines the size of the row based on how many lines of text the biggest subitem has. It takes the itemid and the original rect of the item which comes from the DRAWITEMSTRUCT in my DrawItem function and then it inflates it based on how many lines of text are in the biggest subitem. Thanks for your response though.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
In my Win32 app I have a hidden window and all other windows are a child of it. Actually for this to work I had to *show* the window, so it's at -20, -20 and is 1x1 pixel wide. I've tried making it on screen and bigger, it does not solve the following problem.
The app has a console that accepts Python commands and an indeterminate number of other windows, as they can be dynamically created in Python. So I do the following:
LRESULT CALLBACK MainProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_SETFOCUS:
::SetWindowPos(console, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
::SetWindowPos(hDlg, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
break;
case WM_KILLFOCUS:
::SetWindowPos(console, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return FALSE;
}
in my main window in order to keep the Console above all the other windows. I've tried commenting out this code as well, it does not help. The problem is that right clicking on the taskbar button does not bring up a menu. Can anyone suggest how I can fix this ?
As an aside, I presume it's possible to add to this menu ? Does anyone know how ? I've done Explorer menu shell extensions, but I am not sure if the taskbar menu can be added to the same way.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
> The app has a console
This is just an input window, acting as a console, not an AllocConsole window, right?
> The problem is that right clicking on the taskbar
> button does not bring up a menu. Can anyone
> suggest how I can fix this ?
Ahh, the beauty of windows.
I suspect the window coordinates for your topmost window.
Have you tried to make your "parent" window (really the "owner" window) "invisible" (WS_INVISIBLE) at (0,0)-(1,1). This is how MS solves it IIRC.
As for adding to the taskbar menu, I think you have to 1) "inject" your DLL (I believe you know this or where to find it, MSDN) and then lookup the window class "SysTabControl32".
++luck
/Mike
|
|
|
|
|
Thanks for the reply.
Yes, it's a dialog box, not an actual console window.
I've tried making the co-ordinates such that the window is physically onscreen, it does not help. Or do you mean the co-ordinates of my console ( which is the topmost window ) ? How would that affect things ?
Also, I have the latest SDK ( well I own it and I *think* I have it installed ) and WS_INVISIBLE is not recognised. The latest MSDN also does not find it. Am I missing something, because WS_INVISIBLE sounds like just what I've been looking for.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
> I've tried making the co-ordinates such that
> the window is physically onscreen, it does not
> help. Or do you mean the co-ordinates of my
> console ( which is the topmost window ) ?
Yes, I intended the top-most window.
I suspected that since the "owner" window (the top-most window as I understand it) is outside the visible area, there might be some wrap-around or other errors (negative window coordinates on (0,0)-(x,y) screen).
But I'm not surprised you didn't find the WS_INVISIBLE, it doesn't exist. I was taking that from the top of my head, and apparently that head was somewhere in the blue.
WS_EX_TRANSPARENT was the windows style I was thinking of.
To see where your mouse messages go, try Spy++. It will be lots of mouse messages, but perhaps you can see where the RMB clicks are going?
/Mike
|
|
|
|
|
Hi all,
I have an application that is a MDI app, with multiple views attached
to each document. When I switch between views of the same document,
with the MDI child frames NOT maximized, everything is cool (no
flickering when switching between frames/views). However, when I
switch between frames when the child frames are MAXIMIZED, the
activated frame/view seems to "remember" it's non-maximized
dimensions, display that and THEN subsequently refresh and display
itself as maximized. As you can guess, this causes a momentary
flicker in between the time the maximized frame shows the
"non-maximized" dimensions and the the time it finally displays itself
as maximized. Any clues as to how I might avoid this?
Thanks....
|
|
|
|
|
First of all.. I'm new to MFC
In my mdi app I have a class which derives from CRichEditView. Since I want to be able to use the extended capabilities of Rich Edit 2.0 I added this to my class.
BOOL MyTextView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
CCtrlView::m_strClass = "RICHEDIT_CLASS";
return CRichEditView::PreCreateWindow(cs);
}
This works fine except from when I try to create the window. The call to CreateWindowEx in CWnd fails, GetLastError returns 0 and I get the message that an empty document couldn't be created. It's feels like I'm on the right track but I have no idea what to do next
/Eric
|
|
|
|
|
|