小麻烦

来源:互联网 发布:js中二维数组的定义 编辑:程序博客网 时间:2024/04/27 04:56

真的碰到问题了吧!

下次写代码不能在这样天马行空了,萧萧傻傻地写了几百行代码,什么也没注意,这下完蛋了,BUG一堆。

检查BUG累死我了。

下次得主意点,小心点,设计好了再写,不要乱写,出了乱子就不好了。

什么叫胸有成竹,什么作怀不乱,什么叫大智慧。佛曰:大智若愚。佛又曰:我自所以再天上,是因为我经常说:“我不入地狱,谁入地狱”。佛有大智慧,不是常人能比的,我们要做的就是向佛学习。能学多少是多少。不能再象这次这样了,不顾后果的乱写了。佛有很有远见,看得比我们都要远,我不能达到佛得那种境界,但是起码我可以看得比现在远点啊。这就需要佛得智慧。我们好多人都说:”为人民服务,做人民公仆“。不知道为什么做仆人的总是人民。哎,不扯远了。我靠,都上升到什么高度了,还是闭嘴!!!

     还是说程序和佛吧,我想佛要是当程序员,那佛肯定不是一般的程序员。不像我,哎~~~~天马行空写了个程序,错误一堆,把网友得机器搞的都要关机了,最郁闷的是我想写好那个程序,现在写得跟病毒一样了。郁闷!!!

不乱说了,还是分析我那个傻程序吧!!

其实也是很简单的以个东西,为什么就是设计不好呢!!!

我用的是vc.net;下面的是.cpp的程序

我查了半天还是有BUG存在,估计是菜单消息处理时候出现了问题。

可是真的不知道怎么查这个BUG了!!!

有高手愿意帮忙请++我的QQ:76359121

#include <windows.h>
#include "resource.h"


//全局变量
HINSTANCE hinst;
int TempColor;//保存颜色方案的数字


