关于 windows sdk 编程中遇到的我不能解释的现象~~

//以下是程序代码,可能先要你花上你分钟度懂这个程序,确定读懂后,然后在运行,看看是否与你想的相同。
 
反正最后运行和我想的有区别,我想了很久都没结果,只有到论坛上请教高手解释这一现象了。。
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM lParam
);
LRESULT CALLBACK BuProc(HWND hwnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM lParam
);
void PopMes(LPCSTR sText)
{
 MessageBox(0,sText,"Attension",MB_OK);
}
HWND hButton;
LONG hBuProc;
WNDCLASS wnd_class(HINSTANCE hInstance,LPCSTR classname,WNDPROC wndproc)
{
 WNDCLASS wc;
 wc.style=CS_HREDRAW |CS_VREDRAW;
 wc.lpfnWndProc = wndproc;
 wc.cbClsExtra= 0;
 wc.cbWndExtra=0;
 wc.hInstance = hInstance;
 wc.hIcon=LoadIcon (NULL, IDI_ASTERISK);
 wc.hCursor=LoadCursor (NULL, IDC_APPSTARTING) ;
 wc.hbrBackground= (HBRUSH)COLOR_WINDOW;
 wc.lpszMenuName=0;
 wc.lpszClassName=classname;
 return wc;
}
int WINAPI WinMain(HINSTANCE hInstance,
       HINSTANCE hPreInstance,
       LPSTR lpCmdLine,
       int nCmdShow)
{
 LPCSTR CLname="yhy";
 if(!RegisterClass(& wnd_class(hInstance,CLname,WndProc)))//注册窗口类型
 {
  MessageBox(NULL ,"注册失败","提示框",MB_OK);
  return 0;
 }
 HWND hwnd =CreateWindow(CLname,"My Try Window",WS_OVERLAPPEDWINDOW,
  100,300,400,300,NULL,NULL,hInstance,0);//创建窗口
 ShowWindow(hwnd, nCmdShow);//显示窗口
 UpdateWindow(hwnd);//更新窗口
 MSG msg;
 while (GetMessage (&msg, NULL, 0, 0))//消息循环
 {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
 }
 return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM lParam
)
{
 static bool pt=true;
 PAINTSTRUCT ps;
 HDC hdc;
 RECT rect;
 switch(uMsg)
 {
 case WM_CREATE:
  hButton =CreateWindow("button","My Button",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
     0,0,100,30,hwnd,0,((LPCREATESTRUCT)lParam)->hInstance,0);
  hBuProc = SetWindowLong(hButton,GWL_WNDPROC,(LONG)BuProc);
  break;
 case WM_LBUTTONDOWN:
  PopMes("lbuttondown");
  break;
 case WM_PAINT:
  hdc = BeginPaint (hwnd, &ps) ;
         
  
          EndPaint (hwnd, &ps) ;
  break;
 case WM_COMMAND:
  PopMes("window");
  break;
 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 default:
  return DefWindowProc(hwnd,uMsg,wParam,lParam);
 }
 return 0;
}
LRESULT CALLBACK BuProc(HWND hwnd,
       UINT uMsg,
       WPARAM wParam,
       LPARAM lParam
)
{
 switch(uMsg)
 {
 case WM_LBUTTONDOWN:
  PopMes("Button");
  //SetWindowText(hwnd,"change");
  break;
 }
 return CallWindowProc((WNDPROC)hBuProc,hwnd,uMsg,wParam,lParam);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值