Thread: Need some more assistance

  1. #1
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

    Need some more assistance

    Ok got trying to create 4 windows (this is for testing more then anything). Two windows are showing up just fine but the other two aren't drawing a frame or background. Code and a screenshot attached.
    Code is attached at the bottom
    http://www.mikemill.org/images/error.JPG

    Code:
    #include <windows.h>
    #include <tchar.h>
    #include <stdio.h>
    #include <winuser.h>
    #include <mike.h>
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK WndProc2 (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK WndProc3 (HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK WndProc4 (HWND, UINT, WPARAM, LPARAM);
    
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
                        
    {
        static TCHAR szAppName[] = TEXT ("Main Window");
        static TCHAR szAppName2[] = TEXT ("Battle");
        static TCHAR szAppName3[] = TEXT ("City");
        static TCHAR szAppName4[] = TEXT ("Map");
    
        int tmp;
    
        HWND        hMainWin, hBattleWin, hCityWin, hMapWin;
        WNDCLASS    wndclass, wndclass2, wndclass3, wndclass4;
        MSG         msg;
        
        
        wndclass.style        = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc  = WndProc;
        wndclass.cbClsExtra   = 0;
        wndclass.cbWndExtra   = 0;
        wndclass.hInstance    = hInstance;
        wndclass.hIcon        = LoadIcon (NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
        wndclass.lpszMenuName = NULL;
        wndclass.lpszClassName = szAppName;
        wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
        
        wndclass2.style        = CS_HREDRAW | CS_VREDRAW;
        wndclass2.lpfnWndProc  = WndProc2;
        wndclass2.cbClsExtra   = 0;
        wndclass2.cbWndExtra   = 0;
        wndclass2.hInstance    = hInstance;
        wndclass2.hIcon        = LoadIcon (NULL, IDC_ARROW);
        wndclass2.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
        wndclass2.lpszMenuName = NULL;
        wndclass2.lpszClassName = szAppName2;
        wndclass2.hCursor=LoadCursor(NULL,IDC_ARROW);
        
        wndclass3.style        = CS_HREDRAW | CS_VREDRAW;
        wndclass3.lpfnWndProc  = WndProc3;
        wndclass3.cbClsExtra   = 0;
        wndclass3.cbWndExtra   = 0;
        wndclass3.hInstance    = hInstance;
        wndclass3.hIcon        = LoadIcon (NULL, IDC_ARROW);
        wndclass3.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
        wndclass3.lpszMenuName = NULL;
        wndclass3.lpszClassName = szAppName3;
        wndclass3.hCursor=LoadCursor(NULL,IDC_ARROW);
        
        wndclass4.style        = CS_HREDRAW | CS_VREDRAW;
        wndclass4.lpfnWndProc  = WndProc4;
        wndclass4.cbClsExtra   = 0;
        wndclass4.cbWndExtra   = 0;
        wndclass4.hInstance    = hInstance;
        wndclass4.hIcon        = LoadIcon (NULL, IDC_ARROW);
        wndclass4.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
        wndclass4.lpszMenuName = NULL;
        wndclass4.lpszClassName = szAppName4;
        wndclass4.hCursor=LoadCursor(NULL,IDC_ARROW);
        
        
        if ( !RegisterClass (&wndclass))
            {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("#1 Error Number: %i"), tmp); 
            return 0;}
        
        if ( !RegisterClass (&wndclass2))
            {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("#2 Error Number: %i"), tmp); 
            return 0;}
        
        if ( !RegisterClass (&wndclass3))
            {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("#3 Error Number: %i"), tmp); 
            return 0;}
        
        if ( !RegisterClass (&wndclass4))
            {tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("#4 Error Number: %i"), tmp); 
            return 0;}
        
    
    
        hMainWin = CreateWindow (szAppName,
                             TEXT ("Main Window"),
                             WS_OVERLAPPEDWINDOW,
                             0,
                             0,
                             200,
                             200,
                             NULL,
                             NULL,
                             hInstance,
                             NULL);
        
        hBattleWin = CreateWindowEx (WS_EX_TOOLWINDOW,
                              szAppName2,
                              TEXT("Battle Window"),
                              WS_OVERLAPPED,
                              200,
                              0,
                              200,
                              200,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        hCityWin = CreateWindowEx (WS_EX_TOOLWINDOW,
                              szAppName3,
                              TEXT("City Window"),
                              WS_OVERLAPPED | WS_VISIBLE | WS_THICKFRAME,
                              0,
                              200,
                              200,
                              200,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        hMapWin = CreateWindowEx (WS_EX_TOOLWINDOW,
                              szAppName4,
                              TEXT("Map Window"),
                              WS_OVERLAPPEDWINDOW,
                              200,
                              200,
                              200,
                              200,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
    
        ShowWindow (hMainWin, iCmdShow);                     
        UpdateWindow (hMainWin);
        
        ShowWindow (hBattleWin, iCmdShow);                     
        UpdateWindow (hBattleWin);
        
        ShowWindow (hCityWin, iCmdShow);                     
        UpdateWindow (hCityWin);
        
        ShowWindow (hMapWin, iCmdShow);                     
        UpdateWindow (hMapWin);
        
        while (GetMessage (&msg, NULL, 0, 0))
            {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
            }
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC             hdc;
        PAINTSTRUCT     ps;
        RECT            rect;
        TCHAR           szBuffer[100];
        
        GetCurrentDirectory(100,szBuffer);
        
        switch (message)
            {
            case WM_CREATE:
                    return 0;
                    
            case WM_PAINT:
                    hdc = BeginPaint (hwnd, &ps);
                    GetClientRect (hwnd, &rect);
                    DrawText ( hdc, szBuffer, -1, &rect,
                               DT_SINGLELINE | DT_CENTER);
                    
                    EndPaint (hwnd, &ps);              
                    
                    return 0;
                    
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            
            }
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    
    LRESULT CALLBACK WndProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC             hdc;
        PAINTSTRUCT     ps;
        RECT            rect;
        TCHAR           szBuffer[100];
        
        switch (message)
            {
            case WM_CREATE:
                    return 0;
                    
            case WM_PAINT:
                    hdc = BeginPaint (hwnd, &ps);
                    GetClientRect (hwnd, &rect);
                    DrawText ( hdc, TEXT("#2"), -1, &rect,
                               DT_SINGLELINE | DT_CENTER);
                    
                    EndPaint (hwnd, &ps);              
                    
                    return 0;
                    
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            
            }
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    
    
    LRESULT CALLBACK WndProc3 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC             hdc;
        PAINTSTRUCT     ps;
        RECT            rect;
        TCHAR           szBuffer[100];
    
        switch (message)
            {
            case WM_CREATE:
                    return 0;
                    
            case WM_PAINT:
                    hdc = BeginPaint (hwnd, &ps);
                    GetClientRect (hwnd, &rect);
                    DrawText ( hdc, TEXT("#3"), -1, &rect,
                               DT_SINGLELINE | DT_CENTER);
                    
                    EndPaint (hwnd, &ps);              
                    
                    return 0;
                    
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            
            }
    }
    
    LRESULT CALLBACK WndProc4 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HDC             hdc;
        PAINTSTRUCT     ps;
        RECT            rect;
        TCHAR           szBuffer[100];
        switch (message)
            {
            case WM_CREATE:
                    return 0;
                    
            case WM_PAINT:
                    hdc = BeginPaint (hwnd, &ps);
                    GetClientRect (hwnd, &rect);
                    DrawText ( hdc, TEXT("#4"), -1, &rect,
                               DT_SINGLELINE | DT_CENTER);
                    
                    EndPaint (hwnd, &ps);              
                    
                    return 0;
                    
            case WM_DESTROY:
                    PostQuitMessage (0);
                    return 0;
            
            }
    }

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    I can't compile it, I don't have mike.h. When posting this kind of request, it is a good idea to zip everything needed to enable someone to compile it, 2 minutes in the debugger reveals far more than an hour reading the code.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Damn forgot about that. To compile without mike.h remove:
    tmp = GetLastError();MessageBoxPrintf( TEXT ("Error"),TEXT ("#1 Error Number: %i"), tmp);

    Also never have figured out how to run the debugger to be honest.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Looks like you've forgotten to call DefWindowproc in your 3rd and 4th window procedures.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Thanks. God I feel like an idiot

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Okay, I've got it compiled, but now my wife is telling me to leave the damn machine alone and eat my dinner, so I'll have a look later.

    *** EDIT ***

    Okay, so I won't!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Under the thumb adrian? lol
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 03:32 AM
  2. Variable Timer assistance
    By rich2852 in forum C Programming
    Replies: 2
    Last Post: 01-21-2009, 05:43 AM
  3. Code Assistance
    By Nezmin2 in forum C Programming
    Replies: 12
    Last Post: 12-19-2008, 12:26 AM
  4. Any assistance would be greatly appreciated
    By iiwhitexb0iii in forum C Programming
    Replies: 18
    Last Post: 02-26-2006, 12:06 PM
  5. Need assistance for major text base Arena RPG project
    By Ruflano in forum C++ Programming
    Replies: 0
    Last Post: 04-04-2002, 11:11 AM