怎样摆脱VCL让程序直接从WinMain进入程序,帮忙看一下代码,谢谢!

BoyMgl 2005-05-30 08:55:28
在BCB里新建了一个Win2000 Logo Application,删掉了所有生成的代码,可运行不了,总有Link错误

#include <windows.h>
const char lpCN[] = "NewWin";
LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int CALLBACK WinMain(HINSTANCE hCurrentInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
{
WNDCLASSEX wcex;
memset(&wcex,0,sizeof wcex);
wcex.cbSize = sizeof wcex;
wcex.style = CS_HREDRAW|CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hCurrentInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = (HBRUSH)COLOR_BTNFACE;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = lpCN;
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
HWND hWindow = CreateWindowEx(WS_EX_TOPMOST,lpCN,lpCN,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,100,100,NULL,NULL,hCurrentInstance,NULL);
ShowWindow(hWindow,iCmdShow);
UpdateWindow(hWindow);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
char lpWords[] = "Keep Calm!";
TextOut(hdc,0,0,lpWords,lstrlen(lpWords));
EndPaint(hWnd,&ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hWnd,uMsg,wParam,lParam);
}
return 0;
}
...全文
208 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
COKING 2005-06-01
  • 打赏
  • 举报
回复
菜单
File
New
Console wizard
Souce type :C++ 其它都不选
Maconel 2005-05-31
  • 打赏
  • 举报
回复
用vc的向导建立一个win32工程看看就明白了。
teatool 2005-05-31
  • 打赏
  • 举报
回复
BCB的程序都是从WinMain开始的啊,你看看跟你工程同名的那个cpp文件你就知道了
cczlp 2005-05-31
  • 打赏
  • 举报
回复
BCB支持纯API编程
leonatcs 2005-05-30
  • 打赏
  • 举报
回复
Override VCL窗体的WndProc函数即可。
建一个新工程,在窗体的头文件里private部分写:
void __fastcall WndProc(TMessage &Message);
在cpp文件里写:
void __fastcall TForm1::WndProc(TMessage &Message)
{
switch (Message.Msg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,&ps);
char lpWords[] = "Keep Calm!";
TextOut(hdc,0,0,lpWords,lstrlen(lpWords));
EndPaint(hWnd,&ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
TForm::WndProc(Message); //注意这里!
}
myy 2005-05-30
  • 打赏
  • 举报
回复
把默认的工程中的 Unit1.cpp 从工程中删除即可。
BoyMgl 2005-05-30
  • 打赏
  • 举报
回复
可是我要做的是Win32的基于窗口的应用呀
huabihan 2005-05-30
  • 打赏
  • 举报
回复
你直接用控制台的程序好了。

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