#include <WinUser.h>
#include <Windows.h>
#include <stdlib.h>
#include <string.h>
HWND hWnd;
HDC tDC, cDC;
int Ww, Wh;
void* bgra;
unsigned short sp=80;
int WRender() {
while (1) {
Render();
Sleep(sp);
}
return 0;
}
int Render(){
typedef struct
{
unsigned char b, g, r, a;
}color;
BITMAPINFO bmi;
HBITMAP hbitmap = 0;
void* prgbdata;
color* pclr = (color*)bgra;
color* pwclr;
int x, y;
memset(&bmi,0,sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biHeight = Wh;
bmi.bmiHeader.biWidth = Ww;
bmi.bmiHeader.biPlanes = 1;
hbitmap = CreateDIBSection(NULL, &bmi, DIB_PAL_COLORS, &prgbdata, NULL, 0);
pwclr = (color*)prgbdata;
memcpy(pwclr,pclr,(unsigned long long)1920*1080*4);
if (hbitmap)
{
RECT rect;
rect.left = 1920;
rect.right = 1920 + Ww;
rect.top = 1080;
rect.bottom = 1080 + Wh;
SelectObject(cDC, hbitmap);
BitBlt(tDC, 1920, 1080, Ww, Wh, cDC, 0, 0, SRCCOPY);
DeleteObject(hbitmap);
}
}
int WINAPI WinMain(HINSTANCE hIn,HINSTANCE hIns,LPSTR lp,int nC){
WNDCLASS Wc = {0,0,0,0,hIn,0,0,0,0,"Wc"};
RegisterClass(&Wc);
hWnd = CreateWindow("Wc", "EightLayersOfDream", 0, 0, 0, 960, 540, 0,0,hIn,0);
Ww = 960;
Wh = 540;
ShowWindow(hWnd, nC);
UpdateWindow(hWnd);
tDC = GetDC(hWnd);
cDC = CreateCompatibleDC(tDC);
MSG M;
bgra = calloc(4, (unsigned long long)1920 * 1080);
CreateThread(0,0,WRender,0,0,0);
while (GetMessage(&M, 0, 0, 0)) {
if (M.message == WM_SIZE) {
RECT Rect;
GetWindowRect(hWnd,&Rect);
MoveWindow(hWnd, Rect.left, Rect.top, Rect.right - Rect.left, (Rect.right - Rect.left) / 16 * 9, 1);
}
}
return 0;
}
如上,一个简单的窗口,我用VS编译提示HWND找不到,用GCC编译提示WinUser.h存在语法错误,TCC编译则是提示WinUser.h其中一条typedef没加分号。上述三个编译器的头文件我没动过,VS还是今天才安装的,请问怎回事啊?