Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hi,
I have one win32 dll that is include dialog and menu and two buttons. I changed Caption IDC_BUTTON1. Default caption is " message" and I changing that by SetWindowText(hDlg1,szBuffer).
In my dll have another function that get double number from another platform and must update every 1-2 seconds and change price.
My problem is how to change code from start to show this number"szBuffer" and update automatically?
Now every time that i click on this button it changes caption.
 
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "resource.h"
#include <stdio.h>

double Ask;
HINSTANCE g_hInstance;
 
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		g_hInstance = hModule;
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
 
HWND hDlg1;
INT_PTR CALLBACK DialogFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HMENU hMenu;
	
	 hDlg1=GetDlgItem(hDlg,IDC_BUTTON1);
	switch(uMsg)
	{
	case WM_INITDIALOG:
		hMenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU1));
		SetMenu(hDlg, hMenu);
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDC_BUTTON1:
		case ID_FILE_MESSAGEBOX:
		  
	   TCHAR   szBuffer[32]; 
 
       sprintf( szBuffer, "%f", Ask );
			SetWindowText(hDlg1,szBuffer);
			MessageBox(hDlg, "This is sample for Reza", "Test", MB_OK);
			break;
		case IDC_BUTTON2:
		case ID_FILE_EXIT:
			SendMessage(hDlg, WM_CLOSE, 0, 0);
			break;
		
		}
		break;
	case WM_CLOSE:
		DestroyWindow(hDlg);
		return TRUE;
		break;
	case WM_DESTROY: 
		PostQuitMessage (0); 
		return TRUE;
		break; 
	}
	return FALSE;
}
 
MT4_EXPFUNC void Data(double ask){
 Ask=ask;
}
 
MT4_EXPFUNC int MetaTest(HWND hWnd)
{
	MSG msg; 
	BOOL msgstatus; 
 
	HWND hDlg = CreateDialogParamA(g_hInstance, MAKEINTRESOURCE(IDD_METATEST), hWnd, DialogFunc, 0);
	ShowWindow(hDlg, SW_SHOW);
 
	while ((msgstatus=GetMessage (&msg, NULL, 0, 0)) && msgstatus!=-1)
	{ 
		if (! IsDialogMessage (hDlg, &msg)) 
		{ 
			TranslateMessage (&msg);  
			DispatchMessage (&msg); 
		}
	}
	return 0;
}
 
Regards,
Posted 16-Oct-12 9:58am
Rezame951
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If I understand your problem, you want to automatically display some value in the dialog title. In that case you should set a timer and each time the handler elapses, update the title with the new value.
 
SetTimer function[^]
Using Timers[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Storing mutable data in global variables is usually a bad idea (like not using the power of .cpp) but we will look over that this time. Currently you have a data that is changed by somebody, and there are some listeners ('observers') who want to know about the change (in this case it is your window). For this reasony you should eliminate the direct access to your double Ask; variable by hiding it from other .cpp files by making it static and creating "getter" and "setter" functions for its use:
static double Ask;
 
double GetAsk()
{
    return Ask;
}
 
void SetAsk(double ask)
{
    Ask = ask;
    // Code that notifies listeners about the change comes here...
}
Now you get a lot of compiler errors if you are writing the Ask variable from other .cpp files and you are be forced to change the Ask variable by calling SetAsk(). The SetAsk() method can now notify your dialog about the change. You should make the HWND of the dialog visible to your SetAsk() method to allow it to use PostMessage() for example with a WM_APP+XXX custom message to notify the dialog to refresh its own titlebar. Inside the dialog you should handle WM_APP+XXX of course with the code you currently use for your button handling. To start the window immediately with a correct titlebar your should execute the refersher code not only from your WM_APP+XXX handler but also from your WM_INITDIALOG handler.
 
Note that things could look much nicer in real C++ if both your window and the value resided in their own objects. The window could 'register' itself into the object of the value as a listener then instead of using global variables for communication.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100