回 帖 发 新 帖 刷新版面

主题:一个多线程的问题(有原程序)

#include <windows.h>
        
#include <math.h>
        
#include <process.h>

typedef struct
        
{
        
           HWND          hwnd ;
        
           int           cxClient ;
        
           int           cyClient ;
        
           int           cyChar ;
        
           BOOL bKill ;
        
}PARAMS, *PPARAMS ;
        
LRESULT APIENTRY WndProc (HWND, UINT, WPARAM, LPARAM) ;
        
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                   PSTR szCmdLine, int iCmdShow)
        
{
        
           static TCHAR szAppName[] = TEXT ("Multi2") ;
        
           HWND                                 hwnd ;
        
           MSG                                  msg ;
        
           WNDCLASS                            wndclass ;
        

        
           wndclass.style                               = CS_HREDRAW | CS_VREDRAW ;
        
           wndclass.lpfnWndProc                         = WndProc ;
        
           wndclass.cbClsExtra                          = 0 ;
        
           wndclass.cbWndExtra                          = 0 ;
        
           wndclass.hInstance                           = hInstance ;
        
           wndclass.hIcon                              = LoadIcon (NULL, IDI_APPLICATION) ;
        
           wndclass.hCursor                             = LoadCursor (NULL, IDC_ARROW) ;
        
           wndclass.hbrBackground              = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        
           wndclass.lpszMenuName                = NULL ;
        
           wndclass.lpszClassName               = szAppName ;
        
   
        
           if (!RegisterClass (&wndclass))
        
           {
        
       MessageBox (NULL, TEXT ("This program requires Windows NT!"),
        
                  szAppName, MB_ICONERROR) ;
        
                  return 0 ;
        
           }
        
   
        
           hwnd = CreateWindow ( szAppName, TEXT ("Multitasking Demo"),
        
                         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 ;
        
}

回复列表 (共3个回复)

沙发

int CheckBottom (HWND hwnd, int cyClient, int cyChar, int iLine)
        
{
        
           if (iLine * cyChar + cyChar > cyClient)
        
           {
        
                  InvalidateRect (hwnd, NULL, TRUE) ;
        
                  UpdateWindow (hwnd) ;
        
                iLine = 0 ;
        
           }
        
           return iLine ;
        
}
        

// --------------------------------------------------------------------------
        
// Window 1: Display increasing sequence of numbers
        
// --------------------------------------------------------------------------
        

void Thread1 ( PVOID pvoid )
        
{
        
           HDC                         hdc ;
        
           int                           iNum = 0, iLine = 0 ;
        
           PPARAMS               pparams ;
        
           TCHAR                         szBuffer[16] ;

        
   
        
           pparams       = (PPARAMS) pvoid ;

          // pparams->bKill = FALSE ;
        
   
        
           while (!pparams->bKill)
        
           {
        
                  if (iNum < 0)
        
                                         iNum = 0 ;
        
                  iLine = CheckBottom ( pparams->hwnd,        pparams->cyClient,
        
   pparams->cyChar,iLine) ;
        

                  hdc = GetDC (pparams->hwnd) ;
        
        
        
                  TextOut (     hdc, 0, iLine * pparams->cyChar, szBuffer,
        
                                                        wsprintf (szBuffer, TEXT ("%d"), iNum++)) ;             
        
        
        
                  ReleaseDC (pparams->hwnd, hdc) ;
        
                  iLine++ ;
        
           }
        
    _endthread () ;
        
}

板凳

呵,看这问题问的,没头没尾的,窗口过程函数哪去了,什么时候建立的线程也不知道

3 楼

源代码不全吧................

我来回复

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