我的应用程序中有线程在另一个应用程序中显示消息框,在线程创建它的每个事件上都带有标题“测试”,在该线程结束时,我想关闭所有这些消息。
我试图创建这样的循环
while FindWindow(Nil,PChar('Test')) <> 0 do
begin
Sleep(5); //if i remove the sleep the application will hanging and froze.
SendMessage(FindWindow(Nil,PChar('Test')), WM_CLOSE, 0, 0); // close the window message
end;
Run Code Online (Sandbox Code Playgroud)
但是这个循环只有当我手动关闭最后一条消息时才有效
注意:消息框来自另一个不在同一个应用程序中的应用程序有这个线程。
我想知道验证编辑的最佳实践不是空的
if edt1.Text <> '' then
//DoSomething
else
ShowMessage('Check 1');
if edt1.Text = '' then
ShowMessage('Check 2')
else
//DoSomething
Run Code Online (Sandbox Code Playgroud) 我在delphi中有程序我想用C++编写它但我在c ++中的字符串比较和if语句中失败了
实际上这是我第一次使用c ++我是完全基本的和新的
我的问题是为什么C++中的消息框显示每个进程名称,即使是字符串比较和if语句?
if(DuplicateHandle(hProcess, (HANDLE)pHandleInfo->Handles[dwIdx].Handle,
GetCurrentProcess(), &hObject, STANDARD_RIGHTS_REQUIRED, FALSE, 0) != FALSE)
{
LPWSTR lpwsName = GetObjectInfo(hObject, ObjectNameInformation);
if(lpwsName != NULL)
{
LPWSTR lpwsType = GetObjectInfo(hObject, ObjectTypeInformation);
LPSTR lpszProcess = new CHAR[MAX_PATH];
ZeroMemory(lpszProcess, MAX_PATH);
LPSTR sDummy = "System Process";
if (GetModuleFileNameEx(hProcess, NULL, lpszProcess, MAX_PATH))
LPSTR sDummy = PathFindFileName(lpszProcess);
std::string ProcessName = "Test.exe"; //fail
bool exists = ProcessName.find(LPSTR(sDummy)) != std::string::npos; //fail
if (exists = true) { //fail
std::string HType = "M"; //fail
bool exists = HType.find(LPSTR(lpwsType)) != std::string::npos; //fail …Run Code Online (Sandbox Code Playgroud) 如何用不同的参数类型编写两个具有相同名称的函数,如下所示:
public
{ Public declarations }
function MsgW(const Msg:String):Integer;
function MsgW(const Msg:String;title:String):Integer;
function MsgW(const Msg:String;title:String):Integer;
Begin
Result := MessageboxW(0,Pchar(Msg),Pchar(title),MB_OK);
End;
function MsgW(const Msg:String):Integer;
Begin
Result := MessageboxW(0,Pchar(Msg),'MessageBoxW',MB_OK);
End;
Run Code Online (Sandbox Code Playgroud) 我想生成指定长度的随机数.
function _RandomCode(const CodeLen: Word): Word;
begin
Result := Random(CodeLen);
repeat
Result := Result + Random(CodeLen) + 1;
until (Length(IntToStr(Result)) = CodeLen)
end;
Run Code Online (Sandbox Code Playgroud)
结果总是如此 10000
我怎样才能提高整开始用零00000000,00000001,00000002 ...等等.
var
i:Integer;
begin
i := 00000000;
Inc(i);
ShowMessage(IntToStr(i));
Run Code Online (Sandbox Code Playgroud)
问题是inc程序会修剪左边的零.
输出:
1
Run Code Online (Sandbox Code Playgroud)
不是00000001.
我试图在delphi中调用CreateProcessWithLogonW函数
我的第一次尝试如下
function CreateProcessWithLogonW(
lpUsername,
lpDomain,
lpPassword: LPCWSTR;
dwLogonFlags: DWORD;
lpApplicationName: LPCWSTR;
lpCommandLine: LPWSTR;
dwCreationFlags: DWORD;
lpEnvironment: Pointer;
lpCurrentDirectory: LPCWSTR;
lpStartupInfo: TStartupInfo;
lpProcessInfo: TProcessInformation
): BOOL;
stdcall; external 'Advapi32.dll';
Run Code Online (Sandbox Code Playgroud)
一旦我在我的程序中调用它,我得到AV,我用谷歌搜索如何在Delphi中调用此函数,我发现lpStartupInfo并且lpProcessInfo必须定义如下
var lpStartupInfo: TStartupInfo;
var lpProcessInfo: TProcessInformation
Run Code Online (Sandbox Code Playgroud)
这些功能按预期工作.
我的问题:如果在调用上述外部WinAPI函数时函数参数必须是可变的,我现在怎么办?因为我没有在文档中找到有关此信息的信息.
我正试图从客户端拍摄实时屏幕截图.
服务器端的TImage imgScreen引发了此错误.
EJPEG,消息'JPEG错误#53'
我有谷歌它,发现这个错误来自内存不足 - 图像损坏.
如何在保存/显示之前验证流?
使服务器收到损坏的流的原因是什么?
是在JpegStream.Size和IOHandler.ReadInt64方法中.
这是代码.
客户端
if List[0] = 'RecordScreen' then
begin
pic := TBitmap.Create;
JpegStream := TMemoryStream.Create;
ScreenShot(0,0,pic);
BMPtoJPGStream(pic, JpegStream);
pic.FreeImage;
FreeAndNil(pic);
AConn.Client.IOHandler.Write(JpegStream.Size);
AConn.Client.IOHandler.Write(JpegStream);
FreeAndNil(JpegStream);
end;
Run Code Online (Sandbox Code Playgroud)
服务器端
procedure ScreenRecord(const Item: TListItem);
var
Ctx: TIdContext;
List: TIdContextList;
Dir,PicName:string;
PicStream : TFileStream;
Size : Int64;
begin
if (Item = nil) then Exit;
Ctx := TIdContext(Item.Data);
if (Ctx = nil) then Exit;
Dir := IncludeTrailingBackslash(TMyContext(Ctx).ClinetDir+ScreenshotsDir);
if not DirectoryExists(Dir) then
CreateDir(Dir);
PicName …Run Code Online (Sandbox Code Playgroud)