////////////////// // Window proc-like virtual function which specific CSubclassWnds will // override to do stuff. Default passes the message to the next hook; // the last hook passes the message to the original window. // You MUST call this at the end of your WindowProc if you want the real // window to get the message. This is just like CWnd::WindowProc, except that // a CSubclassWnd is not a window. // LRESULT CSubclassWnd::WindowProc(UINT msg, WPARAM wp, LPARAM lp) { // ASSERT_VALID(this); // removed for speed ASSERT(m_pOldWndProc); return m_pNext ? m_pNext->WindowProc(msg, wp, lp) : ::CallWindowProc(WNDPROC(m_pOldWndProc), m_hWnd, msg, wp, lp); }
//================================================================================================================================= /// /// Funtion to create Window. /// /// \param width the width of the window. /// \param height the height of the window. /// /// \return 0=fail; 1=pass //================================================================================================================================= HWND CreateWind( int width, int height ) { WNDCLASS wc; // Windows Class Structure HWND hWnd; HINSTANCE hInstance; hInstance = GetModuleHandle( NULL ); // Grab An Instance For Our Window wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. wc.lpfnWndProc = WNDPROC( WndProc ); // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // We Don't Want A Menu wc.lpszClassName = "OpenGL"; // Set The Class Name if ( ! RegisterClass( &wc ) ) // Attempt To Register The Window Class { MessageBox( NULL, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION ); return FALSE; } if ( ! ( hWnd=CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window "OpenGL", // Class Name "Triangle ES App", // Window Title WS_OVERLAPPEDWINDOW | // Defined Window Style WS_CLIPSIBLINGS | // Required Window Style WS_CLIPCHILDREN, // Required Window Style 0, 0, // Window Position width, // Window Width height, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL ) ) ) // Dont Pass Anything To WM_CREATE { return 0; } if ( CreateEGLContext( hWnd, hInstance ) == false ) { MessageBox( NULL, "Failed to create a context.", "ERROR", MB_OK|MB_ICONSTOP ); exit( 0 ); } CenterWindow(hWnd, NULL, width, height); ShowWindow( hWnd, SW_SHOW ); SetForegroundWindow( hWnd ); // Slightly Higher Priority SetFocus( hWnd ); // Sets Keyboard Focus To The Window //ResizeScene( width, height ); return hWnd; }
// WM_NCDESTROY handler // cleansup the data and unsubclasses the window // calls PostNcDestroy BOOL cef_window::HandleNcDestroy() { WNDPROC superWndProc = WNDPROC(GetWindowLongPtr(GWLP_WNDPROC)); RemoveProp(::gCefClientWindowPropName); DefaultWindowProc(WM_NCDESTROY, 0, 0); if ((WNDPROC(GetWindowLongPtr(GWLP_WNDPROC)) == superWndProc) && (mSuperWndProc != NULL)) SetWindowLongPtr(GWLP_WNDPROC, reinterpret_cast<INT_PTR>(mSuperWndProc)); mSuperWndProc = NULL; PostNcDestroy(); return TRUE; }
editwin_info::editwin_info(debugger_windows_interface &debugger, bool is_main_console, LPCSTR title, WNDPROC handler) : debugwin_info(debugger, is_main_console, title, handler), m_editwnd(nullptr), m_edit_defstr(), m_original_editproc(nullptr), m_history(), m_last_history(0) { if (window() == nullptr) return; // create an edit box and override its key handling m_editwnd = CreateWindowEx(EDIT_BOX_STYLE_EX, TEXT("EDIT"), nullptr, EDIT_BOX_STYLE, 0, 0, 100, 100, window(), nullptr, GetModuleHandleUni(), nullptr); m_original_editproc = WNDPROC(uintptr_t(GetWindowLongPtr(m_editwnd, GWLP_WNDPROC))); SetWindowLongPtr(m_editwnd, GWLP_USERDATA, LONG_PTR(this)); SetWindowLongPtr(m_editwnd, GWLP_WNDPROC, LONG_PTR(&editwin_info::static_edit_proc)); SendMessage(m_editwnd, WM_SETFONT, WPARAM(metrics().debug_font()), LPARAM(FALSE)); SendMessage(m_editwnd, EM_LIMITTEXT, WPARAM(MAX_EDIT_STRING), LPARAM(0)); set_editwnd_text(""); }
WNDFN FormWndProc (HWND hwnd, UINT msg, UINT wParam,LONG lParam) { TControl *ctrl = TControl::user_data(hwnd); HWND hNext, hDlg = GetParent(hwnd); TEventWindow *ew = (TEventWindow *) GetWindowLong(hDlg,0); switch (msg) { case WM_KEYDOWN: if (wParam==VK_TAB) { bool shift_down = GetKeyState(VK_SHIFT) < 0; int id = GetWindowLong(hwnd,GWL_ID); if (shift_down) { if (id > MIN_ID)id--; hNext = GetDlgItem(hDlg,id); } else { id++; hNext = GetDlgItem(hDlg,id); if (!hNext) hNext = GetDlgItem(hDlg,MIN_ID); } SetFocus(hNext); } else if (wParam==VK_RETURN) { PostMessage(hDlg,WM_COMMAND,IDOK,0); return 0; } else if (wParam==VK_ESCAPE) { PostMessage(hDlg,WM_COMMAND,IDCANCEL,0); return 0; } break; case WM_SETFOCUS: if (ctrl->is_type(L"TEdit")) ctrl->send_msg(EM_SETSEL,0,-1); break; } long ret = CallWindowProc(WNDPROC(ctrl->m_wnd_proc),hwnd,msg,wParam,lParam); if (ew && ew->child_messages()) { if (msg == WM_KEYDOWN || msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) ew->send_msg(msg,wParam,lParam); } return ret; }
//helper function to set up the window properties ATOM MyRegisterClass(HINSTANCE hInstance) { //create the window class structure WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); //fill the struct with info wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WNDPROC(WinProc); wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = HBRUSH(GetStockObject(BLACK_BRUSH)); wc.lpszMenuName = NULL; wc.lpszClassName = APPTITLE; wc.hIconSm = NULL; //set up the window with the class info return RegisterClassEx(&wc); }
bool cWindow::Create( HWND parent, LPCWSTR text, DWORD exstyle,DWORD style, int x,int y,int w,int h, UINT id ) { _hInstance=GetModuleHandle(0); WNDCLASSEX wndc; wndc.lpszClassName=L"MyWnd"; wndc.cbSize=sizeof(WNDCLASSEX); wndc.lpfnWndProc=WNDPROC(_WndProc); wndc.cbClsExtra=0; wndc.cbWndExtra=0; wndc.hbrBackground=HBRUSH(BLACK_PEN); wndc.hInstance=_hInstance; wndc.hCursor=LoadCursor(0,IDC_CROSS); wndc.style=CS_HREDRAW|CS_VREDRAW; wndc.hIcon=0; wndc.hIconSm=0; wndc.lpszMenuName=0; RegisterClassEx(&wndc); //CreateWindow _hwnd=CreateWindowEx(exstyle,wndc.lpszClassName,text, style|WS_CLIPCHILDREN, x,y,w,h,parent,HMENU(id), _hInstance, this ); changeSize(); if(!_hwnd) return false; return true; }
////////////////// // Subclassed window proc for message hooks. Replaces AfxWndProc (or whatever // else was there before.) // LRESULT CALLBACK HookWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { #ifdef _USRDLL // If this is a DLL, need to set up MFC state AFX_MANAGE_STATE(AfxGetStaticModuleState()); #endif // Set up MFC message state just in case anyone wants it // This is just like AfxCallWindowProc, but we can't use that because // a CSubclassWnd is not a CWnd. // MSG& curMsg = AfxGetThreadState()->m_lastSentMsg; MSG oldMsg = curMsg; // save for nesting curMsg.hwnd = hwnd; curMsg.message = msg; curMsg.wParam = wp; curMsg.lParam = lp; // Get hook object for this window. Get from hook map CSubclassWnd* pSubclassWnd = theHookMap.Lookup(hwnd); ASSERT(pSubclassWnd); LRESULT lr; if (msg == WM_NCDESTROY) { // Window is being destroyed: unhook all hooks (for this window) // and pass msg to orginal window proc // LONG_PTR wndproc = pSubclassWnd->m_pOldWndProc; theHookMap.RemoveAll(hwnd); lr = ::CallWindowProc(WNDPROC(wndproc), hwnd, msg, wp, lp); } else { // pass to msg hook lr = pSubclassWnd->WindowProc(msg, wp, lp); } curMsg = oldMsg; // pop state return lr; }
bool CViewSparrow::initialize(int x, int y, unsigned w, unsigned h) { CWindowsApplication* app_inst = dynamic_cast<CWindowsApplication*>(CApplication::get_instance()); if (!app_inst) { return false; } HINSTANCE os_instance = app_inst->os_instance(); HWND main_wnd = app_inst->os_window(); const wchar_t *className = L"D2DTargetWindow"; WNDCLASSEX wndcls; if (!GetClassInfoEx(os_instance, className, &wndcls)) { wndcls.cbSize = sizeof(WNDCLASSEX); wndcls.style = CS_HREDRAW | CS_VREDRAW; wndcls.hInstance = os_instance; wndcls.lpfnWndProc = WNDPROC(&ViewSparrowProcess); wndcls.cbClsExtra = 0; wndcls.cbWndExtra = 0; wndcls.hCursor = LoadCursor(NULL, IDC_ARROW); wndcls.hIcon = NULL; wndcls.hIconSm = NULL; wndcls.hbrBackground = NULL; wndcls.lpszMenuName = NULL; wndcls.lpszClassName = className; if (!RegisterClassEx(&wndcls)) return false; } HWND target_wnd = CreateWindowEx(0, className, NULL, WS_CHILDWINDOW, x, y, w, h, main_wnd, NULL, os_instance, NULL); if (!target_wnd) { return false; } ID2D1Factory *ptr_factory = nullptr; D2D1_FACTORY_OPTIONS options; options.debugLevel = D2D1_DEBUG_LEVEL_NONE; HRESULT result = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, options, &ptr_factory); if (result != S_OK) { error("Failed to initialize Direct2D factory."); return false; } m_hwnd = target_wnd; m_d2d_factory = ptr_factory; if (!rebuild_resource()) { error("Failed to create graphic resource."); return false; } m_target = std::make_shared<CSpwRenderTarget>(); if (!m_target->create(w, h, SPR_COLOR_B8G8R8A8 | SPR_DEPTH_16)) { m_target = nullptr; error("Failed to create sparrow render target."); return false; } m_renderer = std::make_shared<CSpwRenderer>(); m_renderer->set_render_target(m_target); m_view_pos.setValue(x, y); m_view_size.setValue(int(w), int(h)); SetWindowLongPtr(m_hwnd, GWL_USERDATA, LONG_PTR(this)); // do not response user input EnableWindow(target_wnd, FALSE); ShowWindow(target_wnd, SW_NORMAL); debug("Sparrow view at (%d, %d, %d, %d)", x, y, x + w, y + h); return true; }