我正在使用Visual Studio 2013上的Win32应用程序构建一个程序。从我读过的教程中,我知道以下代码是正确的,但我不知道在哪里更改参数类型以阅读以下内容: / p>
case WM_CREATE:
{
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL |
ES_AUTOVSCROLL, 50, 100, 300, 300, hWnd, (HMENU)IDC_EDIT_BOX,
NULL, NULL);
编译器突出显示“编辑”并给出了这个错误:
错误1错误C2664:'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)':无法从'const char转换参数2 5]'到'LPCWSTR'
答案 0 :(得分:8)
您正在使用已定义的UNICODE
进行编译。这意味着CreateWindowEx
是CreateWindowExW
的别名,宽字符版本。之一:
CreateWindowExA
或我个人建议选项1.您的代码将成为:
CreateWindowEx(WS_EX_CLIENTEDGE, L"Edit", L"",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
50, 100, 300, 300, hWnd, (HMENU)IDC_EDIT_BOX, NULL, NULL);
字符串文字的L
前缀用于指定宽字符文字。
答案 1 :(得分:1)
错误消息抱怨CreateWindowExW()
,但您的代码正在调用CreateWindowEx()
。这意味着您的项目正在编译时定义了UNICODE
。在这种情况下,CreateWindowEx()
映射到CreateWindowExW()
,它需要宽(wchar_t*
)数据,但是您传递的是窄(char*
)数据,因此错误。< / p>
您需要:
直接致电CreateWindowExW()
,并在文字前加上L
,使其宽而不是缩小:
hEdit = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", L"", ...);
继续调用CreateWindowEx()
,但用TEXT()
宏包装文字,这样根据是否定义UNICODE
,它会使它们变窄或变宽:
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT(""), ...);
答案 2 :(得分:0)
首先,您需要确定您尝试在字符集方面创建的项目类型。项目类型至少有四个选项
char
)wchar_t
)这是您必须先做出的决定。在做出决定之前,没有必要继续进行。
现在,根据您所做的选择,您应该按照以下步骤进行操作
常规char
项目
"Edit"
,'A'
等。char
,char [N]
,char *
和std::string
类型来处理字符和字符串printf
,strcpy
等。CreateWindowEx
或其缩小的名称:CreateWindowExA
(无论您更喜欢哪个)广wchar_t
个项目
L"Edit"
,L'A'
等。wchar_t
,wchar_t [N]
,wchar_t *
和std::wstring
类型来处理字符和字符串wprintf
,wcscpy
等。CreateWindowEx
或其广泛的名称:CreateWindowExW
(您更喜欢哪个)“变形金刚”项目
<tchar.h>
_T
:_T("Edit")
,_T('A')
等。TCHAR
,TCHAR [N]
,TCHAR *
和std::basic_string<TCHAR>
类型处理字符和字符串_tprintf
,_tcscpy
等。CreateWindowEx
混合搭配项目
当然,如果您启动了类型1或类型2的项目,则可以始终通过混合字符类型将其转换为类型4的项目。但是如果你需要一个3型项目,从一开始就坚持其原则是个好主意(后来转换为3型是一个非常费力的过程)。
您在项目中尝试做的事情并不是很明显。但一个疯狂的猜测是你正在尝试建立一个类型1项目。在这种情况下,您需要做的就是解决问题,转到项目设置并将“字符集”设置为“使用多字节字符集”。
答案 3 :(得分:0)
package com.myapper.hasee.server;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;
import android.widget.EditText;
import android.widget.Button;
import java.util.HashMap;
import java.util.Map;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class MainActivity extends AppCompatActivity {
// Creating EditText.
EditText FirstName, LastName, Email ;
// Creating button;
Button InsertButton;
// Creating Volley RequestQueue.
RequestQueue requestQueue;
// Create string variable to hold the EditText Value.
String FirstNameHolder, LastNameHolder, EmailHolder ;
// Creating Progress dialog.
ProgressDialog progressDialog;
// Storing server url into String variable.
String HttpUrl = "https://bomvibe.com/folder_name/myfile.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Assigning ID's to EditText.
FirstName = (EditText) findViewById(R.id.editTextFirstName);
LastName = (EditText) findViewById(R.id.editTextLastName);
Email = (EditText) findViewById(R.id.editTextEmail);
// Assigning ID's to Button.
InsertButton = (Button) findViewById(R.id.ButtonInsert);
// Creating Volley newRequestQueue .
requestQueue = Volley.newRequestQueue(MainActivity.this);
progressDialog = new ProgressDialog(MainActivity.this);
// Adding click listener to button.
InsertButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Showing progress dialog at user registration time.
progressDialog.setMessage("Please Wait, We are Inserting Your Data on Server");
progressDialog.show();
// Calling method to get value from EditText.
GetValueFromEditText();
// Creating string request with post method.
StringRequest stringRequest = new StringRequest(Request.Method.POST, HttpUrl,
new Response.Listener<String>() {
@Override
public void onResponse(String ServerResponse) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing response message coming from server.
Toast.makeText(MainActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// Hiding the progress dialog after all task complete.
progressDialog.dismiss();
// Showing error message if something goes wrong.
Toast.makeText(MainActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Creating Map String Params.
Map<String, String> params = new HashMap<String, String>();
// Adding All values to Params.
params.put("first_name", FirstNameHolder);
params.put("last_name", LastNameHolder);
params.put("email", EmailHolder);
return params;
}
};
// Creating RequestQueue.
RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
// Adding the StringRequest object into requestQueue.
requestQueue.add(stringRequest);
}
});
}
// Creating method to get value from EditText.
public void GetValueFromEditText(){
FirstNameHolder = FirstName.getText().toString().trim();
LastNameHolder = LastName.getText().toString().trim();
EmailHolder = Email.getText().toString().trim();
}
}