program instance
Blitz3D Forums/Blitz3D Programming/program instance
| ||
Is it possible somehow to know if another instance of the program is open. I have the following case, my program in windowed mode, changing the resolution makes no problem yet full screen resolution for every change that is made in an instance leaves the taskbar, and when I click on them closes only. The question is whether it is possible to close the program from another part a lib or something. |
| ||
This used to be the code in C, but I've no idea how to implement it in Blit3D: (Try MSDN?) int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { WNDCLASS wndClass; MSG msg; HWND hFirstWnd = NULL; HWND hFirstChildWnd = NULL; hInst = hInstance; SetMessageQueue(100); lstrcpy(szAppName, "TopBar"); lstrcpy(szAppIcon, "Icons"); GetModuleFileName(hInst,szHomeFilename,128); ; This is the crucial bit... ; If no previous instance, then create one. if(!hPrevInstance) { wndClass.style = CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW|CS_BYTEALIGNCLIENT; wndClass.lpfnWndProc = WndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInst; wndClass.hIcon = NULL; //LoadIcon(hInstance,"a_tbar"); wndClass.hCursor = NULL; //LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)(hBrushBack); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = szAppName; if(!RegisterClass(&wndClass)) return(FALSE); } else { hFirstWnd = FindWindow (szAppName, NULL); if (hFirstWnd) { ShowWindow(hFirstWnd, SW_SHOWNORMAL); BringWindowToTop (hFirstWnd); MessageBeep(0); hFirstChildWnd = GetLastActivePopup (hFirstWnd); if (hFirstWnd != hFirstChildWnd) BringWindowToTop (hFirstChildWnd); return (FALSE); } } |
| ||
Yue, this is what I've used for my program TopBar:- (literally the first call in the code, before you create your own new window, see if there's a previous one running.) ret = api_FindWindow(0,"TopBar") If ret <>0 WB3D_Notify "TopBar", "Topbar is already running. ",0 End EndIf |