I am fiddling around with making my own popup window by subclassing a static window but I am getting 3 problems. But before I get onto those I wanted to ask, is there a native Win32 Popup window class, you know like how there is "Edit", "Static", "Button"... is there a popup class?
But onto my questions/problems:
- Even though I use the function SetFocus, my popup window does not get the focus, can you help me figure out why?
- I want my popup window to have no border what so ever, not even a title, but I cant find a flag (WS_blah) to do this? Can you suggest which one I can use to have no borders?
- When I left click on the popup window it doesn't even receive the focus then, the only way to make it get the focus is to click the 'X' in the top right to close it, but :P, it doesn't even close? Its really weird, is it because the window is a Static window that has been subclassed, should I sublcass a different type of window & if so what type?
To make the window I just create my class...
PopUpDialog popup = PopUpDialog( hwnd, SUBCLASS_WINDOW, 200, 200,
"Only 2 days until ur bday!!", BOTTOM_RIGHT );
Then in the constructor of PopUpDialog I create the window & position it:
PopUpDialog :: PopUpDialog( HWND nParentHwnd, WindowType type, unsigned int nWidth, unsigned int nHeight, char* caption, DisplayPos position ) : parentHwnd(nParentHwnd), windowType(type), width(nWidth), height(nHeight), positionType(position){ // Constructor: char *winClass; if ( windowType == CUSTOM_WINDOW ) { // Register window if ( !isDialogRegistered() ) { RegisterPopUpDialog(); } winClass = "PopUpDialog"; } else winClass = "Static"; // Calculate window pos according to the position type CalculateWindowPos(); // CreateWindowEx() hwnd = CreateWindowEx( WS_EX_STATICEDGE | WS_EX_NOPARENTNOTIFY, winClass, caption, WS_VISIBLE | WS_POPUPWINDOW | WS_CAPTION, pos.x, pos.y, width, height, NULL, 0, GetModuleHandle( NULL ), NULL ); if ( windowType == SUBCLASS_WINDOW ) { SubClassWindow(); } // Make the popup window on top & have the focus // but the focus never get transfered to this window SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); SetFocus( hwnd ); // HOW DO I INITIALISE A STATIC PROTECTED VAR? // PopUpDialog.isRegistered = false; ? }
My custom window proceedure that occurs before the normal static WndProc:
LRESULT CALLBACK PopUpDialogSubWndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ){ // Post: WNDPROC defaultWndProc = (WNDPROC) GetWindowLongPtr( hwnd, GWL_USERDATA ); switch ( msg ) { case WM_KEYDOWN: { // this works when I have the focus MessageBox( hwnd, "You pressed me", "Notify", MB_OK ); } break; case WM_LBUTTONDOWN: { // Doesnt get the focus even when I have this code aswell SetFocus( hwnd ); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: break; } return CallWindowProc( defaultWndProc, hwnd, msg, wParam, lParam ); }