Acmlm's Board - I2 Archive - Programming - Window DCs getting mixed up, or something...
User | Post |
HyperLamer
Posts: 4908/8210 |
Image (102K, 546x586)
If you can pull your eyes away from my desktop long enough you'll notice a small inconsitency in the numbering of these 10 pink squares, each of which is a window. For some reason which seems to defy all logic, the code that numbers them is simply skipping this window, no matter how many I create (though less than that works fine); drawing a black spot but no number, and somehow not even incrementing the number.
First I register a default window class:
//Create a default window class sprintf(WindowClassName,"DESKTOP_GADGETS");
WindowClass.cbSize = sizeof(WNDCLASSEX); //Struct size (don't fuck with) WindowClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; //Style flags WindowClass.lpfnWndProc = ProcMessage; //Message handler WindowClass.cbClsExtra = 0; //Extra junk WindowClass.cbWndExtra = 0; //Extra junk WindowClass.hInstance = hInst; //Program handle (don't fuck with) WindowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO); //Default icon WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); //Default cursor WindowClass.hbrBackground = WindowBrush; //Default brush WindowClass.lpszMenuName = NULL; //No menu WindowClass.lpszClassName = WindowClassName; //Class name WindowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); //Taskbar icon
//Register the window if(!RegisterClassEx(&WindowClass)) Die("RegisterClassEx() failed" LINENUM); DebugOut(DO_ALL,"Registered default window class\n");
Then create 10 windows using it:
int q; for(q=0;q<10;q++) { NewWindow(-1,-1,NULL,50,q*60,50,50,"Test"); DrawString(WindowInfo[q].hDC,20,20,false,"%d",q); //Sleep(500); ProcessMessages(); } void ProcessMessages() { MSG msgMessage; //Window message for(CurrentWindow=0;CurrentWindow<NumWindows;CurrentWindow++) { if(PeekMessage(&msgMessage,WindowInfo[CurrentWindow].hWnd,0,0,PM_REMOVE)) { //Yes, send it off TranslateMessage(&msgMessage); DispatchMessage(&msgMessage); } if(WindowInfo[CurrentWindow].IsMoving) { GetCursorPos(&point); rect.left = point.x - WindowInfo[CurrentWindow].MouseOffset.x; rect.top = point.y - WindowInfo[CurrentWindow].MouseOffset.y; Window_SetPos(WindowInfo[CurrentWindow].hWnd,rect.left,rect.top); } } }
HWND NewWindow(DWORD Style,DWORD ExStyle,HBRUSH BGBrush,int x, int y, int w, int h, char* Title) { if(NumWindows >= sizeof(WindowInfo)) { DebugOut(DO_MINOR,"Cannot create any more windows\n"); return 0; }
DWORD e,s; if(Style == -1) s = (WS_CHILD | WS_POPUP | WS_VISIBLE); else s = Style; if(ExStyle == -1) e = 0; else e = ExStyle;
//Create the window WindowInfo[NumWindows].hWnd = CreateWindowEx( e, /* Extended styles*/ "DESKTOP_GADGETS", /* Class name again */ Title, /* Title */ s, /* Window style flags */ x, y, w, h, /* Position and size */ hDesktop, /* Parent window handle (desktop) */ NULL, /* Menu handle (none) */ hInst, /* Program handle (don't fuck with) */ NULL); /* Parameter */
WindowInfo[NumWindows].hDC = GetDC(WindowInfo[NumWindows].hWnd); DebugOut(DO_STATUS,"Created window '%s' (#%d); hWnd=0x%08X, hDC=0x%08X\n", Title, NumWindows, WindowInfo[NumWindows].hWnd, WindowInfo[NumWindows].hDC); NumWindows++; }
DrawString() simply processes the string and draws it on a given DC. Somehow, though, this specific window is getting skipped. |
|