请问在手动创建的窗口里面,如何接受其他程序发给它的自定义消息?
请问在手动创建的窗口里面,如何接受其他程序发给它的自定义消息?如何书写代码?代码该写在那里?
例子如下:
(所有应用到的函数事先已经定义申明)
static LRESULT WINAPI g_windowproc(HWND wnd,UINT msg,WPARAM wp,LPARAM lp) {
switch (msg) {
//自定义消息是不是加到这里?
case WM_CREATE:
{
assert (g_wnd == NULL);
// Store the window handle for use by other functions.
g_wnd = wnd;
// If "Remember window positions is enabled, this will
// restore the last position of our window. Otherwise it
// won't do anything.
apply_window_placement(cfg_window_placement, wnd);
}
break;
case WM_DESTROY:
{
// If "Remember window positions is enabled, this will
// save the current position of our window. Otherwise it
// won't do anything.
read_window_placement(cfg_window_placement, wnd);
// Remove our window handle from the global variable.
g_wnd = NULL;
}
break;
case WM_CLOSE:
{
// Hide and disable the window.
g_hide_window();
}
break;
case WM_KEYDOWN:
switch (wp) {
case VK_ESCAPE:
{
// Hide and disable the window.
g_hide_window();
}
break;
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(wnd, &ps);
// We will only paint out client area in white for now.
FillRect(ps.hdc, &ps.rcPaint, (HBRUSH)GetStockObject(WHITE_BRUSH));
EndPaint(wnd, &ps);
}
break;
default:
return uDefWindowProc(wnd,msg,wp,lp);
}
return 0;
}
static void g_show_window() {
static bool registered = false;
static const char * TUTORIAL1_WINDOW_CLASS = "fb2k tutorial 1 class";
if (!registered) {
uWNDCLASS wc;
memset(&wc,0,sizeof(wc));
wc.style = CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
wc.lpfnWndProc = g_windowproc;
wc.hInstance = core_api::get_my_instance();
wc.hCursor = uLoadCursor(0,IDC_ARROW);
wc.hbrBackground = 0;
wc.lpszClassName = TUTORIAL1_WINDOW_CLASS;
registered = uRegisterClass(&wc) != 0;
}
if (!g_wnd && registered) {
uCreateWindowEx(
WS_EX_TOOLWINDOW,
TUTORIAL1_WINDOW_CLASS,
TUTORIAL " " SUPERLYRICS,
WS_POPUP|WS_THICKFRAME|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT,
200, 200,
core_api::get_main_window(),
/* no menu */ 0,
core_api::get_my_instance(),
/* no parameter */ 0 );
cfg_enabled = g_wnd != NULL;
}
}
希望各位大侠高手出招,先谢了!