Skip to main content
gamedev.net
🔒 Locked

design problem, C# problem, callback problem

Started by wah_on_2 3 replies 1.7k views
Original Post
wah_on_2
wah_on_2
Hi all, I have some problems about program design. 1. I created a class call MainWnd, it is the first created Window when the program start and it will initial data members. e.g. database connection object, network connection object..... The MainWnd class is contained three menu items, when user clicked menu item1, item2 or item3, a mdi window will create and called MdiWnd1 MdiWnd2 or MdiWnd3. The three MdiWnds will use the MainWnd.Connection to access database. My question is that should i set the connection data member static in MainWnd and then the three classes can use it without new instance? Or should i pass the connection object to the three mdiwnd classes for the reference when creating itself? It seem the second solution beauty. However, it is unconvenient. How can i make decision? Or any other solution? 2. How can i post/send a message to mdi from parent window or post/send message from parent window to mdi in .Net framework using C#? 3. I have a class call CWindow, it will contain a CallBack method call WinProc(....). And the the callback will used for te value of WNDCLASSEX WinClassEx; WinClassEx.lpfnWndProc = CWindow::WinProc; What is the syntax? I tried the following syntax, but it doesn''t work. //CWindow.h class CWindow { ...... static long WINAPI WinProc(.....); } //CWindow.cpp #include "CWindow.h" CWindow::CWindow() { ...... WNDCLASSEX WinClassEx; WinClassEx.lpfnWndProc = CWindow::WinProc; ..... } long CWindow::WinProc(...){....} Pls help me to answer those question. It make me so tired. Thx a lot of ^_^
original vesoljc
original vesoljc
question3:
wndclassex requires static callback func... do a search for a window wrapper
Abnormal behavior of abnormal brain makes me normal...
wah_on_2
wah_on_2
yes. i set the WinProc to static but it aso cannot work. Why?

And how about question 1 & 2?

Thx
Arild Fines
Arild Fines
quote:
Original post by wah_on_2
2. How can i post/send a message to mdi from parent window or post/send message from parent window to mdi in .Net framework using C#?


You call methods on the child window object from the parent window object or vice versa.



"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
original vesoljc
original vesoljc
for the win wrapper you basically need two functions, your standard winproc (nonstatic) and a sort of a "router" (static)

class header

  
static LRESULT CALLBACK Router (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);


class source, note: AXP_Window is my class name

  
// static function router

LRESULT CALLBACK AXP_Window::Router(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if (msg == WM_NCCREATE)
{
LPCREATESTRUCT lpcs = LPCREATESTRUCT(lparam);
SetWindowLong(hwnd, GWL_USERDATA, (long) lpcs->lpCreateParams);
}
AXP_Window *p_this = (AXP_Window *) GetWindowLong(hwnd, GWL_USERDATA);
if (p_this)
{
return(p_this->WindowProc(hwnd, msg, wparam, lparam));
}
else
{
return(DefWindowProc(hwnd, msg, wparam, lparam));
}
}

// Message handling callback procedure

LRESULT CALLBACK AXP_Window::WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_KEYDOWN:
PostQuitMessage(1);
break;
case WM_DESTROY:
m_destroy = true;
break;
case WM_ACTIVATE:
if(LOWORD(wparam))
Activate(true);
else
Activate(false);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
}




and when creating WNDCLASSEX
m_class.lpfnWndProc = AXP_Window::Router;


since wndclassex wants a static func, u cant use AXP_Window::WndProc(...), so what we do is make a static func which resolves the right address of the function (remeber, class member functions!) and calls the right function. sort of

Abnormal behavior of abnormal brain makes me normal...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.