// 函数的声明
BOOL CALLBACK DialogFun(HWND, UINT,WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
InitApplication(HINSTANCE);
InitInstance(HINSTANCE, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
BOOL PaintWindows(HWND,int);//定义粉刷窗口函数
BOOL PaintSmallWindows(HWND,int);//定义粉刷对话框上的窗口函数HWND是对话框的句柄,int 是变换颜色的参数
// 应用程序进入点函数
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
 MSG msg;
 if (!InitApplication(hinstance))
  return FALSE;
 if (!InitInstance(hinstance, nCmdShow))
  return FALSE;
 while (GetMessage(&msg, (HWND) NULL, 0, 0))
 {
  /*if(GetMessage(&msg, (HWND) NULL, 0, 0) == -1)
  {
  MessageBox(NULL,"the applcation can't run","error",MB_OK);
  return 0;
  }*/
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 return msg.wParam;
 //UNREFERENCED_PARAMETER(lpCmdLine);
}

//应用程序的初始化
BOOL InitApplication(HINSTANCE hinstance)
{
 WNDCLASS wndclass;

 wndclass.cbClsExtra=0;
 wndclass.cbWndExtra=0;
 wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
 wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 wndclass.hInstance=hinstance;
 wndclass.lpfnWndProc=MainWndProc;
 wndclass.lpszClassName="MyClass";
 wndclass.lpszMenuName="MyMenu";
 wndclass.style=CS_HREDRAW | CS_VREDRAW;

 if(0==RegisterClass(&wndclass))
 {
  return FALSE;
 }
 else
  return TRUE;

}

//创建并显示窗口
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
 HWND hwnd;

 // Save the application-instance handle.

 hinst = hinstance;
 // Create the main window.
 hwnd = CreateWindow(
  "MyClass",        // name of window class
  "welcome",            // title-bar string
  WS_OVERLAPPEDWINDOW, // top-level window
  CW_USEDEFAULT,       // default horizontal position
  CW_USEDEFAULT,       // default vertical position
  CW_USEDEFAULT,       // default width
  CW_USEDEFAULT,       // default height
  (HWND) NULL,         // no owner window
  (HMENU) NULL,        // use class menu
  hinstance,           // handle to application instance
  (LPVOID) NULL);      // no window-creation data

 if (!hwnd)
  return FALSE;

 // Show the window and send a WM_PAINT message to the window
 // procedure.


 ShowWindow(hwnd, nCmdShow);
 UpdateWindow(hwnd);
 return TRUE;
}
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)   
{
 //PAINTSTRUCT    ps ;

 //HMENU hMenu;
 switch (uMsg)
 {
 case WM_COMMAND:
  //hMenu = GetMenu(hwnd);
  switch(LOWORD(wParam))
  {
  case IDM_DIALOG_TEST:
   DialogBox(hinst,"MyDialog",hwnd,(DLGPROC)DialogFun);
   return DefWindowProc(hwnd, uMsg, wParam, lParam);
 
  case IDM_TEST1:
   MessageBox(hwnd,"Test Menu1","menu1",MB_OK);
   return DefWindowProc(hwnd, uMsg, wParam, lParam);

  case IDM_TEST2:
   MessageBeep(0);
   MessageBox(hwnd,"菜单2测试","navyblue",MB_OK);
   return DefWindowProc(hwnd, uMsg, wParam, lParam);

  case IDM_ABOUT_ME:
   MessageBox(hwnd,"                   做人要厚道!","这家伙很懒提示您:",MB_OK);
   return DefWindowProc(hwnd, uMsg, wParam, lParam);

   //CreateDialog
  }


 case WM_CREATE:
  // Initialize the window.
  return DefWindowProc(hwnd, uMsg, wParam, lParam);

 case WM_PAINT:
  // Paint the window's client area.

  PaintWindows(hwnd,TempColor);
  return DefWindowProc(hwnd, uMsg, wParam, lParam);

 case WM_SIZE:
  // Set the size and position of the window.
  return 0;
 case WM_DESTROY:
  // Clean up window-specific data objects.
  PostQuitMessage (0) ;
  return DefWindowProc(hwnd, uMsg, wParam, lParam);


  //
  // Process other messages.

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

}

//处理对话框消息
BOOL CALLBACK DialogFun(HWND hDlg, UINT message,WPARAM wParam, LPARAM lParam)
{
 HWND colorHwnd;
 colorHwnd=GetDlgItem(hDlg,IDC_COLOR);
 switch(message)
 {
 case   WM_INITDIALOG :
  SetWindowText (hDlg, TEXT ("::深蓝工作室出品::"));
  return TRUE ;
 case WM_COMMAND:
  switch(LOWORD(wParam))
  {
  case ID_OK:
   EndDialog(hDlg, 0) ;
   return TRUE;
  case IDC_CHANGECOLOR:
   TempColor=0;
   return TRUE;
  case IDC_CHANGECOLOR2:
   TempColor=1;
   return TRUE;
  }
  case   WM_PAINT:
  PaintSmallWindows(colorHwnd,TempColor);
  break ;
 }
 return 0;
}

//定义粉刷窗口函数过程,主要功能是变换窗口背景
BOOL PaintWindows(HWND ihwnd,int iColor)
{
 /*InvalidateRect(hwnd,NULL,TRUE);
 UpdateWindow(hwnd);*/
 static COLORREF SelectColor[2]={RGB(128,128,128),RGB(156,100,25)};//定义一个颜色数组
 HBRUSH brush;
 RECT rect;
 HDC hdc;
 hdc=GetDC(ihwnd);
 brush=CreateSolidBrush(SelectColor[iColor]);//创建画刷
 GetClientRect(ihwnd,&rect);//获得主窗口的面积
 brush=(HBRUSH)SelectObject(hdc,brush);
 Rectangle(hdc,rect.left, rect.top, rect.right, rect.bottom);
 DeleteObject(SelectObject(hdc,brush));
 DeleteDC(hdc);
 return TRUE;
}
BOOL PaintSmallWindows(HWND dlgIstance,int dlgColor)
{
    InvalidateRect (dlgIstance, NULL, TRUE) ;
 UpdateWindow (dlgIstance) ;
 if(0==PaintWindows(dlgIstance,dlgColor))
 {
  return TRUE;
 }
 else
  return FALSE;
}

原创粉丝点击