|
I am not getting it.
This is what my code is:
void CEgAppDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect wRect,eRect;
GetClientRect(wRect);
m_edit.GetClientRect(eRect);
POINT * pt;
pt->x=eRect.left;
pt->y=eRect.top;
::ClientToScreen(m_edit.m_hWnd,pt);
eRect.bottom+=30;
eRect.right+=30;
::MoveWindow(m_edit.m_hWnd,pt->x,pt->y,eRect.Width(),
eRect.Height(),TRUE);
}
I am getting an Exception
|
|
|
|
|
i guess m_edit.m_hWnd=NULL
insert this
if(m_edit.m_hWnd!=NULL)
{
...
}
whitesky
|
|
|
|
|
Hey, just reduce the code lines do as follows
void CEgAppDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
CRect ClientRect( 0, 0, 0, 0 );
GetClientRect( ClientRect );
if( FALSE != IsWindow( m_edit.GetSafeHwnd()))
{
m_edit.MoveWindow( ClientRect );
}
}
This code is expected to work only when the Dialog is forcely resize by using Minimize, Maximize, Drag Size etc. To resize the control in Initial state you have to put some similiar code in the OnInitDialog of the dialog class like
CRect ClientRect( 0, 0, 0, 0 );
GetClientRect( ClientRect );
m_edit.MoveWindow( ClientRect );
In OnInitDialog you do not have to check the Window handle because OnInitDialog is called after the creation of the Dialog Box and it's control. But you should check the Validity of m_edit window in OnSize because it is called by the framework when the DialogBox alone is created, before the edit is created.
OK ?
Regards,
Benoy Bose
|
|
|
|
|
sruti_p wrote: How can i resize the dialog box controls when i resize the dialog box?
Either Subclass the control to handle the Dialog resize or use MoveWindow api!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
what is the best way to open a program and check for a file if its not there make it? its a ini file. 
|
|
|
|
|
locoone wrote: what is the best way to open a program and check for a file if its not there make it? its a ini file.
_tgetcwd , GetModuleFileName .
Hope I understood your question.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
from ur question what i understood that, u have an exe it will check for a file and if not existing, u need to create one right?
here is a sample snippet
CFileFind finder;<br />
BOOL bWorking = finder.FindFile("test.ini");<br />
<br />
if(FALSE == bWorking)
{<br />
}<br />
SaRath.
"Don't Do Different things... Do Things Differently..."
|
|
|
|
|
you can use
<br />
WIN32_FIND_DATA m_data;<br />
HANDLE hFile;<br />
hFile=FindFirstFile(filename,&m_data)<br />
if(hFile==INVALID_HANDLE_VALUE)
else<br />
FindClose(hFile);<br />
whitesky
|
|
|
|
|
|
Hi,
I am using USB-to-Serial cable to connect to my device. In my windows application, I use ReadFile/WriteFile to communicate with my device.
Everything is working fine. But one question I would like to ask.
Is DCB setttings important if we are using virtual COM port, eg:
Dcb.BaudRate
Dcb.ByteSize
Dcb.Parity
Dcb.StopBits
Will those settings affect the communication link because we are actually using VIRTUAL COM PORT not the actual port?
Thanks.
|
|
|
|
|
tctan wrote: Dcb.BaudRate
Dcb.ByteSize
Dcb.Parity
Dcb.StopBits
Almost all!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
So, you mean, even though it is virtual COM port, the DCB setting should also be set properly?
The reason I asked this question is that, someone actually told me that, if you are using virtual com port, you don't need to care about those settings. The only setting concerned is the COM port number.
-- modified at 4:24 Friday 2nd June, 2006
|
|
|
|
|
This may or may not be true depending on the "virtual" COM port.
Sometimes USB devices register themselves as one or more COM ports and those could be called virtual. Different devices behave differently.
I've experienced USB devices used as COM ports that are "enabled" by setting the DTR line, which requires the use of DCB.
However, all COM devices should support the use of DCB, which means that it doesn't hurt to set up things properly. It would also make the code more portable between COM devices.
What you heard regarding not having to set the DCB for virtual COM ports may be true for some specific devices, but certainly not all.
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Recently,I am writing a smtp server ,when I test it in the internet ,
I find that it can't send local email to other remote smtp server,
for example smtp.mail.yahoo.com etc.I don't know why?
Can anyone give me some advince?
|
|
|
|
|
I should know pointers by now but still struggle to get code working when dealing with them..
If anyone has any recommended articles I'd be very appreciative. But, the articles dealing with pointer basics don't seem to help me... not sure why. I can understand casting ints, etc. but when it gets to more complex data types, I get confused.
A good example of a tough pointer problem for me is seen below. Not sure why/where I'm reading/changing memory I shouldn't be and I also don't know how I would be able to get the value of the TextualSid in a format usable for strcmp, printf, etc.
Thanks..
//////////
<br />
LPUSER_INFO_23 pBuf = NULL;<br />
LPTSTR TextualSid ;<br />
LPTSTR * TextualSid2= NULL ;<br />
<br />
ConvertSidToStringSid(pBuf, TextualSid2); <br />
<br />
<br />
DWORD sidLen;<br />
sidLen = GetLengthSid(pBuf);<br />
LPDWORD lpdwSize = NULL;<br />
*lpdwSize = sidLen;<br />
GetTextualSid(pBuf->usri23_user_sid, TextualSid, (LPDWORD)lpdwSize);<br />
if (pBuf != NULL) NetApiBufferFree(pBuf);<br />
<br />
Data types used: <br />
<br />
<br />
BOOL GetTextualSid(
PSID pSid,
LPTSTR TextualSid,
LPDWORD lpdwBufferLen
)<br />
{<br />
PSID_IDENTIFIER_AUTHORITY psia;<br />
DWORD dwSubAuthorities;<br />
DWORD dwSidRev=SID_REVISION;<br />
DWORD dwCounter;<br />
DWORD dwSidSize;<br />
<br />
<br />
if(!IsValidSid(pSid)) return FALSE;<br />
<br />
<br />
psia = GetSidIdentifierAuthority(pSid);<br />
<br />
<br />
dwSubAuthorities = *GetSidSubAuthorityCount(pSid);<br />
<br />
<br />
dwSidSize=(15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);<br />
<br />
<br />
if (*lpdwBufferLen < dwSidSize)<br />
{<br />
*lpdwBufferLen = dwSidSize;<br />
SetLastError(ERROR_INSUFFICIENT_BUFFER);<br />
return FALSE;<br />
}<br />
<br />
<br />
dwSidSize=wsprintf(TextualSid, TEXT("S-%lu-"), dwSidRev );<br />
<br />
<br />
if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )<br />
{<br />
dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid),<br />
TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),<br />
(USHORT)psia->Value[0],<br />
(USHORT)psia->Value[1],<br />
(USHORT)psia->Value[2],<br />
(USHORT)psia->Value[3],<br />
(USHORT)psia->Value[4],<br />
(USHORT)psia->Value[5]);<br />
}<br />
else<br />
{<br />
dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid),<br />
TEXT("%lu"),<br />
(ULONG)(psia->Value[5] ) +<br />
(ULONG)(psia->Value[4] << 8) +<br />
(ULONG)(psia->Value[3] << 16) +<br />
(ULONG)(psia->Value[2] << 24) );<br />
}<br />
<br />
for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)<br />
{<br />
dwSidSize+=wsprintf(TextualSid + dwSidSize, TEXT("-%lu"),<br />
*GetSidSubAuthority(pSid, dwCounter) );<br />
}<br />
<br />
return TRUE;<br />
}<br />
|
|
|
|
|
Hi everyone.
I am trying to implement a chat application that communicates using sockets. The problem is, when i try create a dialog when the application receive a connection request, the DoModal function doesn't works at all.
//Function called from InitDialog of a class derived from CWinThread
void CConexao::Connect()
{
CDlg dlg;
dlg.DoModal()
}
Would anyone help me solving this problem?
Thanks in advance
|
|
|
|
|
Dennis Furlaneto wrote: The problem is, when i try create a dialog when the application receive a connection request, the DoModal function doesn't works at all.
You are wrong! If DoModal doesn't work from threads none of the Dialog based applications will start because CWinApp is derived from CWinThread .
Try to write the code inside InitInstance . This is the function that gets called when an instance of CWinThread starts up or call Connect from InitInstance .
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
Well, i didnt't say that CDialog doesn't work with threads... it was a question.
I really didn't say it, but i'm calling connect insitde InitInstance and it is not working.
I think that i have to syncronize the calls, but i don't know how. When i call DoModal, the application will immediatly go back to were i started the thread, not allowing the dialog to be shown.
|
|
|
|
|
Hi again
Just when i thought i'm done this comes up
i wrote this code for testing it compiles ok but
it then crashes at a certain point
can anyone help me find the error
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \<br />
no_namespace rename("EOF", "EndOfFile")<br />
<br />
<br />
using namespace std;<br />
<br />
void main()<br />
{<br />
<br />
string token="viagra";<br />
HRESULT hr = S_OK;<br />
CoInitialize(NULL);<br />
<br />
try<br />
{<br />
_ConnectionPtr m_pConn;<br />
HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection));<br />
if (FAILED( hr ))<br />
cout<<"Can't create an intance of ADO.Connection"<<endl;<br />
<br />
if (FAILED( m_pConn->Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =bayesfilter.MDB"),<br />
_bstr_t( "" ),<br />
_bstr_t( "" ), <br />
adModeUnknown )))<br />
<br />
cout<<"Can't open datasource"<<endl;<br />
<br />
<br />
<br />
_CommandPtr pCommand;<br />
pCommand.CreateInstance (__uuidof (Command));<br />
pCommand->ActiveConnection = m_pConn;
<br />
string command="SELECT token,Spam,Ham,P,app FROM tblDictionary WHERE token='"+ token;<br />
command+="'";<br />
pCommand->CommandText = command.data(); <br />
<br />
<br />
<br />
_RecordsetPtr pRecordset;<br />
pRecordset.CreateInstance (__uuidof (Recordset));<br />
pRecordset->CursorLocation = adUseClient;<br />
pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic,<br />
adLockBatchOptimistic, adCmdUnknown);<br />
<br />
_bstr_t valField1;<br />
int valField2;<br />
int valField3;<br />
double valField4;<br />
int valField5;<br />
pRecordset->MoveFirst();<br />
if (!pRecordset->EndOfFile)<br />
{<br />
while(!pRecordset->EndOfFile)<br />
{<br />
valField1 = pRecordset->Fields->GetItem("Token")->Value;<br />
valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal;<br />
valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal;<br />
valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal;<br />
valField5 = pRecordset->Fields->GetItem("app")->Value.intVal;<br />
printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5);<br />
pRecordset->MoveNext();<br />
}<br />
}<br />
else<br />
cout<<"No record found insert?"<<endl;<br />
<br />
<br />
m_pConn->Close();<br />
<br />
}catch( _com_error &ce )<br />
{<br />
printf("Error:%s\n",ce.Description);<br />
<br />
}<br />
<br />
CoUninitialize();<br />
<br />
}
Any ideas thanks again
-- modified at 14:41 Thursday 1st June, 2006
|
|
|
|
|
Sorry i forgot to give some more details
The table of the database is tblDatabase and the colums are
token:: text
Spam::Number
Ham::Number
P::Number(with decimal points)
app::number
Thanks
|
|
|
|
|
|
Without actually knowing where it is crashing (and not being able to run it myself), here are the most likely places based on the code:
antonaras wrote: valField1 = pRecordset->Fields->GetItem("Token")->Value;
valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal;
valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal;
valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal;
valField5 = pRecordset->Fields->GetItem("app")->Value.intVal;
printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5);
If GetItem returns NULL for any of those items at any point in time, you will get an access violation. Also, if the types don't match up (that is, if the field is a double and you are checking the int value), you will get strange results that could blow up your stack in a weird place.
Additionally, the printf statement will blow up your stack the way it is written. When you have 2 arguments in the printf string, you should only have 2 variables to match them (you have 2 in the string and 4 trying to match them).
antonaras wrote: m_pConn->Close();
You didn't close the recordset, so at this point, the connection is being closed. Now, when the Recordset smart pointer goes out of scope, it will attempt to close, but it will no longer have a connection. Try adding a pRecordset->Close(); call prior to the connection's close call.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
-- modified at 15:21 Thursday 1st June, 2006
|
|
|
|
|
antonaras wrote: printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5);
This should be:
printf("%d - %s\n", valField2, (LPCSTR) valField1);
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
I was handed down a big windows base project at work that requires some attention. We have been experiencing some random crashes and bugs in the field. I’m working on debugging this issues but I need a little help. We have limited time to debug all issues so I was wondering if there are any commercially available tools (I’m currently looking at SOFTICE) that I could use to monitor the executable and record system parameters when the system is in the field. I need to pin point the root cause of the problems. I’m trying to get a sense of what’s going on in the field that’s causing the random behavior of the executable.
Thank you
|
|
|
|
|
|