|
dear Sandip,
thanks so much. i can do it already~~~
|
|
|
|
|
Welcome
Regards,
Sandip.
|
|
|
|
|
hi
it is a dialog based MFC application
it has only a dialog with a web browser (activex)object
i have created it dynamicaly with CWnd wrapper class
everything ok and works well
but i want to remove sunken border of web browser object
i want it to be complete flat ,is it possible
i have tried something with class name Internet Explorer_Server
but no success
can you help me with this
also is there a way to disable contex menu of web browser object
thank you
|
|
|
|
|
Did you try removing the border style?
|
|
|
|
|
yes of course
SetWindowlong()
CWnd::ModifyStyle()
not working or i could not implement
|
|
|
|
|
Hi
1-) I compiled a DLL which is a hook dll. It calls SetWindowHookEx and hook Keyboard. and there is a hookproc.
void StartHook(HWND hWnd)
{
hHook = SetWindowsHookEx(WH_KEYBOARD, HookProc, hmod, NULL);
hWndServer = hWnd;
};
2-) And I compiled a MFC app. which includes this dll. And calls StartHook. Also it sends its handle to dll. So they can communicate each other.
HWND hWnd = ::GetDlgItem(this->m_hWnd, IDC_EDIT1);
StartHook(hWnd);
3-) In MFC app. there is an edit control which I want to show dynamically which keys user pressed.
So first i get editcontrols textlength
int textlength = SendMessage(hWndServer, WM_GETTEXTLENGTH, 0, 0) + 1 ;
and then try to replace text of the edit control with WM_SETTEXT:
TCHAR *td = new TCHAR(textlength+1);
SendMessage(hWndServer, WM_GETTEXT, textlength, (LPARAM)td);
SendMessage(hWndServer, WM_SETTEXT, 0, (LPARAM)td);
delete[] td;
4-) It doesn't work and run-time error.
Here something wrong.
In MSDN for WM_Settext's lParam parameter:
"Pointer to a null-terminated string that is the window text."
It is a pointer to another process address space and with sendmessage it is sended to another process. And it is meaningless for other process.
Is this caused run-time error?
How can i solve this problem? (I mean using WM_settext to send a string to another process)
Thanks..
modified on Tuesday, September 9, 2008 4:42 PM
|
|
|
|
|
sawerr wrote: SendMessage(hWndServer, WM_GETTEXT, textlength, (LPARAM)td);
That should be
SendMessage(hWndServer, WM_GETTEXT, textlength+1, (LPARAM)td);
sawerr wrote: 4-) It doesn't work and run-time error.
What error?
You may get better results posting a message to a window on the same
thread as the message loop the edit control is on. Let the handler
for that message do the WM_GETTEXT/WM_SETTEXT stuff instead of doing
it from the hook proc.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
OK. Understood.
But is there a way to send a text string to another application with SendMessage+WM_SETTEXT?
Because of lPararm is just a pointer, this way doesn't allow to send a buffer to another application i think. Or I couldn't find a way...
|
|
|
|
|
sawerr wrote: is there a way to send a text string to another application with SendMessage+WM_SETTEXT?
No. You could use WM_COPYDATA or some other IPC mechanism[^] however.
Did you mention another application and I missed it?
I thought this was DLL to EXE...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes, it is dll to exe. But dll calls SetWindowsHookEx. So it is loaded to all processes address spaces.
So it becomes exe to exe, as in the figure:
http://www.codeproject.com/KB/DLL/hooks.aspx[^]
I thought i could update textbox's text from dll as i tried to explain above.(In dll first get text with Sendmessage-WM_gettext and append new presssed key and send it to the application with SendMessage+WM_SETTEXT)
|
|
|
|
|
sawerr wrote: So it becomes exe to exe, as in the figure:
Then I guess other options are to one of the IPC methods described
at the previous link or do something similar to what Joe does in his
article but post the WPARAM and LPARAM passed to the KeyboardProc to
a window in the exe process and let the EXE do the string stuff.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I just noticed this
sawerr wrote: int textlength = SendMessage(hWndServer, WM_GETTEXTLENGTH, 0, 0) + 1 ;
You already added 1 ... I didn't see that, but this:
sawerr wrote: TCHAR *td = new TCHAR(textlength+1);
is BAD! That should be
TCHAR *td = new TCHAR[textlength];
The wrong brackets is probably the runrime error problem, since not enough
space is allocated for a string longer than 0 TCHARs if you use parenthesis.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Shame on me. OK. I see it.
But although these stupid errors, i think wm_settext+sendmessage could not send text as i tried to explain my previous post.
|
|
|
|
|
Hi
Am new to the registry concept in C++, I need help regarding registry subkey concepts. If possible please solve my issue with example source code to get registry subkey value.
|
|
|
|
|
This article should help.
Regards,
--Perspx
Don't trust a computer you can't throw out a window
-- Steve Wozniak
|
|
|
|
|
|
|
I'm losing my mind over some Unicode issue and hopefully someone can help me out. I haven't done a ton of MFC stuff before, so hopefully it's a simple problem.
I've Unicode enabled in this project because I've got a 3rd party library that requires it. I've subclassed CListBox to get a list box that shows multiple lines per item. I'm overriding DrawItem and MeasureItem. In DrawItem I have the following lines for drawing text:
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
...
dc.DrawText(lpszText, _tcslen(lpszText), &lpDrawItemStruct->rcItem, DT_LEFT | DT_TOP | DT_WORDBREAK);
In my main dialog class I add data to the list box like this:
m_ProductList.AddString((LPCTSTR)updates[i]->ToString().c_str());
And my text comes out looking like garbage. Usually Chinese characters. I can get the output to look correct if I do:
m_ProductList.AddString(TEXT("yoyoyoyoy\nzomgzomg\nblabla"));
I tried looking at what the TEXT macro does, but the farthest I can get is that is is an alias for L## which is difficult to google.
I've tried a lot of stuff and nothing has worked. I've tried: MultiByteToWideChar, CT2CW, A2W, and some other stuff.
My understanding of this issue is that I've got a UTF-8 encoded string from an XML file that's stored in a std::string. Then, since I'm using Unicode, DrawText is actually DrawTextW. So, I have to convert my string to Unicode, but nothing seems to be able to do that conversion.
Thanks,
Nick
|
|
|
|
|
Instead of trying a bunch of stuff, it may be easier to take a close
look at the type of the characters in your strings.
A good clue is the need for casts. You shouldn't need any casts.
If you do, then look at why.
For example:
m_ProductList.AddString((LPCTSTR)updates[i]->ToString().c_str());
Why the cast to LPCTSTR?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I was a little confused about that part too. If I don't cast it, I get a compile error: cannont convert from const char* to LPCTSTR. I always thought those were the same thing.
Another odd part of this problem is that when I use a standard CListBox, I can correctly add items to it like this:
USES_CONVERSION;
CA2CT converted(updates[i]->ToString().c_str());
m_UpdateBox.AddString(converted)
Which makes it seem like I'm incorrectly calling DrawText in my subclass because when I add the same text to my list box I get bad data on the display.
|
|
|
|
|
thebeekeeper wrote: I get a compile error: cannont convert from const char* to LPCTSTR. I always thought those were the same thing.
That's exactly what I'm talking about That's a perfect example why
casting away problems is BAD. C++ is a strongly typed language - know
your data types!
No, LPCTSTR is NOT the same as a char *.
Here's the macro breakdown for LPCTSTR:
LP = long pointer
C = constant
T = generic-character-type (wchar_t for Unicode builds, else char)
STR = string
thebeekeeper wrote: when I use a standard CListBox, I can correctly add items to it like this:
Yes, because you're converting the string to the type the
listbox is expecting.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for that tip on data types. I never realized LPCTSTR was just an alias for the generic string type of the build.
I guess this is really what I don't understand. CA2CT converts ASCII to wchar_t since this is a Unicode build, right?
CListBox::AddItem expects LPCTSTR. But this is actually a LPCWSTR, right? So, why does converting with CA2CT work with the stock CListBox and not my subclass? CListBox::DrawItem has to be calling DrawTextW, which is the same thing I'm calling.
|
|
|
|
|
thebeekeeper wrote: CA2CT converts ASCII to wchar_t since this is a Unicode build, right?
Right. A is ANSI, T is generic...A2T is ANSI to generic.
thebeekeeper wrote: why does converting with CA2CT work with the stock CListBox and not my subclass?
Is the source string already a Unicode (wchar_t) string?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No, it's coming out of std::string c_str(), so it's a const char*. There's no way that can be Unicode, right?
Also, if I use OutputDebugString, it works after I use the CA2W conversion and looks correct in the output window. So, I've got this:
USES_CONVERSION;
CA2W converted(updates[i]->ToString().c_str());
m_UpdateBox.AddString(converted);
m_ProductList.AddString(converted);
OutputDebugString(converted);
I'm starting to think I'm pulling out bad data in my DrawItem method, but I copied that code from MSDN, so it can't be wrong
|
|
|
|
|
thebeekeeper wrote: it's coming out of std::string c_str(), so it's a const char*. There's no way that can be Unicode, right?
Right, but a deeper question is why are you using a string
type hardwired to char in a Unicode environment?
I recommend using generic string types everywhere in
an MFC app. MFC does, so it works out nice when we do.
Using all generics makes any code you write compilable in
both Unicode and non-Unicode builds, just like MFC. Plus
you don't need to do all those string conversions, which are
inefficient.
If you must use STL strings, you could make your own generic
string class:
typedef std::basic_string<TCHAR, char_traits<TCHAR>,
allocator<TCHAR>> genericstdstring;
Use genericstdstring in place of std::string.
thebeekeeper wrote: but I copied that code from MSDN, so it can't be wrong
Umm...if you say so
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|