请问在手动创建的窗口里面,如何接受其他程序发给它的自定义消息?如何书写代码?代码该写在那里?
例子如下:
(所有应用到的函数事先已经定义申明)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;
}
}希望各位大侠高手出招,先谢了!
例子如下:
(所有应用到的函数事先已经定义申明)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;
}
}希望各位大侠高手出招,先谢了!
解决方案 »
- High-speed Charting Control控件问题
- 关于OnPaint()的使用
- 郁闷!为什么我在一继承CView(CMyview)里添加一继承于CTreeView的CMytreeview(m_a)成员变量,在初始化时动态创建m_a,但关闭系统时却抛出异常是怎么回事?
- 关于取得别的进程中,ListView控件中的文本内容的问题!
- 如何在程序中响应COM控件中的事件?
- 谁能告诉我MUSIC的算法
- 再再问关于屏幕的刷新!!
- 请大家参谋一下!
- 关于CRecordset 的open问题。
- 求VC6操作WPS电子表格源代码
- 有关winsock2的重叠IO模型问题
- -----CSDN让你技术硬起来,CSYN让你腰包鼓起来------------
WM_APP+1。
switch (msg)
{
...
case WM_USER+300:
// Your code
break ;
...
}
}