Hello,
I am trying to create an application which will display two forms, one will "roll" a dice (create a random number) and I will then pass this to the other window/form which will display the result.
Unfortunately I need to be able to do it within another thread so I will be sharing memory between them so I can pass the data across.
So far i've completed the first screen, added menus and the random number side of things and now i'm trying to implement a second form in a similar attempt as the first one to display the results. I'm adding the CreateWindowEx() command in the WM_CREATE section so it is created when the first window starts.
I've been trawling the internet and documents for a few days and I still can't find a solution to what I need.
I've posted the entire solution I have so far (Minus the random number stuff, not really important).
Would anybody be able to help in getting another window up and running? Im primarily from a C# background and i've not used C for long so it's all a bit new to me still.
Thank you for your time.
The application so far
Code:
//////////////////
// WINDOWS MAIN //
//////////////////
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{
// Declaration of window class (used to register program),
// handle to window (returned by CreateWindow)
// and windows message (holds messages received from windows)
WNDCLASS wcl;
HWND hwnd;
MSG msg;
// Name of window and window class
LPCWSTR szWinName = L"DiceRoller - Producer";
LPCWSTR szClassName = L"DiceRollProd";
// Set up the windows class struct
wcl.hInstance = hThisInst;
wcl.lpszClassName = szClassName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = 0;
wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
// Register the windows class
if(!RegisterClass(&wcl))
{
return 0;
}
// Create the main window
hwnd = CreateWindowEx(0,
szClassName,
szWinName,
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
100,
100,
400,
400,
HWND_DESKTOP,
NULL,
hThisInst,
NULL );
// Show the main window
ShowWindow(hwnd, nWinMode);
UpdateWindow(hwnd);
// Main message processing loop
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
//////////////////////
// WINDOWS FUNCTION //
//////////////////////
LRESULT CALLBACK WindowFunc(HWND hMainWindow, UINT message,
WPARAM wParam, LPARAM lParam)
{
//Fields
WCHAR buffer[256];
struct DiceData storage;
HWND hwnd;
// Act on current message
switch(message)
{
case WM_CREATE:
AddMenus(hMainWindow);
hwnd = CreateWindowEx(
0,
"ChildWClass",
(LPCTSTR) NULL,
WS_CHILD | WS_BORDER | WS_VISIBLE,
0,
0,
400,
400,
hMainWindow,
NULL,
NULL,
NULL);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
break;