GVKun编程网logo

C ++ Windows:LRESULT CALLBACK和WNDPROC

13

在本文中,我们将为您详细介绍C++Windows:LRESULTCALLBACK和WNDPROC的相关知识,此外,我们还会提供一些关于android–Handler.removeCallbacksAn

在本文中,我们将为您详细介绍C ++ Windows:LRESULT CALLBACK和WNDPROC的相关知识,此外,我们还会提供一些关于android – Handler.removeCallbacksAndMessages(null)和主循环、android – 不调用带缓冲区的PreviewCallback和PreviewCallback、android – 如何使用setResultCallback方法?、android – 如何使用“CookieManager :: removeAllCookies(ValueCallback callback)”的有用信息。

本文目录一览:

C ++ Windows:LRESULT CALLBACK和WNDPROC

C ++ Windows:LRESULT CALLBACK和WNDPROC

我有一个class级:

class SomeClass { public: void Init (); private: LRESULT CALLBACK WndProc (HWND wnd,UINT msg,WParaM wparam,LParaM lparam); };

另外,在另一个文件中,我有一个function:

void MakeWindow (WNDPROC wnd_proc,DWORD style,HICON lg_icon,...);

第一个参数应该采用LRESULT CALLBACK函数作为input。 我也有一个Init函数的定义:

void SomeClass::Init () { MakeWindow (this->WndProc,WM_POPUP,NULL,...); }

当我尝试将this->WndProc传递给WNDPROC wnd_proc时,这给了我VS2012中的错误WNDPROC wnd_proc 。 有没有什么办法可以将LRESULT CALLBACK WndProc函数传递给MakeWindow ?

从单独的文件C ++链接类的Cmake麻烦

在Python中分组一些动作的类

G ++对class :: function的未定义引用

C ++类中的问题与静态variables和函数

运行时types和属性标识在c + +

在int main()中使用类函数

制作对话框

search主类的图像?

如何find包含类定义的jar文件?

如何在LINUX shell中用Java编译多个类文件?

问题是您的WndProc方法是一个实例方法,因此不匹配WNDPROC 。 因为它是一个实例方法,所以它会收到一个额外的暗示, this参数。

您需要将其声明为static方法才能与WNDPROC兼容。

android – Handler.removeCallbacksAndMessages(null)和主循环

android – Handler.removeCallbacksAndMessages(null)和主循环

在片段的onDestory中,我放置代码来清理我开始使用Handler.postDelayed的所有待处理的runnable.
mUiHandler.removeCallbacksAndMessages(null);

我在这里有一个问题.调用mUiHandler.removeCallbacksAndMessages(null)是否安全;?据我所知,Android在主循环中执行所有UI操作,如UI布局,UI渲染,组件生命周期(onCreate,onPause,onResume).我理解正确吗?然后,当我在片段中调用mUiHandler.removeCallbacksAndMessages(null)时,它会搞乱或清理主循环器中消息队列中的所有Android系统UI操作,因为主循环器中只有一个消息队列.

谢谢.

解决方法

这只会删除已发布到特定处理程序的消息和回调.它不会删除任何其他内容,所以是的,这样做是安全的.

总结

以上是小编为你收集整理的android – Handler.removeCallbacksAndMessages(null)和主循环全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

android – 不调用带缓冲区的PreviewCallback和PreviewCallback

android – 不调用带缓冲区的PreviewCallback和PreviewCallback

我对 Android 4.0.x的预览回调有疑问.
我设置了一个摄像头,创建一个表面来在previewCallback-event上显示摄像头图像.一切正常.

但是使用Android 4.0.x既不调用onPreviewCallback也不调用onPreviewCallbackWithBuffer.
这个问题有解决方法吗?

我想拍摄一个屏幕截图并且不想使用takePicture() – 因为它会在短时间内冻结实时图像.

解决方法

