大家帮我检查一下好吗?实在搞不明白,在对话框中输入数据,在主窗口绘直线

#include
#include "resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
char chr1[10], chr2[10], chr3[10],chr4[10];
int number1, number2, number3,number4;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("About1") ;
MSG msg ;
HWND hwnd ;
WNDCLASS wndclass ;

 wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
 wndclass.lpfnWndProc   = WndProc ;
 wndclass.cbClsExtra    = 0 ;
 wndclass.cbWndExtra    = 0 ;
 wndclass.hInstance     = hInstance ;
 wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
 wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
 wndclass.lpszMenuName  = szAppName ;
 wndclass.lpszClassName = szAppName ;

 if (!RegisterClass (&wndclass))
 {
      MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                  szAppName, MB_ICONERROR) ;
      return 0 ;
 }

 hwnd = CreateWindow (szAppName, TEXT ("********大学"),
                      WS_OVERLAPPEDWINDOW,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      CW_USEDEFAULT, CW_USEDEFAULT,
                      NULL, NULL, hInstance, NULL) ;

 ShowWindow (hwnd, iCmdShow) ;
 UpdateWindow (hwnd) ; 

 while (GetMessage (&msg, NULL, 0, 0))
 {
      TranslateMessage (&msg) ;
      DispatchMessage (&msg) ;
 }
 return msg.wParam ;

}
void PaintWindow (HWND hwnd)
{
HBRUSH hBrush ;
HDC hdc ;
RECT rect ;
hdc = GetDC (hwnd) ;
MoveToEx (hdc, number1, number2, NULL) ;
LineTo (hdc, number3,number4) ;
ReleaseDC (hwnd, hdc) ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance ;
HDC hdc ;
PAINTSTRUCT ps ;
switch (message)
{
case WM_CREATE :
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;

PaintWindow (hwnd);
EndPaint (hwnd, &ps) ;
return 0 ;

 case WM_COMMAND :
      switch (LOWORD (wParam))
      {
      case IDM_APP_ABOUT :
           DialogBox (hInstance, TEXT ("ABOUTBOX"), hwnd, AboutDlgProc) ;
           break ;
      }
      return 0 ;


 case WM_DESTROY :
      PostQuitMessage (0) ;
      return 0 ;
 }
 return DefWindowProc (hwnd, message, wParam, lParam) ;

}

BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{

switch (message)
 {
 case WM_INITDIALOG :
      return TRUE ;

 case WM_COMMAND :
      switch (LOWORD (wParam))
      {

      case IDOK :

GetDlgItem( hDlg,IDC_EDIT1);
GetWindowText(IDC_EDIT1,chr1,10);
GetDlgItem( hDlg,IDC_EDIT2);
GetWindowText(IDC_EDIT2,chr2,10);
GetDlgItem( hDlg,IDC_EDIT3);
GetWindowText(IDC_EDIT3,chr3,10);
GetDlgItem( hDlg,IDC_EDIT4);
GetWindowText(IDC_EDIT4,chr4,10);
number1=atoi(chr1);
number2=atoi(chr2);
number3=atoi(chr3);
number4=atoi(chr4);
EndDialog (hDlg, TRUE) ;
return TRUE ;
case IDCANCEL :
EndDialog (hDlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE ;
}

查看全部
baidu_30118209
baidu_30118209
2015/07/27 16:00
  • winapi
  • 对话框
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复