Thread: win32 api, bloodshed Dev C++

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

    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.)

    #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"};
    	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");
          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");
        case WM_COMMAND :
          case ID_OPEN :{
               if(MessageBox(hwnd,"opening, (just a test)","Opening",MB_OK) == IDOK){
                                            return 0;
                    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;
          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){
          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);*/
        case WM_CLOSE :
    	case WM_DESTROY :
    	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);
    	case WM_KEYUP :
    		if (wParam == 'R')
    			MessageBox(hwnd, "R Pressed", "R", MB_OK);
    	return DefWindowProc(hwnd, msg, wParam, lParam);
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    				   LPSTR lpCmdLine, int nShowCmd)
    	LPCTSTR className = "ClassName";
    	wc.cbSize = sizeof(WNDCLASSEX); = 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(
    		"07 - Keyboard Input",
    		300, 300,
    	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)
    	return (int)msg.wParam;

    Thanks in advance.

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

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Yeah, hence moved.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    638 FAQ 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
    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
    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, 07: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