您必须在surfaceChanged方法中调用setPreviewCallback,而不仅仅是在surfaceCreated中.
public void surfaceChanged(SurfaceHolder holder,int format,int w,int h) {
    if (mHolder.getSurface() == null){
      return;
    }

    try {
        mCamera.stopPreview();
    } catch (Exception e){
      // ignore: tried to stop a non-existent preview
    }

    try {
        mCamera.setPreviewCallback(this);
        mCamera.setPreviewdisplay(mHolder);
        mCamera.startPreview();

    } catch (Exception e){
        Log.d(TAG,"Error starting camera preview: " + e.getMessage());
    }
}

android – 如何使用setResultCallback方法?

android – 如何使用setResultCallback方法?

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.Googleapiclient;
import com.google.android.gms.common.api.Googleapiclient.ConnectionCallbacks;
import com.google.android.gms.common.api.Googleapiclient.OnConnectionFailedListener;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.drive.DriveApi.ContentsResult;
import com.google.android.gms.drive.MetadataChangeSet;


public class Phototodrive extends Activity implements ConnectionCallbacks,OnConnectionFailedListener{

    private static final String TAG = "android-drive-quickstart";
    private static final int REQUEST_CODE_CAPTURE_IMAGE = 1;
    private static final int REQUEST_CODE_CREATOR = 2;
    private static final int REQUEST_CODE_RESOLUTION = 3;

    private Googleapiclient mGoogleapiclient;            
    private Bitmap mBitmapToSave;  

    /**
     * Create a new file and save it to Drive. 
     */ 
    private void saveFiletoDrive() {  
        // Start by creating a new contents,and setting a callback.
        Log.i(TAG,"Creating new contents.");
        final Bitmap image = mBitmapToSave;  
        Drive.DriveApi.newContents(mGoogleapiclient).setResultCallback(new ResultCallback<ContentsResult>() { 


            public void onResult(ContentsResult result) {
                // If the operation was not successful,we cannot do anything
                // and must
                // fail.
                if (!result.getStatus().isSuccess()) {
                    Log.i(TAG,"Failed to create new contents."); 
                    return; 
                }
                // Otherwise,we can write our data to the new contents.
                Log.i(TAG,"New contents created.");
                // Get an output stream for the contents.
                OutputStream outputStream = result.getContents().getoutputStream();
                // Write the bitmap data from it.
                ByteArrayOutputStream bitmapStream = new ByteArrayOutputStream();
                image.compress(Bitmap.CompressFormat.PNG,100,bitmapStream);
                try {
                    outputStream.write(bitmapStream.toByteArray());
                } catch (IOException e1) { 
                    Log.i(TAG,"Unable to write file contents.");
                }
                // Create the initial Metadata - MIME type and title.
                // Note that the user will be able to change the title later.
                MetadataChangeSet MetadataChangeSet = new MetadataChangeSet.Builder()
                        .setMimeType("image/jpeg").setTitle("Android Photo.png").build();
                // Create an intent for the file chooser,and start it.
                IntentSender intentSender = Drive.DriveApi
                        .newCreateFileActivityBuilder() 
                        .setinitialMetadata(MetadataChangeSet)
                        .setinitialContents(result.getContents())
                        .build(mGoogleapiclient);
                try {
                    startIntentSenderForResult(
                            intentSender,REQUEST_CODE_CREATOR,null,0);
                } catch (SendIntentException e) {
                    Log.i(TAG,"Failed to launch file chooser.");
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mGoogleapiclient == null) {
            // Create the API client and bind it to an instance variable.
            // We use this instance as the callback for connection and connection
            // failures.
            // Since no account name is passed,the user is prompted to choose.
            mGoogleapiclient = new Googleapiclient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.ScopE_FILE)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        // Connect the client. Once connected,the camera is launched.
        mGoogleapiclient.connect();
    }

    @Override
    protected void onPause() { 
        if (mGoogleapiclient != null) {
            mGoogleapiclient.disconnect();
        }
        super.onPause();
    }

    @Override
    protected void onActivityResult(final int requestCode,final int resultCode,final Intent data) {
        switch (requestCode) {
            case REQUEST_CODE_CAPTURE_IMAGE:
                // Called after a photo has been taken.
                if (resultCode == Activity.RESULT_OK) {
                    // Store the image data as a bitmap for writing later.
                    mBitmapToSave = (Bitmap) data.getExtras().get("data");
                }
                break;
            case REQUEST_CODE_CREATOR:
                // Called after a file is saved to Drive.
                if (resultCode == RESULT_OK) {
                    Log.i(TAG,"Image successfully saved.");
                    mBitmapToSave = null;
                    // Just start the camera again for another photo.
                    startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),REQUEST_CODE_CAPTURE_IMAGE);
                }
                break;
        }
    }

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // Called whenever the API client fails to connect.
        Log.i(TAG,"Googleapiclient connection Failed: " + result.toString());
        if (!result.hasResolution()) {
            // show the localized error dialog.
            GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(),this,0).show();
            return;
        }
        // The failure has a resolution. Resolve it.
        // Called typically when the app is not yet authorized,and an
        // authorization
        // dialog is displayed to the user.
        try {
            result.startResolutionForResult(this,REQUEST_CODE_RESOLUTION);
        } catch (SendIntentException e) {
            Log.e(TAG,"Exception while starting resolution activity",e);
        }
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        Log.i(TAG,"API client connected.");
        if (mBitmapToSave == null) {
            // This activity has no UI of its own. Just start the camera.
            startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),REQUEST_CODE_CAPTURE_IMAGE);
            return;
        }
        saveFiletoDrive();
    }

    @Override
    public void ondisconnected() {
        Log.i(TAG,"Googleapiclient connection suspended");
    }   





}

