Resource file issues

This is a discussion on Resource file issues within the Windows Programming forums, part of the Platform Specific Boards category; Ok, so I recently took up windows programming again and wanted to create a simple modeless dialog. I downloaded Resedit ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    Resource file issues

    Ok, so I recently took up windows programming again and wanted to create a simple modeless dialog. I downloaded Resedit to make the file and am using Visual C++ Express 2008 to compile and debug the application. However, my window looks funny for some reason. The window is sort of not there, no title bar or close buttons, no window around the controls. the controls are just hanging mid-screen with nothing around them. I would suppose it has something to do with my resource script but i cant figure out what is going on. Here is the code i am using to load the window:

    Code:
    #include <windows.h>
    #include <winsock.h>
    #include <process.h>
    #include <shellapi.h>
    #include <commctrl.h>
    
    #include <stdio.h>
    #include <string.h>
    
    #include "resource.h"
    
    #define Alert(x) MessageBox(NULL, x, "Alert:", MB_OK);
    //#define ID_TASKICON 1010
    
    //structures
    struct THREADOPCTRL
    {
    	bool operate;
    	bool operating;
    };
    
    //global variables
    NOTIFYICONDATA tray_icon;
    OPENFILENAME set_file;
    bool error_log = false, client_info = false;
    THREADOPCTRL serv_ctrl;
    
    //function declarations
    void FlipState (bool&);
    
    //window procedures
    BOOL CALLBACK SettingsWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_COMMAND:
    
    		switch (LOWORD (wParam))
    		{
    		case IDSAVE:
    
    			Alert("You pressed ok!");
    			break;
    
    		case IDCANCEL:
    
    			Alert ("You pressed cancel!");
    			break;
    
    		case IDC_ERRORLOG:
    
    			FlipState (error_log);
    			
    			if (error_log == true)
    			{
    				Alert("I will make an error log!");
    			}
    
    			else if (error_log == false)
    			{
    				Alert("I will not make an error log!");
    			}
    
    			break;
    		}
    		break;
    
    	case WM_CLOSE:
    
    		DestroyWindow (hwnd);
    		break;
    
    	case WM_DESTROY:
    
    		PostQuitMessage (0);
    		break;
    
    	default:
    
    		return TRUE;
    	}
    
    	return TRUE;
    }
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	HWND SettingsDialog;
    	MSG msg;
    
    	serv_ctrl.operate = true;
    	serv_ctrl.operating = false;
    
    	SettingsDialog = CreateDialog (GetModuleHandle (NULL), MAKEINTRESOURCE (MAIN_DIALOG), NULL, SettingsWindowProc);
    
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
    		TranslateMessage (&msg);
    		DispatchMessage  (&msg);
    	}
    
    	return msg.wParam;
    }
    
    void FlipState (bool& to_filp)
    {
    	to_filp = !to_filp;
    }
    This is a work in progress so i know it is VERY incomplete. If the error is in my code i would much appreciate if someone would be able to point it out. If anyone needs more information, please feel free to ask. I plan to add a tray icon and some other functionality as well. thanks all!
    HA! I WIN!

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    66
    Moin Sir,

    try this, please ...
    Code:
    	while (GetMessage (&msg, NULL, 0, 0) > 0)
    	{
    		if (IsDialogMessage (SettingsDialog, &msg))
    		{
    			TranslateMessage (&msg);
    			DispatchMessage  (&msg);
    		}
    	}
    and maybe try ShowWindow/UpdateWindow after the call to CreateDialog ...


    Regards
    Greenhorn
    Last edited by Greenhorn__; 09-06-2009 at 07:49 PM.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    That had no effect. i actually omitted it because I was having a problem with the Dialog Procedure. If it helps at all this also happens when I use modal dialogs created with ResEdit. I dont understand it. is this a problem with the editor or with visual c++? I seem to remember trying to use it with Dev-C++ too and had the same problem. sometimes it worked, sometimes it didnt.
    HA! I WIN!

  4. #4
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Code:
    	default:
    
    		return TRUE;
    Returning TRUE tells Windows that you've handled the message and that it shouldn't do its default processing. As you tell it you've handled all messages that you recieve, it doesn't do squat, including painting your windows. Return FALSE if you don't do anything, and Windows will pick up the slack for you.

    Code:
    if (!IsDialogMessage (SettingsDialog, &msg))
    Fixed

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by adeyblue View Post
    Returning TRUE tells Windows that you've handled the message
    Not 100% true. Many msgs expect FALSE on processing (WM_CHAR) and you should always check MSDN.

    You should call the default processor and let it do the work.

    Code:
    default: 
                return DefWindowProc(hwnd, msg, wParam, lParam);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    Ok. I made some changes, just to get the window to show up right. The changes i made caused the window to show up, but now it wont move, minimize, or close for me w/ the DefWindowProc as it should:

    Code:
    #include <windows.h>
    #include <winsock.h>
    #include <process.h>
    #include <shellapi.h>
    #include <commctrl.h>
    
    #include <stdio.h>
    #include <string.h>
    
    #include "resource.h"
    
    #define Alert(x) MessageBox(NULL, x, "Alert:", MB_OK);
    //#define ID_TASKICON 1010
    
    //structures
    struct THREADOPCTRL
    {
    	bool operate;
    	bool operating;
    };
    
    //global variables
    NOTIFYICONDATA tray_icon;
    OPENFILENAME set_file;
    bool error_log = false, client_info = false;
    THREADOPCTRL serv_ctrl;
    
    //function declarations
    void FlipState (bool&);
    
    //window procedures
    BOOL CALLBACK SettingsWindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_COMMAND:
    
                    break;
    
    	case WM_CLOSE:
    
    		DestroyWindow (hwnd);
    		break;
    
    	case WM_DESTROY:
    
    		PostQuitMessage (0);
    		break;
    
    	default:
    
    		return DefWindowProc (hwnd, msg, wParam, lParam);
    	}
    
    	return TRUE;
    }
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	HWND SettingsDialog;
    	MSG msg;
    
    	serv_ctrl.operate = true;
    	serv_ctrl.operating = false;
    
    	SettingsDialog = CreateDialog (GetModuleHandle (NULL), MAKEINTRESOURCE (MAIN_DIALOG), NULL, SettingsWindowProc);
    
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
                    if (!IsDialogMessage (SettingsDialog, &msg))
                    {
    		         TranslateMessage (&msg);
    		         DispatchMessage  (&msg);
                    }
    	}
    
    	return msg.wParam;
    }
    
    void FlipState (bool& to_filp)
    {
    	to_filp = !to_filp;
    }
    well at least the window is solid now...
    HA! I WIN!

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    Sry to bump my own post, but i just found this on theForger's Win32 API Tutorial site:

    Most of the same message handling rules apply to dialogs created with CreateDialog() as with DialogBox(), don't call DefWindowProc(), return FALSE for messages you don't handle and TRUE for those you do.
    So this is an inaccurate statement. just wanted to let u guys know that.

    Quote Originally Posted by novacain View Post
    Not 100% true. Many msgs expect FALSE on processing (WM_CHAR) and you should always check MSDN.

    You should call the default processor and let it do the work.

    Code:
    default: 
                return DefWindowProc(hwnd, msg, wParam, lParam);
    HA! I WIN!

  8. #8
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by novacain View Post
    Not 100% true. Many msgs expect FALSE on processing (WM_CHAR) and you should always check MSDN.
    That's for a normal window procedure. For Dialog procedures you return TRUE then return the message specific value via SetWindowLongPtr(hwnd, DWLP_MSGRESULT, ...) if you process the message. See Mr Chen's blog for more info.

  9. #9
    Registered User
    Join Date
    Jul 2008
    Posts
    66
    Hi Sirs,

    I don't exactly know if the problem is solved, but in case it isn't take a look at this template, token from CodeBlocks ...

    Code:
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    
    #include "resource.h"
    
    HINSTANCE hInst;
    
    BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch(uMsg)
        {
            case WM_INITDIALOG:
                /*
                 * TODO: Add code to initialize the dialog.
                 */
                return TRUE;
    
            case WM_CLOSE:
                EndDialog(hwndDlg, 0);
                return TRUE;
    
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    /*
                     * TODO: Add more control ID's, when needed.
                     */
                    case IDC_BTN_QUIT:
                        EndDialog(hwndDlg, 0);
                        return TRUE;
    
                    case IDC_BTN_TEST:
                        MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
                        return TRUE;
                }
        }
    
        return FALSE;
    }
    
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
        hInst = hInstance;
    
        // The user interface is a modal dialog box
        return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, DialogProc);
    }

    Regards
    Greenhorn

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by xixpsychoxix View Post
    So this is an inaccurate statement. just wanted to let u guys know that.
    Sorry my bad, missed the use of CreateDialog() in the OP.

    Hope it did not cost you too much time.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Need help in resource file
    By Darkinyuasha1 in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 06:31 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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