dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: win32- hook: why i can't change anything?

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    1,272

    win32- hook: how changing the aligment text and position of messagebox?

    i have these functions for show a messagebox:
    Code:
    int GetWindowString(HWND hwnd, std::string &s)
    {
        char buffer[65536];
    
        int txtlen=GetWindowTextLength(hwnd) + 1;
        GetWindowText(hwnd, buffer, txtlen);
    
        s = buffer;
        return txtlen;
    }
    
    HHOOK hhookCBTProc = 0;
    
    LRESULT CALLBACK pfnCBTMsgBoxHook(int nCode, WPARAM wParam, LPARAM lParam)
    {
      if (nCode == HCBT_CREATEWND)
      {
        CREATESTRUCT *pcs = ((CBT_CREATEWND *)lParam)->lpcs;
    
        if ((pcs->style & WS_DLGFRAME) || (pcs->style & WS_POPUP))
        {
          HWND hwnd = (HWND)wParam;
    
          // At this point you have the hwnd of the newly created
          // message box that so you can position it at will
          HDC test=GetDC(hwnd);
          //these 2 messages aren't showed
          if(SetTextAlign(test,TA_CENTER)==GDI_ERROR)
            MessageBox(NULL,"aligment", "error", MB_OK);
          if(SetWindowPos(hwnd, 0, 10,10,0,0,SWP_NOSIZE | SWP_NOZORDER)==FALSE)
            MessageBox(NULL,"position", "error", MB_OK);
          ReleaseDC(hwnd,test);
        }
      }
    
      return (CallNextHookEx(hhookCBTProc, nCode, wParam, lParam));
    }
    
    void MessageBox(string text, string title="",UINT flags=MB_OK, bool modal=false)
    {
        HWND parent=NULL;
        if(modal==true)
            parent=ActivatedForm;
        if(title=="")
        {
            GetWindowString(ActivatedForm,title);
        }
        if(hhookCBTProc==0)
            hhookCBTProc = SetWindowsHookEx(WH_CBT,
                                    pfnCBTMsgBoxHook,
                                    0, GetCurrentThreadId());
        if(hhookCBTProc==NULL)
            ::MessageBox(parent,"error","error", MB_OK);
        ::MessageBox(parent,text.c_str(),title.c_str(), flags);
        if(hhookCBTProc!=0)
            UnhookWindowsHookEx(hhookCBTProc);
    
    }
    i have an error on pfnCBTMsgBoxHook() function. how i know? the aligment and position aren't changed. why?
    and no error messageboxes are showed
    Last edited by Cambalinho; July 31st, 2015 at 10:25 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)