求教为什么我这个线程无法显示出相应的窗口

Antinucleon 2010-05-01 09:13:22
在创建线程前,已加入必要的初始化
hMod 为 hInstance的全局表示


DWORD WINAPI animate(LPVOID lpParam){
ANIMATE* lpAnimate=(ANIMATE*)lpParam;

lpAnimate->wndclass.style=CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS;
lpAnimate->wndclass.lpfnWndProc=NULL;
lpAnimate->wndclass.cbClsExtra=0;
lpAnimate->wndclass.cbWndExtra=0;
lpAnimate->wndclass.hInstance=hMod;
lpAnimate->wndclass.hCursor=NULL;
lpAnimate->wndclass.hIcon=NULL;
lpAnimate->wndclass.hbrBackground=(HBRUSH)GetStockObject(0);
lpAnimate->wndclass.lpszMenuName=NULL;
lpAnimate->wndclass.lpszClassName=lpAnimate->ID;

if(!RegisterClass(&(lpAnimate->wndclass))){
MessageBox(NULL,TEXT(lpAnimate->ID),TEXT("CAN NOT SUPPORT THE SYSTEM"),MB_ICONERROR);
}

lpAnimate->hwnd=CreateWindow(lpAnimate->ID,
TEXT(""),
WS_BORDER|WS_POPUP,
lpAnimate->ini_x,
lpAnimate->ini_y,
64,
64,
NULL,
NULL,
hMod,
NULL);

AnimateWindow(lpAnimate->hwnd,500,AW_VER_POSITIVE);
return 0;

}


typedef struct ANIMATE{
HWND hwnd;
WNDCLASS wndclass;
TCHAR ID[9];
int ini_x;
int ini_y;
int obj_x;
int obj_y;
int pic_ID;
HBITMAP hBitmap;
HBRUSH hBrush;
}ANIMATE;



bow先
...全文
155 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Antinucleon 2010-05-02
  • 打赏
  • 举报
回复
自己解决了


不是这样的
应该把typedef里的LRESULT前加上static


把线程说明里改成wndclass.lpWndProc=ANIMATE::WndProc就好了



[Quote=引用楼主 antinucleon 的回复:]
在创建线程前,已加入必要的初始化
hMod 为 hInstance的全局表示

C/C++ code

DWORD WINAPI animate(LPVOID lpParam){
ANIMATE* lpAnimate=(ANIMATE*)lpParam;

lpAnimate->wndclass.style=CS_HREDRAW|CS_VREDRAW|CS_SAVE……
[/Quote]
Antinucleon 2010-05-01
  • 打赏
  • 举报
回复
应该怎么修改呢?

[Quote=引用 4 楼 yincheng01 的回复:]

ANIMATE::WndProc此处指针有些问题
[/Quote]
Eleven 2010-05-01
  • 打赏
  • 举报
回复
LRESULT CALLBACK ThreadWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}


lpAnimate->wndclass.lpfnWndProc=ThreadWndProc;

你没有窗口过程,所以你CreateWindow()是不可能成功的
尹成 2010-05-01
  • 打赏
  • 举报
回复
ANIMATE::WndProc此处指针有些问题
Antinucleon 2010-05-01
  • 打赏
  • 举报
回复
我在struct里加入了普通的WndProc函数
并且修改了一行: lpAnimate->wndclass.lpfnWndProc=lpAnimate->WndProc;

这个错误怎么修改呢?


f:\dawn\dawn\animate.cpp(8) : error C3867: “ANIMATE::WndProc”: 函数调用缺少参数列表;请使用“&ANIMATE::WndProc”创建指向成员的指针
f:\dawn\dawn\animate.cpp(8) : error C2440: “=”: 无法从“LRESULT (__stdcall ANIMATE::* )(HWND,UINT,WPARAM,LPARAM)”转换为“WNDPROC”

[Quote=引用 1 楼 zyq5945 的回复:]

AnimateWindow后面没消息循环,无法处理消息,执行AnimateWindow完线程就退出了。
[/Quote]
Antinucleon 2010-05-01
  • 打赏
  • 举报
回复

那我可以在struct里加入一个LRESULT CALLBACK WndProc函数可以吗?


[Quote=引用 1 楼 zyq5945 的回复:]

AnimateWindow后面没消息循环,无法处理消息,执行AnimateWindow完线程就退出了。
[/Quote]
zyq5945 2010-05-01
  • 打赏
  • 举报
回复
AnimateWindow后面没消息循环,无法处理消息,执行AnimateWindow完线程就退出了。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