|
Hi
Could someone tell me how I can accomplish string case conversion using STL string, something like MakeUpper() and MakeLower() in CString?
Thanks!
|
|
|
|
|
Use foreach with a funtion that calls toupper on each character in the string.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian almost had it, but at least under my version of VC (.NET 7.0) toupper isn't passed the parameter by reference so you need to use std::transform
std::string str = "hello world";
std::transform(str.begin(),str.end(),str.begin(),::toupper);
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
Hello..
i've got a problem with threads and modeless dialogs.
With modal dialogs i had no problems. This is a mfc app(VC++6.0), in the main view, i created a button, and when i clicked on it i created a thread (which opened a dialog), then waited for the user to close the dialog, and delete the thread:
<br />
void CHilosView::OnButton1() <br />
{<br />
<br />
hilo = new CThread(); <br />
delete hilo;<br />
}
when i did the new CThread, it would create the dialog, when the user clicked on the cancel button of the dialog, the dialog would close, then it would get to the delete hilo line and it would be ok.
But now with modeless dialogs my function has become:
<br />
void CHilosView::OnButton1() <br />
{<br />
<br />
hilo = new CAccionarHilo();<br />
hilo->dlg->CThread(130); (dlg is a dialog, 130 it's id)<br />
hilo->dlg->ShowWindow(1);<br />
//delete hilo;<br />
}<br />
and i can't delete the thread there, because i would never be able to see the dialog!!.
So i'd love to be able to call the delete from the new dialog (that is created everytime i press button1 in the main window) 'cancel' button.
i can close the dialog, but i never get to delete the hilo (or thread (it's spanish))
I can't call the delete method as :'hilo' : undeclared identifier, and i can't include the hilosView header in the dialog class, because i include the Cthread file in the hilosView class, and it includes the dialog class.
hope you can help me!!
thanks!!
|
|
|
|
|
It's usually not a good idea to put a window/dialog in a secondary thread. You should post a user-defined message back to the main GUI thread to perform this service for you. If you really, really need to have GUI objects operating from a thread, you must not use a worker thread. You must use a user-interface thread, which has a message pump.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi,
I am have a program that uses serial port to transfer data from one machine to another. My program is actually running fine except for the problem that I have an intermittent scrambling of data received from the serial port. The bytes are actually interchanged position. Does anyone of you who knows this kind of problem ? Here is the sample data transmitted from the other machine. "test message" the data received by my program is like this "tets messgae"
then if I repeat it, sometimes the data is correct.
Any help is highly appreciated.!
Thanks,
Mar
Mar Solero Jr.
|
|
|
|
|
Thats impossible!
I think its a little bug in your code not a bug in serial comm.
Kamyar Souri
Booria CAD/CAM Systems
www.booria.com
|
|
|
|
|
i was just wondering how everyone gets there demo's and project's so small i just compiled a very small dialog it has 3 buttons 2 edits 1 combobox and 2 static text and its 2 mb i wanna know how to get it smaller
|
|
|
|
|
perhaps (in vb6.0)
project -> setting -> use MFC in a shared dll?
|
|
|
|
|
Did you compile it in debug mode?
|
|
|
|
|
1) VC++: Release < Debug build.
2) VC++: MFC: Shared Link < Static Link.
3) VC++: Win32 SDK < MFC.
4) Platform SDK Cmd-Prompt Build < VC++.
5) VC++ 7.x < VC++ 6.
Maxwell Chen
|
|
|
|
|
|
|
thanks mike that works wonders went from 2 mb to 236 kb
|
|
|
|
|
Whether the dialog has 3 controls on it, or 23, the net result will be almost the same. Debug compilation aside, there are a lot of factors that go into why a file is a certain size, and why the size is misleading most of the time. Read this article to get a better understanding.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi, sorry for asking so many hook related questions, I'm new to them, and the people here have been very helpful, and I'm grateful for that. Basically I want to recieve all mouse and keyboard events, and selectively process and block them. I have a WH_GETMESSAGE hook, which looks something like the following:
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
if(HC_ACTION==nCode)<br />
{<br />
MSG *pMsg=(MSG*)lParam;<br />
<br />
...<br />
<br />
pMsg->message=WM_NULL;<br />
lParam=(LPARAM)pMsg;<br />
}<br />
<br />
return CallNextHookEx(g_hHookMouse,nCode,wParam,lParam);<br />
}
This works fairly well, except some messages get through. The user can click to change windows, "restore" the window by clicking on the title bar, and I think just generally change the focus. I'm checking for and blocking these messages:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MBUTTONDBLCLK
WM_RBUTTONDOWN
WM_RBUTTONUP
WM_RBUTTONDBLCLK
WM_NCLBUTTONUP
WM_NCLBUTTONDOWN
Are there additional messages I should consider? Or should I take a different approach?
Thanks a lot!
modified 12-Jul-20 21:01pm.
|
|
|
|
|
There is a more efficient way. A WH_GETMESSAGE hook will get called for every message that is retrieved with GetMessage() (incidentally, AFAIK, messages retrieved with PeekMessage() are not passed to the hook procedure). Processing every message in the system is extremely slow and inefficient.
A far better way would be to install keyboard and mouse hooks (WH_KEYBOARD and WH_MOUSE ). That way, you get the keyboard and mouse events before they go in the message queue, and only process keyboard and mouse events.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
That was the way I originally implemented the hooks. The problem is that there doesn't seem to be a way to block both of the types of messages. The classic way seems to be to return -1, but that means that either the mouse or keyboard callback won't get called. Also, setting wParam=WM_NULL doesn't seem to work. So thats the reason I was trying to use a WH_GETMESSAGE hook. I'm open to suggestions on how to approach it though.
modified 12-Jul-20 21:01pm.
|
|
|
|
|
If you use WH_KEYBOARD_LL and WH_MOUSE_LL hooks and DO NOT call the CallNextHookEx, then the message will be blocked.
From the MSDN:
"Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications."
We use the WH_KEYBOARD_LL to block ALT+TAB and other key combinations and it works great!
|
|
|
|
|
The problem is, that if I first hook the keyboard and then the mouse, and I don't call CallNextHookEx from the keyboard hook, the mouse hook won't be called, so I can't get the messages. Same applies if its the other way around. That's why I was thinking the WH_GETMESSAGE hook would be preferable.
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Don't use the same function for each hook, or figure out why you are being called and decode the message and decide to send it further on or not.
There is no fundamental reason one hook should be interfering with the other, unless you inadvertently coded it that way.
|
|
|
|
|
I'm using separate functions for the hook. They are below:
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(HC_ACTION==nCode)
{
switch(wParam)
{
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
PostMessage(g_hWnd,g_hMouseMove,wParam,lParam);
break;
default:
PostMessage(g_hWnd,g_hMouseAct,wParam,lParam);
break;
}
}
if(g_bBlock)
return -1;
return CallNextHookEx(g_hHookMouse,nCode,wParam,lParam);
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(HC_ACTION==nCode)
{
PostMessage(g_hWnd,g_hKeyboard,wParam,lParam);
}
if(g_bBlock)
return -1;
return CallNextHookEx(g_hHookKey,nCode,wParam,lParam);
}
I install the hooks with this:
g_hHookMouse=SetWindowsHookEx(WH_MOUSE,MouseProc,g_hInst,0);
if(NULL==g_hHookMouse)
return FALSE;
g_hHookKey=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,g_hInst,0);
if(NULL==g_hHookKey)
return FALSE;
If g_bBlock is true, then it will block the mouse messages and the keyboard messages, though my app will still be able to process the mouse messages, but not the keyboard messages.
Maybe I misunderstood you, please tell me if I did.
modified 12-Jul-20 21:01pm.
|
|
|
|
|
This looks fine, mostly.
Also, you have to 'ignore' your block code if the nCode is less than zero:
<br />
LRESULT CALLBACK MouseProc(<br />
int nCode, <br />
WPARAM wParam, <br />
LPARAM lParam<br />
){<br />
if( HC_ACTION == nCode ){<br />
<br />
switch( wParam ){<br />
case WM_MOUSEMOVE:<br />
case WM_NCMOUSEMOVE:<br />
PostMessage(g_hWnd,g_hMouseMove,wParam,lParam);<br />
break;<br />
default:<br />
PostMessage(g_hWnd,g_hMouseAct,wParam,lParam);<br />
break;<br />
}<br />
<br />
if( g_bBlock ){<br />
return -1;<br />
}<br />
}<br />
<br />
return CallNextHookEx(g_hHookMouse,nCode,wParam,lParam);<br />
}<br />
You should do similarly for the mouse handler.
If you process a hook message while the nCode is NOT HC_ATION you will see bizarre results.
I notice you 'dont pass on' based upon the same global variable: g_bBlock
So, it would seem to me, if your 'block' variable is true, you won't see mouse or keyboard messages posted to anything but your global window.
Except, you might try changing it to
<br />
g_hHookMouse=SetWindowsHookEx(WH_MOUSE_LL,MouseProc,g_hInst,0);<br />
and
<br />
g_hHookKey=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProc,g_hInst,0);<br />
So you get raw events, and not ones that have been translated.
Also, in your install code, you will leak a hook handle:
If you keyboard hook install fials, you should unhook the mouse hook before returning false...
|
|
|
|
|
Good caught on the blocking statement, my fault on copying and pasting, it was in the right place originally.
After making your changes it works to some extent. All the messages are sent, but they're strange. Keyboard events lParam seem to be intact, I can still see if it was key up or down, but the key that was pressed seems to be scrambled, it doesn't map out to the right key, if it maps out at all. And the mouse move messages send the point that the mouse was last at, which I guess makes sense, and I guess I didn't specify that I need the coordinates of the mouse where it would be on screen if the mouse moved.
Sorry to be so whiny , but here's what I have now:
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(HC_ACTION==nCode && nCode>=0)
{
switch(wParam)
{
case WM_MOUSEMOVE:
case WM_NCMOUSEMOVE:
PostMessage(g_hWnd,g_hMouseMove,wParam,lParam);
break;
default:
PostMessage(g_hWnd,g_hMouseAct,wParam,lParam);
break;
}
if(g_bBlock)
return -1;
}
return CallNextHookEx(g_hHookMouse,nCode,wParam,lParam);
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(HC_ACTION==nCode && nCode>=0)
{
if(wParam==VK_F12)
InputBlock(FALSE);
PostMessage(g_hWnd,g_hKeyboard,wParam,lParam);
if(g_bBlock)
return -1;
}
return CallNextHookEx(g_hHookKey,nCode,wParam,lParam);
}
...
g_hHookKey=SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProc,g_hInst,0);
if(NULL==g_hHookKey)
return FALSE;
g_hHookMouse=SetWindowsHookEx(WH_MOUSE_LL,MouseProc,g_hInst,0);
if(NULL==g_hHookMouse)
return FALSE;
I imagine its a case of the code working perfectly (well, it always does, but you know what I mean), and that I need to be more specific on what I want. Basically, I need the mouse to actually move, so I can get the need coordinates and I need the actual key pressed.
Thanks for all the help so far!
Oh, and the leak is handled, when the DLL is unloaded it uninstalls and hooks that were installed.
modified 12-Jul-20 21:01pm.
|
|
|
|
|
When you use the low level keyboard hook, the lParam is different:
"lParam [in] Pointer to a KBDLLHOOKSTRUCT structure."
When you use the low level mouse hook, the lParam is different:
"lParam [in] Pointer to an MSLLHOOKSTRUCT structure."
You need to decode the data structure and pass the information to your program.
You can decode these data structures and pack the information intersting to your program into the lParam posted to your window, or else make a thread-safe queue and copy data to the queue, and then retrieve the queued data when a special message is processed by your window - perhaps a registered message indicating that new data is in the queue.
|
|
|
|
|