我才开始学习sdk,下面的一个程序不能输出文字,为什么??
麻烦各位大侠帮忙!!!
/*---------------------------------------------------------
DEVCAPS1.C -- Device Capabilities Display Program No. 1
(c) Charles Petzold, 1998
---------------------------------------------------------*/#include <windows.h>#define NUMLINES ((int) (sizeof devcaps / sizeof devcaps [0]))struct
{
int iIndex ;
TCHAR * szLabel ;
TCHAR * szDesc ;
}
devcaps [] =
{
HORZSIZE, TEXT ("HORZSIZE"), TEXT ("Width in millimeters:"),
0A VERTSIZE, TEXT ("VERTSIZE"), TEXT ("Height in millimeters:"),
HORZRES, TEXT ("HORZRES"), TEXT ("Width in pixels:"),
VERTRES, TEXT ("VERTRES"), TEXT ("Height in raster lines:"),0D
BITSPIXEL, TEXT ("BITSPIXEL"), TEXT ("Color bits per pixel:"),
0A PLANES, TEXT ("PLANES"), TEXT ("Number of color planes:"),0D
NUMBRUSHES, TEXT ("NUMBRUSHES"), TEXT ("Number of device brushes:"),
NUMPENS, TEXT ("NUMPENS"), TEXT ("Number of device pens:"),
NUMMARKERS, TEXT ("NUMMARKERS"), TEXT ("Number of device ers:"),
NUMFONTS, TEXT ("NUMFONTS"), TEXT ("Number of device fonts:"),0D
NUMCOLORS, TEXT ("NUMCOLORS"), TEXT ("Number of device colors:"),0D
PDEVICESIZE, TEXT ("PDEVICESIZE"), TEXT ("Size of device structure:"),
ASPECTX, TEXT ("ASPECTX"), TEXT ("Relative width of pixel:"),0D
ASPECTY, TEXT ("ASPECTY"), TEXT ("Relative height of pixel:"),
ASPECTXY, TEXT ("ASPECTXY"), TEXT ("Relative diagonal of pixel:"),
LOGPIXELSX, TEXT ("LOGPIXELSX"), TEXT ("Horizontal dots per inch:"),
LOGPIXELSY, TEXT ("LOGPIXELSY"), TEXT ("Vertical dots per inch:"),0D
SIZEPALETTE, TEXT ("SIZEPALETTE"), TEXT ("Number of palette entries:"),
NUMRESERVED, TEXT ("NUMRESERVED"), TEXT ("Reserved palette entries:"),
COLORRES, TEXT ("COLORRES"), TEXT ("Actual color resolution:")0D
} ;LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{......}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
0A{
static int cxChar, cxCaps, cyChar, cxClient, cyClient, iMaxWidth ;
TCHAR szBuffer[10] ;
int i, x, y, iVertPos, iHorzPos, iPaintBeg, iPaintEnd;
HDC hdc ;
PAINTSTRUCT ps ;
TEXTMETRIC tm ;
SCROLLINFO si;
switch (message)
{
case WM_CREATE:
hdc = GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
ReleaseDC (hwnd, hdc) ;
return 0 ;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMin=0;
si.nMax=NUMLINES-1;
si.nPage=cyClient/cxClient;
SetScrollInfo(hwnd,SB_VERT,26si,TRUE);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMin=0;
si.nMax=2+iMaxWidth/cxClient;
si.nPage=cxClient/cyClient;
SetScrollInfo(hwnd,SB_HORZ,26si,TRUE);
return 0;
case WM_HSCROLL:
si.cbSize=sizeof(si);
si.fMask =SIF_ALL;
GetScrollInfo(hwnd,SB_HORZ,26si);
iVertPos=si.nPos;
switch(LOWORD(lParam))
{
case SB_LINELEFT:
si.nPos -= 1;
break;
// user clicked right arrow
case SB_LINERIGHT: 0D
si.nPos += 1;
break;
// user clicked shaft left of the scroll box
case SB_PAGELEFT:
0A si.nPos -= si.nPage;
break;
// user clicked shaft right of the scroll box
case SB_PAGERIGHT:
si.nPos += si.nPage;
break;
// user dragged the scroll box
case SB_THUMBTRACK: 0D
si.nPos = si.nTrackPos;
break;
default :
break;
}
si.fMask = SIF_POS;
SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
GetScrollInfo (hwnd, SB_HORZ, &si);
// If the position has changed, scroll the window 0D
if (si.nPos != iHorzPos)
{
ScrollWindow(hwnd, cxChar * (iHorzPos - si.nPos), 0, NULL, NULL);
0A }
return 0;
case WM_VSCROLL:
// Get all the vertial scroll bar information
si.cbSize = sizeof (si);
si.fMask = SIF_ALL;
GetScrollInfo (hwnd, SB_VERT, &si); // Save the position for comparison later on
iVertPos = si.nPos; switch (LOWORD (wParam))
{
// user clicked the HOME keyboard key
case SB_TOP:
si.nPos = si.nMin;
break;
// user clicked the END keyboard key
case SB_BOTTOM:
si.nPos = si.nMax;
break;
// user clicked the top arrow
case SB_LINEUP:
si.nPos -= 1;
break;
// user clicked the bottom arrow
case SB_LINEDOWN:
0A si.nPos += 1;
break;
// user clicked the shaft above the scroll box
0A case SB_PAGEUP:
si.nPos -= si.nPage;
break;
// user clicked the shaft below the scroll box
0A case SB_PAGEDOWN:
0A si.nPos += si.nPage;
break;
// user dragged the scroll box
case SB_THUMBTRACK:0D
si.nPos = si.nTrackPos;
break;
default:
break;
} // Set the position and then retrieve it. Due to adjustments
// by Windows it may not be the same as the value set.
si.fMask = SIF_POS;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
GetScrollInfo (hwnd, SB_VERT, &si); // If the position has changed, scroll window and update it
if (si.nPos != iVertPos)
{
ScrollWindow(hwnd, 0, cyChar * (iVertPos - si.nPos), NULL, NULL);
UpdateWindow (hwnd);
}
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
si.cbSize = sizeof (si);
si.fMask = SIF_POS;
GetScrollInfo (hwnd, SB_VERT, &si);
iVertPos = si.nPos;
GetScrollInfo (hwnd,SB_HORZ,&si);
iHorzPos=si.nPos;
iPaintBeg =max (0, iVertPos + ps.rcPaint.top / cyChar);
0A iPaintEnd = min (NUMLINES - 1, iVertPos + ps.rcPaint.bottom / cyChar);0D
for (i = iPaintBeg; i < iPaintEnd ; i2B+)
{
x=cxClient*(1-iHorzPos);
y=cyClient*(1-iVertPos); TextOut (hdc, x, y,
devcaps[i].szLabel,
lstrlen (devcaps[i].szLabel)) ;
TextOut (hdc, x+14 * cxCaps, y,
devcaps[i].szDesc,
lstrlen (devcaps[i].szDesc)) ;
SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
TextOut (hdc, x+14 * cxCaps + 35 * cxChar, y, szBuffer,
0A wsprintf (szBuffer, TEXT ("]"),
GetDeviceCaps (hdc, devcaps[i].iIndex))) ;
SetTextAlign (hdc, TA_LEFT | TA_TOP) ;
}
EndPaint (hwnd, &ps) ;
麻烦各位大侠帮忙!!!
/*---------------------------------------------------------
DEVCAPS1.C -- Device Capabilities Display Program No. 1
(c) Charles Petzold, 1998
---------------------------------------------------------*/#include <windows.h>#define NUMLINES ((int) (sizeof devcaps / sizeof devcaps [0]))struct
{
int iIndex ;
TCHAR * szLabel ;
TCHAR * szDesc ;
}
devcaps [] =
{
HORZSIZE, TEXT ("HORZSIZE"), TEXT ("Width in millimeters:"),
0A VERTSIZE, TEXT ("VERTSIZE"), TEXT ("Height in millimeters:"),
HORZRES, TEXT ("HORZRES"), TEXT ("Width in pixels:"),
VERTRES, TEXT ("VERTRES"), TEXT ("Height in raster lines:"),0D
BITSPIXEL, TEXT ("BITSPIXEL"), TEXT ("Color bits per pixel:"),
0A PLANES, TEXT ("PLANES"), TEXT ("Number of color planes:"),0D
NUMBRUSHES, TEXT ("NUMBRUSHES"), TEXT ("Number of device brushes:"),
NUMPENS, TEXT ("NUMPENS"), TEXT ("Number of device pens:"),
NUMMARKERS, TEXT ("NUMMARKERS"), TEXT ("Number of device ers:"),
NUMFONTS, TEXT ("NUMFONTS"), TEXT ("Number of device fonts:"),0D
NUMCOLORS, TEXT ("NUMCOLORS"), TEXT ("Number of device colors:"),0D
PDEVICESIZE, TEXT ("PDEVICESIZE"), TEXT ("Size of device structure:"),
ASPECTX, TEXT ("ASPECTX"), TEXT ("Relative width of pixel:"),0D
ASPECTY, TEXT ("ASPECTY"), TEXT ("Relative height of pixel:"),
ASPECTXY, TEXT ("ASPECTXY"), TEXT ("Relative diagonal of pixel:"),
LOGPIXELSX, TEXT ("LOGPIXELSX"), TEXT ("Horizontal dots per inch:"),
LOGPIXELSY, TEXT ("LOGPIXELSY"), TEXT ("Vertical dots per inch:"),0D
SIZEPALETTE, TEXT ("SIZEPALETTE"), TEXT ("Number of palette entries:"),
NUMRESERVED, TEXT ("NUMRESERVED"), TEXT ("Reserved palette entries:"),
COLORRES, TEXT ("COLORRES"), TEXT ("Actual color resolution:")0D
} ;LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{......}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
0A{
static int cxChar, cxCaps, cyChar, cxClient, cyClient, iMaxWidth ;
TCHAR szBuffer[10] ;
int i, x, y, iVertPos, iHorzPos, iPaintBeg, iPaintEnd;
HDC hdc ;
PAINTSTRUCT ps ;
TEXTMETRIC tm ;
SCROLLINFO si;
switch (message)
{
case WM_CREATE:
hdc = GetDC (hwnd) ;
GetTextMetrics (hdc, &tm) ;
cxChar = tm.tmAveCharWidth ;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
cyChar = tm.tmHeight + tm.tmExternalLeading ;
ReleaseDC (hwnd, hdc) ;
return 0 ;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMin=0;
si.nMax=NUMLINES-1;
si.nPage=cyClient/cxClient;
SetScrollInfo(hwnd,SB_VERT,26si,TRUE);
si.cbSize=sizeof(si);
si.fMask=SIF_RANGE|SIF_PAGE;
si.nMin=0;
si.nMax=2+iMaxWidth/cxClient;
si.nPage=cxClient/cyClient;
SetScrollInfo(hwnd,SB_HORZ,26si,TRUE);
return 0;
case WM_HSCROLL:
si.cbSize=sizeof(si);
si.fMask =SIF_ALL;
GetScrollInfo(hwnd,SB_HORZ,26si);
iVertPos=si.nPos;
switch(LOWORD(lParam))
{
case SB_LINELEFT:
si.nPos -= 1;
break;
// user clicked right arrow
case SB_LINERIGHT: 0D
si.nPos += 1;
break;
// user clicked shaft left of the scroll box
case SB_PAGELEFT:
0A si.nPos -= si.nPage;
break;
// user clicked shaft right of the scroll box
case SB_PAGERIGHT:
si.nPos += si.nPage;
break;
// user dragged the scroll box
case SB_THUMBTRACK: 0D
si.nPos = si.nTrackPos;
break;
default :
break;
}
si.fMask = SIF_POS;
SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
GetScrollInfo (hwnd, SB_HORZ, &si);
// If the position has changed, scroll the window 0D
if (si.nPos != iHorzPos)
{
ScrollWindow(hwnd, cxChar * (iHorzPos - si.nPos), 0, NULL, NULL);
0A }
return 0;
case WM_VSCROLL:
// Get all the vertial scroll bar information
si.cbSize = sizeof (si);
si.fMask = SIF_ALL;
GetScrollInfo (hwnd, SB_VERT, &si); // Save the position for comparison later on
iVertPos = si.nPos; switch (LOWORD (wParam))
{
// user clicked the HOME keyboard key
case SB_TOP:
si.nPos = si.nMin;
break;
// user clicked the END keyboard key
case SB_BOTTOM:
si.nPos = si.nMax;
break;
// user clicked the top arrow
case SB_LINEUP:
si.nPos -= 1;
break;
// user clicked the bottom arrow
case SB_LINEDOWN:
0A si.nPos += 1;
break;
// user clicked the shaft above the scroll box
0A case SB_PAGEUP:
si.nPos -= si.nPage;
break;
// user clicked the shaft below the scroll box
0A case SB_PAGEDOWN:
0A si.nPos += si.nPage;
break;
// user dragged the scroll box
case SB_THUMBTRACK:0D
si.nPos = si.nTrackPos;
break;
default:
break;
} // Set the position and then retrieve it. Due to adjustments
// by Windows it may not be the same as the value set.
si.fMask = SIF_POS;
SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
GetScrollInfo (hwnd, SB_VERT, &si); // If the position has changed, scroll window and update it
if (si.nPos != iVertPos)
{
ScrollWindow(hwnd, 0, cyChar * (iVertPos - si.nPos), NULL, NULL);
UpdateWindow (hwnd);
}
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
si.cbSize = sizeof (si);
si.fMask = SIF_POS;
GetScrollInfo (hwnd, SB_VERT, &si);
iVertPos = si.nPos;
GetScrollInfo (hwnd,SB_HORZ,&si);
iHorzPos=si.nPos;
iPaintBeg =max (0, iVertPos + ps.rcPaint.top / cyChar);
0A iPaintEnd = min (NUMLINES - 1, iVertPos + ps.rcPaint.bottom / cyChar);0D
for (i = iPaintBeg; i < iPaintEnd ; i2B+)
{
x=cxClient*(1-iHorzPos);
y=cyClient*(1-iVertPos); TextOut (hdc, x, y,
devcaps[i].szLabel,
lstrlen (devcaps[i].szLabel)) ;
TextOut (hdc, x+14 * cxCaps, y,
devcaps[i].szDesc,
lstrlen (devcaps[i].szDesc)) ;
SetTextAlign (hdc, TA_RIGHT | TA_TOP) ;
TextOut (hdc, x+14 * cxCaps + 35 * cxChar, y, szBuffer,
0A wsprintf (szBuffer, TEXT ("]"),
GetDeviceCaps (hdc, devcaps[i].iIndex))) ;
SetTextAlign (hdc, TA_LEFT | TA_TOP) ;
}
EndPaint (hwnd, &ps) ;
解决方案 »
- 当文档视图 如何得到类似于WORD的 中间一块白周围一圈的视图效果
- 将图片读入内存的问题。
- 是否可以动态加载同文件夹下不定数量的DLL?
- 怎样使DLL中的窗体或对话框PreTranslateMessage能有用呢?进者有分,不够再加
- DLL运行出错,大哥们帮忙看看
- BMP(或是jpg)文件的实现问题(高分相赠!)
- 使用ADO连接Oracle、DB2,没有数据库客户端、不能使用ODBC数据源,怎么搞?哪位大侠救命啊!
- 大家好,请问我在com中创建一个窗体。为什么客户程序就失去了鼠标的左右键消息了?
- 用什么语言开发图象处理软件效果最佳,速度嘴快
- mfc 引用CodeSoft 6 的lppx2.tlb ,出错了
- vc版的高手们,有两个dll谁能帮忙找出其中的函数和调用参数,要多少分给多少分!!
- 求教如何判断一个文件是否已经存在于目录中?
一个也没出来
我只是增加了滚动条
case WM_VSCROLL:
case WM_HSCROLL:
修改了case WM_PAINT
这些都是死东东,应该不会错啊
可是到了那里就进行不下去了,按了f5运行一下,还是原处!!!
真是麻烦你了!
2、监测变量,看是否写到你设定的范围内。
不好意思,只是推断。
后变为0