终于好了,貌似不需要同步
LRESULT CALLBACK _disapp_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
/* Upon destruction, tell the main thread to stop */
/*TODO :Deal with other message.*/
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
/* All other messages (a lot of them) are processed using default procedures */
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
bool _disapp_isaready = false;
void _disapp_GetMyMsg(void* wParam)
{
WNDCLASSEX wc; // A properties struct of our window
// zero out the struct and set the stuff we want to modify
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = _disapp_WndProc; // This is where we will send messages to
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Load a standard icon
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // use the name "A" to use the project icon
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
exit(0);
}
_disappHWnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT/*x*/, CW_USEDEFAULT/*y*/,_disappW /*width*/,_disappH /*height*/,NULL,NULL,hInstance,NULL);
if(_disappHWnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
exit(0);
}
_disappHDC = GetDC(_disappHWnd);
if(_disappHDC == NULL)
{
MessageBox(NULL, "Getting HDC Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
exit(0);
}
_disappLine = CreatePen(PS_SOLID, 1, 0xffffff);
_disappFill = CreatePen(PS_SOLID, 1, 0xffffff);
_disappcline = 0xffffff;
_disappcfill = 0xffffff;
_disappEmpHdc = CreateCompatibleDC(NULL);
_disappEmpHbitmap = CreateCompatibleBitmap(_disappHDC,_disappW,_disappH);
SelectObject(_disappEmpHdc, _disappEmpHbitmap);
SetTextColor(_disappHDC, 0xffffff);
MSG msg;
_disapp_isaready = true;
while(1)
{
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
HWND initgraph(int x, int y)
{
_beginthread(_disapp_GetMyMsg, 0, NULL);
while(!_disapp_isaready);
return _disappHWnd;
}