_beginthreadex不能从'重载函数' [英] _beginthreadex cannot convert from 'overloaded-function'

查看:310
本文介绍了_beginthreadex不能从'重载函数'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我制作了一个功能来打印文本分层到不同的窗口,我希望它在一个单独的线程,所以我可以运行一个定时器的文本显示,而让用户打开继续使用该程序。然而,当我编译我得到这个错误:

So I was making a function to print text layered across a different window, and I wanted it to be in a separate thread so I can run a timer for the text to display while leaving the user open to continue using the program. However, when I compile I get this error:

error C2664: '_beginthreadex' : cannot convert parameter 3 from 'overloaded-function' to 'unsigned int (__stdcall *)(void *)'

这里是主要的cpp文件: / p>

Here's the main cpp file:

#include "stdafx.h"
#include "Trial.h"

int main()
{
wchar_t* text = L"Message!";
HWND hwnd = FindWindowW(0, L"Halo");
unsigned threadID;
_beginthreadex(0, 0, DrawText,(void *)(hwnd, 175, 15, text, 8), 0 , &threadID);
// Other function here
}

这里是头文件Trial。 h:(它有点马虎,但工作正常,由于大多数显示器是大约2毫秒更新,睡眠(2)应该有助于防止闪烁)。

And here's the header file Trial.h: (it's a little sloppy, but works fine and since most monitors are around 2ms updates, sleep(2) should help prevent flicker).

#pragma once    
#include <Windows.h>
#include <string>
#include <process.h>

void DrawText(HWND hWnd, float x, float y, wchar_t* mybuffer, float DisplayTime)
{
SetForegroundWindow(hWnd);
HDC hdc = GetDC(hWnd);
SetBkColor(hdc,RGB(255, 255, 255));                   // While Background color...
SetBkMode(hdc, TRANSPARENT);                        // Set background to transparent so we don't see the white...

int howmany = sizeof(mybuffer) * 2;

DisplayTime *= 500;
int p = 0;
while(p < DisplayTime)
{
            // Shadow Offset
    SetTextColor(hdc,RGB(0, 0, 0)); 
    TextOut(hdc,x+2,y+2, (LPCWSTR)mybuffer,howmany);

    // Primary text
    SetTextColor(hdc,RGB(255, 0, 0));   
    TextOutW(hdc,x,y,(LPCWSTR)mybuffer,howmany);

    UpdateWindow(hWnd);
    p++;
    Sleep(2);
}
ReleaseDC(hWnd,hdc);
_endthreadex(0);
}



我查看了多个例子,检查语法,我没有搞砸在_beginthreadex,但似乎找不到问题的原因:|

I've looked through multiple examples, checked the syntax, and made sure that I didn't mess up on _beginthreadex, but can't seem to find the cause of the problem :|

推荐答案

它们可以接受一个需要一个void *的函数。

They can accept a function that takes a single void *.

有几种解决方案。


  1. 更改函数以接受void *。立即将其转换为您已创建的某种类型的struct *,并具有所需的数据。您通常在main中使用new / malloc创建struct,然后在线程函数中不需要它时删除/释放它。

  2. 你上一个类的对象。给这个类一个公共静态方法,接受void *。使用静态方法作为线程启动程序,并将对象的地址作为this。然后有静态转换void *到对象类型,并调用一些'开始/运行'例程在对象上。在从线程例程返回之前,该对象将自行删除,除非您在线程之间有更协调的解决方案。

这篇关于_beginthreadex不能从'重载函数'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