vc++字符集的问题
如下程序,#pragmaonce#include<Windows.h>#include<iostream>#include<WinUser.h>#include<minw...
如下程序,
#pragma once
#include <Windows.h>
#include <iostream>
#include <WinUser.h>
#include <minwindef.h>
#include <windef.h>
#include <tchar.h>
//global structures for task enumeration
typedef struct _TASK_LIST
{
DWORD dwProcessId;
DWORD dwInheritedFromProcessId;
BOOL flags;
HWND hwnd;
TCHAR ProcessName[MAX_PATH];
TCHAR WindowTitle[MAX_PATH];
} TASK_LIST, *PTASK_LIST;
typedef struct _TASK_LIST_ENUM
{
PTASK_LIST tlist;
DWORD numtasks;
} TASK_LIST_ENUM, *PTASK_LIST_ENUM;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD i;
RECT r;
TCHAR buf[MAX_PATH];
PTASK_LIST_ENUM te = (PTASK_LIST_ENUM)lParam;
PTASK_LIST tlist = te->tlist;
DWORD numTasks = te->numtasks;
i = 1 + tlist[0].dwProcessId;
// max 255 windows (I think it's enough)
if(i < 255)
{
// filter the windows to capture
if(IsWindowVisible(hwnd) && !IsIconic(hwnd))
{
GetClientRect(hwnd, &r);
//discard strange windows
if(r.right > 4 && r.bottom > 4)
{
// get the window caption
if(GetWindowText(hwnd, buf, MAX_PATH))
{
tlist[i].hwnd = hwnd; // store hwnd
_tcscpy(tlist[i].WindowTitle, buf); // store caption
tlist[0].dwProcessId++;
}
}
}
}
return TRUE;
}
int main()
{
TASK_LIST_ENUM te;
TASK_LIST tlist[256];
tlist[0].dwProcessId = 0;
te.tlist = tlist;
// get the windows
EnumWindows(EnumWindowsProc, (LPARAM)(&te));
int numtasks = tlist[0].dwProcessId;
// fill the list with the other windows
for(int i = 1; i < numtasks; i++)
{
//idx = m_list.InsertString(-1, tlist[i].WindowTitle);
//m_list.SetItemData(idx, (DWORD)tlist[i].hwnd);
std::cout << tlist[i].WindowTitle << std::endl;
}
return 0;
}
1,UNICODE字符集下的输出结果
2,Multibyte时的输出,如下
请高手给出合理解释!! 展开
#pragma once
#include <Windows.h>
#include <iostream>
#include <WinUser.h>
#include <minwindef.h>
#include <windef.h>
#include <tchar.h>
//global structures for task enumeration
typedef struct _TASK_LIST
{
DWORD dwProcessId;
DWORD dwInheritedFromProcessId;
BOOL flags;
HWND hwnd;
TCHAR ProcessName[MAX_PATH];
TCHAR WindowTitle[MAX_PATH];
} TASK_LIST, *PTASK_LIST;
typedef struct _TASK_LIST_ENUM
{
PTASK_LIST tlist;
DWORD numtasks;
} TASK_LIST_ENUM, *PTASK_LIST_ENUM;
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
DWORD i;
RECT r;
TCHAR buf[MAX_PATH];
PTASK_LIST_ENUM te = (PTASK_LIST_ENUM)lParam;
PTASK_LIST tlist = te->tlist;
DWORD numTasks = te->numtasks;
i = 1 + tlist[0].dwProcessId;
// max 255 windows (I think it's enough)
if(i < 255)
{
// filter the windows to capture
if(IsWindowVisible(hwnd) && !IsIconic(hwnd))
{
GetClientRect(hwnd, &r);
//discard strange windows
if(r.right > 4 && r.bottom > 4)
{
// get the window caption
if(GetWindowText(hwnd, buf, MAX_PATH))
{
tlist[i].hwnd = hwnd; // store hwnd
_tcscpy(tlist[i].WindowTitle, buf); // store caption
tlist[0].dwProcessId++;
}
}
}
}
return TRUE;
}
int main()
{
TASK_LIST_ENUM te;
TASK_LIST tlist[256];
tlist[0].dwProcessId = 0;
te.tlist = tlist;
// get the windows
EnumWindows(EnumWindowsProc, (LPARAM)(&te));
int numtasks = tlist[0].dwProcessId;
// fill the list with the other windows
for(int i = 1; i < numtasks; i++)
{
//idx = m_list.InsertString(-1, tlist[i].WindowTitle);
//m_list.SetItemData(idx, (DWORD)tlist[i].hwnd);
std::cout << tlist[i].WindowTitle << std::endl;
}
return 0;
}
1,UNICODE字符集下的输出结果
2,Multibyte时的输出,如下
请高手给出合理解释!! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询