回 帖 发 新 帖 刷新版面

主题:请各位大侠看一下程序

是一段生成窗口的程序代码,在键盘或者鼠标按下的时候是实现显示字符ASC码,可以关闭和最大化和最小化窗口,但是我在系统VC6.O编译通过,在运行的时候,窗口不接受任何字符和鼠标按键,也不能最大化和最小化和关闭窗口,退不出窗口,请问什么原因啊?
[code=c]
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam 
    );

int WINAPI WinMain(
  HINSTANCE hInstance, // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
     WNDCLASS wndcls;
     wndcls.cbClsExtra=0;
     wndcls.cbWndExtra=0;
     wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
     wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);

     wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
     wndcls.hInstance=hInstance;
     wndcls.lpfnWndProc=WinSunProc;
     wndcls.lpszClassName="weixin2003";
     wndcls.lpszMenuName=NULL;
     wndcls.style=CS_HREDRAW | CS_VREDRAW;
     RegisterClass(&wndcls);
      
    HWND hwnd;
    hwnd=CreateWindow("weixin2003","北京维新科学技术培训中心",WS_OVERLAPPEDWINDOW,
         0,0,600,400,NULL,NULL,hInstance,NULL);
     ShowWindow(hwnd,SW_SHOWNORMAL);
     UpdateWindow(hwnd);
     MSG  msg;
     while (GetMessage(&msg,NULL,0,0));
     {    
         TranslateMessage(&msg);
          DispatchMessage(&msg);
     }
     return 0;


}
 static LRESULT CALLBACK WinSunProc(
    HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam 
)
{
    switch(uMsg)
    {
     case WM_CHAR:
     char szChar[20];
      sprintf(szChar,"char is%d",wParam);
     MessageBox(hwnd,szChar,"weixin",0);
        break;
     case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked,","weixin",0);
        HDC hdc;
        hdc=GetDC(hwnd);
        TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));

        ReleaseDC(hwnd,hdc);
         break;
     case WM_PAINT:
        HDC hDC    ;
      PAINTSTRUCT ps;
      hDC=BeginPaint(hwnd,&ps);
      TextOut(hDC,0,0,"维新培训",strlen("维新培训"));


      EndPaint(hwnd,&ps);
        break;
     case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
        {
           DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);

        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
}


    



[/code]

回复列表 (共3个回复)

沙发

看了,不懂!

板凳

static LRESULT CALLBACK WinSunProc()声明时并不是static函数,这有关系吗

3 楼


static LRESULT CALLBACK WinSunProc()声明时并不是static函数,这有关系吗

去掉static也一样,运行出现窗口就死机了,再也不动了!

我来回复

您尚未登录,请登录后再回复。点此登录或注册