首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

WIN32窗口 刚入门 书上1个例子 不知道哪里错了 各位帮帮忙

2012-02-16 
WIN32窗口 刚入门 书上1个例子 不知道错哪了 各位帮帮忙#include windows.hLRESULT CALLBACK WNDFUN(HWN

WIN32窗口 刚入门 书上1个例子 不知道错哪了 各位帮帮忙
#include "windows.h"
LRESULT CALLBACK WNDFUN(HWND hWnd,UNIT msg,WPARAM wparam,LPARAM lparam)
{
switch(msg)
{
case WM_PAINT:
{
HDC hdc=GetDC(hWnd);
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc,20,20,"明日科技有限公司",16);
DeleteDC(hdc);
break;
}
case WM_CLOSE:
{
DestroyWindow(hWnd);
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd,msg,wparam,lparam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASS wndcls;
wndcls.style=CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
wndcls.lpszMenuName=NULL;
wndcls.lpszClassName="CustomWnd";
wndcls.lpfnWndProc=WNDFUN;
wndcls.hInstance=GetModuleHandle(NULL);
wndcls.hIcon=NULL:
wndcls.hCursor=NULL;
wndcls.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("CustomWnd","Win32APP",WS_CAPTION|WS_OVERLAPPEDWINDOW|
WS_SYSMENU,50,50,500,500,NULL,NULL,wndcls.hInstance,NULL);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

[解决办法]
提示什么错误?

[解决办法]
LRESULT CALLBACK WNDFUN(HWND hWnd,UNIT msg,WPARAM wparam,LPARAM lparam);你有注册么?
[解决办法]
你的代码中主要有两个错误,看起来象你粗心的打字错误
一是将UINT写成UNIT,另一个是将;写成:
所以造成编译出错,修正后的代码如下:

C/C++ code
#include "windows.h"LRESULT CALLBACK WNDFUN(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam){    switch(msg)    {        case WM_PAINT:        {            HDC hdc = GetDC(hWnd);            SetBkMode(hdc, TRANSPARENT);            TextOut(hdc, 20, 20, "明日科技有限公司", 16);            DeleteDC(hdc);            break;        }        case WM_CLOSE:        {            DestroyWindow(hWnd);            break;        }        case WM_DESTROY:        {            PostQuitMessage(0);            break;        }        default:            return DefWindowProc(hWnd, msg, wparam, lparam);    }    return 0;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,    LPSTR lpCmdLine, int nCmdShow){    WNDCLASS wndcls;    wndcls.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;    wndcls.lpszMenuName = NULL;    wndcls.lpszClassName = "CustomWnd";    wndcls.lpfnWndProc = WNDFUN;    wndcls.hInstance = GetModuleHandle(NULL);    wndcls.hIcon = NULL;    wndcls.hCursor = NULL;    wndcls.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);    wndcls.cbClsExtra = 0;    wndcls.cbWndExtra = 0;    RegisterClass(&wndcls);    HWND hwnd;    hwnd = CreateWindow("CustomWnd", "Win32APP",        WS_CAPTION | WS_OVERLAPPEDWINDOW | WS_SYSMENU, 50, 50, 500, 500, NULL,        NULL, wndcls.hInstance, NULL);    ShowWindow(hwnd, SW_SHOW);    UpdateWindow(hwnd);    MSG msg;    while (GetMessage(&msg, NULL, 0, 0))    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return msg.wParam;}
[解决办法]
WM_PAINT事件里最好不要用GetDC来获取hdc,推荐用BeginPaint和EndPaint。

热点排行