SDK找错,高手帮忙,我查了很久也查不出到底哪错了,但就是在VC++6.0上编译不过。
[code=C/C++][/code]
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevinstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[255] ;
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 require 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 ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HINSTANCEhInstance ;
HDChdc, hdcmem ;
PAINTSTRUCTps ;
BITMAPbitmap ;
static HBITMAP hBitmap ;
static intcxClient, cyClient, cxSource, cySourse ;
intx, y ;
switch (message)
{
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
hBitmap = LoadBitmap (hInstance, TEXT ("1.bmp")) ;
GetObject (hBitmap, sizeof (BITMAP), &bitmap) ;
cxSource = bitmap.bmWidth ;
cySourse = bitmap.bmHeight ;
return 0;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
hdcmem = CreateCompatibleDC (hdc) ;
SelectObject (hdcmem, hBitmap) ;
for (y = 100 ; y < cyClient - 100 ; y += cySourse)
{
for (x = 100 ; x < cxClient - 100 ; x += cxSource)
{
BitBlt (hdc, x, y, cxSource, cySource, hdcmem, 0, 0, SRCCOPY) ;
}
}
DeleteDC (hdcmem) ;
EndPaint (hdc, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
[解决办法]
cySourse cySource 这两个单词名字不一样。
真不如复制《windows程序设计》一书的源代码来得快。另外《VC技术内幕》第4或5版也是经典。
还有一个应用名字,一个!号。
vc2005编译通过。但只有一白窗口。
#include <windows.h>LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevinstance, PSTR szCmdLine, int iCmdShow){ static TCHAR szAppName[255]="3ee" ; 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 require 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 ;}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ HINSTANCE hInstance ; HDC hdc, hdcmem ; PAINTSTRUCT ps ; BITMAP bitmap ; static HBITMAP hBitmap ; static int cxClient, cyClient, cxSource, cySource ; int x, y ; switch (message) { case WM_CREATE: hInstance = ((LPCREATESTRUCT) lParam)->hInstance ; hBitmap = LoadBitmap (hInstance, TEXT ("1.bmp")) ; GetObject (hBitmap, sizeof (BITMAP), &bitmap) ; cxSource = bitmap.bmWidth ; cySource = bitmap.bmHeight ; return 0; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; hdcmem = CreateCompatibleDC (hdc) ; SelectObject (hdcmem, hBitmap) ; for (y = 100 ; y < cyClient - 100 ; y += cySource) { for (x = 100 ; x < cxClient - 100 ; x += cxSource) { BitBlt (hdc, x, y, cxSource, cySource, hdcmem, 0, 0, SRCCOPY) ; } } DeleteDC (hdcmem) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ;}