Topwnd for a small and practical green software, you can top most of the window, a key to the top, a button to cancel!
Paste on:
I've been working on this gadget, curious today, to decide how it's going to work inside.
Online search, did not find the source of this gadget.
Helpless had had to step by step of their own to achieve it.
Finally, the mfc+ global Hook successfully imitated a similar program.
- Preparatory work
- Visual Studio 2012
- Building MFC Project
- Drag several controls
- Reference article: http://blog.csdn.net/friendan/article/details/12168273
- Global Hooks
- Handling the communication between the main program and the hook DLL
- Define a message in the main program header file as defined by the DLL
- #define WM_MYMSG Wm_user + 305
- Declaring a message-handler function in a header file
- afx_msg LRESULT onmymsg (WPARAM wparam,lparam LPARAM);
- Write a message map in the main file
- On_message (WM_MYMSG,ONMYMSG)
- Implement the message handler function, implement the top and restore functions within the function
- Master Program Implementation Control
- To open a connection function to a DLL
1 //Load Hook DLL2G_hinstdll=loadlibrary (_t ("MouseHook.dll"));3 if(g_hinstdll==NULL)4 {5AfxMessageBox (_t ("No MouseHook.dll"));6 return;7 }8 9typedef BOOL (CALLBACK *starthookmouse) (HWND hwnd); Ten Starthookmouse Starthook; One AStarthook= (starthookmouse):: GetProcAddress (G_hinstdll,"Starthookmouse"); - if(starthook==NULL) - { theAfxMessageBox (_t ("func starthookmouse not found!")); - return; - } - + //Pass the handle of this program to the hook DLL for communication - if(Starthook ( This-m_hwnd)) + { A Setdlgitemtext (idc_state,state1); at } - Else - { - Setdlgitemtext (idc_state,state2); -}
- To close a connection function to a DLL
typedef VOID (CALLBACK *stophookmouse) (); Stophookmouse Stophook; = LoadLibrary (_t ("MouseHook.dll")); = (Stophookmouse):: GetProcAddress (G_hinstdll,"stophookmouse"); if (Stophook = = NULL) { setdlgitemtext (idc_state,state2); } Stophook (); if (G_hinstdll! = NULL) { :: FreeLibrary (G_hinstdll); }
- sticky button, restore button
- True functionality in message-handling functions
- Determine if the received mouse event is a click
- Handle to the program where the mouse is located when clicked
- Call the SetWindowPos function to make the window sticky. Parameter 1: Handle to the target program window, Parameter 2: (hwnd_topmost) top parameter, parameter 7: Does not change the window size and position
- Processing ends, closing the connection to the DLL
1 //handle the information of the hooks, the implementation of sticky and recovery2 LRESULT ctopwnddlg::onmymsg (WPARAM wparam,lparam LPARAM) {3 CString str;4 Staticpmsllhookstruct mousehookstruct;5MouseHookStruct =(pmsllhookstruct) LParam;6 if(WParam = =wm_lbuttondown) {7HWND Hwnd=::windowfrompoint (mousehookstruct->PT);8 TCHAR Title[max_path];9 :: GetWindowText (Hwnd,title,max_path);Ten if(openorclose) { One //hwnd_topmost window pinned Swp_nomove | Swp_nosize does not change window size and position A:: SetWindowPos (HWnd, Hwnd_topmost,0,0,0,0, Swp_nomove |swp_nosize); -GetDlgItem (Id_open)EnableWindow (TRUE); -Str. Format (_t ("%s%s"), state3,title); the setdlgitemtext (idc_state, str); - } - Else{ -:: SetWindowPos (HWnd, Hwnd_notopmost,0,0,0,0, Swp_nomove |swp_nosize); +GetDlgItem (Id_close)EnableWindow (TRUE); -Str. Format (_t ("%s%s"), state4,title); + Setdlgitemtext (IDC_STATE,STR); A } at Closehook (); - } - return 1; -}
- Source: C + + manual implementation of Topwnd source code
- Thank you for watching ~
Topwnd a key to the implementation of the window, share the source code