12
16
2013
83

Windows API笔记1

 

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE PrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HANDLE hFile;
DWORD dwWritten;
TCHAR szSystemDir[MAX_PATH];
GetSystemDirectory(szSystemDir,MAX_PATH);

hFile = CreateFile(TEXT("systemroot.txt"),
GENERIC_WRITE,
0,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);

if (hFile != INVALID_HANDLE_VALUE)
{
if (!WriteFile(hFile,szSystemDir,lstrlen(szSystemDir),&dwWritten,NULL))
{
return GetLastError();
}
}
CloseHandle(hFile);
return 0;
}
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,
			HINSTANCE PrevInstance,
			LPSTR lpCmdLine,
			int nCmdShow)
{
	LPWSTR szUnicode = L"This is a Unicode String;";
	LPSTR szMutliByte = "This is not a Unicode String;";
	LPTSTR szString = TEXT("This string is Unicode or not depends on the option.");
	MessageBoxW(NULL,szUnicode,L"<字符编码1>",MB_OK);
	MessageBoxA(NULL,szMutliByte,"<字符编码2>",MB_OK);
	MessageBox(NULL,szString,TEXT("<字符编码3>"),MB_OK);
	return 0;
} 0;
}
Category: 其他 | Tags:

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com