Thread: Create a duplicate window?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    18

    Create a duplicate window?

    Hi,

    I have been programming C/C++ for a while now and decided to learn the windows API, so I've been writing a little sticky notes application to get to grips with it, but I am currently stuck on one thing.

    I would like to be able to create a duplicate of the window I created, this is my code so far:

    Code:
    #include <windows.h>
    #define IDB_BUTTON1 50001
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[ ] = "Stickies";
    int nFunSti;
    void makeNewSticky (HINSTANCE);
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil) {
        MSG messages;            
        makeNewSticky (hThisInstance);
        nFunSti = nFunsterStil;
        while (GetMessage (&messages, NULL, 0, 0))
        {
        
            TranslateMessage(&messages);
           
            DispatchMessage(&messages);
        }
    
       
        return messages.wParam;
    }
    void makeNewSticky (HINSTANCE hThisInstance) {
        HWND hwnd;              
        MSG messages;          
        WNDCLASSEX wincl;       
        
      
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;   
        wincl.style = CS_DBLCLKS;              
        wincl.cbSize = sizeof (WNDCLASSEX);
    
     
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;            
        wincl.cbClsExtra = 0;                 
        wincl.cbWndExtra = 0;                  
      
        HBRUSH hbrushBg = CreateSolidBrush(RGB(255,235,27));
      wincl.hbrBackground = (HBRUSH)hbrushBg;
     
      if (!RegisterClassEx (&wincl))
          exit (0);
    
        hwnd = CreateWindowEx (
               0,                  
               szClassName,       
               "Sticky Notes",     
               WS_POPUP,
               100,      
               100,      
               200,               
               175,               
               HWND_DESKTOP,       
               NULL,              
               hThisInstance,     
               NULL            
               );
    
    
        ShowWindow (hwnd, SW_SHOW);
        SetWindowPos ( hwnd, HWND_TOPMOST, 0, 0, 0, 0,SWP_NOMOVE|SWP_NOSIZE );
    }         
    
    
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static RECT titleRect  = { 0, 0, 180, 20  };
        static RECT dupeRect  = { 180, 0, 200, 20  };
        HWND hwndEdit;
        HINSTANCE hThisInstance;
        int nFunsterStil;
        switch (message)                 
        {
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            case WM_CREATE:
    hwndEdit = CreateWindow("Edit", NULL, WS_CHILD|WS_VISIBLE|
                                       ES_MULTILINE, 1, 20, 198, 154,
                                       hwnd, (HMENU) 2, hThisInstance, NULL);
    HWND button;
    button=CreateWindowEx(0,"Button","+", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 180, 0, 20, 20, hwnd, (HMENU)IDB_BUTTON1, GetModuleHandle(NULL), NULL);
               break;
               
            case WM_LBUTTONDOWN: {
                POINT pt = { LOWORD(lParam), HIWORD(lParam) };
                if ( PtInRect(&titleRect, pt) )
                      SendMessage(hwnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam  ) ;
                if ( PtInRect(&dupeRect, pt) )
                      makeNewSticky (hThisInstance);
                      return 0 ;
                }
                        break;
            case WM_LBUTTONDBLCLK: 
                 PostQuitMessage (0);
            break;
            case WM_COMMAND:
                 switch (wParam) {
                        case IDB_BUTTON1:
                             makeNewSticky (GetModuleHandle(NULL));
                        break;
                 }
            break;
            default:            
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    As you can see I have the function makeNewSticky(), which creates a new window, but whenever I click the button I have created to run that function, the program just closes. All I want to do is to basically create a new window which is a duplicate of the original as many times as needed.

    Thanks,

    -Ben
    Check out my blog!
    http://www.om3ga.co.uk

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    do you need to register the window class twice? I'm not sure on this, but try only registering the class once and see if it will allow you to create more than one window from that.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    18
    Wow, thanks, it works!

    Now another few questions:
    • How do I change the colour of an edit box? (I know it has something to do with WM_CTLCOLOREDIT or something like that)

    • I have made my sticky notes not appear on the taskbar by making them children to invisible windows, but when I press ALT+TAB I get all of the sticky notes clogging that up, how do I get rid of their entries there? [EDIT: Have found a way to make only one entry appear, check my code below to see]

    • How do I give each sticky an individual handle? So that when I call DestroyWindow(hwnd) on a button click it doesn't destroy them all?

    • How do I trap keypresses in another window? I want to have a key combination like ALT+F9 or something so that when those keys are pressed the stickies all go to the bottom (I know how to change their depth, I just want to trap keypresses)


    -Ben
    Last edited by om3ga; 10-26-2005 at 04:02 AM.
    Check out my blog!
    http://www.om3ga.co.uk

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    18
    Sorry, I should probably have posted my current code to make this easier for you if you decide to help:
    Code:
    #include <windows.h>
    #define IDB_BUTTON1 50001
    #define IDB_BUTTON2 50002
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[ ] = "Stickies";
    HINSTANCE hThatInstance;
    HWND hwndHidden;
    void makeNewSticky (HINSTANCE);
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil) {
        MSG messages;            
        WNDCLASSEX wincl;       
    
        
      
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;   
        wincl.style = CS_DBLCLKS;              
        wincl.cbSize = sizeof (WNDCLASSEX);
    
     
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;            
        wincl.cbClsExtra = 0;                 
        wincl.cbWndExtra = 0;                  
      
        HBRUSH hbrushBg = CreateSolidBrush(RGB(255,235,27));
      wincl.hbrBackground = (HBRUSH)hbrushBg;
     
      if (!RegisterClassEx (&wincl))
          exit (0);
    
              hwndHidden = CreateWindowEx (
               0,                  
               szClassName,       
               "Hidden parent",     
               WS_VISIBLE,
               100,      
               100,      
               200,               
               175,               
               HWND_DESKTOP,       
               NULL,              
               hThisInstance,     
               NULL            
               );
               
                   ShowWindow (hwndHidden, SW_HIDE);
    
        makeNewSticky (hThisInstance);
        hThatInstance = hThisInstance;
        while (GetMessage (&messages, NULL, 0, 0))
        {
        
            TranslateMessage(&messages);
           
            DispatchMessage(&messages);
        }
    
       
        return messages.wParam;
    }
    void makeNewSticky (HINSTANCE hThisInstance) {
        HWND hwnd;       
        MSG messages;          
    
        hwnd = CreateWindowEx (
               0,                  
               szClassName,       
               "Sticky Notes",     
               WS_POPUP | WS_EX_TOOLWINDOW,
               100,      
               100,      
               200,               
               175,               
               hwndHidden,       
               NULL,              
               hThisInstance,     
               NULL            
               );
    
        ShowWindow (hwnd, SW_SHOW);
        SetWindowPos ( hwnd, HWND_TOPMOST, 0, 0, 0, 0,SWP_NOMOVE|SWP_NOSIZE );
    }         
    
    
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static RECT titleRect  = { 0, 0, 180, 20  };
        static RECT dupeRect  = { 180, 0, 200, 20  };
        HWND hwndEdit;
        HINSTANCE hThisInstance;
        int nFunsterStil;
        switch (message)                 
        {
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            case WM_CREATE:
    hwndEdit = CreateWindow("Edit", NULL, WS_CHILD|WS_VISIBLE|
                                       ES_MULTILINE, 1, 20, 198, 154,
                                       hwnd, (HMENU) 2, hThisInstance, NULL);
    HWND button;
    button=CreateWindowEx(0,"Button","+", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 160, 0, 20, 20, hwnd, (HMENU)IDB_BUTTON1, GetModuleHandle(NULL), NULL);
    button=CreateWindowEx(0,"Button","X", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 180, 0, 20, 20, hwnd, (HMENU)IDB_BUTTON2, GetModuleHandle(NULL), NULL);
               break;
               
            case WM_LBUTTONDOWN: {
                POINT pt = { LOWORD(lParam), HIWORD(lParam) };
                if ( PtInRect(&titleRect, pt) )
                      SendMessage(hwnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam  ) ;
                if ( PtInRect(&dupeRect, pt) )
                      makeNewSticky (hThatInstance);
                      return 0 ;
                }
                        break;
    /*        case WM_LBUTTONDBLCLK: 
                 PostQuitMessage (0);*/
            break;
            case WM_COMMAND:
                 switch (wParam) {
                        case IDB_BUTTON1:
                             makeNewSticky (GetModuleHandle(NULL));
                        break;
                        case IDB_BUTTON2:
                             DestroyWindow (hwnd);
                        break;
                 }
            break;
            default:            
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    Last edited by om3ga; 10-26-2005 at 04:02 AM.
    Check out my blog!
    http://www.om3ga.co.uk

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    57
    Quote Originally Posted by om3ga
    • How do I change the colour of an edit box? (I know it has something to do with WM_CTLCOLOREDIT or something like that)
    //example: change editbox colors; left/right mouse clicks in main window

    Code:
    //example: change editbox colors; left/right mouse clicks in main window
    //gcc prog.c -mwindows -o prog.exe
    #include <windows.h>
    
    //--- global ---------------------------------------
    HWND    hwndMain;
    HWND    hwndEdit;
    HBRUSH  hBrush;
    
    //--- prototypes -----------------------------------
    void initMainWindow(HINSTANCE, int);
    void initEditWindow(HINSTANCE);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    //-----------------------------------------------------------------------------
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
       MSG Msg;
    
       initMainWindow(hInstance,nCmdShow);
       initEditWindow(hInstance);
    
       UpdateWindow(hwndMain);
    
       while(GetMessage(&Msg, NULL, 0, 0) > 0) {
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
    
    //---------------------------------------------------------------------------
    void initMainWindow(HINSTANCE hInstance, int nCmdShow) {
       WNDCLASSEX wc;
    
       //--- register ----------------------------------
       wc.cbSize         = sizeof(WNDCLASSEX);
       wc.style          = 0;
       wc.lpfnWndProc    = WndProc;
       wc.cbClsExtra     = 0;
       wc.cbWndExtra     = 0;
       wc.hInstance      = hInstance;
       wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
       wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
       wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
       wc.lpszMenuName   = NULL;
       wc.lpszClassName  = "myMainClass";
       wc.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
       
       if(!RegisterClassEx(&wc)) {
          MessageBox(NULL, "Window Registration Failed!", "", MB_OK);
          exit(0);
       }
    
       //--- create ------------------------------------
       hwndMain = CreateWindowEx(
                   0,
                   "myMainClass",
                   "EditBox example",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT, 0,
                    480, 320,
                   NULL, NULL, hInstance, NULL);
    
       if(hwndMain == NULL) {
          MessageBox(NULL, "Window Creation Failed!", "", MB_OK);
          exit(0);
       }
       
       ShowWindow(hwndMain, nCmdShow);
       return;
    }
    
    //---------------------------------------------------------------------------
    void initEditWindow(HINSTANCE hInst) {
    
       hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "Some text", 
          WS_CHILD | WS_VISIBLE, 
          50, 10, 100, 100, hwndMain, (HMENU) 101, hInst, NULL);
    
       if(hwndEdit == NULL) {
          MessageBox(hwndMain, "Could not create edit box.", "", MB_OK);
          exit(0);
       }
    
       hBrush = CreateSolidBrush(RGB(255, 0, 0));
    }
    
    //-----------------------------------------------------------------------------
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       switch(msg)
    	{
    
       case WM_CTLCOLOREDIT:
          //SetTextColor((HDC) wParam, RGB(0, 255, 255));
          //SetBkColor((HDC) wParam, RGB(0, 0, 255));
          //SetBkMode((HDC) wParam, OPAQUE);
          //SetBkMode((HDC) wParam, TRANSPARENT);
          return (DWORD)hBrush;
       case WM_LBUTTONDOWN:
          hBrush = CreateSolidBrush(RGB(0, 0, 255));
          InvalidateRect(hwnd, NULL, TRUE); 
          break;
       case WM_RBUTTONDOWN:
          hBrush = CreateSolidBrush(RGB(255, 0, 0));
          InvalidateRect(hwnd, NULL, TRUE); 
          break;
       case WM_DESTROY:
          PostQuitMessage(0);
          break;
       default:
          return DefWindowProc(hwnd, msg, wParam, lParam);
       }
       return 0;
    }

  6. #6
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    subclass the edit window and handle the WM_ERASEBACKGROUND (something like that) message.

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    18
    Thanks cdave, that did it

    Anyone know the answers to my other two questions?

    Thanks!

    -Ben
    Check out my blog!
    http://www.om3ga.co.uk

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    57
    Quote Originally Posted by om3ga
    • How do I give each sticky an individual handle? So that when I call DestroyWindow(hwnd) on a button click it doesn't destroy them all?
    This seems to work:
    Code:
           case WM_DESTROY:
                if (hwnd == hwndHidden)
                   PostQuitMessage (0);
                break;

    Quote Originally Posted by om3ga
    • I have made my sticky notes not appear on the taskbar by making them children to invisible windows, but when I press ALT+TAB I get all of the sticky notes clogging that up, how do I get rid of their entries there? [EDIT: Have found a way to make only one entry appear, check my code below to see]
    This code has neither the sticky notes nor the main window shown by alt+tab. I used WS_EX_TOOLWINDOW on the main window too, instead of making it a hidden window. Also, note that WS_EX_TOOLWINDOW is the 1st arg (not 4th). Use Windows Task Manager to kill the main (hidden) window (for now).:
    Code:
    //WS_EX_TOOLWINDOW...windows do not appear on any taskbar,
    //gcc prog.c -mwindows -o prog.exe
    #include <windows.h>
    
    //--- global ---------------------------------------
    HWND    hwndMain;
    HWND    hwndC1;
    HWND    hwndC2;
    HWND    hwndC3;
    
    //--- prototypes -----------------------------------
    void initMainWindow(HINSTANCE, int);
    HWND createChildWindow(HINSTANCE);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    //-----------------------------------------------------------------------------
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
       MSG Msg;
    
       initMainWindow(hInstance,nCmdShow);
    
       hwndC1 = createChildWindow(hInstance);
       hwndC2 = createChildWindow(hInstance);
       hwndC3 = createChildWindow(hInstance);
    
       UpdateWindow(hwndMain);
    
       while(GetMessage(&Msg, NULL, 0, 0) > 0) {
    	TranslateMessage(&Msg);
    	DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
    
    //---------------------------------------------------------------------------
    void initMainWindow(HINSTANCE hInstance, int nCmdShow) {
       WNDCLASSEX wc;
    
       //--- register ----------------------------------
       wc.cbSize         = sizeof(WNDCLASSEX);
       wc.style          = 0;
       wc.lpfnWndProc    = WndProc;
       wc.cbClsExtra     = 0;
       wc.cbWndExtra     = 0;
       wc.hInstance      = hInstance;
       wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
       wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
       wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
       wc.lpszMenuName   = NULL;
       wc.lpszClassName  = "myMainClass";
       wc.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
       
       if(!RegisterClassEx(&wc)) {
          MessageBox(NULL, "Window Registration Failed!", "", MB_OK);
          exit(0);
       }
    
       //--- create ------------------------------------
       hwndMain = CreateWindowEx(
                   WS_EX_TOOLWINDOW,
                   "myMainClass",
                   "Basic Window - not on taskbar",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT, 0,
                    480, 320,
                   NULL, NULL, hInstance, NULL);
    
       if(hwndMain == NULL) {
          MessageBox(NULL, "Main Window Creation Failed!", "", MB_OK);
          exit(0);
       }
       
       ShowWindow(hwndMain, SW_HIDE);
       return;
    }
    
    //-----------------------------------------------------------------------------
    HWND createChildWindow(HINSTANCE hInstance){
       HWND    hwndChild;
    
       //--- create ------------------------------------
       hwndChild = CreateWindowEx(
                   WS_EX_TOOLWINDOW,
                   "myMainClass",
                   "A Child Window",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT, 0,
                    200, 200,
                   hwndMain, NULL, hInstance, NULL);
    
       if(hwndChild == NULL) {
          MessageBox(NULL, "Child Window Creation Failed!", "", MB_OK);
          exit(0);
       }
       
       ShowWindow(hwndChild, SW_SHOW);
    
       return hwndChild;
    
    }
    
    //-----------------------------------------------------------------------------
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       switch(msg) {
    
          case WM_DESTROY:
             if (hwnd == hwndMain)
                PostQuitMessage(0);
             break;
          default:
             return DefWindowProc(hwnd, msg, wParam, lParam);
       }
       return 0;
    }

  9. #9
    Registered User
    Join Date
    Oct 2005
    Posts
    18
    Wow!

    Thank you so much cdave! That really helped!

    Now, I'm going to be annoying you, but I have one more question (sorry!):

    How do I find out what key is being pressed, even if my window isn't focused?

    Thanks!

    -Ben
    Check out my blog!
    http://www.om3ga.co.uk

  10. #10
    Registered User
    Join Date
    Sep 2004
    Posts
    57
    Quote Originally Posted by om3ga
    How do I find out what key is being pressed, even if my window isn't focused?
    RegisterHotKey().

    Here. I've added just 5 new lines of code, and alt-k will kill everything.

    Code:
    //WS_EX_TOOLWINDOW...windows do not appear on any taskbar,
    // hotkey alt-k kill window
    //gcc prog.c -mwindows -o prog.exe
    #include <windows.h>
    
    #define RESUME_KEY    101
    
    //--- global ---------------------------------------
    HWND    hwndMain;
    HWND    hwndC1;
    HWND    hwndC2;
    HWND    hwndC3;
    
    //--- prototypes -----------------------------------
    void initMainWindow(HINSTANCE, int);
    HWND createChildWindow(HINSTANCE);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    //-----------------------------------------------------------------------------
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
       MSG Msg;
    
       initMainWindow(hInstance,nCmdShow);
    
       hwndC1 = createChildWindow(hInstance);
       hwndC2 = createChildWindow(hInstance);
       hwndC3 = createChildWindow(hInstance);
    
       RegisterHotKey( hwndMain, RESUME_KEY, MOD_ALT, 'K' );
    
       UpdateWindow(hwndMain);
    
       while(GetMessage(&Msg, NULL, 0, 0) > 0) {
          TranslateMessage(&Msg);
          DispatchMessage(&Msg);
       }
       return Msg.wParam;
    }
    
    //---------------------------------------------------------------------------
    void initMainWindow(HINSTANCE hInstance, int nCmdShow) {
       WNDCLASSEX wc;
    
       //--- register ----------------------------------
       wc.cbSize         = sizeof(WNDCLASSEX);
       wc.style          = 0;
       wc.lpfnWndProc    = WndProc;
       wc.cbClsExtra     = 0;
       wc.cbWndExtra     = 0;
       wc.hInstance      = hInstance;
       wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
       wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
       wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
       wc.lpszMenuName   = NULL;
       wc.lpszClassName  = "myMainClass";
       wc.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
       
       if(!RegisterClassEx(&wc)) {
          MessageBox(NULL, "Window Registration Failed!", "", MB_OK);
          exit(0);
       }
    
       //--- create ------------------------------------
       hwndMain = CreateWindowEx(
                   WS_EX_TOOLWINDOW,
                   "myMainClass",
                   "Basic Window - not on taskbar",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT, 0,
                    480, 320,
                   NULL, NULL, hInstance, NULL);
    
       if(hwndMain == NULL) {
          MessageBox(NULL, "Main Window Creation Failed!", "", MB_OK);
          exit(0);
       }
       
       ShowWindow(hwndMain, SW_HIDE);
       return;
    }
    
    //-----------------------------------------------------------------------------
    HWND createChildWindow(HINSTANCE hInstance){
       HWND    hwndChild;
    
       //--- create ------------------------------------
       hwndChild = CreateWindowEx(
                   WS_EX_TOOLWINDOW,
                   "myMainClass",
                   "A Child Window",
                   WS_OVERLAPPEDWINDOW,
                   CW_USEDEFAULT, 0,
                    200, 200,
                   hwndMain, NULL, hInstance, NULL);
    
       if(hwndChild == NULL) {
          MessageBox(NULL, "Child Window Creation Failed!", "", MB_OK);
          exit(0);
       }
       
       ShowWindow(hwndChild, SW_SHOW);
    
       return hwndChild;
    
    }
    
    //-----------------------------------------------------------------------------
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
       switch(msg) {
    
          case WM_HOTKEY:
             DestroyWindow(hwndMain); 
             break;
          case WM_DESTROY:
             if (hwnd == hwndMain)
                PostQuitMessage(0);
             break;
          default:
             return DefWindowProc(hwnd, msg, wParam, lParam);
       }
       return 0;
    }
    This is a good learning experience for me too!

  11. #11
    Registered User
    Join Date
    Oct 2005
    Posts
    18
    Yeah, thanks, I just found RegisterHotKey on msdn earlier, thanks anyway!

    -om3ga
    Check out my blog!
    http://www.om3ga.co.uk

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how i create a window whith all it's elements
    By rasheed in forum Windows Programming
    Replies: 1
    Last Post: 05-31-2006, 06:53 PM
  2. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. Create a window from a dialogbox ?
    By peter in forum Windows Programming
    Replies: 7
    Last Post: 09-09-2001, 07:42 AM