|
If you look under the books in the Visual C++ MSDN Library you will find "Developing International Software for Windows 95 and WinNT" and you may be happy to know that Microsoft press had planed releas a newer edition of this book some time this year.
Thanks for reminding me I am off to see if it has been released yet, so I can order it.
Trust in the code Luke. Yea right!
|
|
|
|
|
Thank you John. Think it will help.
Olli
Make it idiot proof and someone will make a better idiot......
|
|
|
|
|
dear all,
i've written a small piece of code ( a hidden window) which detects windows shutdown and then logs the timestamp in a file. i'm using the following code in the message loop-
while(GetMessage(&Msg, hwnd, 0, 0) > 0)
{
if (flg_shutdown == 1)
{
flg_shutdown = 0;
Run(); //logs time stamp in a file
ShutDown(); // shutsdown the system using ExitWindowsEx(...)
}
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
now my wm_queryendsession handler is as follows
case WM_QUERYENDSESSION:
{
if (lParam & ENDSESSION_LOGOFF)
flg_type = 1; //logoff
else
flg_type = 2; //shut down
flg_shutdown = 1;
return false; // don't shutdown now. shutdown after Run() is executed
}
break;
the problem is that when i logoff/shutdown nothing happens until i do something with the window (move cursor over it or click on it or resize it).
when i do so, everything works fine.
what could be the problem. i even tried the following message loop
while(GetMessage(&Msg, hwnd, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
if (flg_shutdown == 1)
{
flg_shutdown = 0;
Run(); //logs time stamp in a file
ShutDown(); // shutsdown the system using ExitWindowsEx(...)
}
}
but same problem.
can someone help me out.
Thanx and Regards
|
|
|
|
|
WM_QUERYENDSESSION is sent which means that it is not seen by the message loop. The code in the message loop will be executed the next time a message is posted to your window.
Maybe you should move your code to the message handler.
regards Oliver
|
|
|
|
|
thanx for ur concern.
i am executing the code when wm_queryendsession returns 0 (i.e. logoff or shutdown is aborted)
if i try to run the code (starting an application for file write operation) in the messagehandler itself, i cannot execute the application because windows is shutting down.
i also tried to send a message(wm_lbuttonup) in the loop, but still i can't make it work
|
|
|
|
|
The problem is that the message loop does not get called when a message is sent to your handler. If you cannot perform your task in the message handler you have to make sure that the message loop is triggered without any user interaction.
Maybe you coud post a message to your window, e.g.
PostMessage(hYourWindow, WM_NULL, NULL, NULL);
This will trigger the message loop some time after your handler has finished.
regards Oliver
|
|
|
|
|
I have a MFC (server) application that works with sockets.
It should do the following:
1. Waits for an incomming client connection request (only 1).
2. Accept that connection request.
3. Send something to the client.
4. Receive something from the client.
5. Close the accepted connection.
6. ... go to 1. (wait for incomming client connection request)
Only 1 client can send something to the server.
So, I tried to imeplement it like this:
WSAStartup(...);
server = socket(...);
bind(server, ...);
listen(server, ...);
client = accept(server, ...);
send(client, ...);
recv(client, ...);
closesocket(client);
...
So... my question!
This code runs in a own thread and should never ends (only when the user terminates the app).
After ther closesocket(client); when I want to re-listen to some incomming
connection request, have I to call only client = accept(server,...); or
listen(server,...); client = accept(server,...); ?
What's the wright way:
WSAStartup(...);
server = socket(...);
bind(server, ...);
place <code>while (TRUE) {</code> here ???
listen(server, ...);
or place <code>while (TRUE) {</code> here ???
client = accept(server, ...);
send(client, ...);
recv(client, ...);
closesocket(client);
<code>}
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
The second place, between listen and accept .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Hi Daniel,
the usual way is the following:
First, start with
CREATE a socket object.
Then Call BIND (if you use MFC, CAsyncSocket::Create() will do that for you)
After this, set your ServerSocket LISTEN.
(and here is your loop...)
Then comes the connection handling,
that means you have to implement each acceptet connection in a own thread, if you want to have a multi connection server. After accepting (and creating your connection thread) go back.
Hope this helps a little..
Cheers,
Olli!
Olli
Make it idiot proof and someone will make a better idiot......
|
|
|
|
|
Thanks, this will help!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
Hi Dear Developers,
From my application I'm executing a exe (by ShellExecute) and I want to do further processing once the program I executed is over. How will my application know when the program is terminated??
Thanks and Take Care
|
|
|
|
|
|
|
Dear friends,
I want advice regarding the efficient way of string searching. I got a text file in which about ten thousand english words are written (one word per line). All the words are arranged in alpabetical order.
Now you all people are aware of the intellisense feature of Visual studio. I also want to give like same feature in my application. There is a rich text box in my application. What i want is that whenever user type any word, a combo box automatically gets open and show all the words that starts from the first letter typed by the user, when user type second letter, the combo list decrease and only show those words having first and second letters same as what typed by user.
Letme give you example. If you have Win2k/XP, just go to start menu, and open the "Run" dialog box. Then type, c:\winnt\system32\s you will notice that as you type it, the combobox automatically expands showing the names of files or folders. The maximum files are in system32 and when you type any file name after typing system32\ then you may notice that how fast the operation of file sorting performed by the application to expand or contract the combo box.
I also want something like what i described above in my application. I have 10,000 words in text file. Now can anyone tell me that how can i efficiently perform this operation i.e how and when i load file. Do i need any appropriate STL container. How to perform string searching on the basis of characters typed by user e.t.c
Thanks.
|
|
|
|
|
Dictionary lookup is customarily implemented using a special kind of structures called tries. I'm afraid STL does not provide such a container, but possibly googling around will dig out some suitable library.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
|
I mean trie; it is a very remarkable structure that stores data in an efficient way both space- and looukp-wise. For instance, if the three words "the", "thunk" and "thunder" are stored in the trie, the following structure would result:
|->e
th->| |->k
|->un->|
|->der Hope you get the idea. There's an excellent article in CodeProject wich explains some more about tries, R. Reyes' Optimized IP to ISO3166 Country Code Mapping in C#[^], although it is for C# only.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
ups, that was kinda new to me, thx for the info.
|
|
|
|
|
Maybe looking into Bioinformatics can help you. These guys regularily solve the problems of searching through really huge amounts of letters (Genomics data) and find the spot where a given substring resides.
Just google..
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
You could load you list of words into a hash table of some sort.
Of cource you could use this very simple method:
(ASCII only solution)
class CIndexWhatEver
{
int m_Start, m_End;
....
};
Now create 2 arrays one to hold your list of strings and one to hold a list of CIndexWhatEver items. While you are loading your list into a CStringArray simply keep track of the ranges and add them to CIndexWhatEverArry. This works with ASCII to reduce search to range of strings starting with the given character.
int FindWhatEver(LPCTSTR lpStr)
{
TCHAR chStart = tolower(*lpStr);
// if in ranage 'a'-'z'
...
int nStart, nEnd;
m_WhatEverArray.GetRange(chStart-_T('a'),&nStart,&nEnd);
for( int i=nStart; i
|
|
|
|
|
Whoops! I should have use preview. But even though the FindWhatEver() code was trucated I thik the general idea is still clear
Trust in the code Luke. Yea right!
|
|
|
|
|
When I browse a file under a share folder in server, if the folder is a mapped drive in my computer. I will get the file path like Z:\\abc.dll, how
can I translate it to a UNC path like \\\Server\\Open\\abc.dll.
Liu Xilin
|
|
|
|
|
following is from msdn :
To find the UNC path associated with a mapped network drive letter, follow these steps:
1.Create a module and type the following lines in the Declarations section:
Option Explicit
' These represent the possible returns errors from API.
Public Const ERROR_BAD_DEVICE = 1200&
Public Const ERROR_CONNECTION_UNAVAIL = 1201&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_MORE_DATA = 234
Public Const ERROR_NOT_SUPPORTED = 50&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Public Const ERROR_NO_NETWORK = 1222&
Public Const ERROR_NOT_CONNECTED = 2250&
Public Const NO_ERROR = 0
' This API declaration is used to return the
' UNC path from a drive letter.
Declare Function WNetGetConnection Lib "mpr.dll" Alias _
"WNetGetConnectionA" _
(ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
cbRemoteName As Long) As Long
2.Type the following procedure:
Function GetUNCPath(strDriveLetter As String) As String
On Local Error GoTo GetUNCPath_Err
Dim Msg As String, lngReturn As Long
Dim lpszLocalName As String
Dim lpszRemoteName As String
Dim cbRemoteName As Long
lpszLocalName = strDriveLetter
lpszRemoteName = String$(255, Chr$(32))
cbRemoteName = Len(lpszRemoteName)
lngReturn = WNetGetConnection(lpszLocalName, _
lpszRemoteName, _
cbRemoteName)
Select Case lngReturn
Case ERROR_BAD_DEVICE
Msg = "Error: Bad Device"
Case ERROR_CONNECTION_UNAVAIL
Msg = "Error: Connection Un-Available"
Case ERROR_EXTENDED_ERROR
Msg = "Error: Extended Error"
Case ERROR_MORE_DATA
Msg = "Error: More Data"
Case ERROR_NOT_SUPPORTED
Msg = "Error: Feature not Supported"
Case ERROR_NO_NET_OR_BAD_PATH
Msg = "Error: No Network Available or Bad Path"
Case ERROR_NO_NETWORK
Msg = "Error: No Network Available"
Case ERROR_NOT_CONNECTED
Msg = "Error: Not Connected"
Case NO_ERROR
' all is successful...
End Select
If Len(Msg) Then
MsgBox Msg, vbInformation
Else
' Display the path in a Message box or return
' the UNC through the function.
MsgBox Left$(lpszRemoteName, cbRemoteName)
GetUNCPath = Left$(lpszRemoteName, cbRemoteName)
End If
GetUNCPath_End:
Exit Function
GetUNCPath_Err:
MsgBox Err.Description, vbInformation
Resume GetUNCPath_End
End Function
3.To test this function, type the following line in the Debug window, and then press ENTER. A simple message box appears containing the UNC path of the specified network drive letter.
?GetUNCPath("h:")
NOTE: This example assumes that you have a mapped network drive assigned to driver letter H.
Some of the possible return values for the GetUNCPath function include ERROR_BAD_DEVICE, ERROR_CONNECTION_UNAVAIL, and ERROR_NOT_CONNECTED.
Other run-time errors could be returned from the function and error trapping should be implemented.
|
|
|
|
|
;PI have posted this question in codeguru but none reply me. My question is:
How to get a particular line height in the CRichEditCtrl. For instance, the RichEditCtrl contains total of 20 lines and each line use different character format(CHARFORMAT) to show the text, then, how can I know the height in pixels of 4th line?
Thanks in advance.
lauch2
|
|
|
|