WM_SHOWWINDOW problem

I want my window to handle the case
in which is state is changed from shown
to hidden ( and vice versa), but I want
to do it only after the window show status was changed.
The WM_SHOWWINDOW message is sent before the actual visibilty state of the window was changed.
zonaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nils pipenbrinckConnect With a Mentor Commented:
try wm_activate...

0
 
nietodCommented:
This doesn't seem to have anything to do with WM_ACTIVATE or its associated messages or anything to do with activation.

zona, I'm having trouble understanding the question.  But it sounds like you want to do something AFTER the window has been hidden/shown.  Is that right?   If so, just handle the WM_SHOWWINDOW message by calling the default window procedure and then when that procedure returns, perform your processing.
0
 
NickRepinCommented:
You have to post user-defined message from the WM_SHOWWINDOW message:

#define WMU_WINDOW_IS_SHOWN   WM_USER+1

case WM_SHOWWINDOW:
   // Post, but not send
   PostMessage(hWnd,WMU_WINDOW_IS_SHOWN,0,0);
   break;

case WMU_WINDOW_IS_SHOWN:
   if(IsWindowVisible(hWnd) {
      // Window just have been shown
   }
   else {
      // Window just have been hidden
   }
   break;
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
nietodCommented:
Why?  If would be sufficient to handle the WM_SHOWWINDOW After the default window procedure has hidden/shown the window.
0
 
NickRepinCommented:
Here is the test program.

OptionA: we call DefWindowProc and stops to see what's happened. Nothing.
Window is hidden.

OptionB: window is visible.


WM_SHOWWINDOW doesn't show window itself. I mean, you can skip DefWindowProc(WM_SHOWWINDOW) and return 0, but window will be shown anyway.


#include <windows.h>
#include <iostream.h>
#include <conio.h>

#define WMU_SHOWN WM_USER+1

LRESULT CALLBACK wndProc(HWND w,UINT msg,WPARAM wp,LPARAM lp)
{
   switch(msg) {
   case WM_CLOSE:
      PostQuitMessage(0);
      break;
   case WM_SHOWWINDOW:
     cout<<"Show"<<endl;
//***********
// Option A
//***********
     LRESULT r=DefWindowProc(w,msg,wp,lp);
     getch();
     cout<<"After getch"<<endl;
     return r;
//************

//***********
// Option B
//***********
     PostMessage(w,WMU_SHOWN,0,0);
     return 0;
   case WMU_SHOWN:
     cout<<"WNU_SHOWN"<<endl;
     getch();
     cout<<"After getch"<<endl;
     return 0;
//**********
   }
   return DefWindowProc(w,msg,wp,lp);
}

void main(void)
{
   WNDCLASS cls;
   memset(&cls,0,sizeof(cls));
   cls.lpfnWndProc=wndProc;
   cls.hInstance=GetModuleHandle(0);
   cls.lpszClassName="AZA";
   cls.hbrBackground=HBRUSH(COLOR_WINDOW+1);
   RegisterClass(&cls);
   MSG msg;
   PeekMessage(&msg,0,WM_USER,WM_USER,PM_NOREMOVE);
   HWND w=CreateWindowEx(0,"AZA","test",WS_POPUP|WS_CAPTION|WS_SYSMENU|
      WS_VISIBLE,
      5,5,200,200,0,0,cls.hInstance,0);
   while(GetMessage(&msg,0,0,0)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
}
0
 
NickRepinCommented:
By the way, zona has 8/19 grading record. So I think our dispute is useless.
0
 
chensuCommented:
NickRepin is on the right track. I often use PostMessage with a user-defined message in this case. Many Windows messages have not completely finished their jobs when the messages are received. Therefore, you have to wait.
0
All Courses

From novice to tech pro — start learning today.