|
Dear Cool_Dev
Thank you for your help
I've solved this problem.
Here are what I've done;
First of all,
It is not nessesary to move the ON_MESSAGE( USER_MESSAGE_2, &CMyWnd::OnMyMessage1HandlerApp ) entry to CMyWnd class's message map.
Even though CWinApp derived class is never meant to handle windows messages,
We still can hanlde windows messages in CWinApp derived class.
How?
This is how to get it done. It was simple.
Cast the Handler in App class's message map with CWnd::*
It should be like this;
ON_MESSAGE( USER_MESSAGE_2, (afx_msg LRESULT(AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))OnMyMessage1HandlerApp )
Cast the Handler with (afx_msg LRESULT(AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))
Then, problem solved.
But I haven't proved the safety of this casting during the application run-time.
Well, I compiled and run the application. It seems fine. Nothing odd happened so far with this type casting.
Thanks.
Chan from SEOUL
modified on Wednesday, August 11, 2010 3:50 AM
|
|
|
|
|
Yes.. you are right. The above scenario works well with theApp.PostThreadMessage(USER_MESSAGE_2, 0, 0);
But when you want to send USER_MESSAGE_2 message to a window, you should move the entry to curresponding window's message map.
|
|
|
|
|
let me write you my coding for user defined msgs maybe this will give you something:
#define WM_USER_THREAD_COMPLETED WM_USER + 2
#define WM_USER_THREAD_ENDED WM_USER + 3 in stdafx.h
ON_MESSAGE( WM_USER_THREAD_COMPLETED, OnThreadCompleted )
ON_MESSAGE( WM_USER_THREAD_ENDED, OnThreadEnded ) on the messagemap
and my handles are like this:
LRESULT CStartStopDlg::OnThreadCompleted( WPARAM wParam, LPARAM lParam)
{
...
return 1;
}
LRESULT CStartStopDlg::OnThreadEnded( WPARAM wParam, LPARAM )
{
...
return 1;
}
to call these,
i use
::PostMessage( m_hWnd, WM_USER_THREAD_COMPLETED, (WPARAM)ps, (LPARAM)ns );
::PostMessage(m_hWnd,WM_USER_THREAD_ENDED,(WPARAM)ps,0); where m_hWnd is my main dialog window
|
|
|
|
|
I encapsulate an ActiveX control(Microsoft web browser) in DLL!
which offer to a game program~ in the game program there's maybe some hotkey for example: press 'M' will open a map.etc! but my DLL will display some page which allow user to input some text!
the problem occur~ if user input 'm' in the textbox. the operation will activate the hotkey 'M' to open a map!! how can i solve the problem~ or i don't need to solve it~~but let the game programmer do that????
|
|
|
|
|
I think, its the game programmer who can do some thing in his WM_HOTKEY message handler to check whether the edit field in webpage of web browser is active and being changed. Then he can show the map accordingly.
The webpage can have java script functions to return the state of edit fields in Form. This article shows the javaScript calls from C++. http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399
|
|
|
|
|
en....i think so~~ thx so much for your help!!!!
|
|
|
|
|
Hi,
I am trying to display unicode text read from a file.
I am using messagebox to display the text.
VC 6.0 does not store unicode text as it is so i want to try whether reading from a file works.
Here is the code.
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <tchar.h>
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
void pint(int);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
int f,len;
char str[100];
TCHAR tstr[100];
f = open("c:\\uni.txt",O_RDONLY|O_BINARY);
len = read(f,str,50);
close(f);
str[len] = '\0';
tstr[len] = 0;
pint(len);
MultiByteToWideChar(CP_ACP, 0, str, len, tstr, len);
MessageBoxW(NULL, tstr, _T("Note"), MB_OK);
return 0;
}
void pint(int src)
{
char buff[512];
TCHAR tbuff[512];
int len;
itoa(src,buff,10);
len = strlen(buff);
buff[len] = 0;
tbuff[len] = 0;
MultiByteToWideChar(CP_ACP, 0, buff, len, tbuff, 512);
MessageBoxW(NULL,tbuff,_T("PINT"),MB_OK);
}
Project Options
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /Fp"Debug/uni.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
Pre processor definition
WIN32,_DEBUG,_WINDOWS,_MBCS
The length of the text file in UFT-8 format is 18 bytes and when i echoed the size it said 18 bytes.
But the characters are junk with extended ascii charset.
The text in the file is தமிழ்
What am i missing.
I have been using devc++ but it had problems so i thought it should work in vc6.0 and if so then i can change my ide. Using .Net ... i will do that after some time but now i want to make it work in vc 6.0 or devc++...
In codeblocks it is working fine with GCC compiler.
|
|
|
|
|
From the title of the question (even though you don't mention it in the question itself) shouldn't the codepage be CP_UTF8?
Cheers,
Ash
|
|
|
|
|
Exactly. I was about to update that to my own reply and found your reply.
thank you.
here was the line i was about to post.
MultiByteToWideChar(CP_UTF8, 0, str, len, tstr, len);
But in the alert i get extra chars. IF it is a multi line text box notting appears.
|
|
|
|
|
Are you sure you're providing the correct length parameters? It looks like you're saying convert len bytes which won't include the terminating '\0' which means the UTF-16 output won't be zero terminated either.
Just out of interest I wouldn't bother using TCHAR. You use TCHAR when you want two builds of your app, one that's wide character and one that's multibyte. As you're essentially writing a wide character app and explicitly converting to UTF-8 you might as well use wchat_t. If you compiled your code without UNICODE and _UNICODE it would get a bit confused.
Cheers,
Ash
|
|
|
|
|
For now my app is totally unicode. So i have converted all to unicode.
I still have to figure out all the data types. still TCHAR and wchar_t ???
Finally my program was working well. and... what is it with '\0'; how to terminate an unicode string?
|
|
|
|
|
anyway the code is finally working as expected. i will analyse your response. thank you.
|
|
|
|
|
I am writing to a USB device using the WriteFile() API in synchrounos mode but it returns 0x05
error code which means that access is denied.This error occur on Windows 7 though i am an administrator.
The following is the code i am working with it.
CreateFile() successfully create a file.
then I check via DeviceIoControl()that disk is write able , it return true.
and after that when i write via WriteFile() , the api fails and return.
Any help would be appreciated.
|
|
|
|
|
You should show the exact code if you want help. Maybe there is a problem in your WriteFile call that we could see that you're overlooking.
|
|
|
|
|
Member 3903154 wrote: I check via DeviceIoControl()that disk is write able , it return true
that doesn't make much sense to me, for a couple of reasons.
1. The disk being writable does not imply you will be able to write the specific file.
2. If CreateFile succeeded, it already was able to modify the directory.
3. And anyways, DeviceIoControl returns true whenever it succeeds at executing what you ordered, so it returning true may or may not indicate the disk is writable.
As Richard suggested, show more of the code.
|
|
|
|
|
Does anyone know to quickly make a multiple search & replace app (in either C or C++)? Am not interested in searching multiple files, just one file. I want to translate a list of unicode characters into something else (pair-value lookup table) ... so it's basically a crude/naive translator!
I just need a quick pseudocode to get me started. Or maybe there's an opensource/free code already written?
PS: Or maybe it's easier quicker with sed/awk/perl?
|
|
|
|
|
Look like a FAQ question for any programming language. While this needs some C/C++ copy and paste skills, it's a Perl/Python/Lua/sed/awk three liner with regular expression. There is probably a very elegant monad transformer in Haskell too (that nobody understands).
What have you tried so far?
/M
|
|
|
|
|
I would use awk (just because I know a bit it). Go with Lua (check out the LPeg[^] library) to experience real power.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I was hoping you give a Haskell example.
|
|
|
|
|
Sorry man, I don't know Haskell .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
How to Get CMenu Rect?
CRect rectMenu;
::GetWindowRect((HWND)?, rectMenu);
if so, how to get HWND of CMenu.
I want to ClipCursor(), limit the range of cursor movement within the Rect of PopupMenu.
to do this, first I have to get the shown rect of my CMenu(from rightbutton contextmenu).
modified on Tuesday, August 10, 2010 9:39 AM
|
|
|
|
|
CMenu has no HWND .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
then...
How to Get CMenu Rect?
|
|
|
|
|
For what purpose? Explain what you are trying to do. Knowing that, someone may be able to explain a better approach.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I want to ClipCursor(), limit the range of cursor movement within the Rect of PopupMenu.
|
|
|
|