Hyutars
Mario & Luigi
- 26/11/05
- 713
- 3
Cho mình hỏi típ: khi mình học lập trình trong win, có viết chương trình sau:
Đây là file cpp:
#include <windows.h>
#include <sysmets.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SysMets1");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.hCursor = LoadCursor (NULL, IDC_APPLICATION);
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Chuong trinh nay yeu cau Windows NT!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow (szAppName, TEXT ("Get System Merics No.1"), 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)
{
static int cxChar, cxCaps, cyChar;
HDC hdc;
int i;
PAINTSTRUCT ps;
TCHAR szBuffer [10];
TEXTMETRIC tm;
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_PAINT:
{
hdc = BeginPaint (hwnd, &ps);
for (i = 0; i<NUMLINES; i++)
{
TextOut (hdc, 0, cyChar * i, sysmetrics.szLabel, lstrlen (sysmetrics.szLabel));
TextOut (hdc, 22 * cxCaps, cyChar * i, sysmetrics.szDesc, lstrlen (sysmetrics.szDesc));
SetTextAlign (hdc, TA_RIGHT | TA_TOP);
TextOut (hdc, 22 * cxCaps + 40 * cxChar, cyChar * i, szBuffer, wsprintf (szBuffer, TEXT ("%5d"), GetSystemMetrics (sysmetrics.iIndex)));
SetTextAlign (hdc, TA_LEFT | TA_TOP);
}
EndPaint (hwnd, &ps);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
Và đây là file header sysmets.h (mình chọn new->header file)
#define NUMLINES ((int) (sizeof sysmetrics / sizeof sysmetrics [0]))
struct
{
int iIndex;
TCHAR * szLabel;
TCHAR * szDesc;
}
sysmetrics [] =
{
SM_CXSCREEN, TEXT ("SM_CXSCREEN"),TEXT("Screen width in pixels")
};
Nhưng khi chạy thử nó báo lỗi:
cannot open include file sysmets.h
bạn nào giúp mình với, thx
Đây là file cpp:
#include <windows.h>
#include <sysmets.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SysMets1");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.hCursor = LoadCursor (NULL, IDC_APPLICATION);
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("Chuong trinh nay yeu cau Windows NT!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow (szAppName, TEXT ("Get System Merics No.1"), 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)
{
static int cxChar, cxCaps, cyChar;
HDC hdc;
int i;
PAINTSTRUCT ps;
TCHAR szBuffer [10];
TEXTMETRIC tm;
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_PAINT:
{
hdc = BeginPaint (hwnd, &ps);
for (i = 0; i<NUMLINES; i++)
{
TextOut (hdc, 0, cyChar * i, sysmetrics.szLabel, lstrlen (sysmetrics.szLabel));
TextOut (hdc, 22 * cxCaps, cyChar * i, sysmetrics.szDesc, lstrlen (sysmetrics.szDesc));
SetTextAlign (hdc, TA_RIGHT | TA_TOP);
TextOut (hdc, 22 * cxCaps + 40 * cxChar, cyChar * i, szBuffer, wsprintf (szBuffer, TEXT ("%5d"), GetSystemMetrics (sysmetrics.iIndex)));
SetTextAlign (hdc, TA_LEFT | TA_TOP);
}
EndPaint (hwnd, &ps);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
Và đây là file header sysmets.h (mình chọn new->header file)
#define NUMLINES ((int) (sizeof sysmetrics / sizeof sysmetrics [0]))
struct
{
int iIndex;
TCHAR * szLabel;
TCHAR * szDesc;
}
sysmetrics [] =
{
SM_CXSCREEN, TEXT ("SM_CXSCREEN"),TEXT("Screen width in pixels")
};
Nhưng khi chạy thử nó báo lỗi:
cannot open include file sysmets.h
bạn nào giúp mình với, thx
:p :'>
.Bạn cài webserver,php,sql server vào luôn máy mình mà nghịch cho dễ. Khi nào tốt hãy kiếm host trên mạng mà "khoe hàng".
.