关于WPARAM如何转换为LPCTSTR

关于WPARAM怎么转换为LPCTSTR


LRESULT CALLBACK WinProc(HWND hwnd,
UINT message,
WPARAM wparam,
additional message information,
LPARAM lparam) 
{
 ………………
MessageBox(hwnd, lpctstr, _T("WinMain"), MB_OKCANCEL);
}

在MessageBox中的第二参数是LPCTSTR类型,而回调函数WinProc的第三个参数是WPARAM类型,他们之间怎么转换啊?
看了许多帖子,也尝试了,但是还是不管用额。

------解决方案--------------------
这个看你传进来是什么参数了
如果传进来就是CString *
那么CString res = *(CString *)wparam;

根据你传进来的类型来转换
------解决方案--------------------
WPARAM 是一个32位的整数
LPCTSTR 也是一个32位的整数

你是不是想自定义消息啊?
然后把WPARAM 传进来一个LPCTSTR指向的字符串

那样你在MessageBox的第二个参数直接强制转换一下就行了
(LPCTSTR)wparam
------解决方案--------------------

不知道你要的是否是这种效果
#include <windows.h>

#define WM_USERDEF WM_USER+100 // 在此定义消息

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

// LPCTSTR lpStr = TEXT("this is a LPCTSTR string"); // 这里有个字符串
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

PSTR szCmdLine, int iCmdShow)

{

    static TCHAR szAppName[] = TEXT ("HelloWin") ;

    HWND   hwnd ;

    MSG    msg ;

    WNDCLASS wndclass ;


wndclass.style        = CS_HREDRAW 
------解决方案--------------------
 CS_VREDRAW ;

wndclass.lpfnWndProc  = WndProc ;

    wndclass.cbClsExtra   = 0 ;

    wndclass.cbWndExtra   = 0 ;

    wndclass.hInstance    = hInstance ;

    wndclass.hIcon        = LoadIcon (NULL, IDI_APPLICATION) ;

wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW) ;

wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ;

wndclass.lpszMenuName  = NULL ;

    wndclass.lpszClassName= szAppName ;


    if (!RegisterClass (&wndclass))
        
    {
        
MessageBox (  NULL, TEXT ("This program requires Windows NT!"),

szAppName, MB_ICONERROR) ;
        
return 0 ;
        
    }

    hwnd = CreateWindow( szAppName,      // window class name
        
TEXT ("The Hello Program"),   // window caption