Thread: Overlapped Text and Window

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Question Overlapped Text and Window

    I want to make a simple addition calculator for my own learning, and im trying to paint the '+' sign in, but my border window is overlapping it. Obviously if I take out the border window, it shows up, but I would like to keep it there....looks cool

    Heres my code:

    Code:
    #include <windows.h>
    
    static char gszClassName[]  = "MyWindowClass";
    static HINSTANCE ghInstance = NULL;
    
    HWND hBorder,hBox1,hBox2,hEqual,hBox3;
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) 
    {
        HDC hdc;
        PAINTSTRUCT ps;
        LPSTR szMessage = "text_test";
    
        switch(Message) 
        {
    	   case WM_PAINT:
    	   {
    		  hdc = BeginPaint(hwnd, &ps);
    		  TextOut(hdc, 70, 40, szMessage, strlen(szMessage));
    		  EndPaint(hwnd, &ps);
    	   }
    	   break;
    
    	   case WM_CREATE:				 										   		 
    	   {		    
    		  hBorder = CreateWindowEx 
    				(
    				    NULL,
    				    "Static",
    				    "",
    				    WS_CHILD | WS_VISIBLE | WS_BORDER,
    				    4, 2,
    				    196, 46,
    				    hwnd, NULL,
    				    ghInstance,
    				    NULL
    				);	
    
    		  hBox1   = CreateWindowEx
    				(
    				    WS_EX_RIGHT | WS_EX_CLIENTEDGE,
    				    "Edit",
    				    "",
    				    WS_CHILD | WS_VISIBLE,
    				    10, 14,
    				    30, 20,
    				    hwnd, NULL,
    				    ghInstance,
    				    NULL
    				);
    	   }
    	   break;
    		
    	   case WM_CLOSE:
    		  DestroyWindow(hwnd);
    	   break;
    
    	   case WM_DESTROY:
    		  PostQuitMessage(0);
    	   break;
    
    	   default:
    		  return DefWindowProc(hwnd, Message, wParam, lParam);
        }
        
        return 0;
    } 
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
    {
        WNDCLASSEX WndC;
        HWND hwnd;
        MSG Msg;
    
        ghInstance = hInstance;
    
        WndC.cbSize        = sizeof(WNDCLASSEX);
        WndC.style         = NULL;
        WndC.lpfnWndProc   = WndProc;
        WndC.cbClsExtra    = 0;
        WndC.cbWndExtra    = 0;
        WndC.hInstance     = ghInstance;
        WndC.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndC.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndC.hbrBackground = (HBRUSH)(COLOR_WINDOW+0);
        WndC.lpszMenuName  = NULL;
        WndC.lpszClassName = gszClassName;
        WndC.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&WndC)) 
        {
    	   MessageBox(0, "Window Registration Failed!", "Error!", MB_ICONSTOP | MB_OK);
    	   return 0;
        }
    
        hwnd = CreateWindowEx
    	   (
    		  WS_EX_STATICEDGE,
    		  gszClassName,
    		  "math_test",
    		  WS_SYSMENU | WS_MINIMIZEBOX,	//WS_OVERLAPPEDWINDOW 
    		  CW_USEDEFAULT, CW_USEDEFAULT,
    		  210, 75,
    		  NULL, NULL,
    		  ghInstance,
    		  NULL
    	   );
    
        if(hwnd == NULL) 
        {
    	   MessageBox(0, "Window Creation Failed!", "Error!", MB_ICONSTOP | MB_OK);
    	   return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0)) 
        {
    	   TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        
        return Msg.wParam;
    }
    Last edited by xlnk; 11-03-2002 at 09:45 PM.
    the best things in life are simple.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    So why not make the edit bigger?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    I want the text to be on top of hBorder.

    Code:
    	   case WM_PAINT:
    	   {
    		  hdc = BeginPaint(hwnd, &ps);
    		  TextOut(hdc, 70, 40, szMessage, strlen(szMessage));
    		  EndPaint(hwnd, &ps);
    	   }
    	   break;
    Is there way to get that to paint before i create hBorder?
    the best things in life are simple.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    ...try this after you create the static window:

    Code:
    HDC dc = GetDC(hBorder);
    int mode = GetBkMode(dc);
    mode = (mode == 1) ? 2 : 1;
    SetBkMode(dc, mode);
    ReleaseDC(hBorder, dc);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Actually, use this first:

    Code:
    HDC dc = GetDC(hBorder);
    if(GetROP2(dc) != R2_COPYPEN) {
      SetROP2(dc, R2_COPYPEN);
     }
    ReleaseDC(hBorder, dc);
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    None of those worked, but I found another way:
    Code:
    hPlus   = CreateWindowEx
           (
    	NULL,
    	TEXT("Static"),
    	TEXT("+"),
    	WS_CHILD | WS_VISIBLE | SS_SIMPLE,
    	45, 12,
    	30, 25,
    	hwnd, NULL,
    	ghInstance,
    	 NULL
           );
    Another thing....how would you extract data from a text box?

    For example if someone typed in 5 into a text box, how could i extract out the data so it could be used as a variable to be added to another number in another text box.

    Thanks!
    Last edited by xlnk; 11-04-2002 at 10:45 PM.
    the best things in life are simple.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    GetWindowText returns zero if there is no text in the control....

    Code:
    int buffmax = 100;
    char * buffer = new char[buffmax];
    //...
    if( GetWindowText(hwnd, buffer, buffmax) ) {
      int val = atoi(buffer);
     }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM