strange

This is a discussion on strange within the Windows Programming forums, part of the Platform Specific Boards category; i coded this programm for fun last couple of days it sets font for window and changes the desktop color ...

  1. #1
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218

    strange

    i coded this programm for fun last couple of days it sets font for window and changes the desktop color and font color and a few other stuff that get activated by certain menu item.

    now i have this menue item"show comp name" id = 81 that if pressed shows comp name on screen. but the funny thing is that if i push menu "pop up view" which has no members and no id, it shows the comp name as well and thats bizzar i cant think of the reason why .
    i have included the main source code here and didnt bother with other headers and source code definitions may be some one will figure it out * .thx

    *look for specified code under:

    WM_COMMAND:
    case 81:

    Code:
    #include <windows.h>
    #include "sia0016.h"
    
    
    WNDPROC od;
    
    
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
    	
         static char szAppName[] = TEXT ("Hello Lovely Sara, Experimental all in one Programm") ;
    	  
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASSEX     wndclass ;
         wndclass.cbSize        = sizeof(wndclass); 
         wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (hInstance, MAKEINTRESOURCE(20));
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
         wndclass.hIconSm       = LoadIcon(hInstance, MAKEINTRESOURCE(20));
    
         RegisterClassEx(&wndclass);
         
           
                        
           
         
         
         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("The, Hello Lovely Sara, Experimental all in one programm"), // window caption
                              WS_OVERLAPPEDWINDOW,       // window style
                              CW_USEDEFAULT,              // initial x position
                              CW_USEDEFAULT,              // initial y position
                              CW_USEDEFAULT,              // initial x size
                              CW_USEDEFAULT,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    { 
    	
    static     HBRUSH hbrush, hb;
              
               PAINTSTRUCT ps ;
               HDC  hdc;
    static int cxchar, cychar, cxcaps,  cxclient,n = 3, u, cyclient, i = 0,j = 0,  y = 0, m = 0,
                x = 0,cxchard, cychard,  cxbuffer, cybuffer;
    	       
    	       TEXTMETRIC tm;
    static	   HMENU hmenu, hmenu1;
    static     HWND hwndedit, hwndlist;
               POINT point;
      static   HINSTANCE hInstance;
               //HFONT hfont;
    
    static char *pbuffer = NULL; 
    static char ptext[300];	
    static char achar;	 
    static      BOOL bdraw = FALSE, bwrite = FALSE;
    static      COLORREF  cr = RGB(0, 0, 0); 
                DWORD color[3]; 
    int         aielements[3] = {COLOR_DESKTOP, 
                          COLOR_ACTIVECAPTION, 
                                COLOR_WINDOW}; 
    const       DWORD dwresult = RGB(0x3e, 0x7d, 0x77);                        // original desktop color
    static char    buf[256];
                DWORD bufsize; 
    const char  *compinfo[] = {"computer name = ", "computer type = "};
    static char *tempinfo = NULL;
    
        
         switch (message)
         {
         case WM_CREATE:
              cxchard = LOWORD (GetDialogBaseUnits ()) ;
              cychard = HIWORD (GetDialogBaseUnits ()) ;
             
    		  
    	
    	 hwndedit = CreateWindow (TEXT ("edit"), NULL,
                            WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                                       WS_BORDER | ES_LEFT | ES_MULTILINE |
                                       ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                             0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
                              ((LPCREATESTRUCT) lParam) -> hInstance, NULL);
    	
    	hwndlist =CreateWindow (TEXT ("listbox"), NULL,
                                  WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD,
                                  0, 0, 0, 0,hwnd, (HMENU) ID_LIST,
                                  (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                                  NULL) ;
                                  
                                  
    
                              
    		  hInstance = ((LPCREATESTRUCT )lParam)->hInstance;
              hmenu = LoadMenu(hInstance, TEXT ("sia0016"));
              SetMenu(hwnd, hmenu);
               
    		  PopFontInitialize(hwnd);
    		  
    		  hdc = GetDC(hwnd); 
    	      
    		  
              GetTextMetrics(hdc, &tm);
    		  cxchar = tm.tmAveCharWidth;
    		  cychar = tm.tmHeight + tm.tmExternalLeading;
    		  cxcaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxchar / 2;
              
    		 pbuffer = (char *)malloc(200 * sizeof(char));
              ReleaseDC(hwnd, hdc);
    		
             	
    		  return 0;
          case WM_SIZE:
    		
              
              cxclient = LOWORD (lParam) ;
              cyclient = HIWORD (lParam) ;
             
    		  
    		 // if(pbuffer != NULL)
    			  //free(pbuffer);
    		  //pbuffer = (char *)malloc(200 * sizeof(char));
    		  
              
    		 return 0;
    	  case WM_TIMER:
    		  bdraw = !bdraw;
    		  InvalidateRect(hwnd, NULL, FALSE);
    		  return 0;
    	 case WM_PAINT:
    	   hdc =  BeginPaint (hwnd, &ps) ;
    	   
    	   if(n == 1){
           
    	   if(bdraw = TRUE)
    		drawrect(hwnd, cxclient, cyclient);
    	   
    	   }
    	   EndPaint (hwnd, &ps) ;
    	     return 0 ;
    	 case WM_SETFOCUS:
    		 SetFocus(hwnd);
    		 return 0;
    		 
         case WM_KILLFOCUS:
    
    		 SetFocus(hwndedit);
    		 return 0;
    
    	 case WM_COMMAND:
           
    			 
            // if (LOWORD (wParam) == ID_EDIT)
              
                    
                         
    
                
    
    		 switch(LOWORD (wParam))
    		 {
             case 17:
    			 bwrite = TRUE;
    		return 0;
    		 case  18:
    			 bwrite = FALSE;
    			 return 0;
           
             case 21:
            hmenu = LoadMenu(hInstance, TEXT ("sia0016"));
              SetMenu(hwnd, hmenu);                              //sub menu back to main menu
    		  return 0;
    		 case 31:
     
           hbrush = CreateSolidBrush(siachcolor(hwnd));
    	   SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hbrush);  //background coloring
    	   InvalidateRect(hwnd, NULL, TRUE);
    	  // DeleteObject(hbrush);
           return 0;
    
    	    case 32:
    			 cr = siachcolor(hwndedit);
             hb = CreateSolidBrush(cr);
    		 m++;
    		 InvalidateRect(hwndedit, NULL, TRUE);             // choose color for edit
             InvalidateRect(hwndlist, NULL, TRUE);
    		 SetFocus(hwndedit); 
    		 return  0;
    	
    		case 33:
    
             
             color[0] =  siachcolor(hwnd);                //setting desktop color 
             SetSysColors(1, &aielements[0], &color[0]); 
            return 0;
    
    		case 34:
    		SetSysColors(1, &aielements[0], &dwresult);   //setting original desktop color
    			
    	    return 0;
    
    		
    		case 41:
    			 
    			 hdc = GetDC(hwnd);
    	   if(PopFontChooseFont(hwnd))
    	   SelectObject(hdc, PopFontSetFont(hwnd));
    	   SetTextColor(hdc, fontchoosecolor(hwnd));
    	   ReleaseDC(hwnd, hdc);
    	     return 0;
    		 case 42:
    	   hdc = GetDC(hwnd);
           DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));    //choose sys font
    	   SetTextColor(hdc, RGB(0, 0, 0));
           ReleaseDC(hwnd, hdc);
    			 return 0;
    		 case 51:
    			 ShowWindow(hwndedit, TRUE);
    			
    			 MoveWindow(hwndedit, 0, 0, cxclient / 2, cyclient / 2, TRUE);//edit open
    			 SetFocus(hwndedit);
            
                
    	//	InvalidateRect(hwndedit, NULL, TRUE);
    	     return 0;
    		 case 52:
    			 SetFocus(hwnd);
                MoveWindow(hwndedit, 0, 0, 0, 0, TRUE);
    			 ShowWindow(hwndedit, FALSE);                                 //edit close
    			 return 0;
         
    		 case 61:
    			 SetTimer(hwnd, ID_TIMER, 1000, NULL);    //randome rects
    			 n = 1;
    		  return 0;	
    	     case 62:
    			 n = 2;
    			 KillTimer(hwnd, ID_TIMER);
    			 InvalidateRect(hwnd, NULL, TRUE);
    			 return 0;
    		 case 71:
                 ShowWindow(hwndlist, TRUE);
    			 MoveWindow(hwndlist, cxchard, cychard * 20,cxchard * 13 + GetSystemMetrics (SM_CXVSCROLL),
                 cychard * 10, TRUE);
    			 SetFocus(hwndlist);                
    			 return 0;
    		 case 72:
    			 ShowWindow(hwndlist, FALSE);
                 MoveWindow(hwndlist, 0, cyclient, 0, 0, TRUE);
    			 SetFocus(hwnd);
    			 return 0;
    			 }
    		 case 81:
    			 tempinfo =(char *) malloc(255 * sizeof(char));
    			 bufsize = sizeof(buf);
    		     GetComputerName(buf,  &bufsize);                  //getting computername and print it
                 hdc = GetDC(hwnd);
    			
                
    			 sprintf(tempinfo, "%s %s", *(compinfo + 0), buf);
    			 tempinfo[strlen(tempinfo) + 1] = '\0';
                 TextOut(hdc, 0, 0, tempinfo, strlen(tempinfo));
    			 ReleaseDC(hwnd, hdc);
    			 InvalidateRect(hwnd, NULL, FALSE);
                 free(tempinfo);
    		 return 0;
    		 break;
    
             case  WM_CTLCOLOREDIT:
                                                                          //setting the hbrbkgr for edi
       
                 SetBkColor((HDC)wParam,m > 0 ? cr: RGB(255, 255, 217));
        	     return (LRESULT) hb;
    		 
    		 
    		 case WM_CTLCOLORLISTBOX:
                                                                          //setting the hbrbkgr for list
    		     SetBkColor((HDC)wParam,m > 0 ? cr: RGB(255, 255, 217));
    		     return (LRESULT) hb;
    		 
    		 
    		 case WM_CHAR:
    
    			 if(bwrite == TRUE){
    	   hdc = GetDC(hwnd);
          
    	  *(pbuffer + x) = (char) wParam;
    	  *(pbuffer + x + 1) = '\0';
          
    	   
    	     
    	  TextOut(hdc, i * cxchar, j * cychar , pbuffer + x, 1);
    	  
          i++;
    	  x++;
    		
    	  if((char) wParam == '\r'){
    	  j++;		  
    	  i = 0;
    		
              
    	  }
    		
    	 TextOut(hdc,  50, 200  , pbuffer , strlen(pbuffer));
         InvalidateRect(hwnd, NULL, FALSE);
    		
    		 ReleaseDC(hwnd, hdc);
    			 }
    		  return 0;
    	 case WM_RBUTTONUP:
    		 hmenu1 = LoadMenu(hInstance, TEXT("sia0016sm"));
    		 SetMenu(hwnd, hmenu1);
    		  hmenu1 = GetSubMenu(hmenu1, 0);
    		 // SetMenu(hwnd, hmenu);
    		  point.x = LOWORD (lParam) ;
              point.y = HIWORD (lParam) ;
              ClientToScreen (hwnd, &point) ;
              
              TrackPopupMenu (hmenu1, TPM_RIGHTBUTTON, point.x, point.y, 
                              0, hwnd, NULL) ;
              return 0 ;
    
         case WM_DESTROY:
    		 hdc = GetDC(hwnd);
    		 DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
             
            
             ReleaseDC(hwnd, hdc);
    		// DeleteObject(hfont);
    		 
    	 if(pbuffer)
    		 free(pbuffer);
    	     KillTimer(hwnd, ID_TIMER);
    		 DeleteObject(hbrush);
    		 DeleteObject(hmenu1);
    		 PopFontDeinitialize();
    		 DeleteObject(hb);
             PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    Last edited by SAMSAM; 01-31-2003 at 06:53 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 09:32 AM
  2. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 11:21 AM
  3. Strange response from MSVC
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 04-17-2004, 08:40 AM
  4. Very strange bug...
    By JaWiB in forum Tech Board
    Replies: 6
    Last Post: 04-27-2003, 02:56 PM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21