trying Ex and its not working

This is a discussion on trying Ex and its not working within the Windows Programming forums, part of the Platform Specific Boards category; hi im messing with CreateWindowEx and some things but now my app wont show..heres the code Code: #include <windows.h> LRESULT ...

  1. #1
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214

    trying Ex and its not working

    hi im messing with CreateWindowEx and some things but now my app wont show..heres the code

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND , UINT , WPARAM , LPARAM);
    
    static char szAppName[] = "test";
    HWND hwnd , button1 , button2;
    MSG msg;
    WNDCLASSEX wc;
    
    int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR szCmdLine , int iCmdShow)
    {
    	wc.style = CS_DBLCLKS;
    	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 = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = szAppName;
    
    	if(!RegisterClassEx(&wc)) return 0;
    
    	hwnd = CreateWindowEx(0 , szAppName , "test" ,
    						WS_OVERLAPPEDWINDOW ,
    						CW_USEDEFAULT , CW_USEDEFAULT ,
    						CW_USEDEFAULT , CW_USEDEFAULT ,
    						HWND_DESKTOP , NULL , hInstance , NULL);
    
    	button1 = CreateWindow("button" , "test" ,
    						WS_CHILD | WS_VISIBLE | BS_GROUPBOX ,
    						50 , 50 ,
    						200 , 100 ,
    						hwnd ,
    						NULL ,
    						(HINSTANCE)GetWindowLong(hwnd , GWL_HINSTANCE) ,
    						NULL);
    
    	button2 = CreateWindowEx(WS_EX_WINDOWEDGE , "button" , "test" ,
    							WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
    							75 , 75 ,
    							120 , 20 ,
    							hwnd ,
    							NULL ,
    							(HINSTANCE)GetWindowLong(hwnd , GWL_HINSTANCE) ,
    							NULL);
    
    
    
    	ShowWindow(hwnd , SW_SHOW);
    	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)
    {
    	switch(message)
    	{
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    
    	}
    	return DefWindowProc(hwnd , message , wParam , lParam);
    }
    the window doesnt show

  2. #2
    Registered User whackaxe's Avatar
    Join Date
    Mar 2004
    Posts
    332
    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND , UINT , WPARAM , LPARAM);
    
    static char szAppName[] = "test";
    
    
    int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR szCmdLine , int iCmdShow)
    {
    
    HWND hwnd , button1 , button2;
    MSG msg;
    WNDCLASSEX wc;
    
        wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_DBLCLKS;
    	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 = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = szAppName;
        wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
        {
        MessageBox(NULL,"class reg failed","doh!",MB_OK);
        return(1);
        }
    
    	hwnd = CreateWindowEx(0 , szAppName , "test" ,
    						WS_OVERLAPPEDWINDOW ,
    						CW_USEDEFAULT , CW_USEDEFAULT ,
    						CW_USEDEFAULT , CW_USEDEFAULT ,
    						HWND_DESKTOP , NULL , hInstance , NULL);
    
    	button1 = CreateWindow("button" , "test" ,
    						WS_CHILD | WS_VISIBLE | BS_GROUPBOX ,
    						50 , 50 ,
    						200 , 100 ,
    						hwnd ,
    						NULL ,
    						(HINSTANCE)GetWindowLong(hwnd , GWL_HINSTANCE) ,
    						NULL);
    
    	button2 = CreateWindowEx(WS_EX_WINDOWEDGE , "button" , "test" ,
    							WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
    							75 , 75 ,
    							120 , 20 ,
    							hwnd ,
    							NULL ,
    							(HINSTANCE)GetWindowLong(hwnd , GWL_HINSTANCE) ,
    							NULL);
    
    
    
    	ShowWindow(hwnd , SW_SHOW);
    	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)
    {
    	switch(message)
    	{
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    
    	}
    	return DefWindowProc(hwnd , message , wParam , lParam);
    }
    changes made:
    moved your MSG, HWND and WNDCLASSEX statemnts inside of minmain
    added: wc.cbSize = sizeof(WNDCLASSEX);
    added: wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    changed: your regclassex function to return if it worked, before the app just flunked.

    w00t just solved someone's problem. a first for me here

  3. #3
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    hehe..thanks

  4. #4
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    would you happen to know how to take the doted lines out from the inside of a button when its clicked?

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    84
    I don't know if you can completely disable focus rectangle, but you can set focus to your parent window after button has been clicked like so:
    Code:
    case WM_COMMAND:
      {
        WORD wNotifyCode = HIWORD(wParam);
        WORD wID         = LOWORD(wParam);
        if (lParam)
        {
          switch (wID)
          {
          case IDC_MYBUTTON:
            if (wNotifyCode == BN_CLICKED)
            {
              SetFocus(hWnd);
              // TODO: Add button code here
            }
            break;
          }
        }
      }
      return 0;
    But you have to add control ID to your button like this (remember to #define IDC_MYBUTTON):
    Code:
    button2 = CreateWindowEx(WS_EX_WINDOWEDGE, "button", "test",
                             WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                             75, 75, 120, 20,
                             hwnd, (HMENU)IDC_MYBUTTON,
                             (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    If you don't like focus rectangle then you can allways use BS_OWNERDRAW syle of course...

  6. #6
    Registered User Rare177's Avatar
    Join Date
    May 2004
    Posts
    214
    hmmm..i was thinking there would be a way because MFC and ATL dont have it and there based on api

Popular pages Recent additions subscribe to a feed

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