我正在尝试运行android google drive api quickstart应用程序.
我得到一个错误
– 对于PendingResult类型,方法setResultCallback(new ResultCallback(){})未定义
– 无法将ResultCallback解析为某种类型
我应该更改什么,或者为什么我收到此错误?

解决方法

由于’ondisconnect()’的存在,代码看起来过时(Google Play Services lib ver 14).检查您是否拥有版本15(Android SDK Manager),然后尝试 quickstart,demos或 this code.您的设备应该在Google Play Services 4.2上…

android – 如何使用“CookieManager :: removeAllCookies(ValueCallback callback)”

android – 如何使用“CookieManager :: removeAllCookies(ValueCallback callback)”

我是 java的新手并尝试使用CookieManager :: removeAllCookies(ValueCallback回调)方法删除WebView cookie.无法确定必须将哪些值传递给removeAllCookie方法.

文档https://developer.android.com/reference/android/webkit/ValueCallback.html和https://developer.android.com/reference/android/webkit/CookieManager.html#getInstance%28%29没有说明如何使用它.

我的理解是ValueCallback类似于c模板.但无法理解为什么需要传递一个对象来删除cookie.

解决方法

从文档:

If a ValueCallback is provided,onReceiveValue() will be called on the current thread’s Looper once the operation is complete. The value provided to the callback indicates whether any cookies were removed. You can pass null as the callback if you don’t need to kNow when the operation completes or whether any cookies were removed

所以你可以做到这一点

CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() {
           @Override
           public void onReceiveValue(Boolean value) {
               Log.d(TAG,"onReceiveValue " + value);
           }
       });

要么

CookieManager.getInstance().removeAllCookies(null);

此方法在API级别21中引入.如果您支持旧版本,则可能必须提供类似的内容.

if(API Level >= 21){
     CookieManager.getInstance().removeAllCookies(null);
}else{
  CookieManager.getInstance().removeAllCookie();
}

关于C ++ Windows:LRESULT CALLBACK和WNDPROC的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于android – Handler.removeCallbacksAndMessages(null)和主循环、android – 不调用带缓冲区的PreviewCallback和PreviewCallback、android – 如何使用setResultCallback方法?、android – 如何使用“CookieManager :: removeAllCookies(ValueCallback callback)”的相关知识,请在本站寻找。

本文标签: