|
It would only take a couple of minutes to cut and paste your code from OnInitDialog into a FillContactsCombo function. Having a seperate function is the correct way to code this.
A quick look through the base level CDialog::OnInitDialog shows a code that loads and locks resources as well as sending off other WM_x to the dialog controls. I'd say it isn't safe to do it and also a very poor and lazy programming style.
Michael
Fat bottomed girls
You make the rockin' world go round -- Queen
|
|
|
|
|
Michael P Butler wrote:
lazy programming style.
Yup, but it's just an app i'm building for myself and I use the waterfall (i think??) approach to designing apps. I don't really create much of a design doc (cuz well I don't know what one looks like to be honest) I just kind of start building...take away what i've learned and rebuild correcting and optimizing as I go...over and over again
Thanks
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
I've been programming for a long time, it is now second nature for me to write my code in small functions rather than putting everything into one function. I very often don't have a design document but you soon learn to get into the habit of writing structured code - if only to make your own life easier.
Michael
Fat bottomed girls
You make the rockin' world go round -- Queen
|
|
|
|
|
I'd move the code to seperate functions to be on the safe side. I don't think it would be safe to constantly call OnInitDialog.
Regards,
Brian Dela
|
|
|
|
|
I was going to, but when I tried it with calling OnInitDialog() it worked so I left it, but then thought i'd get some opinions on CP.
Cheers!
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
when i resize my CFormVIew based window my controls donot resize accrodinfg to it.. how can i resize my controls placed on the dialog attached to CFormView when i maximize the window???
Shoaib Khan
sbk_one@yahoo.com
|
|
|
|
|
WM_SIZE I would think should work.
I would just resize/reposition each control inside OnSize()
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I am Korean.
I English not very well.
please!
I don't know how to do FTP file status find a way. ^.^
|
|
|
|
|
I don't know what you mean, but did you take a look at this?
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi All
I appreciate greatly a quick response. Thank you.
I am using unicast sockets (sync) where i bind the socket in one thread and keep accept() new calls in another thread. and Closesocket() in another.
When I closesocket(), the program terminates. and if i remove closesocket(), it does not allow me to bind() again.
I forgot to mention that I need to close and connect again without terminating the application (reuse the socket). Is there any way to do this or what am i doing wrong?
int UnicastConnect()
{
printf("Establishing the listener...");
WORD version = MAKEWORD(1,1);
WSADATA wsaData;
WSAStartup(version, &wsaData);
// Next, create the socket itself
listeningSocket = socket(AF_INET, SOCK_STREAM,IPPROTO_TCP);
if (listeningSocket == INVALID_SOCKET) {
AfxMessageBox("Error at socket()");
WSACleanup();
return 0;
}
// Use SOCKADDR_IN to fill in address information
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr.s_addr = INADDR_ANY; saServer.sin_port = htons(g_InetPort);
/*
setsockopt( listeningSocket, SOL_SOCKET, SO_REUSEADDR, NULL, NULL );
*/
// Bind the socket to our local server address
nRet = bind(listeningSocket, (LPSOCKADDR)&saServer, sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR) {
AfxMessageBox("Error Binding Socket");
WSACleanup();
return 0;
}
// Make the socket listen
nRet = listen(listeningSocket, MAX_CLIENTS);
if (nRet == SOCKET_ERROR) {
WSACleanup();
return 0;
}
if (listeningSocket == INVALID_SOCKET) {
return false;
}
CreateThread(0, 0, AcceptConnections, (void *)
listeningSocket, 0, NULL);
}
DWORD WINAPI AcceptConnections(void *ListeningSocket)
{
sockaddr_in sinRemote;
int nAddrSize = sizeof(sinRemote);
while (1) {
SOCKET sd = accept((SOCKET) ListeningSocket, (sockaddr*)&sinRemote,&nAddrSize);
*p = 1 ;
ioctlsocket(sd, FIONBIO, p); // Sets the Non-Blocking Mode of Socket.
if (sd != INVALID_SOCKET) {
AfxMessageBox ("BeaconSender::Accepted Unicast connection from ");
}
else {
AfxMessageBox ("Closed");
return false;
}
}
}
void stop(){
shutdownsocket(listeningsocket)
closesocket(listeningsocket); //Gives an error
wsacleanup();
}
Thanks for your help.
Yogi
|
|
|
|
|
Consider WSASocket().
listeningsocket = ::WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0);
::closesocket(listeningsocket);
Kuphryn
|
|
|
|
|
Thanks for the suggestion.
I forgot to mention that all the code is built inside an ActiveX. Does that cause a problem??
CloseSocket() was terminating the application. Then if i remove the closesocket(), the binding to the IP/Port does not occur (obviously).
WSASocket() is showing as undeclared identifier with ws2_32.lib included.
Best Regards
Yogi
|
|
|
|
|
Hi.
Is it possible to create a file with a long path name? For example:
-----
std::string pathFile("c:\testing\December 27\newfile.type");
// CreateFile fails
if (::CreateFile(pathFile->c_str(),...) == INVALID_HANDLE_VALUE)
{
}
-----
I would like to know two properties of CreateFile(). First, is it possible to create a file in a directory that does not exist via CreateFile()? In the example above, directories "testing" and "December 27" do not exist.
Secondly, is it possible to create directories with spaces between one or more words, i.e. December 27. Notice the space before "2."
Thanks,
Kuphryn
|
|
|
|
|
1. CreateFile will NOT create directories. You'll need a recursive create directory function. There are a few hanging around CP. And I have you if you need it.
2. Yes. Spaces are fine.
CreateDirectory("December 27");
should work
Todd Smith
|
|
|
|
|
kuphryn wrote:
is it possible to create a file in a directory that does not exist
No, if the dir doesn't exist there's no place to create the file.
Secondly, is it possible to create directories with spaces between one or more words
Yes, CreateFile() uses whatever string you pass it for the name.
--Mike--
If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Okay. Thanks everyone.
Is there a Win32 API for checking the existence of a directory? Otherwise, recursive creation will do.
One last inquiry. I have seen in the past members mentioning directories with two backslashes. Is there something special about creating directories with two backslashes instead of one?
Example:
std::string pathFile("c:\\testing\\December 27\\file.type");
Kuphryn
|
|
|
|
|
kuphryn wrote:
Is there a Win32 API for checking the existence of a directory? Otherwise, recursive creation will do.
Technically, no. At least I haven't seen one. In an instance that I had, I had to create a file, several dirs deep. So I had to do a _access(filename, 00) to see if the dir existed. If not, I would create it. That might be how you will have to do it.
kuphryn wrote:
I have seen in the past members mentioning directories with two backslashes. Is there something special about creating directories with two backslashes instead of one?
I am not sure about this. In some cases, if you are required to use \\ in order to have just one \. In other cases, it doesn't matter. For instance in your case, I think it will work to have just one c:\ instead of c:\. I know in other cases, for instance, in a wsprintf, strcpy, you have to have \\.
|
|
|
|
|
|
kuphryn wrote:
Is there something special about creating directories with two backslashes instead of one?
The two backslashes are necessary to comply with C++ syntax. In string and character literals, a backslash is a special character and indicates that the next character should be treated specially. For instance, \t means "the tab character". One backslash by itself is meaningless*, so in order to have a backslash character in a string, you write \\ in your code.
So to create a directory C:\testing , you write "C:\\testing" . If you write "C:\testing" , that is interpreted as C followed by colon followed by TAB followed by "esting", which is not what is intended.
*Except when the backslash comes at the end of a line, in which case it is an instruction to the preprocessor to join the line with the following one.
--Mike--
If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
Hi!
I wanted to create a MFC dll which displays a SDI window when I call it
whith rundll. The function is - let's say - "EntryPoint". It worked so far,
but the SDI doesn't want to stay on the screen, it just pops up and closes.
In the MSDN, I've read that a dll is being unloaded when the function I'm
calling (EntryPoint) returns. How can I make the SDI staying on the screen?
Is there a workaround or somewhat? Perhaps a wait loop which doesn't take
much processor time?
Mfg
the Datalord
|
|
|
|
|
I'm adding IRC chat to my game launcher, and am wanting to show the chat text in colors using a Rich Edit 2.0 control in a dialog. I'm doing the following to add a line of text (Tmp is a CString containing the chat line text):
<br />
CHARFORMAT cf;<br />
<br />
cf.cbSize = sizeof(cf);<br />
cf.dwMask = CFM_COLOR | CFM_FACE;<br />
strcpy(cf.szFaceName,"Subway");<br />
...<br />
cf.crTextColor = RGB(255,0,0);<br />
...<br />
ChatList.SetSel(-1,0);<br />
ChatList.SetDefaultCharFormat(cf);<br />
ChatList.ReplaceSel(Tmp);<br />
ChatList.LineScroll(ChatList.GetLineCount());<br />
Now, the text is correctly show using the "Subway" font, but it's still only black What am I doing wrong?
Thanks!
|
|
|
|
|
Hmm, the coloring works in release builds!
|
|
|
|
|
i love this site!
can Somebody tell me why ?
-=Ehsan-de-Burge=-
|
|
|
|
|
1) Easy to navigate and pleasant interface
2) Super fast message boards responses
3) Quality articles which seldomly require H scrolling
4) Emoticons are so damn cool
5) A real sense of community
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|