win32 api, bloodshed Dev C++

This is a discussion on win32 api, bloodshed Dev C++ within the Windows Programming forums, part of the Platform Specific Boards category; hello everybody, I have been making a program (my first win32 api program). But anyways I don't know if this ...

  1. #1
    That weird Java guy xniinja's Avatar
    Join Date
    Jun 2010
    Posts
    230

    win32 api, bloodshed Dev C++

    hello everybody, I have been making a program (my first win32 api program). But anyways I don't know if this is off topic or not
    but When i try to compile my code in Dev c++ it looks like it compiles all the way then it just makes a ding noise and the program doesn't even come up,
    it doesn't even give me an error it just dings,
    any help would be appreciated.
    Here is my code. (I know that when you press on the open button it will say it is opening but it is not. this code will be put in later.)

    Code:
    #include <windows.h>
    #include <stdio.h>
    #define     ID_OPEN        1000
    #define     ID_CLOSE       1001
    #define     ID_EXIT        1002
    #define     ID_CUT         1003
    #define     ID_COPY        1004
    #define     ID_PASTE       1005
    
    #define     ID_1           1006
    #define     ID_2           1007
    #define     ID_3           1008
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, 
    						 WPARAM wParam, LPARAM lParam)
    {
         static HWND hwndEdit;
         CREATESTRUCT            *cs;
       HMENU                   hMenu, hSubMenu, hSubMenu2;
       char                    szText[64];
       // Menu-item identifiers 
       static   char           szMenuItem[6][10] = {"Open", "Close", "Exit", "Cut", "Copy", "Paste"};
    
    	switch(msg)
    	{
    	case WM_CREATE :
          
          cs = (LPCREATESTRUCT)lParam;
          hMenu = CreateMenu();
          SetMenu(hwnd, hMenu);
          
          
          hwndEdit = CreateWindow(TEXT("Edit"), "Alarm msg here", WS_CHILD | WS_VISIBLE | WS_BORDER,
                                    90, 80, 110, 20, hwnd, (HMENU) 10,
                                    NULL, NULL);
          	 
    	       
          
          hSubMenu = CreatePopupMenu();
          AppendMenu(hSubMenu, MF_STRING, ID_OPEN, "&Open");
          AppendMenu(hSubMenu, MF_STRING, ID_CLOSE, "&Close");
          AppendMenu(hSubMenu, MF_STRING, ID_EXIT, "E&xit");
          AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
          InsertMenu(hMenu, 0, MF_POPUP|MF_BYPOSITION, (UINT_PTR)hSubMenu, "File");
          
          hSubMenu2 = CreatePopupMenu();
          AppendMenu(hSubMenu2, MF_STRING, ID_1, "File 1");
          AppendMenu(hSubMenu2, MF_STRING, ID_2, "File 2");
          AppendMenu(hSubMenu2, MF_STRING, ID_3, "File 3");
          InsertMenu(hSubMenu, 5, MF_POPUP|MF_BYPOSITION, (UINT_PTR)hSubMenu2, "Recent &Files");
          DestroyMenu(hSubMenu2);
          DestroyMenu(hSubMenu);
    
          hSubMenu = CreatePopupMenu();
          AppendMenu(hSubMenu, MF_STRING, ID_CUT, "Cut");
          AppendMenu(hSubMenu, MF_STRING, ID_COPY, "Copy");
          AppendMenu(hSubMenu, MF_STRING, ID_PASTE, "Paste");
          InsertMenu(hMenu, 1, MF_POPUP|MF_BYPOSITION, (UINT_PTR)hSubMenu, "Edit");
          DestroyMenu(hSubMenu);
          DestroyMenu(hMenu);
    
          DrawMenuBar(hwnd);
          break;
        case WM_COMMAND :
          
          switch(LOWORD(wParam))
          {
          case ID_OPEN :{
               if(MessageBox(hwnd,"opening, (just a test)","Opening",MB_OK) == IDOK){
                                            return 0;
                                            }
               else{
                    if(MessageBox(hwnd,"there has been a fatal error in your application,\nwould you like to continue using it?","error",MB_YESNO || MB_ICONWARNING) == IDYES){
                    
                    return 0;
                   }
               else{
            WM_CLOSE;
    }
    
    }
               }
          case ID_CLOSE :
          {
               if(MessageBox(hwnd,"are you sure you want to close your appointments.","Close",MB_YESNO)== IDYES){
                                    if(MessageBox(hwnd,"your appointments are now closed, would you like to exit the program","exit",MB_YESNO)== IDYES){
                                                             WM_CLOSE;
                                                             }                                 
          else {return 0;}
          } 
            else {
                 }
               }
          
          case ID_EXIT :
          case ID_CUT :
          case ID_COPY :
          case ID_PASTE :
        /*     printf(szText, "You chose %s", szMenuItem[LOWORD(wParam) - 1000]);
             MessageBox(hwnd, szText, "MenuApp", MB_OK);*/
             break;
          }
        
        case WM_CLOSE :
    	
        	DestroyWindow(hwnd);
    		break;
    
    	case WM_DESTROY :
    		PostQuitMessage(0);
    
    	case WM_KEYDOWN :
    		if(wParam == 'O'){
             if (MessageBox(hwnd,"Do you want to open your appointments to look at them.","Open",MB_YESNO) == IDYES){
              MessageBox(hwnd,"your appointments have been opened.","Open",MB_OK);}
    	else {
    	               MessageBox(hwnd,"your appointments will not be opened","Open",MB_OK);}
        
        
        return 0;
    }
            else if (wParam == 'T')
    			MessageBox(hwnd, "T Pressed", "T", MB_OK);
    		else if (wParam == VK_ESCAPE)
    			SendMessage(hwnd, WM_CLOSE, 0, 0);
    		break;
    
    	case WM_KEYUP :
    		if (wParam == 'R')
    			MessageBox(hwnd, "R Pressed", "R", MB_OK);
    		break;
    	
        }
    
    	return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    				   LPSTR lpCmdLine, int nShowCmd)
    {
    	LPCTSTR className = "ClassName";
    	WNDCLASSEX wc;
    
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = className;
    	wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    
    	if (!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Error registering class",
    			"Error", MB_OK | MB_ICONERROR);
    		return 1;
    	}
    
    	HWND hwnd = CreateWindowEx(
    		0,
    		className,
    		"07 - Keyboard Input",
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT,
    		300, 300,
    		NULL,
    		NULL,
    		hInstance,
    		NULL
    		);
    
    	if (!hwnd)
    	{
    		MessageBox(NULL, "Error creating window",
    			"Error", MB_OK | MB_ICONERROR);
    		return 1;
    	}
    
    	ShowWindow(hwnd, nShowCmd);
    
    	MSG msg;
    
    	while (GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return (int)msg.wParam;
    }



    Thanks in advance.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    And you posted this in C# Programming why exactly?

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Yeah, hence moved.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    Cprogramming.com FAQ
    Cprogramming.com FAQ > How do I get my program to wait for a keypress?

    your prog did open up so fast you could not see it and close. you have to set it up to wait for a key press so you can see the window before it closes. what do you mean you will add this code ? you did not add it yet ? the basic window program is just a template to get you started. adding the stuff in before you compile it. did you just compile it or compile and run button ? if you used compile and run button it worked. if compile only then you need to run the prog. also make sure you have all the components to the program.... the defines here should be in a .rc file not at the top of this prog. the ding noise is telling you it is done compiling. make sure your settings are correct if you compiled it as .cpp or .c

    and answered.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    1
    Hi xninja

    If you are still interested, the best introduction to windows GUIs and Win32 APIs on the net is a resource called theForger's Win32 API Programming Tutorial from theForger's Win32 API Tutorial and it can be downloaded in pdf.

    It takes you step by step through each program, from coding up to compilation.

    The code in this tut can be used with Dev Bloodshed C++, and the site also code which can downloaded for use with Visual Studio 2008, and may even work on VS 2005.

    I recommend this tut because it introduced me to GUIs and Win32 API programming, and both the tut and the site have even been referenced by a C++ programming book or two.

    It would also be advantageous to be familiar with C++ basics before you tackle GUIs and Win32 API programming, so that you have some idea of what's going on, before using the many conventions needed to write programs that work.

    Wish you the very best of Luck.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  2. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 06:46 PM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM

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