C++Builder 笔记

时间:2023-02-06 15:50:45

1、界面窗口如何不显示标题栏?

  在Form属性栏里面把BorderStyle的值设为None

2.wchar_t

wchar_t是C/C++的字符类型,是一种扩展的存储方式,wchar_t类型主要用在国际化程序的实现中

定义方式:

wchar_t *str = "Hello World!!";

3.C++如何启动一个其他程序

HINSTANCE ShellExecute(
                          
HWND hwnd,                   //句柄
                          
LPCTSTR lpOperation,       //操作类型  open、runas、print、edit、explore、find
                          
LPCTSTR lpFile,               // 需要打开的文件或者程序的名字
                          
LPCTSTR lpParameters,    // NULL
                          
LPCTSTR lpDirectory,       //NULL
                          
INT nShowCmd               //打开选项
);

ShowCmd 参数可选值:SW_HIDE = 0; {隐藏}
SW_SHOWNORMAL = 1; {用最近的大小和位置显示, 激活}
SW_NORMAL = 1; {同 SW_SHOWNORMAL}
SW_SHOWMINIMIZED = 2; {最小化, 激活}
SW_SHOWMAXIMIZED = 3; {最大化, 激活}
SW_MAXIMIZE = 3; {同 SW_SHOWMAXIMIZED}
SW_SHOWNOACTIVATE = 4; {用最近的大小和位置显示, 不激活}
SW_SHOW = 5; {同 SW_SHOWNORMAL}
SW_MINIMIZE = 6; {最小化, 不激活}
SW_SHOWMINNOACTIVE = 7; {同 SW_MINIMIZE}
SW_SHOWNA = 8; {同 SW_SHOWNOACTIVATE}
SW_RESTORE = 9; {同 SW_SHOWNORMAL}
SW_SHOWDEFAULT = 10; {同 SW_SHOWNORMAL}
SW_MAX = 10; {同 SW_SHOWNORMAL}
例如打开一个网页:
  const wchar_t *open = L"open";
    const wchar_t URL[] = L"www.baidu.com";
    ShellExecute(NULL, open, URL, NULL, NULL, SW_SHOWNORMAL);

4.窗口Form以及组件属性

Form->Caption = "title"  窗体标题

Form->BorderStyle = bsNone    没有窗体默认边界

Form->Position = poScreenCenter  窗体位于屏幕中心

Form->FormStyle = fsStayOnTop  窗体始终位于窗口最前面

Image->Align = alClient  图片的尺寸和窗体大小一样

Image->Stretch = true  图片看扩展

5.控制台输出Debug信息

#if 1
AllocConsole();
AttachConsole(GetCurrentProcessId());
freopen("CON","w",stdout);
#endif

6.监听某段程序的运行时间(VCL)

首先加上头文件

#include <System.Diagnostics.hpp>

#include <Windows.h>

然后初始化  TStopwatch::Create();

DWORD start_time = TStopwatch::GetTimeStamp() / (TStopwatch::Frequency/1000);// GetTickCount();

.......

DWORD end_time = TStopwatch::GetTimeStamp() / (TStopwatch::Frequency/1000); //GetTickCount();

end_time-start_time 就是时间差