質問

Im trying to make a simple program for a old pocketpc application.

Want it to get the time and show it when i use the pushbutton.

With the code below, i get two compiler errors:

error C2664: 'SetWindowTextW' : cannot convert parameter 1 from 'int' to 'HWND' Line: 201
error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'  Line: 233

Ive tried to search, seems to be a common misunderstanding this, but i cant see an explanation that fits..

_strdate( dateStr);
SetWindowText(1003, dateStr);

Also this:

hwndLabel = CreateWindow("STATIC","Time",
        WS_VISIBLE | WS_CHILD | SS_RIGHT,
        10,200,75,35,hWnd,NULL,1003,NULL);

Edit:

After Xearinox suggestions, i get three new faults.

These:

error C2664: '_wstrdate' : cannot convert parameter 1 from 'char [9]' to 'wchar_t *'    199
error C2664: 'SetDlgItemTextW' : cannot convert parameter 3 from 'char [9]' to 'LPCWSTR'    201
error C2440: '=' : cannot convert from 'HWND' to 'int'  233

if i remove (HMENU) from the static, i get another last error:

error C2664: 'CreateWindowExW' : cannot convert parameter 10 from 'int' to 'HMENU'  233
役に立ちましたか?

解決

First parameter of SetWindowText is hwnd, not control identifier. Try this:

SetDlgItemTextW(hWnd, 1003, dateStr);

Use this for retrieve date:

WCHAR dateStr[256] = {0};
_wstrdate(dateStr);

Also use wide string parameters for CreateWindow:

hwndLabel = CreateWindowW(L"STATIC",L"Time",
        WS_VISIBLE | WS_CHILD | SS_RIGHT,
        10,200,75,35,hWnd, (HMENU)1003, NULL, NULL);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top