|
Version 2 of the question
While I've learned a lot of this page, still I do not know the following:
I've the code:
class hehheh
{
HWND somewhere;
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
void SomeFunction()
{
SetWindowLong(this->somewhere, GWL_WNDPROC, (LONG)WndProc);
}
}
which doesn't work (that I know, and I know why), but the solution of giving the
this as parameter can't be done, because there isn't room for it, how to work arround this problem.
I'm fighting with the code for several weeks already.
Thanks already
N.B. I'm not using MFC / WTL, and I just cut'n'paste some rules out of the code, so I gave it some other names for easyness.
LPCSTR Dutch = "Double Dutch "
|
|
|
|
|
Sorry, I misread the question.
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
If you are trying to SetWindowLong and you want the HWND of "this" try..
SetWindowLong(this->GetSafeHwnd(), GWL_WNDPROC, (LONG)SubClassProc);
instead of the
this->somewhere
Hope this helps..
Rob
|
|
|
|
|
Where is the SubClassProc function defined, did you mean to put hehheh::WndProc as the function that you want to set in SetWindowLong?
If so you can make WndProc a static function of the class. Then when you create your window that the class represents, store a pointer to the class in the USER_DATA of the window by calling SetWindowLong(GWL_USERDATA, this);
Then inside of the static version of WndProc, get the USER_DATA variable and cast it to a hehheh pointer like this:
hehheh *obj = dynamic_cast<hehheh*>(::GetWindowLong(GWL_USERDATA));
if (NULL == obj)
{
}
With this pointer inside of your class you can call the real WNDProc of your class with the pointer that you just decoded.
If you really want to do it efficiently, look at how it is done in WTL's WndProcThunk class.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Now I'm coming to what I wanted. So the GWL_USERDATA contains this (the pointer to the class instance) and that I can call it back (Ah, now I understand why they called it CALLBACK ) via the obj, and obj is still the same pointer to the address of the class instance: this I guess?
LPCSTR Dutch = "Double Dutch "
|
|
|
|
|
SetWindowLong(this->somewhere, GWL_WNDPROC, (LONG)SubClassProc); I guess you meant this to read
SetWindowLong(this->somewhere, GWL_WNDPROC, (LONG)WndProc); Otherwise, I'm not catching your question.
I think this thread addreses your problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I wasn't really clear about what I wanted, but I'm not using MFC or WTL, so I think that has to clear bit's up. the HWND somewhere I declared is just an existing working HWND, but I just had to take a name.
The SubClassProc is indeed a failure, it has to bee WndProc instead.
LPCSTR Dutch = "Double Dutch "
|
|
|
|
|
Maybe you haven't noticed my previous post contained a link to another discussion where a solution is provided (In my browser the link appears almost unnoticeable.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am having problems with running this code twice..
I have a function that calls OnStartThread() after the thread has finished the work and the data has been updated I try to run this again and my program crashes. I think it has to do with the PostMessage (not sure though).. do I have to kill the msg after I post it? What am I doing wrong?
......
void run();
void OnStartThread();
volatile BOOL running;
static UINT run(LPVOID p);
......
void CMainFrame::OnStartThread()
{
running = TRUE;
UpdateData(FALSE);
AfxBeginThread(run, this);
}
UINT CMainFrame::run(LPVOID p)
{
CMainFrame * me = (CMainFrame *)p;
me->run();
return 0;
}
void CMainFrame::run()
{
.....
PostMessage(ID_UPDATE_TIME,0,0);
running = FALSE;
}
Thanks,
Rob
|
|
|
|
|
You are not doing it in thread. You sure have to use PostMessage to start a function in another thread. Look, CMainFrame belongs to one thread and when you are calling a function of it from another, the function is still running in same thread and context as CMainFrame
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
I'm not sure I fully understand.. If I start the worker thread from CMainFrame and I want to call a function inside CMainFrame I shouldn't use PostMessage? When I try to run the function with out posting the msg. it crashes because the function that gets called assigns and accesses a pointer to CListView..
The PostMessage seems to work only once.. If I try to run the worker thread again the app crashes at PostMessage?
Can you give me some more details so I can understand what I am doing wrong?
Thanks!
Rob
|
|
|
|
|
Omg... now I'm confused, lol. I saw that you have 2 functions with same name, one is static and one is not. But this is doesn't matter, you should not use pointer to CMainFrame in another thread to un functions, you should use PostMessage always to communicate between threads, then in the handler of that message (in CMainFrame) you can call any function of the frame.
So it goes like this:
CMainFrame (thread 1) -> [New thread] -> PostMessage to CMainFrame (thread 2) -> Handle message in CMainFrame (thread 1) -> call to run (thread 1)
You see? There is no direct access to CMainFrame functions from thread 2. Instead you are posting message, and it works like trigger, command to CMainFrame to start working with run
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
so with in run(LPVOID p) instead of passing a pointer to CMainFrame and executing run() I should PostMessage to CMainFrame to run the run()? Then with in run() I can post a msg back to CMainFrame to run the UpdateTime() function?
hehe how weird..
|
|
|
|
|
Errr.... lol, well it is because you have function names that are not suitable for such communication
But yes, this is the preffered way. Of course you can use Events, mutexes, semaphores and another such tricks, but PostMessage is the easiest one. The point is that you can't use a pointer (class, whatever) from another thread to run functions from the second
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
Ah, well, discard my previos post. I just paid attention that your "run" function is static, which has same meaning as global. So you should not use the pointer to CMainFrame to reach it, but: CMainFrame::run()
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
Does anyone know of a line drawing function where I can specify the degrees the line should be drawn (i.e. - 0 to 360 degrees). I am also looking for a function to export this line as an image and save it to a file. Any help would be great. Thanks.
Nick Parker
Actually, real programmers don't need the enter key- they just type in 00001101."
|
|
|
|
|
I believe you should be able to use just sine and cosine calculations to figure this out and use LineTo etc to draw the lines.
|
|
|
|
|
Is it the same way you do when exporting functions from a DLL when exporting a function from an EXE??
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
As I remember it is the same way. And same way you are exporting them. I did such thing about 2 years ago, using DEF file ,not __declspec . So not sure if you can export/import classes in exe. But LoadLibrary and all that stuff is working fine
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
Philip Patrick wrote:
So not sure if you can export/import classes in exe
But I can export functions as you said!
Thanks!
ps. this is my 400th message!
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Rickard Andersson wrote:
this is my 400th message!
Congratulations!
Philip Patrick
Web-site: www.stpworks.com
"Two beer or not two beer?" Shakesbeer
Need Web-based database administrator? You already have it!
|
|
|
|
|
congrats
|
|
|
|
|
How can I make my app check if there is any current transfer??
I mean, if the internet connection is on and nobody is sitting and surfing I want the modem to disconnect. But how will I know if there is any transfer?
I hope you understand me!! Please ask me if you don't!
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|
|
Isn't there already a "Disconnect timeout" in some of the RAS dialogs? If you can't find it, surely your modem has this ability. Read up on it's AT command set.
|
|
|
|
|
Mike Nordell wrote:
Disconnect timeout
ooh.. I will check that out!
Thank you!
Mike Nordell wrote:
surely your modem has this abil
But how do I put my modem in to the Visual Studio IDE!?!?!!?
Rickard Andersson@Suza Computing
ICQ#: 50302279 (Add me!)
E-mail: nikado@pc.nu
I'm from the winter country SWEDEN!
|
|
|
|