I'm relatively new to programming and i was reading a tutorial to set to modeless dialogs. However I got it to work once and now it keeps returning null.I'm using dev c++ 4.9.9.2 portable and ResEdit (Unicode). Does anyone know what the problem is?
code listed below
#include <windows.h> //contains the functions we need to use to make native windows apps
#include "resource.h" //resource header file we included for menus and icons
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)// start of program
{
//windows class window handel and message varrible declarations
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
//window class data
wc.cbSize = sizeof(WNDCLASSEX); // size of the windows class
wc.style = 0; // class style
wc.lpfnWndProc = wndproc; // name or handel to the wndproc function
wc.cbClsExtra = 0; // amount of extra class data
wc.cbWndExtra = 0; // amount of extra window data
wc.hInstance = hInstance; // handle to this instance of the application
wc.hIcon = NULL; // 32 x 32 icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // handle to brush to be used for background
wc.lpszMenuName = NULL; // menu name from resource
wc.lpszClassName = g_szClassName; // window class name
wc.hIconSm = NULL; // 16 x 16 icon
if(!RegisterClassEx(&wc)) //register and check if registration was sucessful with os
{
MessageBox(NULL, "Failed to register window class", "Error", MB_OK);
return -1;
}
hwnd = CreateWindowEx( // create a handle to the window
WS_EX_CLIENTEDGE,//exstyle
g_szClassName, // widow class name
WNDNAME, // title of the window
WS_OVERLAPPEDWINDOW, //style
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, // x position, y position, width, height
NULL, NULL, hInstance, NULL); // parrent, handel to Menu, handle to instance, null
ShowWindow(hwnd, nCmdShow); // show window
UpdateWindow(hwnd); // idk but its there
//message loop
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
if(!IsDialogMessage(g_hToolsbar, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;//idk *** but it works
}
break;
}
case WM_COMMAND: // menu commands
switch(LOWORD(wparam))
{
case ID_FILE_EXIT:
DestroyWindow(hwnd);
break;
case ID_STUFF_GO:
MessageBox(hwnd,"Go away","Go",MB_OK | MB_ICONINFORMATION);
break;
}
break;
case WM_CLOSE: // if close button is pressed
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
Your code is okay, and being properly built in VC++ it runs fine. Evidently it's something wrong with your project. Most probably, you miss resources to get compiled or linked to your binary. To find the reason out, you need to analyze the last error code after getting NULL.
Your code for a modeless dialog box works quite well with Dev c++ 4.9.9.2
after I added the linker 'libcomctl32.a' in the parameter linker box in the project options.
Bookmarks